summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-04-14 19:26:49 +0200
committerGravatar default2024-04-14 19:26:49 +0200
commit0275658a3602f74035ff776dac8d8f64b9a2794f (patch)
treed9489684e46d7cd0d5bd8347a880316abe22f48f
parentBetter redirection URL building in oauth_post_handler(). (diff)
downloadpenes-snac2-0275658a3602f74035ff776dac8d8f64b9a2794f.tar.gz
penes-snac2-0275658a3602f74035ff776dac8d8f64b9a2794f.tar.xz
penes-snac2-0275658a3602f74035ff776dac8d8f64b9a2794f.zip
Backport from xs.
-rw-r--r--xs.h4
-rw-r--r--xs_json.h10
-rw-r--r--xs_mime.h22
-rw-r--r--xs_unicode.h16
-rw-r--r--xs_url.h2
-rw-r--r--xs_version.h2
6 files changed, 32 insertions, 24 deletions
diff --git a/xs.h b/xs.h
index d2de44a..bab315a 100644
--- a/xs.h
+++ b/xs.h
@@ -45,6 +45,10 @@ typedef char xs_data;
45/* not really all, just very much */ 45/* not really all, just very much */
46#define XS_ALL 0xfffffff 46#define XS_ALL 0xfffffff
47 47
48#ifndef xs_countof
49#define xs_countof(a) (sizeof((a)) / sizeof((*a)))
50#endif
51
48void *xs_free(void *ptr); 52void *xs_free(void *ptr);
49void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func); 53void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func);
50#define xs_realloc(ptr, size) _xs_realloc(ptr, size, __FILE__, __LINE__, __FUNCTION__) 54#define xs_realloc(ptr, size) _xs_realloc(ptr, size, __FILE__, __LINE__, __FUNCTION__)
diff --git a/xs_json.h b/xs_json.h
index 1494fe8..6706d7e 100644
--- a/xs_json.h
+++ b/xs_json.h
@@ -328,7 +328,7 @@ static xs_val *_xs_json_load_lexer(FILE *f, js_type *t)
328 328
329int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c) 329int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c)
330/* loads the next scalar value from the JSON stream */ 330/* loads the next scalar value from the JSON stream */
331/* if the value ahead is complex, value is NULL and pt is filled */ 331/* if the value ahead is compound, value is NULL and pt is set */
332{ 332{
333 js_type t; 333 js_type t;
334 334
@@ -348,7 +348,7 @@ int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c)
348 } 348 }
349 349
350 if (*value == NULL) { 350 if (*value == NULL) {
351 /* possible complex type ahead */ 351 /* possible compound type ahead */
352 if (t == JS_OBRACK) 352 if (t == JS_OBRACK)
353 *pt = XSTYPE_LIST; 353 *pt = XSTYPE_LIST;
354 else 354 else
@@ -365,7 +365,7 @@ int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c)
365 365
366 366
367xs_list *xs_json_load_array(FILE *f) 367xs_list *xs_json_load_array(FILE *f)
368/* loads a JSON array (after the initial OBRACK) */ 368/* loads a full JSON array (after the initial OBRACK) */
369{ 369{
370 xstype t; 370 xstype t;
371 xs_list *l = xs_list_new(); 371 xs_list *l = xs_list_new();
@@ -406,7 +406,7 @@ xs_list *xs_json_load_array(FILE *f)
406 406
407int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt, int *c) 407int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt, int *c)
408/* loads the next key and scalar value from the JSON stream */ 408/* loads the next key and scalar value from the JSON stream */
409/* if the value ahead is complex, value is NULL and pt is filled */ 409/* if the value ahead is compound, value is NULL and pt is set */
410{ 410{
411 js_type t; 411 js_type t;
412 412
@@ -453,7 +453,7 @@ int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt,
453 453
454 454
455xs_dict *xs_json_load_object(FILE *f) 455xs_dict *xs_json_load_object(FILE *f)
456/* loads a JSON object (after the initial OCURLY) */ 456/* loads a full JSON object (after the initial OCURLY) */
457{ 457{
458 xstype t; 458 xstype t;
459 xs_dict *d = xs_dict_new(); 459 xs_dict *d = xs_dict_new();
diff --git a/xs_mime.h b/xs_mime.h
index 84af49c..853b092 100644
--- a/xs_mime.h
+++ b/xs_mime.h
@@ -55,19 +55,23 @@ const char *xs_mime_by_ext(const char *file)
55 const char *ext = strrchr(file, '.'); 55 const char *ext = strrchr(file, '.');
56 56
57 if (ext) { 57 if (ext) {
58 const char **p = xs_mime_types; 58 xs *uext = xs_tolower_i(xs_dup(ext + 1));
59 xs *uext = xs_tolower_i(xs_dup(ext + 1)); 59 int b = 0;
60 int t = xs_countof(xs_mime_types) / 2 - 2;
60 61
61 while (*p) { 62 while (t >= b) {
62 int c; 63 int n = (b + t) / 2;
64 const char *p = xs_mime_types[n * 2];
63 65
64 if ((c = strcmp(*p, uext)) == 0) 66 int c = strcmp(uext, p);
65 return p[1]; 67
68 if (c < 0)
69 t = n - 1;
66 else 70 else
67 if (c > 0) 71 if (c > 0)
68 break; 72 b = n + 1;
69 73 else
70 p += 2; 74 return xs_mime_types[(n * 2) + 1];
71 } 75 }
72 } 76 }
73 77
diff --git a/xs_unicode.h b/xs_unicode.h
index 47e1101..6654da4 100644
--- a/xs_unicode.h
+++ b/xs_unicode.h
@@ -27,8 +27,8 @@
27 27
28#ifdef XS_IMPLEMENTATION 28#ifdef XS_IMPLEMENTATION
29 29
30#ifndef countof 30#ifndef xs_countof
31#define countof(a) (sizeof((a)) / sizeof((*a))) 31#define xs_countof(a) (sizeof((a)) / sizeof((*a)))
32#endif 32#endif
33 33
34int _xs_utf8_enc(char buf[4], unsigned int cpoint) 34int _xs_utf8_enc(char buf[4], unsigned int cpoint)
@@ -125,7 +125,7 @@ int xs_unicode_width(unsigned int cpoint)
125/* returns the width in columns of a Unicode codepoint (somewhat simplified) */ 125/* returns the width in columns of a Unicode codepoint (somewhat simplified) */
126{ 126{
127 int b = 0; 127 int b = 0;
128 int t = countof(xs_unicode_width_table) / 3 - 1; 128 int t = xs_countof(xs_unicode_width_table) / 3 - 1;
129 129
130 while (t >= b) { 130 while (t >= b) {
131 int n = (b + t) / 2; 131 int n = (b + t) / 2;
@@ -193,7 +193,7 @@ unsigned int *_xs_unicode_upper_search(unsigned int cpoint)
193/* searches for an uppercase codepoint in the case fold table */ 193/* searches for an uppercase codepoint in the case fold table */
194{ 194{
195 int b = 0; 195 int b = 0;
196 int t = countof(xs_unicode_case_fold_table) / 2 + 1; 196 int t = xs_countof(xs_unicode_case_fold_table) / 2 + 1;
197 197
198 while (t >= b) { 198 while (t >= b) {
199 int n = (b + t) / 2; 199 int n = (b + t) / 2;
@@ -216,7 +216,7 @@ unsigned int *_xs_unicode_lower_search(unsigned int cpoint)
216/* searches for a lowercase codepoint in the case fold table */ 216/* searches for a lowercase codepoint in the case fold table */
217{ 217{
218 unsigned int *p = xs_unicode_case_fold_table; 218 unsigned int *p = xs_unicode_case_fold_table;
219 unsigned int *e = p + countof(xs_unicode_case_fold_table); 219 unsigned int *e = p + xs_countof(xs_unicode_case_fold_table);
220 220
221 while (p < e) { 221 while (p < e) {
222 if (cpoint == p[1]) 222 if (cpoint == p[1])
@@ -251,7 +251,7 @@ int xs_unicode_nfd(unsigned int cpoint, unsigned int *base, unsigned int *diac)
251/* applies unicode Normalization Form D */ 251/* applies unicode Normalization Form D */
252{ 252{
253 int b = 0; 253 int b = 0;
254 int t = countof(xs_unicode_nfd_table) / 3 - 1; 254 int t = xs_countof(xs_unicode_nfd_table) / 3 - 1;
255 255
256 while (t >= b) { 256 while (t >= b) {
257 int n = (b + t) / 2; 257 int n = (b + t) / 2;
@@ -279,7 +279,7 @@ int xs_unicode_nfc(unsigned int base, unsigned int diac, unsigned int *cpoint)
279/* applies unicode Normalization Form C */ 279/* applies unicode Normalization Form C */
280{ 280{
281 unsigned int *p = xs_unicode_nfd_table; 281 unsigned int *p = xs_unicode_nfd_table;
282 unsigned int *e = p + countof(xs_unicode_nfd_table); 282 unsigned int *e = p + xs_countof(xs_unicode_nfd_table);
283 283
284 while (p < e) { 284 while (p < e) {
285 if (p[1] == base && p[2] == diac) { 285 if (p[1] == base && p[2] == diac) {
@@ -298,7 +298,7 @@ int xs_unicode_is_alpha(unsigned int cpoint)
298/* checks if a codepoint is an alpha (i.e. a letter) */ 298/* checks if a codepoint is an alpha (i.e. a letter) */
299{ 299{
300 int b = 0; 300 int b = 0;
301 int t = countof(xs_unicode_alpha_table) / 2 - 1; 301 int t = xs_countof(xs_unicode_alpha_table) / 2 - 1;
302 302
303 while (t >= b) { 303 while (t >= b) {
304 int n = (b + t) / 2; 304 int n = (b + t) / 2;
diff --git a/xs_url.h b/xs_url.h
index f335709..6c9c8b5 100644
--- a/xs_url.h
+++ b/xs_url.h
@@ -56,7 +56,7 @@ xs_dict *xs_url_vars(const char *str)
56 56
57 l = args; 57 l = args;
58 while (xs_list_iter(&l, &v)) { 58 while (xs_list_iter(&l, &v)) {
59 xs *kv = xs_split_n(v, "=", 2); 59 xs *kv = xs_split_n(v, "=", 1);
60 60
61 if (xs_list_len(kv) == 2) { 61 if (xs_list_len(kv) == 2) {
62 const char *key = xs_list_get(kv, 0); 62 const char *key = xs_list_get(kv, 0);
diff --git a/xs_version.h b/xs_version.h
index ef52120..f655735 100644
--- a/xs_version.h
+++ b/xs_version.h
@@ -1 +1 @@
/* 0df383371d207b0adfda40912ee54b37e5b01152 2024-03-15T03:45:39+01:00 */ /* f712d1336ef427c3b56305364b2687578537543f 2024-04-14T19:11:53+02:00 */