mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
Backport from xs (fix regex.h compilation with tcc).
This commit is contained in:
parent
f631fc5ed2
commit
a292080000
24
xs.h
24
xs.h
@ -798,11 +798,10 @@ int xs_list_len(const xs_list *list)
|
||||
{
|
||||
XS_ASSERT_TYPE_NULL(list, XSTYPE_LIST);
|
||||
|
||||
int c = 0;
|
||||
xs_list *p = (xs_list *)list;
|
||||
int c = 0, ct = 0;
|
||||
const xs_val *v;
|
||||
|
||||
while (xs_list_iter(&p, &v))
|
||||
while (xs_list_next(list, &v, &ct))
|
||||
c++;
|
||||
|
||||
return c;
|
||||
@ -817,11 +816,10 @@ const xs_val *xs_list_get(const xs_list *list, int num)
|
||||
if (num < 0)
|
||||
num = xs_list_len(list) + num;
|
||||
|
||||
int c = 0;
|
||||
xs_list *p = (xs_list *)list;
|
||||
int c = 0, ct = 0;
|
||||
const xs_val *v;
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
while (xs_list_next(list, &v, &ct)) {
|
||||
if (c == num)
|
||||
return v;
|
||||
|
||||
@ -880,16 +878,16 @@ xs_list *xs_list_dequeue(xs_list *list, xs_val **data, int last)
|
||||
{
|
||||
XS_ASSERT_TYPE(list, XSTYPE_LIST);
|
||||
|
||||
xs_list *p = list;
|
||||
int ct = 0;
|
||||
const xs_val *v = NULL;
|
||||
|
||||
if (!last) {
|
||||
/* get the first */
|
||||
xs_list_iter(&p, &v);
|
||||
xs_list_next(list, &v, &ct);
|
||||
}
|
||||
else {
|
||||
/* iterate to the end */
|
||||
while (xs_list_iter(&p, &v));
|
||||
while (xs_list_next(list, &v, &ct));
|
||||
}
|
||||
|
||||
if (v != NULL) {
|
||||
@ -909,11 +907,11 @@ int xs_list_in(const xs_list *list, const xs_val *val)
|
||||
XS_ASSERT_TYPE_NULL(list, XSTYPE_LIST);
|
||||
|
||||
int n = 0;
|
||||
xs_list *p = (xs_list *)list;
|
||||
int ct = 0;
|
||||
const xs_val *v;
|
||||
int sz = xs_size(val);
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
while (xs_list_next(list, &v, &ct)) {
|
||||
if (sz == xs_size(v) && memcmp(val, v, sz) == 0)
|
||||
return n;
|
||||
|
||||
@ -930,13 +928,13 @@ xs_str *xs_join(const xs_list *list, const char *sep)
|
||||
XS_ASSERT_TYPE(list, XSTYPE_LIST);
|
||||
|
||||
xs_str *s = NULL;
|
||||
xs_list *p = (xs_list *)list;
|
||||
const xs_val *v;
|
||||
int c = 0;
|
||||
int ct = 0;
|
||||
int offset = 0;
|
||||
int ssz = strlen(sep);
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
while (xs_list_next(list, &v, &ct)) {
|
||||
/* refuse to join non-string values */
|
||||
if (xs_type(v) == XSTYPE_STRING) {
|
||||
int sz;
|
||||
|
@ -16,6 +16,11 @@ xs_list *xs_regex_replace_in(xs_str *str, const char *rx, const char *rep, int c
|
||||
|
||||
#ifdef XS_IMPLEMENTATION
|
||||
|
||||
#ifdef __TINYC__
|
||||
/* fix a compilation error in tcc */
|
||||
#define _REGEX_NELTS(n)
|
||||
#endif
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
xs_list *xs_regex_split_n(const char *str, const char *rx, int count)
|
||||
|
5
xs_set.h
5
xs_set.h
@ -85,7 +85,6 @@ int xs_set_add(xs_set *s, const xs_val *data)
|
||||
{
|
||||
/* is it 'full'? */
|
||||
if (s->used >= s->elems / 2) {
|
||||
char *p;
|
||||
const xs_val *v;
|
||||
|
||||
/* expand! */
|
||||
@ -96,8 +95,8 @@ int xs_set_add(xs_set *s, const xs_val *data)
|
||||
memset(s->hash, '\0', s->elems * sizeof(int));
|
||||
|
||||
/* add the list elements back */
|
||||
p = s->list;
|
||||
while (xs_list_iter(&p, &v))
|
||||
int ct = 0;
|
||||
while (xs_list_next(s->list, &v, &ct))
|
||||
_store_hash(s, v, v - s->list);
|
||||
}
|
||||
|
||||
|
5
xs_url.h
5
xs_url.h
@ -51,11 +51,10 @@ xs_dict *xs_url_vars(const char *str)
|
||||
/* split by arguments */
|
||||
xs *args = xs_split(str, "&");
|
||||
|
||||
xs_list *l;
|
||||
int ct = 0;
|
||||
const xs_val *v;
|
||||
|
||||
l = args;
|
||||
while (xs_list_iter(&l, &v)) {
|
||||
while (xs_list_next(args, &v, &ct)) {
|
||||
xs *kv = xs_split_n(v, "=", 1);
|
||||
|
||||
if (xs_list_len(kv) == 2) {
|
||||
|
@ -1 +1 @@
|
||||
/* 65265483c102909393287bfb173d1a7ae9c3be00 2024-05-23T09:57:20+02:00 */
|
||||
/* 65769f25ed99b886a643522bef21628396cd118d 2024-05-25T08:18:51+02:00 */
|
||||
|
Loading…
Reference in New Issue
Block a user