liblist-c

C type-agnostic linked-list library
git clone https://git.sinitax.com/sinitax/liblist-c
Log | Files | Refs | LICENSE | sfeed.txt

commit fe0f9615b3e0be82a258b62edf6f72779bf71fd9
parent 3fc6f5caa994dcb2b0118f2401831f7f67532d2f
Author: Louis Burda <quent.burda@gmail.com>
Date:   Mon, 29 May 2023 15:28:32 +0200

Make LIST_ITER_ITEMS more concise and add install targets

Diffstat:
Mbuild.jst | 22+++++++++++++++++-----
Minclude/list.h | 20++++++++++----------
Msrc/test.c | 3+--
3 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/build.jst b/build.jst @@ -1,19 +1,20 @@ -CC = gcc + + cflags = -Wunused-function -Wunused-variable -Wconversion - -I include + -I include -O2 rule liba - $CC -o $out.tmp.o $in $cflags -r + gcc -o $out.tmp.o $in $cflags -r objcopy --keep-global-symbols=liblist.api $out.tmp.o $out.fixed.o ar rcs $out $out.fixed.o rm $out.tmp.o $out.fixed.o rule libso - $CC -o $out $in $cflags -shared -Wl,-version-script liblist.lds + gcc -o $out $in $cflags -shared -Wl,-version-script liblist.lds rule cc - $CC -o $out $in $cflags + gcc -o $out $in $cflags rule mkdir mkdir $out @@ -36,6 +37,17 @@ command clean command cleanall just clean +command install + install -m755 build/liblist.a -t "/usr/local/lib" + install -m755 build/liblist.so -t "/usr/local/lib" + install -m755 include/list.h -t "/usr/local/include" + +command uninstall + rm -f "/usr/local/lib/liblist.a" + rm -f "/usr/local/lib/liblist.so" + rm -f "/usr/local/include/list.h" + command all just build/liblist.a build/liblist.so build/test + diff --git a/include/list.h b/include/list.h @@ -18,16 +18,16 @@ #define LIST_ITER_BWD(list, iter) (iter) = (list)->tail.prev; \ (iter) != &(list)->head; (iter) = (iter)->prev -#define LIST_ITER_ITEMS(list, iter, item, type, member) \ - (iter) = (list)->head.next; \ - (iter) != &(list)->tail \ - && ((item) = LIST_UPCAST(iter, type, member)); \ - (iter) = (iter)->next -#define LIST_ITER_ITEMS_BWD(list, iter, item, type, member) \ - (iter) = (list)->tail.prev; \ - (iter) != &(list)->head \ - && ((item) = LIST_UPCAST(iter, type, member)); \ - (iter) = (iter)->prev +#define LIST_ITER_ITEMS(list, item, type, member) \ + struct list_link *_iter = (list)->head.next; \ + _iter != &(list)->tail \ + && ((item) = LIST_UPCAST(_iter, type, member)); \ + _iter = _iter->next +#define LIST_ITER_ITEMS_BWD(list, item, type, member) \ + struct link_link *_iter = (list)->tail.prev; \ + _iter != &(list)->head \ + && ((item) = LIST_UPCAST(_iter, type, member)); \ + _iter = _iter->prev #define LIST_FRONT_ITEM(list, type, member) \ ((type *) ({ void *p = list_front(list); \ diff --git a/src/test.c b/src/test.c @@ -21,7 +21,6 @@ test_sort(const void *p1, const void *p2) int main(int argc, const char **argv) { - struct list_link *iter; struct list list; struct arg *item; const char **arg; @@ -44,7 +43,7 @@ main(int argc, const char **argv) list_insertion_sort(&list, atoi(argv[1]), test_sort, LIST_OFFSET(struct arg, link)); - for (LIST_ITER_ITEMS(&list, iter, item, struct arg, link)) + for (LIST_ITER_ITEMS(&list, item, struct arg, link)) printf("%s\n", item->str); list_free_items(&list, free, LIST_OFFSET(struct arg, link));