--- rxvt-unicode/src/rxvtutil.h 2007/11/20 17:44:44 1.30 +++ rxvt-unicode/src/rxvtutil.h 2007/12/14 11:11:31 1.36 @@ -13,7 +13,7 @@ #define HAVE_GCC_BUILTINS (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ == 4)) -#if __GNUC__ >= 3 +#if __GNUC__ >= 4 # define rxvt_attribute(x) __attribute__(x) #else # define rxvt_attribute(x) @@ -64,6 +64,25 @@ return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100; } +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)); +} + // some bit functions, xft fuck me plenty #if HAVE_GCC_BUILTINS static inline int ctz (unsigned int x) { return __builtin_ctz (x); } @@ -82,6 +101,9 @@ #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 { void *operator new (size_t s); @@ -345,7 +367,17 @@ template struct vector : simplevec -{ }; +{ +}; + +struct stringvec : simplevec +{ + ~stringvec () + { + for (char **c = begin (); c != end (); c++) + free (*c); + } +}; #if 0 template @@ -363,15 +395,6 @@ }; #endif -template -I find (I first, I last, const T& value) -{ - while (first != last && *first != value) - ++first; - - return first; -} - template struct auto_ptr { T *p; @@ -432,24 +455,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