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 <cstring> |
5 | #include <cstring> |
5 | |
6 | |
6 | #define PP_CONCAT_(a, b) a ## b |
7 | #define PP_CONCAT_(a, b) a ## b |
7 | #define PP_CONCAT(a, b) PP_CONCAT_(a, b) |
8 | #define PP_CONCAT(a, b) PP_CONCAT_(a, b) |
8 | #define PP_STRINGIFY_(a) #a |
9 | #define PP_STRINGIFY_(a) #a |
… | |
… | |
256 | return pos; |
257 | return pos; |
257 | } |
258 | } |
258 | void erase (iterator first, iterator last) |
259 | void erase (iterator first, iterator last) |
259 | { |
260 | { |
260 | if (last != first) { |
261 | if (last != first) { |
261 | memmove (first, last, (end ()-last)*sizeof (T)); |
262 | memmove (first, last, (end () - last) * sizeof (T)); |
262 | _last -= last - first; |
263 | _last -= last - first; |
263 | } |
264 | } |
264 | } |
265 | } |
265 | void erase (iterator pos) |
266 | void erase (iterator pos) |
266 | { |
267 | { |
267 | if (pos != end ()) { |
268 | if (pos != end ()) { |
268 | memmove (pos, pos+1, (end ()- (pos+1))*sizeof (T)); |
269 | memmove (pos, pos+1, (end () - (pos+1)) * sizeof (T)); |
269 | --_last; |
270 | --_last; |
270 | } |
271 | } |
271 | } |
272 | } |
272 | void swap (simplevec<T> &t) |
273 | void swap (simplevec<T> &t) |
273 | { |
274 | { |
… | |
… | |
391 | struct stringvec : simplevec<char *> |
392 | struct stringvec : simplevec<char *> |
392 | { |
393 | { |
393 | ~stringvec () |
394 | ~stringvec () |
394 | { |
395 | { |
395 | for (char **c = begin (); c != end (); c++) |
396 | for (char **c = begin (); c != end (); c++) |
396 | delete [] *c; |
397 | free (*c); |
397 | } |
398 | } |
398 | }; |
399 | }; |
399 | |
400 | |
400 | // temporarily replace the process environment |
401 | // return a very temporary (and never deallocated) buffer. keep small. |
401 | extern char **environ; |
402 | void *rxvt_temp_buf (int len); |
402 | |
403 | |
403 | struct temp_environ |
404 | template<typename T> |
|
|
405 | inline T * |
|
|
406 | rxvt_temp_buf (int len) |
404 | { |
407 | { |
405 | char **prev; |
408 | return (T *)rxvt_temp_buf (len * sizeof (T)); |
406 | |
409 | } |
407 | temp_environ (const stringvec *envv) |
|
|
408 | : prev (environ) |
|
|
409 | { |
|
|
410 | if (envv) |
|
|
411 | environ = (char **)envv->begin (); |
|
|
412 | } |
|
|
413 | |
|
|
414 | ~temp_environ () |
|
|
415 | { |
|
|
416 | environ = prev; |
|
|
417 | } |
|
|
418 | }; |
|
|
419 | |
410 | |
420 | #endif |
411 | #endif |
421 | |
412 | |