uthash-0.0~git20180501.e412ea0/0000755000175000017500000000000013612346666014431 5ustar iliasiliasuthash-0.0~git20180501.e412ea0/Makefile.standalone0000644000175000017500000000115013272054031020175 0ustar iliasiliasOBJS=libut.a all: $(OBJS) INCDIR=./include CFLAGS+=-I$(INCDIR) CFLAGS+=-Wall -Wextra CFLAGS+=-g libut.a: libut.o utvector.o utmm.o ringbuf.o ar r $@ $^ libut.o: src/libut.c $(INCDIR)/libut.h $(CC) $(CFLAGS) $(CPPFLAGS) -c $< utvector.o: src/utvector.c $(INCDIR)/utvector.h $(CC) $(CFLAGS) $(CPPFLAGS) -c $< utmm.o: src/utmm.c $(INCDIR)/utmm.h $(CC) $(CFLAGS) $(CPPFLAGS) -c $< ringbuf.o: src/ringbuf.c $(INCDIR)/ringbuf.h $(CC) $(CFLAGS) $(CPPFLAGS) -c $< .PHONY: clean tests install clean: rm -f $(OBJS) *.o make -C tests clean tests: libut.a make -C tests install: libut.a cp $< /usr/local/lib uthash-0.0~git20180501.e412ea0/tests/0000755000175000017500000000000013272054031015553 5ustar iliasiliasuthash-0.0~git20180501.e412ea0/tests/test6.c0000644000175000017500000000154713272054031016773 0ustar iliasilias#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); printf("extend\n"); p = utvector_extend(&v); utstring_printf(p,"extended element"); dump(&v); printf("pop\n"); utvector_pop(&v); dump(&v); printf("clear\n"); utvector_clear(&v); dump(&v); printf("push\n"); utstring_new(p); utstring_printf(p,"allocated utstring"); utvector_push(&v, p); utstring_free(p); dump(&v); printf("done1\n"); utvector_fini(&v); printf("done2\n"); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test10.ans0000644000175000017500000000007113272054031017374 0ustar iliasiliasextend 1000 pop result: non-null 1000 pop result: null 0 uthash-0.0~git20180501.e412ea0/tests/test18.c0000644000175000017500000000115513272054031017051 0ustar iliasilias#include #include "libut.h" int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 9); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 9); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test15.ans0000644000175000017500000000154213272054031017405 0ustar iliasiliaslen: 16 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ head: non-null . tail: non-null ................ shift len: 15, head: non-null .. shift len: 14, head: non-null ... shift len: 13, head: non-null .... shift len: 12, head: non-null ..... shift len: 11, head: non-null ...... shift len: 10, head: non-null ....... shift len: 9, head: non-null ........ shift len: 8, head: non-null ......... shift len: 7, head: non-null .......... shift len: 6, head: non-null ........... shift len: 5, head: non-null ............ shift len: 4, head: non-null ............. shift len: 3, head: non-null .............. shift len: 2, head: non-null ............... shift len: 1, head: non-null ................ shift len: 0, head: null - extend len: 1, head: non-null extended uthash-0.0~git20180501.e412ea0/tests/test3.ans0000644000175000017500000000005713272054031017322 0ustar iliasiliaslen 10 len 9 0 1 2 3 4 5 6 7 8 11 len 10 len 0 uthash-0.0~git20180501.e412ea0/tests/test19.c0000644000175000017500000000076713272054031017062 0ustar iliasilias#include #include "libut.h" int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<1; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 0); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test4.c0000644000175000017500000000046413272054031016766 0ustar iliasilias#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v,*k; utvector_init(&v, utmm_int); for(i=0; i<10; i++) utvector_push(&v, &i); k = utvector_clone(&v); while ( (p=(int*)utvector_next(k,p))) printf("%d\n",*p); utvector_fini(&v); utvector_free(k); return 0; } uthash-0.0~git20180501.e412ea0/tests/test22.c0000644000175000017500000000242613272054031017046 0ustar iliasilias#include #include "ringbuf.h" int main() { int sc, rc = -1; size_t len; char *data; ringbuf *r = NULL; r = ringbuf_new(10); if (r == NULL) goto done; sc = ringbuf_put(r, "hello", 5); if (sc < 0) goto done; len = ringbuf_get_next_chunk(r, &data); assert(len == 5); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); /* now there are 10 bytes free but only 5 contiguous */ len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 5); memcpy(data, "abcde", 5); ringbuf_wrote(r, len); /* now there are 5 bytes free, starting at wrap */ len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 5); memcpy(data, "fghij", 5); ringbuf_wrote(r, len); /* read abcde */ len = ringbuf_get_next_chunk(r, &data); assert(len == 5); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); /* read fghji after the wrap */ len = ringbuf_get_next_chunk(r, &data); assert(len == 5); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); done: if (r) ringbuf_free(r); return rc; } uthash-0.0~git20180501.e412ea0/tests/Makefile0000644000175000017500000000115213272054031017212 0ustar iliasiliasPROGS=test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11 test12 \ test13 test14 test15 test16 test17 test18 test19 test20 test21 test22 test23 OBJS=$(patsubst %,%.o,$(PROGS)) CFLAGS += -I../include CFLAGS += -g CFLAGS += -Wall -Wextra LDFLAGS += -L.. -lut TEST_TARGET=run_tests TESTS=./do_tests all: $(OBJS) $(PROGS) $(TEST_TARGET) # static pattern rule: multiple targets $(OBJS): %.o: %.c $(CC) -c $(CPPFLAGS) $(CFLAGS) $< $(PROGS): %: %.o $(CC) -o $@ $(CPPFLAGS) $(CFLAGS) $< $(LDFLAGS) run_tests: $(PROGS) perl $(TESTS) .PHONY: clean clean: rm -f $(PROGS) $(OBJS) test*.out uthash-0.0~git20180501.e412ea0/tests/test2.ans0000644000175000017500000000002413272054031017313 0ustar iliasilias0 1 2 3 4 5 6 7 8 9 uthash-0.0~git20180501.e412ea0/tests/test7.c0000644000175000017500000000106113272054031016763 0ustar iliasilias#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_vector v; utvector_init(&v, utstring_mm); UT_vector *k; UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); printf("clone\n"); k = utvector_clone(&v); dump(k); utvector_fini(&v); utvector_free(k); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test7.ans0000644000175000017500000000023013272054031017317 0ustar iliasiliaslen: 10 . .. ... .... ..... ...... ....... ........ ......... .......... clone len: 10 . .. ... .... ..... ...... ....... ........ ......... .......... uthash-0.0~git20180501.e412ea0/tests/test14.c0000644000175000017500000000135613272054031017050 0ustar iliasilias#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<16; i++) utvector_push(&v, &i); p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); p = (int*)utvector_head(&v); printf("head: (%s) %d\n", p?"non-null":"null", p?*p:0); p = (int*)utvector_tail(&v); printf("tail: (%s) %d\n", p?"non-null":"null", p?*p:0); printf("len: %d\n", utvector_len(&v)); printf("shift\n"); utvector_shift(&v); printf("len: %d\n", utvector_len(&v)); p = (int*)utvector_head(&v); printf("head: (%s) %d\n", p?"non-null":"null", p?*p:0); printf("clear\n"); utvector_clear(&v); printf("len: %d\n", utvector_len(&v)); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test12.ans0000644000175000017500000000011513272054031017375 0ustar iliasilias0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 head: (non-null) 0 tail: (non-null) 15 uthash-0.0~git20180501.e412ea0/tests/test21.ans0000644000175000017500000000011213272054031017372 0ustar iliasiliaswritable space: 5 next chunk length : 10 helloabcde next chunk length : 0 uthash-0.0~git20180501.e412ea0/tests/test20.c0000644000175000017500000000142013272054031017035 0ustar iliasilias#include #include "ringbuf.h" int main() { int rc = -1; size_t len; char *data; ringbuf *r = NULL; r = ringbuf_new(10); if (r == NULL) goto done; len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 10); memcpy(data, "abcdefghik", 10); ringbuf_wrote(r, len); len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 0); len = ringbuf_get_next_chunk(r, &data); assert(len == 10); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); len = ringbuf_get_next_chunk(r, &data); assert(len == 0); printf("next chunk length : %zu\n", len); done: if (r) ringbuf_free(r); return rc; } uthash-0.0~git20180501.e412ea0/tests/README0000644000175000017500000000130613272054031016433 0ustar iliasiliastest1: test utvector init/fini test2: test utvector of int, push, next test3: test utvector push, pop, extend test4: test utvector_copy test5: test utvector of utstring test6: test utvector of utstring more ops test7: test utvector of utstring even more ops test8: test utextend past initial size int test9: test utextend past initial size utstring test10: test utvector_pop on empty list (int) test11: test utvector_pop on empty list (utstring) test12: test utvector head/tail (int) test13: test utvector head/tail (utstring) test14: test utvector_shift (int) test15: test utvector_shift (utstring) test16: test utvector_elt test17: test utvector_erase test18: test utvector_erase test19: test utvector_erase uthash-0.0~git20180501.e412ea0/tests/test13.c0000644000175000017500000000200613272054031017040 0ustar iliasilias#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_string *t; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<16; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); t = (UT_string*)utvector_head(&v); printf("head: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); t = (UT_string*)utvector_tail(&v); printf("tail: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); printf("extend\n"); t = (UT_string*)utvector_extend(&v); utstring_bincpy(t, "hello", 5); dump(&v); t = (UT_string*)utvector_head(&v); printf("head: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); t = (UT_string*)utvector_tail(&v); printf("tail: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test8.ans0000644000175000017500000000005313272054031017323 0ustar iliasilias0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1000 uthash-0.0~git20180501.e412ea0/tests/test19.ans0000644000175000017500000000000213272054031017377 0ustar iliasilias. uthash-0.0~git20180501.e412ea0/tests/test10.c0000644000175000017500000000100613272054031017034 0ustar iliasilias#include #include "utvector.h" int main() { int *p; UT_vector v; utvector_init(&v, utmm_int); printf("extend\n"); p = (int*)utvector_extend(&v); *p = 1000; p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); printf("pop\n"); p = (int*)utvector_pop(&v); printf("result: %s %d\n", p ? "non-null" : "null", p ? *p : 0); printf("pop\n"); p = (int*)utvector_pop(&v); printf("result: %s %d\n", p ? "non-null" : "null", p ? *p : 0); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test3.c0000644000175000017500000000100513272054031016755 0ustar iliasilias#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<10; i++) utvector_push(&v, &i); printf("len %d\n", utvector_len(&v)); utvector_pop(&v); printf("len %d\n", utvector_len(&v)); p = (int*)utvector_extend(&v); *p = 11; p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); printf("len %d\n", utvector_len(&v)); utvector_clear(&v); printf("len %d\n", utvector_len(&v)); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test13.ans0000644000175000017500000000064413272054031017405 0ustar iliasiliaslen: 16 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ head: non-null . tail: non-null ................ extend len: 17 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ hello head: non-null . tail: non-null hello uthash-0.0~git20180501.e412ea0/tests/do_tests0000755000175000017500000000055713272054031017334 0ustar iliasilias#!/usr/bin/perl use strict; use warnings; my @tests; for (glob "test*[0-9]") { push @tests, $_ if -e "$_.ans"; } my $num_failed=0; for my $test (@tests) { `./$test > $test.out`; `diff $test.out $test.ans`; print "$test failed\n" if $?; $num_failed++ if $?; } print scalar @tests . " tests conducted, $num_failed failed.\n"; exit $num_failed; uthash-0.0~git20180501.e412ea0/tests/test5.ans0000644000175000017500000000010113272054031017312 0ustar iliasilias. .. ... .... ..... ...... ....... ........ ......... .......... uthash-0.0~git20180501.e412ea0/tests/test18.ans0000644000175000017500000000025513272054031017410 0ustar iliasilias. .. ... .... ..... ...... ....... ........ ......... .......... . .. ... .... ..... ...... ....... ........ ......... . .. ... .... ..... ...... ....... ........ ......... uthash-0.0~git20180501.e412ea0/tests/test15.c0000644000175000017500000000217413272054031017050 0ustar iliasilias#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_string *t; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<16; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); t = (UT_string*)utvector_head(&v); printf("head: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); t = (UT_string*)utvector_tail(&v); printf("tail: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); for(i=0; i<16; i++) { printf("shift\n"); utvector_shift(&v); t = (UT_string*)utvector_head(&v); printf("len: %d, head: %s %s\n", utvector_len(&v), t?"non-null":"null", t?utstring_body(t):"-"); } printf("extend\n"); t= (UT_string*)utvector_extend(&v); utstring_printf(t,"extended"); t = (UT_string*)utvector_head(&v); printf("len: %d, head: %s %s\n", utvector_len(&v), t?"non-null":"null", t?utstring_body(t):"-"); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test1.ans0000644000175000017500000000000013272054031017304 0ustar iliasiliasuthash-0.0~git20180501.e412ea0/tests/test2.c0000644000175000017500000000040213272054031016754 0ustar iliasilias#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<10; i++) utvector_push(&v, &i); while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test11.c0000644000175000017500000000143513272054031017043 0ustar iliasilias#include #include "libut.h" int main() { UT_string *s; UT_vector v; utvector_init(&v, utstring_mm); printf("extend\n"); s = (UT_string*)utvector_extend(&v); utstring_printf(s,"hello"); printf("iterate\n"); s=NULL; while ( (s=(UT_string*)utvector_next(&v,s))) printf("%s\n",utstring_body(s)); printf("pop\n"); s=(UT_string*)utvector_pop(&v); printf("%s\n", s ? utstring_body(s) : "(null)"); printf("iterate\n"); s=NULL; while ( (s=(UT_string*)utvector_next(&v,s))) printf("%s\n",utstring_body(s)); printf("pop\n"); s=(UT_string*)utvector_pop(&v); printf("%s\n", s ? utstring_body(s) : "(null)"); printf("iterate\n"); s=NULL; while ( (s=(UT_string*)utvector_next(&v,s))) printf("%s\n",utstring_body(s)); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test6.ans0000644000175000017500000000045713272054031017331 0ustar iliasiliaslen: 10 . .. ... .... ..... ...... ....... ........ ......... .......... extend len: 11 . .. ... .... ..... ...... ....... ........ ......... .......... extended element pop len: 10 . .. ... .... ..... ...... ....... ........ ......... .......... clear len: 0 push len: 1 allocated utstring done1 done2 uthash-0.0~git20180501.e412ea0/tests/test8.c0000644000175000017500000000046413272054031016772 0ustar iliasilias#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<16; i++) utvector_push(&v, &i); p = utvector_extend(&v); *p = 1000; p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test9.c0000644000175000017500000000111613272054031016766 0ustar iliasilias#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_string *t; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<16; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); printf("extend\n"); t = (UT_string*)utvector_extend(&v); utstring_bincpy(t, "hello", 5); dump(&v); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test20.ans0000644000175000017500000000011313272054031017372 0ustar iliasiliaswritable space: 10 next chunk length : 10 abcdefghik next chunk length : 0 uthash-0.0~git20180501.e412ea0/tests/test11.ans0000644000175000017500000000007213272054031017376 0ustar iliasiliasextend iterate hello pop hello iterate pop (null) iterate uthash-0.0~git20180501.e412ea0/tests/test16.ans0000644000175000017500000000017013272054031017402 0ustar iliasilias0 1 2 3 4 5 6 7 8 9 elt 0: 0 elt 1: 1 elt 2: 2 elt 3: 3 elt 4: 4 elt 5: 5 elt 6: 6 elt 7: 7 elt 8: 8 elt 9: 9 p is null uthash-0.0~git20180501.e412ea0/tests/test16.c0000644000175000017500000000077213272054031017053 0ustar iliasilias#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v,*k; utvector_init(&v, utmm_int); for(i=0; i<10; i++) utvector_push(&v, &i); k = utvector_clone(&v); while ( (p=(int*)utvector_next(k,p))) printf("%d\n",*p); for(i=0; i<10; i++) { p = (int*)utvector_elt(&v, i); printf("elt %d: %d\n", i, *p); } /* expect null */ p = (int*)utvector_elt(&v, 11); printf("p is %snull\n", p ? "not " : ""); utvector_fini(&v); utvector_free(k); return 0; } uthash-0.0~git20180501.e412ea0/tests/test21.c0000644000175000017500000000151113272054031017037 0ustar iliasilias#include #include "ringbuf.h" int main() { int sc, rc = -1; size_t len; char *data; ringbuf *r = NULL; r = ringbuf_new(10); if (r == NULL) goto done; sc = ringbuf_put(r, "hello", 5); if (sc < 0) goto done; len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 5); memcpy(data, "abcde", 5); ringbuf_wrote(r, len); len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 0); len = ringbuf_get_next_chunk(r, &data); assert(len == 10); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); len = ringbuf_get_next_chunk(r, &data); assert(len == 0); printf("next chunk length : %zu\n", len); done: if (r) ringbuf_free(r); return rc; } uthash-0.0~git20180501.e412ea0/tests/test23.c0000644000175000017500000000243213272054031017044 0ustar iliasilias#include #include "ringbuf.h" int main() { int sc, rc = -1; size_t len; char *data; ringbuf *r = NULL; r = ringbuf_new(10); if (r == NULL) goto done; sc = ringbuf_put(r, "hello, ed", 9); if (sc < 0) goto done; len = ringbuf_get_next_chunk(r, &data); assert(len == 9); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); /* now there are 10 bytes free but only 1 contiguous */ len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 1); memcpy(data, "a", 1); ringbuf_wrote(r, len); /* now there are 9 bytes free, starting at wrap */ len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 9); memcpy(data, "bcdefghij", 9); ringbuf_wrote(r, len); /* read a */ len = ringbuf_get_next_chunk(r, &data); assert(len == 1); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); /* read bcdefghij after the wrap */ len = ringbuf_get_next_chunk(r, &data); assert(len == 9); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); done: if (r) ringbuf_free(r); return rc; } uthash-0.0~git20180501.e412ea0/tests/test23.ans0000644000175000017500000000017413272054031017404 0ustar iliasiliasnext chunk length : 9 hello, ed writable space: 1 writable space: 9 next chunk length : 1 a next chunk length : 9 bcdefghij uthash-0.0~git20180501.e412ea0/tests/test17.c0000644000175000017500000000115513272054031017050 0ustar iliasilias#include #include "libut.h" int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 0); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 1); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test22.ans0000644000175000017500000000017013272054031017377 0ustar iliasiliasnext chunk length : 5 hello writable space: 5 writable space: 5 next chunk length : 5 abcde next chunk length : 5 fghij uthash-0.0~git20180501.e412ea0/tests/test14.ans0000644000175000017500000000020313272054031017375 0ustar iliasilias0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 head: (non-null) 0 tail: (non-null) 15 len: 16 shift len: 15 head: (non-null) 1 clear len: 0 uthash-0.0~git20180501.e412ea0/tests/test5.c0000644000175000017500000000060413272054031016763 0ustar iliasilias#include #include "libut.h" int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test9.ans0000644000175000017500000000051513272054031017327 0ustar iliasiliaslen: 16 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ extend len: 17 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ hello uthash-0.0~git20180501.e412ea0/tests/test1.c0000644000175000017500000000016513272054031016761 0ustar iliasilias#include "utvector.h" int main() { UT_vector v; utvector_init(&v, utmm_int); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test4.ans0000644000175000017500000000002413272054031017315 0ustar iliasilias0 1 2 3 4 5 6 7 8 9 uthash-0.0~git20180501.e412ea0/tests/test12.c0000644000175000017500000000070113272054031017037 0ustar iliasilias#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<16; i++) utvector_push(&v, &i); p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); p = (int*)utvector_head(&v); printf("head: (%s) %d\n", p?"non-null":"null", p?*p:0); p = (int*)utvector_tail(&v); printf("tail: (%s) %d\n", p?"non-null":"null", p?*p:0); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test17.ans0000644000175000017500000000027313272054031017407 0ustar iliasilias. .. ... .... ..... ...... ....... ........ ......... .......... .. ... .... ..... ...... ....... ........ ......... .......... .. .... ..... ...... ....... ........ ......... .......... uthash-0.0~git20180501.e412ea0/.gitmodules0000644000175000017500000000012513272054031016564 0ustar iliasilias[submodule "uthash"] path = uthash url = https://github.com/troydhanson/uthash.git uthash-0.0~git20180501.e412ea0/src/0000755000175000017500000000000013272054031015200 5ustar iliasiliasuthash-0.0~git20180501.e412ea0/src/utvector.c0000644000175000017500000001202713272054031017221 0ustar iliasilias/* Copyright (c) 2003-2015, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "utvector.h" #define INITIAL_SIZE 16 /* utvector * * maintain a contiguous buffer of 'n' elements ('i' occupied) * the 'n' buffers are deep-inited at the time of allocation * the vector leaves popped slots as-is, clearing them on re-use * the memory management helper mm is used to define the size and * deep-init, deep-fini, deep-copy (into inited slots) and deep-clear. * deep-clear prepares a slot for re-use e.g. reset slot state. * */ void oom(void) { //fprintf(stderr,"out of memory\n"); exit(-1); } UT_vector *utvector_new(const UT_mm *mm) { UT_vector *v = malloc(sizeof(UT_vector)); if (!v) return NULL; utvector_init(v,mm); return v; } unsigned utvector_len(UT_vector *v) { return v->i; } void utvector_init(UT_vector *v, const UT_mm *mm) { v->mm = *mm; // struct copy v->i = v->n = 0; v->d = NULL; utvector_reserve(v, INITIAL_SIZE); // also inits them, sets v->n } void utvector_reserve(UT_vector *v, unsigned num) { if (v->n - v->i >= num) return; // space is big enough, return unsigned n = num - (v->n - v->i); // minimum we need to grow by if (n < (v->n * 2)) n = (v->n * 2); // grow by at least double current size char *d = realloc(v->d, (n + v->n) * v->mm.sz); if (!d) oom(); v->d = d; void *b = v->d + (v->n * v->mm.sz); // start of newly allocated area utmm_init(&v->mm,b,n); v->n = n + v->n; } void utvector_fini(UT_vector *v) { utmm_fini(&v->mm,v->d,v->n); free(v->d); v->d = NULL; v->i = v->n = 0; } UT_vector * utvector_clone(UT_vector *src) { UT_vector *v = utvector_new(&src->mm); utvector_copy(v, src); return v; } void utvector_clear(UT_vector *v) { v->i = 0; } void utvector_copy(UT_vector *dst, UT_vector *src) { /* dst, src both inited */ assert(dst->mm.sz == src->mm.sz); // double check that its inited utvector_clear(dst); utvector_reserve(dst, src->i); dst->i = src->i; utmm_clear(&dst->mm,dst->d,src->i); utmm_copy(&dst->mm, dst->d, src->d, src->i); } void utvector_free(UT_vector *v) { utvector_fini(v); free(v); } void *utvector_extend(UT_vector *v) { utvector_reserve(v,1); void *b = v->d + (v->i * v->mm.sz); utmm_clear(&v->mm,b,1); v->i++; return b; } void *utvector_next(UT_vector *v, void *cur) { if (cur == NULL) return v->i ? v->d : NULL; assert(cur >= (void*)(v->d)); // user pointer must be inside our data area char *n = (char*)cur + v->mm.sz; // next slot address if (n >= v->d + (v->i * v->mm.sz)) n=NULL; // only if next slot occupied return n; } void *utvector_head(UT_vector *v) { if (v->i == 0) return NULL; return v->d; } void *utvector_tail(UT_vector *v) { if (v->i == 0) return NULL; return v->d + ((v->i - 1) * v->mm.sz); } void *utvector_pop(UT_vector *v) { if (v->i == 0) return NULL; return v->d + (--(v->i) * v->mm.sz); } void *utvector_elt(UT_vector *v, unsigned i) { if (i >= v->i) return NULL; return v->d + (i * v->mm.sz); } /* shifting is not very efficient. we end up throwing away/fini'ing the * head of the vector, then doing a memmove, then having to init a new slot. * we don't return the shifted item because its been fini'd, and we have * no caller memory to copy it into anyway. a cpy_shift maybe handy */ void utvector_shift(UT_vector *v) { assert (v->i); utmm_fini(&v->mm,v->d,1); v->i--; memmove(v->d, v->d + v->mm.sz, (v->n-1)*v->mm.sz); char *b = v->d + ((v->n-1) * v->mm.sz); utmm_init(&v->mm,b,1); } void utvector_erase(UT_vector *v, unsigned i) { assert(v->i); if (i >= v->i) return; utmm_fini(&v->mm, v->d + (i * v->mm.sz), 1); v->i--; if (v->n - 1 > i) { memmove(v->d + (i * v->mm.sz), v->d + ((i+1) * v->mm.sz), (((v->n-1) - i) * v->mm.sz)); } char *b = v->d + ((v->n-1) * v->mm.sz); utmm_init(&v->mm,b,1); } void *utvector_push(UT_vector *v, void *e) { void *b = utvector_extend(v); utmm_copy(&v->mm, b, e, 1); return v->d + ((v->i - 1) * v->mm.sz); } uthash-0.0~git20180501.e412ea0/src/libut.c0000644000175000017500000000354713272054031016474 0ustar iliasilias/* Copyright (c) 2003-2014, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "libut.h" static void utstring_init_wrapper(void *_buf) { UT_string *buf = (UT_string*)_buf; utstring_init(buf); } static void utstring_done_wrapper(void *_buf) { UT_string *buf = (UT_string*)_buf; utstring_done(buf); } static void utstring_clear_wrapper(void *_buf) { UT_string *buf = (UT_string*)_buf; utstring_clear(buf); } static void utstring_copy_wrapper(void *_dst, void *_src) { UT_string *dst = (UT_string*)_dst; UT_string *src = (UT_string*)_src; utstring_concat(dst,src); } static UT_mm _utstring_mm = { .sz = sizeof(UT_string), .init = utstring_init_wrapper, .fini = utstring_done_wrapper, .copy = utstring_copy_wrapper, .clear = utstring_clear_wrapper }; UT_mm* utstring_mm = &_utstring_mm; uthash-0.0~git20180501.e412ea0/src/ringbuf.c0000644000175000017500000000734713272054031017013 0ustar iliasilias#include "ringbuf.h" ringbuf *ringbuf_new(size_t sz) { ringbuf *r = malloc(sizeof(*r) + sz); if (r == NULL) { fprintf(stderr,"out of memory\n"); goto done; } r->u = r->i = r->o = 0; r->n = sz; done: return r; } void ringbuf_free(ringbuf* r) { free(r); } /* ringbuf_take: alternative to ringbuf_new; caller * provides the buffer to use as the ringbuf. * buffer should be aligned e.g. from malloc/mmap. * note: do not ringbuf_free afterward. */ #define MIN_RINGBUF (sizeof(ringbuf) + 1) ringbuf *ringbuf_take(void *buf, size_t sz) { if (sz < MIN_RINGBUF) return NULL; ringbuf *r = (ringbuf*)buf; r->u = r->i = r->o = 0; r->n = sz - sizeof(*r); // alignment should be ok assert(r->n > 0); return r; } /* copy data in. fails if ringbuf has insuff space. */ #define MIN(a,b) (((a) < (b)) ? (a) : (b)) int ringbuf_put(ringbuf *r, const void *_data, size_t len) { char *data = (char*)_data; size_t a,b,c; if (r->i < r->o) { // available space is a contiguous buffer a = r->o - r->i; assert(a == r->n - r->u); if (len > a) return -1; memcpy(&r->d[r->i], data, len); } else { // available space wraps; it's two buffers b = r->n - r->i; // in-head to eob (receives leading input) c = r->o; // out-head to in-head (receives trailing input) a = b + c; // available space // the only ambiguous case is i==o, that's why u is needed if (r->i == r->o) a = r->n - r->u; assert(a == r->n - r->u); if (len > a) return -1; memcpy(&r->d[r->i], data, MIN(b, len)); if (len > b) memcpy(r->d, &data[b], len-b); } r->i = (r->i + len) % r->n; r->u += len; return 0; } size_t ringbuf_get_freespace(ringbuf *r) { return r->n - r->u; } size_t ringbuf_get_pending_size(ringbuf *r) { return r->u; } size_t ringbuf_get_next_chunk(ringbuf *r, char **data) { // in this case the next chunk is the whole pending buffer if (r->o < r->i) { assert(r->u == r->i - r->o); *data = &r->d[r->o]; return r->u; } // in this case (i==o) either the buffer is empty of full. // r->u tells distinguishes these cases. if ((r->o == r->i) && (r->u == 0)) { *data=NULL; return 0; } // if we're here, that means r->o > r->i. the pending // output is wrapped around the buffer. this function // returns the chunk prior to eob. the next call gets // the next chunk that's wrapped around the buffer. size_t b,c; b = r->n - r->o; // length of the part we're returning c = r->i; // wrapped part length- a sanity check assert(r->u == b + c); *data = &r->d[r->o]; return b; } void ringbuf_mark_consumed(ringbuf *r, size_t len) { assert(len <= r->u); r->o = (r->o + len ) % r->n; r->u -= len; } void ringbuf_clear(ringbuf *r) { r->u = r->i = r->o = 0; } /* * ringbuf_get_writable * * get a pointer into the next chunk of writable space * whose length is returned in *len. If callers writes * into this space, it must be followed with a call to * ringbuf_wrote */ size_t ringbuf_get_writable(ringbuf *r, char **data) { /* any room in ring? */ if (r->n == r->u) { *data = NULL; return 0; } if (r->i == r->o) { assert(r->u == 0); } *data = r->d + r->i; return (r->i >= r->o) ? r->n - r->i : /* free space is from r->i to end */ r->o - r->i; /* free space is from r->i to r->o */ } /* used after ringbuf_get_writable to indicate len * bytes were written. this can only be used with * a len less than, or equal to, the result from * that function */ void ringbuf_wrote(ringbuf *r, size_t len) { size_t max = (r->i >= r->o) ? r->n - r->i : /* free space is from r->i to end */ r->o - r->i; /* free space is from r->i to r->o */ assert(len <= max); r->u += len; r->i = (r->i + len) % r->n; } uthash-0.0~git20180501.e412ea0/src/utmm.c0000644000175000017500000000444413272054031016334 0ustar iliasilias/* Copyright (c) 2003-2015, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* utmm * * low level memory primitives * */ #include "utmm.h" void *utmm_new(const UT_mm *mm, size_t n) { void *o = calloc(n, mm->sz); if (o) return o; fprintf(stderr,"oom"); exit(-1); } void utmm_init(const UT_mm *mm, void *_buf, size_t n) { char *buf = (char*)_buf; if (mm->init == NULL) { memset(buf,0,n*mm->sz); return; } while(n--) { mm->init(buf); buf += mm->sz; } } void utmm_fini(const UT_mm *mm, void *_buf, size_t n) { char *buf = (char*)_buf; if (mm->fini == NULL) return; while(n--) { mm->fini(buf); buf += mm->sz; } } void utmm_clear(const UT_mm *mm, void *_buf, size_t n) { char *buf = (char*)_buf; if (mm->clear == NULL) { memset(buf,0,n*mm->sz); return; } while(n--) { mm->clear(buf); buf += mm->sz; } } void utmm_copy(const UT_mm *mm, void *_dst, void *_src, size_t n) { char *dst = (char*)_dst; char *src = (char*)_src; if (mm->copy == NULL) { memcpy(dst,src,n*mm->sz); return; } while(n--) { mm->copy(dst,src); dst += mm->sz; src += mm->sz; } } /* convenient predefined utmm */ static UT_mm _utmm_int = {.sz = sizeof(int)}; UT_mm* utmm_int = &_utmm_int; uthash-0.0~git20180501.e412ea0/LICENSE0000777000175000017500000000000013272054031017714 2uthash/LICENSEustar iliasiliasuthash-0.0~git20180501.e412ea0/README.md0000644000175000017500000000054513272054031015674 0ustar iliasiliaslibut is a bundling of uthash and its extra headers (utstring, etc, and including utvector/utmm) into a libut.h header and libut.a library. It was copied from uthash itself (https://github.com/troydhanson/uthash). It relies on uthash as a submodule, thus needs to be cloned recursively. git clone --recursive https://github.com/troydhanson/libut.git uthash-0.0~git20180501.e412ea0/include/0000755000175000017500000000000013272054031016034 5ustar iliasiliasuthash-0.0~git20180501.e412ea0/include/ringbuf.h0000644000175000017500000000155113272054031017643 0ustar iliasilias#ifndef _RINGBUF_H_ #define _RINGBUF_H_ #include #include #include #include /* simple ring buffer */ typedef struct _ringbuf { size_t n; /* allocd size */ size_t u; /* used space */ size_t i; /* input pos */ size_t o; /* output pos */ char d[]; /* C99 flexible array member */ } ringbuf; ringbuf *ringbuf_new(size_t sz); ringbuf *ringbuf_take(void *buf, size_t sz); int ringbuf_put(ringbuf *r, const void *data, size_t len); size_t ringbuf_get_pending_size(ringbuf *r); size_t ringbuf_get_next_chunk(ringbuf *r, char **data); size_t ringbuf_get_writable(ringbuf *r, char **data); void ringbuf_wrote(ringbuf *r, size_t len); void ringbuf_mark_consumed(ringbuf *r, size_t len); void ringbuf_free(ringbuf *r); void ringbuf_clear(ringbuf *r); size_t ringbuf_get_freespace(ringbuf *r); #endif /* _RINGBUF_H_ */ uthash-0.0~git20180501.e412ea0/include/uthash.h0000777000175000017500000000000013272054031024275 2../uthash/include/uthash.hustar iliasiliasuthash-0.0~git20180501.e412ea0/include/utstring.h0000777000175000017500000000000013272054031025243 2../uthash/include/utstring.hustar iliasiliasuthash-0.0~git20180501.e412ea0/include/utmm.h0000644000175000017500000000364013272054031017172 0ustar iliasilias#include #include #include /* Copyright (c) 2003-2016, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* utmm * * low level memory primitives * */ #ifndef __UTMM_H_ #define __UTMM_H_ typedef struct { size_t sz; void (*init)(void *buf); //-> utstring-init void (*fini)(void *buf); //-> utstring-done void (*copy)(void *dst, void *src); //-> ustring_concat void (*clear)(void *buf); //-> utstring-clear } UT_mm; void *utmm_new(const UT_mm *mm, size_t n); void utmm_init(const UT_mm *mm, void *buf, size_t n); void utmm_fini(const UT_mm *mm, void *buf, size_t n); void utmm_clear(const UT_mm *mm, void *buf, size_t n); void utmm_copy(const UT_mm *mm, void *dst, void *src, size_t n); /* convenient predefined mm */ extern UT_mm* utmm_int; extern UT_mm* utstring_mm; #endif /* __UTMM_H_ */ uthash-0.0~git20180501.e412ea0/include/utringbuffer.h0000777000175000017500000000000013272054031026711 2../uthash/include/utringbuffer.hustar iliasiliasuthash-0.0~git20180501.e412ea0/include/libut.h0000644000175000017500000000040613272054031017324 0ustar iliasilias#ifndef __LIBUT_H_ #define __LIBUT_H_ /* libut is a container around other sources */ #include "utmm.h" #include "utvector.h" #include "utstring.h" #include "utarray.h" #include "uthash.h" #include "utringbuffer.h" #include "utlist.h" #endif /* __LIBUT_H_ */ uthash-0.0~git20180501.e412ea0/include/utarray.h0000777000175000017500000000000013272054031024663 2../uthash/include/utarray.hustar iliasiliasuthash-0.0~git20180501.e412ea0/include/utvector.h0000644000175000017500000000527613272054031020072 0ustar iliasilias/* Copyright (c) 2003-2016, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* utvector * * maintain a contiguous buffer of 'n' elements ('i' occupied) * the 'n' buffers are deep-inited at the time of allocation * the vector leaves popped slots as-is, clearing them on re-use * the memory management helper mm is used to define the size and * deep-init, deep-fini, deep-copy (into inited slots) and deep-clear. * deep-clear prepares a slot for re-use e.g. reset slot state. * */ #ifndef __UTVECTOR_H_ #define __UTVECTOR_H_ #include "utmm.h" /* typical usage e.g. a vector of utstring would have * .sz = sizeof(UT_string) .init = utstring-init .fini = utstring-done .copy = ustring_concat .clear= utstring-clear */ typedef struct _UT_vector { UT_mm mm; unsigned i,n;/* i: index of next available slot, n: num slots */ char *d; /* n slots of size icd->sz*/ } UT_vector; UT_vector *utvector_new(const UT_mm *mm); void utvector_init(UT_vector *v, const UT_mm *mm); void utvector_reserve(UT_vector *v, unsigned num); void utvector_fini(UT_vector *v); UT_vector * utvector_clone(UT_vector *src); void utvector_clear(UT_vector *v); void utvector_copy(UT_vector *dst, UT_vector *src); void utvector_free(UT_vector *v); void *utvector_extend(UT_vector *v); void *utvector_head(UT_vector *v); void *utvector_tail(UT_vector *v); void *utvector_next(UT_vector *v, void *cur); void *utvector_pop(UT_vector *v); void *utvector_elt(UT_vector *v, unsigned i); void utvector_shift(UT_vector *v); void utvector_erase(UT_vector *v, unsigned i); void *utvector_push(UT_vector *v, void *e); unsigned utvector_len(UT_vector *v); #endif /* __UTVECTOR_H_ */ uthash-0.0~git20180501.e412ea0/include/utlist.h0000777000175000017500000000000013272054031024355 2../uthash/include/utlist.hustar iliasilias