tllist: use tllist from external git repository
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Daniel Eklöf · committed by Daniel Eklöf · parent 4885681 · Browse files · 4 files·+7 added−159 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+7 added−159 removed
- other:+7 added−159 removed
Provenance
- Commit
9ce2fb5- Tree
11824ab- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
4885681
4 files changed+7 added−159 removed
added:subprojects/tllistnot shown
Its text is not shown, added.
modified:.gitmodules+3 added
1 [submodule "external/wlr-protocols"]2 path = external/wlr-protocols3 url = https://github.com/swaywm/wlr-protocols.git4 branch = master5+[submodule "subprojects/tllist"]6+ path = subprojects/tllist7+ url = https://gitlab.com/dnkl/tllist.gitmodified:meson.build+4 added-2 removed
58 unmodified lines59 build_always_stale: true,60 output: 'version.h',61 command: [generate_version_sh, meson.project_version(), '@SOURCE_DIR@', '@OUTPUT@'])62 63+tllist = subproject('tllist').get_variable('tllist')64+65 executable(66 'fuzzel',67 'application.c', 'application.h',68 'dmenu.c', 'dmenu.h',6 unmodified lines75 'prompt.c', 'prompt.h',76 'render.c', 'render.h',77 'shm.c', 'shm.h',78 'stride.h',77- 'tllist.h',79 'wayland.c', 'wayland.h',80 'xdg.c', 'xdg.h',81 wl_proto_src + wl_proto_headers, version,82 dependencies: [pixman,4 unmodified lines87 librsvg,88 wayland_client,89 wayland_cursor,90 wlroots,90- xkb],91+ xkb,92+ tllist],93 install: true)94 95 subdir('completions')96 subdir('doc')deleted:tllist.h-157 removed
1-#pragma once2-3-#include <stdlib.h>4-#include <stddef.h>5-#include <assert.h>6-7-#define TLL_PASTE2( a, b) a##b8-#define TLL_PASTE( a, b) TLL_PASTE2( a, b)9-10-/* Utility macro to generate a list element struct with a unique struct tag */11-#define TLL_UNIQUE_INNER_STRUCT(TYPE, ID) \12- struct TLL_PASTE(__tllist_ , ID) { \13- TYPE item; \14- struct TLL_PASTE(__tllist_, ID) *prev; \15- struct TLL_PASTE(__tllist_, ID) *next; \16- } *head, *tail;17-18-/*19- * Defines a new typed-list type, or directly instantiate a typed-list variable20- *21- * Example a, declare a variable (list of integers):22- * tll(int) my_list;23- *24- * Example b, declare a type, and then use the type:25- * tll(int, my_list_type);26- * struct my_list_type my_list;27- */28-#define tll(TYPE, ...) \29- struct __VA_ARGS__ { \30- TLL_UNIQUE_INNER_STRUCT(TYPE, __COUNTER__) \31- size_t length; \32- }33-34-/* Initializer: tll(int) my_list = tll_init(); */35-#define tll_init() {.head = NULL, .tail = NULL, .length = 0}36-37-/* Length/size of list: printf("size: %zu\n", tll_length(my_list)); */38-#define tll_length(list) (list).length39-40-/* Adds a new item to the back of the list */41-#define tll_push_back(list, new_item) \42- do { \43- __typeof__((list).head) __e = malloc(sizeof(*__e)); \44- __e->item = (new_item); \45- __e->prev = (list).tail; \46- __e->next = NULL; \47- if ((list).head == NULL) \48- (list).head = (list).tail = __e; \49- else { \50- (list).tail->next = __e; \51- (list).tail = __e; \52- } \53- (list).length++; \54- } while (0)55-56-/* Adds a new item to the front of the list */57-#define tll_push_front(list, new_item) \58- do { \59- __typeof__((list).head) __e = malloc(sizeof(*__e)); \60- __e->item = (new_item); \61- __e->prev = NULL; \62- __e->next = (list).head; \63- if ((list).head == NULL) \64- (list).head = (list).tail = __e; \65- else { \66- (list).head->prev = __e; \67- (list).head = __e; \68- } \69- (list).length++; \70- } while (0)71-72-73-/*74- * Iterates the list. <it> is an iterator pointer. You can access the75- * list item with ->item:76- *77- * tll(int) my_list = vinit();78- * tll_push_back(my_list, 5);79- *80- * tll_foreach(my_list i) {81- * printf("%d\n", i->item);82- * }83-*/84-#define tll_foreach(list, it) \85- for (__typeof__(*(list).head) *it = (list).head, \86- *it_next = it != NULL ? it->next : NULL; \87- it != NULL; \88- it = it_next, \89- it_next = it_next != NULL ? it_next->next : NULL)90-91-/* Same as tll_foreach(), but iterates backwards */92-#define tll_rforeach(list, it) \93- for (__typeof__(*(list).tail) *it = (list).tail, \94- *it_prev = it != NULL ? it->prev : NULL; \95- it != NULL; \96- it = it_prev, \97- it_prev = it_prev != NULL ? it_prev->prev : NULL)98-99-/*100- * Removes an entry from the list. <it> is an iterator. I.e. you can101- * only call this from inside a tll_foreach() or tll_rforeach() loop.102- */103-#define tll_remove(list, it) \104- do { \105- assert((list).length > 0); \106- __typeof__((list).head) __prev = it->prev; \107- __typeof__((list).head) __next = it->next; \108- if (__prev != NULL) \109- __prev->next = __next; \110- else \111- (list).head = __next; \112- if (__next != NULL) \113- __next->prev = __prev; \114- else \115- (list).tail = __prev; \116- free(it); \117- (list).length--; \118- } while (0)119-120-/* Same as tll_remove(), but calls free_callback(it->item) */121-#define tll_remove_and_free(list, it, free_callback) \122- do { \123- free_callback((it)->item); \124- tll_remove((list), (it)); \125- } while (0)126-127-#define tll_front(list) (list).head->item128-#define tll_back(list) (list).tail->item129-130-/*131- * Removes the first element from the list, and returns it (note:132- * returns the *actual* item, not an iterator.133- */134-#define tll_pop_front(list) \135- ({__typeof__((list).head) it = (list).head; \136- __typeof__((list).head->item) __ret = it->item; \137- tll_remove((list), it); \138- __ret; \139- })140-141-/* Same as tll_pop_front(), but returns/removes the *last* element */142-#define tll_pop_back(list) \143- ({__typeof__((list).tail) it = (list).tail; \144- __typeof__((list).tail->item) __ret = it->item; \145- tll_remove((list), it); \146- __ret; \147- })148-149-/* Frees the list. This call is *not* needed if the list is already empty. */150-#define tll_free(list) \151- tll_foreach(list, __it) \152- tll_remove(list, __it)153-154-/* Same as tll_free(), but also calls free_callback(item) for every item */155-#define tll_free_and_free(list, free_callback) \156- tll_foreach(list, __it) \157- tll_remove_and_free(list, __it, free_callback)