diff options
| author | 2024-04-22 07:31:50 +0200 | |
|---|---|---|
| committer | 2024-04-22 07:31:50 +0200 | |
| commit | cf1c2b1ed82b54e5496275c2bab4c828afbb2b06 (patch) | |
| tree | 67a05090676b5e1153f22fe402cf50d99a129216 | |
| parent | Deleted useless recalculation of queue_retry_max. (diff) | |
| download | penes-snac2-cf1c2b1ed82b54e5496275c2bab4c828afbb2b06.tar.gz penes-snac2-cf1c2b1ed82b54e5496275c2bab4c828afbb2b06.tar.xz penes-snac2-cf1c2b1ed82b54e5496275c2bab4c828afbb2b06.zip | |
Backport from xs.
| -rw-r--r-- | xs.h | 44 | ||||
| -rw-r--r-- | xs_version.h | 2 |
2 files changed, 43 insertions, 3 deletions
| @@ -94,6 +94,7 @@ xs_list *xs_list_append_m(xs_list *list, const char *mem, int dsz); | |||
| 94 | xs_list *_xs_list_append(xs_list *list, const xs_val *vals[]); | 94 | xs_list *_xs_list_append(xs_list *list, const xs_val *vals[]); |
| 95 | #define xs_list_append(list, ...) _xs_list_append(list, (const xs_val *[]){ __VA_ARGS__, NULL }) | 95 | #define xs_list_append(list, ...) _xs_list_append(list, (const xs_val *[]){ __VA_ARGS__, NULL }) |
| 96 | int xs_list_iter(xs_list **list, xs_val **value); | 96 | int xs_list_iter(xs_list **list, xs_val **value); |
| 97 | int xs_list_next(const xs_list *list, xs_val **value, int *ctxt); | ||
| 97 | int xs_list_len(const xs_list *list); | 98 | int xs_list_len(const xs_list *list); |
| 98 | xs_val *xs_list_get(const xs_list *list, int num); | 99 | xs_val *xs_list_get(const xs_list *list, int num); |
| 99 | xs_list *xs_list_del(xs_list *list, int num); | 100 | xs_list *xs_list_del(xs_list *list, int num); |
| @@ -752,6 +753,42 @@ int xs_list_iter(xs_list **list, xs_val **value) | |||
| 752 | } | 753 | } |
| 753 | 754 | ||
| 754 | 755 | ||
| 756 | int xs_list_next(const xs_list *list, xs_val **value, int *ctxt) | ||
| 757 | /* iterates a list, with context */ | ||
| 758 | { | ||
| 759 | if (xs_type(list) != XSTYPE_LIST) | ||
| 760 | return 0; | ||
| 761 | |||
| 762 | int goon = 1; | ||
| 763 | |||
| 764 | char *p = (char *)list; | ||
| 765 | |||
| 766 | /* skip the start of the list */ | ||
| 767 | if (*ctxt == 0) | ||
| 768 | *ctxt = 1 + _XS_TYPE_SIZE; | ||
| 769 | |||
| 770 | p += *ctxt; | ||
| 771 | |||
| 772 | /* an element? */ | ||
| 773 | if (xs_type(p) == XSTYPE_LITEM) { | ||
| 774 | p++; | ||
| 775 | |||
| 776 | *value = p; | ||
| 777 | |||
| 778 | p += xs_size(*value); | ||
| 779 | } | ||
| 780 | else { | ||
| 781 | /* end of list */ | ||
| 782 | goon = 0; | ||
| 783 | } | ||
| 784 | |||
| 785 | /* update the context */ | ||
| 786 | *ctxt = p - list; | ||
| 787 | |||
| 788 | return goon; | ||
| 789 | } | ||
| 790 | |||
| 791 | |||
| 755 | int xs_list_len(const xs_list *list) | 792 | int xs_list_len(const xs_list *list) |
| 756 | /* returns the number of elements in the list */ | 793 | /* returns the number of elements in the list */ |
| 757 | { | 794 | { |
| @@ -1199,8 +1236,11 @@ double xs_number_get(const xs_number *v) | |||
| 1199 | { | 1236 | { |
| 1200 | double f = 0.0; | 1237 | double f = 0.0; |
| 1201 | 1238 | ||
| 1202 | if (v != NULL && v[0] == XSTYPE_NUMBER) | 1239 | if (xs_type(v) == XSTYPE_NUMBER) |
| 1203 | f = atof(&v[1]); | 1240 | f = atof(&v[1]); |
| 1241 | else | ||
| 1242 | if (xs_type(v) == XSTYPE_STRING) | ||
| 1243 | f = atof(v); | ||
| 1204 | 1244 | ||
| 1205 | return f; | 1245 | return f; |
| 1206 | } | 1246 | } |
| @@ -1211,7 +1251,7 @@ const char *xs_number_str(const xs_number *v) | |||
| 1211 | { | 1251 | { |
| 1212 | const char *p = NULL; | 1252 | const char *p = NULL; |
| 1213 | 1253 | ||
| 1214 | if (v != NULL && v[0] == XSTYPE_NUMBER) | 1254 | if (xs_type(v) == XSTYPE_NUMBER) |
| 1215 | p = &v[1]; | 1255 | p = &v[1]; |
| 1216 | 1256 | ||
| 1217 | return p; | 1257 | return p; |
diff --git a/xs_version.h b/xs_version.h index f655735..f926e06 100644 --- a/xs_version.h +++ b/xs_version.h | |||
| @@ -1 +1 @@ | |||
| /* f712d1336ef427c3b56305364b2687578537543f 2024-04-14T19:11:53+02:00 */ | /* 0206a65508e86f66b6aa329418ddc8f6f8c1ecb2 2024-04-22T07:31:05+02:00 */ | ||