Rimetto anche i .h
[gapil.git] / sources / macros.h
1 /* macros.h
2  * 
3  * Copyright (C) 2000-2002 Simone Piccardi
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /*
20  * Endianess conversion for int and short types
21  */
22 #define BE32_TO_LE32(val) ({typeof (val) v= (val);  \
23         (v>>24) | ((v>>8)&0xFF00) | (v<<24) | ((v<<8)&0xFF0000); } )
24 #define BE16_TO_LE16(val) ({typeof (val) v= (val);  (v>>8) | (v<<8); } )
25 /* 
26  * Define a protected, right typed, no side effects macro for min
27  */
28 #define min(x, y) ({typeof (x) x_ = (x); typeof (y) y_ = (y); \
29                   x_ < y_ ? x_ : y_;}) 
30 /* 
31  * debugging print definition
32  */
33 #ifdef IS_DAEMON
34 #define report(fmt, args...) UserNotify(fmt,##args)
35 #else
36 #define report(fmt, args...) printf(fmt,##args)
37 #endif /* IS_DAEMON */
38
39 #ifdef DEBUG                     /* done only on debugging */
40 #define debug  report
41 #else
42 #define debug(fmt, arg...)
43 #endif /* DEBUG */
44
45
46 /*
47  * Just to print an hex dump of a buffer,
48  * ptr is the address, m is how many word per line
49  * and l how many lines
50  */
51 #define PRINT_BUF(ptr, l, m) ({ \
52     int _i, _j; \
53     unsigned short *_ptr= (unsigned short *)(ptr); \
54     for (_i = 0; _i< (int) l; _i++) { \
55         printf("Val[%d]=", m * _i); \
56         for (_j = 0; _j < (int) m; _j++) { \
57             printf("%x ", *_ptr);\
58             _ptr++;\
59         }\
60         printf("\n"); \
61     }\
62 })