diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-02-08 00:52:18 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-02-08 00:52:18 -0500 |
| commit | 930c09f46d1e249fc889e8f1179046a48c1eaf32 (patch) | |
| tree | 4900307e726dcbc643b12341a9bb7168edebdff5 /util.h | |
| parent | ee0f45e2959484d390c30a8a1430a0f040f56631 (diff) | |
More features and progress
Diffstat (limited to 'util.h')
| -rw-r--r-- | util.h | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -26,4 +26,29 @@ char *heap_str(const char *str); char *heap_strf(const char *fmt, ...); CORD CORD_asprintf(const char *fmt, ...); +#define REVERSE_LIST(list) do { \ + __typeof(list) _prev = NULL; \ + __typeof(list) _next = NULL; \ + auto _current = list; \ + while (_current != NULL) { \ + _next = _current->next; \ + _current->next = _prev; \ + _prev = _current; \ + _current = _next; \ + } \ + list = _prev; \ +} while(0) + +#define LIST_MAP(src, var, ...) ({\ + __typeof(src) __mapped = NULL; \ + __typeof(src) *__next = &__mapped; \ + for (__typeof(src) var = src; var; var = var->next) { \ + *__next = GC_MALLOC(sizeof(__typeof(*(src)))); \ + **__next = *var; \ + **__next = (__typeof(*(src))){__VA_ARGS__}; \ + __next = &((*__next)->next); \ + } \ + __mapped; }) + + // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
