--- rxvt-unicode/src/rxvtutil.h 2007/10/31 09:55:24 1.29 +++ rxvt-unicode/src/rxvtutil.h 2011/05/30 18:39:04 1.45 @@ -3,29 +3,11 @@ #include #include +#include +#include "ecb.h" using namespace std; -#define PP_CONCAT_(a, b) a ## b -#define PP_CONCAT(a, b) PP_CONCAT_(a, b) -#define PP_STRINGIFY_(a) #a -#define PP_STRINGIFY(a) PP_STRINGIFY_(a) - -#define HAVE_GCC_BUILTINS (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ == 4)) - -#ifndef __attribute__ -# if __GNUC__ -# if (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || (__GNUC__ < 2) -# define __attribute__(x) -# endif -# endif -# define __attribute__(x) -#endif - -#define NORETURN __attribute__ ((noreturn)) -#define UNUSED __attribute__ ((unused)) -#define CONST __attribute__ ((const)) - // increases code size unless -fno-enforce-eh-specs #if __GNUC__ # define NOTHROW @@ -35,17 +17,6 @@ # define THROW(x) throw x #endif -extern class byteorder { - static unsigned int e; // at least 32 bits -public: - byteorder (); - - static bool big_endian () { return e == 0x11223344; }; - static bool network () { return e == 0x11223344; }; - static bool little_endian () { return e == 0x44332211; }; - static bool vax () { return e == 0x44332211; }; -} byteorder; - // various utility functions template static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } template static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } @@ -67,15 +38,24 @@ return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100; } -// some bit functions, xft fuck me plenty -#if HAVE_GCC_BUILTINS -static inline int ctz (unsigned int x) CONST { return __builtin_ctz (x); } -static inline int popcount (unsigned int x) CONST { return __builtin_popcount (x); } -#else -// count trailing zero bits and count # of one bits -int ctz (unsigned int x) CONST; -int popcount (unsigned int x) CONST; -#endif +template +I find (I first, I last, const T& value) +{ + while (first != last && *first != value) + ++first; + + return first; +} + +// return a very temporary (and never deallocated) buffer. keep small. +void *rxvt_temp_buf (int len); + +template +static inline T * +rxvt_temp_buf (int len) +{ + return (T *)rxvt_temp_buf (len * sizeof (T)); +} // in range including end #define IN_RANGE_INC(val,beg,end) \ @@ -85,8 +65,12 @@ #define IN_RANGE_EXC(val,beg,end) \ ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) +// for m >= -n, ensure remainder lies between 0..n-1 +#define MOD(m,n) (((m) + (n)) % (n)) + // makes dynamically allocated objects zero-initialised -struct zero_initialized { +struct zero_initialized +{ void *operator new (size_t s); void operator delete (void *p, size_t s); }; @@ -97,7 +81,8 @@ * Copyright (C) 1997-98 Kay Roemer & Arno Puder */ template -struct simplevec { +struct simplevec +{ typedef T* iterator; typedef const T* const_iterator; typedef unsigned long size_type; @@ -348,11 +333,22 @@ template struct vector : simplevec -{ }; +{ +}; + +struct stringvec : simplevec +{ + ~stringvec () + { + for (char **c = begin (); c != end (); c++) + free (*c); + } +}; #if 0 template -struct rxvt_vec : simplevec { +struct rxvt_vec : simplevec +{ typedef T *iterator; void push_back (T d) { simplevec::push_back ((void *)d); } @@ -366,17 +362,9 @@ }; #endif -template -I find (I first, I last, const T& value) -{ - while (first != last && *first != value) - ++first; - - return first; -} - template -struct auto_ptr { +struct auto_ptr +{ T *p; auto_ptr () : p (0) { } @@ -435,24 +423,5 @@ typedef auto_ptr auto_str; -struct stringvec : simplevec -{ - ~stringvec () - { - for (char **c = begin (); c != end (); c++) - free (*c); - } -}; - -// return a very temporary (and never deallocated) buffer. keep small. -void *rxvt_temp_buf (int len); - -template -static inline T * -rxvt_temp_buf (int len) -{ - return (T *)rxvt_temp_buf (len * sizeof (T)); -} - #endif