diff options
| author | user <user@clank> | 2026-08-17 14:22:38 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-17 14:22:38 +0200 |
| commit | ec91ccffe631ae34b111bf6161fd0e3c487f684c (patch) | |
| tree | 4a9fdbb720d9bf03edd5f538d1d87afd2bf51bfb /src/jsonval.c | |
| parent | sl0ppty: clang-format, and a hook that runs it on what you staged (diff) | |
| download | slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.tar.gz slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.tar.xz slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.zip | |
sl0ppty: clang-format the tree
The bumpy one. `make fmt` over every `.c` and `.h` outside `vendor/`: 32 files,
1,843 lines rewritten, no behaviour changed. Nothing here is worth reading -- the
next commit adds it to `.git-blame-ignore-revs` so `git blame` walks past it.
Two thirds of it is alignment the formatter now owns: trailing comments in a
struct, continuation lines under a signature. The rest is the hand-packed tables
opening up to one entry per line -- `ACTIONS`, `NAMED_KEYS`, `ACTION_HELP`. That
is a real loss of density and a real gain in diffs: adding an action was a reflow
of the block and is now one line. Anything worth keeping packed can be fenced with
`// clang-format off`; nothing was, on the grounds that a table is the thing a
formatter is for.
**One change is not formatting.** `src/config.h` had three trailing comments glued
onto one field:
uint16_t hover_delay_ms; /* how long the pointer must rest to arm a guide */
/* how long an announcement stays up */ /* rows per wheel notch */
-- `toast_ms`'s and `scroll_lines`' comments, landed on their neighbour by an
earlier edit, documenting the wrong things ever since. It is in this commit
because it is what caught it: clang-format could not settle on that line, wrapping
it one way and then re-indenting the wrap on a second pass, so `make fmt` was not
idempotent. The comments are back where they belong and it is.
Verified after the reformat, not before: `make clean && make all` is
warning-free, `make retest` is 1801 checks green, and `make fmt` twice in a row
changes nothing the second time. A formatter that alters behaviour would be worse
than none, so the gate was the whole suite rather than a reading of the diff.
Diffstat (limited to 'src/jsonval.c')
| -rw-r--r-- | src/jsonval.c | 102 |
1 files changed, 67 insertions, 35 deletions
diff --git a/src/jsonval.c b/src/jsonval.c index acc3334..bd718b1 100644 --- a/src/jsonval.c +++ b/src/jsonval.c @@ -12,7 +12,8 @@ typedef struct { static jv_t *parse_value(P *s); static void skip_ws(P *s) { - while (*s->p == ' ' || *s->p == '\t' || *s->p == '\n' || *s->p == '\r') s->p++; + while (*s->p == ' ' || *s->p == '\t' || *s->p == '\n' || *s->p == '\r') + s->p++; } static jv_t *jv_new(jv_kind_t k) { @@ -23,7 +24,8 @@ static jv_t *jv_new(jv_kind_t k) { static void utf8_put(char **out, unsigned cp) { char *o = *out; - if (cp < 0x80) *o++ = (char)cp; + if (cp < 0x80) + *o++ = (char)cp; else if (cp < 0x800) { *o++ = (char)(0xc0 | (cp >> 6)); *o++ = (char)(0x80 | (cp & 0x3f)); @@ -45,9 +47,12 @@ static unsigned hex4(const char *p) { for (int i = 0; i < 4; i++) { char c = p[i]; v <<= 4; - if (c >= '0' && c <= '9') v |= (unsigned)(c - '0'); - else if (c >= 'a' && c <= 'f') v |= (unsigned)(c - 'a' + 10); - else if (c >= 'A' && c <= 'F') v |= (unsigned)(c - 'A' + 10); + if (c >= '0' && c <= '9') + v |= (unsigned)(c - '0'); + else if (c >= 'a' && c <= 'f') + v |= (unsigned)(c - 'a' + 10); + else if (c >= 'A' && c <= 'F') + v |= (unsigned)(c - 'A' + 10); } return v; } @@ -66,29 +71,29 @@ static char *parse_string_raw(P *s, size_t *out_len) { if (*s->p == '\\') { s->p++; switch (*s->p) { - case 'n': *o++ = '\n'; break; - case 't': *o++ = '\t'; break; - case 'r': *o++ = '\r'; break; - case 'b': *o++ = '\b'; break; - case 'f': *o++ = '\f'; break; - case '/': *o++ = '/'; break; - case '"': *o++ = '"'; break; - case '\\': *o++ = '\\'; break; - case 'u': { - unsigned cp = hex4(s->p + 1); - s->p += 4; - if (cp >= 0xd800 && cp < 0xdc00 && s->p[1] == '\\' && s->p[2] == 'u') { - unsigned lo = hex4(s->p + 3); - s->p += 6; - cp = 0x10000 + ((cp - 0xd800) << 10) + (lo - 0xdc00); - } - utf8_put(&o, cp); - break; + case 'n': *o++ = '\n'; break; + case 't': *o++ = '\t'; break; + case 'r': *o++ = '\r'; break; + case 'b': *o++ = '\b'; break; + case 'f': *o++ = '\f'; break; + case '/': *o++ = '/'; break; + case '"': *o++ = '"'; break; + case '\\': *o++ = '\\'; break; + case 'u': { + unsigned cp = hex4(s->p + 1); + s->p += 4; + if (cp >= 0xd800 && cp < 0xdc00 && s->p[1] == '\\' && s->p[2] == 'u') { + unsigned lo = hex4(s->p + 3); + s->p += 6; + cp = 0x10000 + ((cp - 0xd800) << 10) + (lo - 0xdc00); } - default: - s->bad = true; - free(buf); - return NULL; + utf8_put(&o, cp); + break; + } + default: + s->bad = true; + free(buf); + return NULL; } s->p++; } else { @@ -121,20 +126,38 @@ static jv_t *parse_value(P *s) { for (;;) { skip_ws(s); char *key = parse_string_raw(s, NULL); - if (s->bad) { jv_free(v); return NULL; } + if (s->bad) { + jv_free(v); + return NULL; + } skip_ws(s); - if (*s->p != ':') { s->bad = true; free(key); jv_free(v); return NULL; } + if (*s->p != ':') { + s->bad = true; + free(key); + jv_free(v); + return NULL; + } s->p++; jv_t *val = parse_value(s); - if (!val) { free(key); jv_free(v); return NULL; } + if (!val) { + free(key); + jv_free(v); + return NULL; + } v->keys = realloc(v->keys, (v->len + 1) * sizeof *v->keys); v->kids = realloc(v->kids, (v->len + 1) * sizeof *v->kids); v->keys[v->len] = key; v->kids[v->len] = val; v->len++; skip_ws(s); - if (*s->p == ',') { s->p++; continue; } - if (*s->p == '}') { s->p++; return v; } + if (*s->p == ',') { + s->p++; + continue; + } + if (*s->p == '}') { + s->p++; + return v; + } s->bad = true; jv_free(v); return NULL; @@ -151,12 +174,21 @@ static jv_t *parse_value(P *s) { } for (;;) { jv_t *val = parse_value(s); - if (!val) { jv_free(v); return NULL; } + if (!val) { + jv_free(v); + return NULL; + } v->kids = realloc(v->kids, (v->len + 1) * sizeof *v->kids); v->kids[v->len++] = val; skip_ws(s); - if (*s->p == ',') { s->p++; continue; } - if (*s->p == ']') { s->p++; return v; } + if (*s->p == ',') { + s->p++; + continue; + } + if (*s->p == ']') { + s->p++; + return v; + } s->bad = true; jv_free(v); return NULL; |
