Merge branch 'master' of ssh://gapil.gnulinux.it/srv/git/gapil
[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 and max
27  */
28 #define min(x, y) ({typeof (x) x_ = (x); typeof (y) y_ = (y); \
29                   x_ < y_ ? x_ : y_;}) 
30 #define max(x, y) ({typeof (x) x_ = (x); typeof (y) y_ = (y); \
31                   x_ > y_ ? x_ : y_;}) 
32 /* 
33  * debugging print definition
34  */
35 #ifdef IS_DAEMON
36 #define report(fmt, args...) UserNotify(fmt,##args)
37 #else
38 #define report(fmt, args...) printf(fmt,##args)
39 #endif /* IS_DAEMON */
40
41 #ifdef DEBUG                     /* done only on debugging */
42 #define debug  report
43 #else
44 #define debug(fmt, arg...)
45 #endif /* DEBUG */
46
47
48 /*
49  * Just to print an hex dump of a buffer,
50  * ptr is the address, m is how many word per line
51  * and l how many lines
52  */
53 #define PRINT_BUF(ptr, l, m) ({ \
54     int _i, _j; \
55     unsigned short *_ptr= (unsigned short *)(ptr); \
56     for (_i = 0; _i< (int) l; _i++) { \
57         printf("Val[%d]=", m * _i); \
58         for (_j = 0; _j < (int) m; _j++) { \
59             printf("%x ", *_ptr);\
60             _ptr++;\
61         }\
62         printf("\n"); \
63     }\
64 })