Versione funzionante di un CGI che produce PNG di codici a barre.
[gapil.git] / sources / macros.h
1 /*
2  * Endianess conversion for int and short types
3  */
4 #define BE32_TO_LE32(val) ({typeof (val) v= (val);  \
5         (v>>24) | ((v>>8)&0xFF00) | (v<<24) | ((v<<8)&0xFF0000); } )
6 #define BE16_TO_LE16(val) ({typeof (val) v= (val);  (v>>8) | (v<<8); } )
7 /* 
8  * Define a protected, right typed, no side effects macro for min
9  */
10 #define min(x, y) ({typeof (x) x_ = (x); typeof (y) y_ = (y); \
11                   x_ < y_ ? x_ : y_;}) 
12 /* 
13  * debugging print definition
14  */
15 #define report(fmt, args...) printf(fmt,##args)
16 #ifdef DEBUG                     /* done only on debugging */
17 #define debug  report
18 #else
19 #define debug(fmt, arg...)
20 #endif
21
22
23 /*
24  * Just to print an hex dump of a buffer,
25  * ptr is the address, m is how many word per line
26  * and l how many lines
27  */
28 #define PRINT_BUF(ptr, l, m) ({ \
29     int _i, _j; \
30     unsigned short *_ptr= (unsigned short *)(ptr); \
31     for (_i = 0; _i< (int) l; _i++) { \
32         printf("Val[%d]=", m * _i); \
33         for (_j = 0; _j < (int) m; _j++) { \
34             printf("%x ", *_ptr);\
35             _ptr++;\
36         }\
37         printf("\n"); \
38     }\
39 })