--- rxvt-unicode/src/rxvtutil.h 2005/12/20 19:30:59 1.11 +++ rxvt-unicode/src/rxvtutil.h 2006/01/11 00:59:58 1.16 @@ -3,6 +3,11 @@ #include +#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) + extern class byteorder { static unsigned int e; // at least 32 bits public: @@ -14,12 +19,16 @@ static bool vax () { return e == 0x44332211; }; } byteorder; -template -static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } -template -static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } -template -static inline void swap (T& a, T& b) { T t=a; a=b; b=t; } +// 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; } +template static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } +template static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; } + +template static inline T clamp (T v, U a, V b) { return v < (T)a ? a : v >(T)b ? b : v; } +template static inline void clamp_it (T &v, U a, V b) { v = v < (T)a ? a : v >(T)b ? b : v; } + +template static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } // in range including end #define IN_RANGE_INC(val,beg,end) \ @@ -29,6 +38,7 @@ #define IN_RANGE_EXC(val,beg,end) \ ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) +// makes dynamically allocated objects zero-initialised struct zero_initialized { void *operator new (size_t s); void operator delete (void *p, size_t s); @@ -387,5 +397,25 @@ } }; +// temporarily replace the process environment +extern char **environ; + +struct temp_environ +{ + char **prev; + + temp_environ (const stringvec *envv) + : prev (environ) + { + if (envv) + environ = (char **)envv->begin (); + } + + ~temp_environ () + { + environ = prev; + } +}; + #endif