ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtutil.h
(Generate patch)

Comparing rxvt-unicode/src/rxvtutil.h (file contents):
Revision 1.44 by root, Mon Jan 3 18:52:41 2011 UTC vs.
Revision 1.48 by root, Thu Jan 19 17:10:51 2012 UTC

1#ifndef RXVT_UTIL_H 1#ifndef RXVT_UTIL_H
2#define RXVT_UTIL_H 2#define RXVT_UTIL_H
3 3
4#include <cstdlib> 4#include <stdlib.h>
5#include <cstring> 5#include <string.h>
6#include <inttypes.h> 6#include "ecb.h"
7
8using namespace std;
9
10#define ARRAY_LENGTH(v) (sizeof (v) / sizeof ((v)[0]))
11
12#define PP_CONCAT_(a, b) a ## b
13#define PP_CONCAT(a, b) PP_CONCAT_(a, b)
14#define PP_STRINGIFY_(a) #a
15#define PP_STRINGIFY(a) PP_STRINGIFY_(a)
16
17#define HAVE_GCC_BUILTINS (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ == 4))
18
19#if __GNUC__ >= 4
20# define rxvt_attribute(x) __attribute__(x)
21# define expect(expr,value) __builtin_expect ((expr),(value))
22#else
23# define rxvt_attribute(x)
24# define expect(expr,value) (expr)
25#endif
26
27// put into ifs if you are very sure that the expression
28// is mostly true or mostly false. note that these return
29// booleans, not the expression.
30#define expect_false(expr) expect ((expr) != 0, 0)
31#define expect_true(expr) expect ((expr) != 0, 1)
32
33#define NORETURN rxvt_attribute ((noreturn))
34#define UNUSED rxvt_attribute ((unused))
35#define CONST rxvt_attribute ((const))
36 7
37// increases code size unless -fno-enforce-eh-specs 8// increases code size unless -fno-enforce-eh-specs
38#if __GNUC__ 9#if __GNUC__
39# define NOTHROW 10# define NOTHROW
40# define THROW(x) 11# define THROW(x)
41#else 12#else
42# define NOTHROW throw() 13# define NOTHROW throw()
43# define THROW(x) throw x 14# define THROW(x) throw x
44#endif 15#endif
45 16
46namespace byteorder {
47 static unsigned char e ()
48 {
49 const uint32_t u = 0x11223344;
50 return *(unsigned char *)&u;
51 }
52
53 static bool big_endian () { return e () == 0x11; };
54 static bool network () { return big_endian (); };
55 static bool little_endian () { return e () == 0x44; };
56 static bool vax () { return little_endian (); };
57};
58
59// various utility functions 17// various utility functions
60template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } 18template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; }
61template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } 19template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; }
62template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } 20template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; }
63template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; } 21template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; }
93static inline T * 51static inline T *
94rxvt_temp_buf (int len) 52rxvt_temp_buf (int len)
95{ 53{
96 return (T *)rxvt_temp_buf (len * sizeof (T)); 54 return (T *)rxvt_temp_buf (len * sizeof (T));
97} 55}
98
99// some bit functions, xft fuck me plenty
100#if HAVE_GCC_BUILTINS
101/* netbsd stupidly defines popcount itself and puts it into string.h */
102static inline int rxvt_ctz (unsigned int x) { return __builtin_ctz (x); }
103static inline int rxvt_popcount (unsigned int x) { return __builtin_popcount (x); }
104#else
105// count trailing zero bits and count # of one bits
106int rxvt_ctz (unsigned int x) CONST;
107int rxvt_popcount (unsigned int x) CONST;
108#endif
109 56
110// in range including end 57// in range including end
111#define IN_RANGE_INC(val,beg,end) \ 58#define IN_RANGE_INC(val,beg,end) \
112 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) 59 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg))
113 60

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines