… | |
… | |
3 | |
3 | |
4 | #include <cstdlib> |
4 | #include <cstdlib> |
5 | #include <cstring> |
5 | #include <cstring> |
6 | |
6 | |
7 | using namespace std; |
7 | using namespace std; |
|
|
8 | |
|
|
9 | #define ARRAY_LENGTH(v) (sizeof (v) / sizeof ((v)[0])) |
8 | |
10 | |
9 | #define PP_CONCAT_(a, b) a ## b |
11 | #define PP_CONCAT_(a, b) a ## b |
10 | #define PP_CONCAT(a, b) PP_CONCAT_(a, b) |
12 | #define PP_CONCAT(a, b) PP_CONCAT_(a, b) |
11 | #define PP_STRINGIFY_(a) #a |
13 | #define PP_STRINGIFY_(a) #a |
12 | #define PP_STRINGIFY(a) PP_STRINGIFY_(a) |
14 | #define PP_STRINGIFY(a) PP_STRINGIFY_(a) |
… | |
… | |
20 | # define rxvt_attribute(x) |
22 | # define rxvt_attribute(x) |
21 | # define expect(expr,value) (expr) |
23 | # define expect(expr,value) (expr) |
22 | #endif |
24 | #endif |
23 | |
25 | |
24 | // put into ifs if you are very sure that the expression |
26 | // put into ifs if you are very sure that the expression |
25 | // is mostly true or mosty false. note that these return |
27 | // is mostly true or mostly false. note that these return |
26 | // booleans, not the expression. |
28 | // booleans, not the expression. |
27 | #define expect_false(expr) expect ((expr) != 0, 0) |
29 | #define expect_false(expr) expect ((expr) != 0, 0) |
28 | #define expect_true(expr) expect ((expr) != 0, 1) |
30 | #define expect_true(expr) expect ((expr) != 0, 1) |
29 | |
31 | |
30 | #define NORETURN rxvt_attribute ((noreturn)) |
32 | #define NORETURN rxvt_attribute ((noreturn)) |
… | |
… | |
91 | return (T *)rxvt_temp_buf (len * sizeof (T)); |
93 | return (T *)rxvt_temp_buf (len * sizeof (T)); |
92 | } |
94 | } |
93 | |
95 | |
94 | // some bit functions, xft fuck me plenty |
96 | // some bit functions, xft fuck me plenty |
95 | #if HAVE_GCC_BUILTINS |
97 | #if HAVE_GCC_BUILTINS |
|
|
98 | /* netbsd stupidly defines popcount itself and puts it into string.h */ |
96 | static inline int ctz (unsigned int x) { return __builtin_ctz (x); } |
99 | static inline int rxvt_ctz (unsigned int x) { return __builtin_ctz (x); } |
97 | static inline int popcount (unsigned int x) { return __builtin_popcount (x); } |
100 | static inline int rxvt_popcount (unsigned int x) { return __builtin_popcount (x); } |
98 | #else |
101 | #else |
99 | // count trailing zero bits and count # of one bits |
102 | // count trailing zero bits and count # of one bits |
100 | int ctz (unsigned int x) CONST; |
103 | int rxvt_ctz (unsigned int x) CONST; |
101 | int popcount (unsigned int x) CONST; |
104 | int rxvt_popcount (unsigned int x) CONST; |
102 | #endif |
105 | #endif |
103 | |
106 | |
104 | // in range including end |
107 | // in range including end |
105 | #define IN_RANGE_INC(val,beg,end) \ |
108 | #define IN_RANGE_INC(val,beg,end) \ |
106 | ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) |
109 | ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) |