diff options
| author | 2024-05-25 08:24:08 +0200 | |
|---|---|---|
| committer | 2024-05-25 08:24:08 +0200 | |
| commit | a2920800007c291bdf2b5264622cbc713d4961ee (patch) | |
| tree | 9fb1b2b89e0bfbb4b8bf1e85d840c8653e646bb7 /xs.h | |
| parent | Added a 'title' to each list timeline. (diff) | |
| download | penes-snac2-a2920800007c291bdf2b5264622cbc713d4961ee.tar.gz penes-snac2-a2920800007c291bdf2b5264622cbc713d4961ee.tar.xz penes-snac2-a2920800007c291bdf2b5264622cbc713d4961ee.zip | |
Backport from xs (fix regex.h compilation with tcc).
Diffstat (limited to 'xs.h')
| -rw-r--r-- | xs.h | 24 |
1 files changed, 11 insertions, 13 deletions
| @@ -798,11 +798,10 @@ int xs_list_len(const xs_list *list) | |||
| 798 | { | 798 | { |
| 799 | XS_ASSERT_TYPE_NULL(list, XSTYPE_LIST); | 799 | XS_ASSERT_TYPE_NULL(list, XSTYPE_LIST); |
| 800 | 800 | ||
| 801 | int c = 0; | 801 | int c = 0, ct = 0; |
| 802 | xs_list *p = (xs_list *)list; | ||
| 803 | const xs_val *v; | 802 | const xs_val *v; |
| 804 | 803 | ||
| 805 | while (xs_list_iter(&p, &v)) | 804 | while (xs_list_next(list, &v, &ct)) |
| 806 | c++; | 805 | c++; |
| 807 | 806 | ||
| 808 | return c; | 807 | return c; |
| @@ -817,11 +816,10 @@ const xs_val *xs_list_get(const xs_list *list, int num) | |||
| 817 | if (num < 0) | 816 | if (num < 0) |
| 818 | num = xs_list_len(list) + num; | 817 | num = xs_list_len(list) + num; |
| 819 | 818 | ||
| 820 | int c = 0; | 819 | int c = 0, ct = 0; |
| 821 | xs_list *p = (xs_list *)list; | ||
| 822 | const xs_val *v; | 820 | const xs_val *v; |
| 823 | 821 | ||
| 824 | while (xs_list_iter(&p, &v)) { | 822 | while (xs_list_next(list, &v, &ct)) { |
| 825 | if (c == num) | 823 | if (c == num) |
| 826 | return v; | 824 | return v; |
| 827 | 825 | ||
| @@ -880,16 +878,16 @@ xs_list *xs_list_dequeue(xs_list *list, xs_val **data, int last) | |||
| 880 | { | 878 | { |
| 881 | XS_ASSERT_TYPE(list, XSTYPE_LIST); | 879 | XS_ASSERT_TYPE(list, XSTYPE_LIST); |
| 882 | 880 | ||
| 883 | xs_list *p = list; | 881 | int ct = 0; |
| 884 | const xs_val *v = NULL; | 882 | const xs_val *v = NULL; |
| 885 | 883 | ||
| 886 | if (!last) { | 884 | if (!last) { |
| 887 | /* get the first */ | 885 | /* get the first */ |
| 888 | xs_list_iter(&p, &v); | 886 | xs_list_next(list, &v, &ct); |
| 889 | } | 887 | } |
| 890 | else { | 888 | else { |
| 891 | /* iterate to the end */ | 889 | /* iterate to the end */ |
| 892 | while (xs_list_iter(&p, &v)); | 890 | while (xs_list_next(list, &v, &ct)); |
| 893 | } | 891 | } |
| 894 | 892 | ||
| 895 | if (v != NULL) { | 893 | if (v != NULL) { |
| @@ -909,11 +907,11 @@ int xs_list_in(const xs_list *list, const xs_val *val) | |||
| 909 | XS_ASSERT_TYPE_NULL(list, XSTYPE_LIST); | 907 | XS_ASSERT_TYPE_NULL(list, XSTYPE_LIST); |
| 910 | 908 | ||
| 911 | int n = 0; | 909 | int n = 0; |
| 912 | xs_list *p = (xs_list *)list; | 910 | int ct = 0; |
| 913 | const xs_val *v; | 911 | const xs_val *v; |
| 914 | int sz = xs_size(val); | 912 | int sz = xs_size(val); |
| 915 | 913 | ||
| 916 | while (xs_list_iter(&p, &v)) { | 914 | while (xs_list_next(list, &v, &ct)) { |
| 917 | if (sz == xs_size(v) && memcmp(val, v, sz) == 0) | 915 | if (sz == xs_size(v) && memcmp(val, v, sz) == 0) |
| 918 | return n; | 916 | return n; |
| 919 | 917 | ||
| @@ -930,13 +928,13 @@ xs_str *xs_join(const xs_list *list, const char *sep) | |||
| 930 | XS_ASSERT_TYPE(list, XSTYPE_LIST); | 928 | XS_ASSERT_TYPE(list, XSTYPE_LIST); |
| 931 | 929 | ||
| 932 | xs_str *s = NULL; | 930 | xs_str *s = NULL; |
| 933 | xs_list *p = (xs_list *)list; | ||
| 934 | const xs_val *v; | 931 | const xs_val *v; |
| 935 | int c = 0; | 932 | int c = 0; |
| 933 | int ct = 0; | ||
| 936 | int offset = 0; | 934 | int offset = 0; |
| 937 | int ssz = strlen(sep); | 935 | int ssz = strlen(sep); |
| 938 | 936 | ||
| 939 | while (xs_list_iter(&p, &v)) { | 937 | while (xs_list_next(list, &v, &ct)) { |
| 940 | /* refuse to join non-string values */ | 938 | /* refuse to join non-string values */ |
| 941 | if (xs_type(v) == XSTYPE_STRING) { | 939 | if (xs_type(v) == XSTYPE_STRING) { |
| 942 | int sz; | 940 | int sz; |