talfmt take a ctx pointer and return NULL or a valid pointer. * fmt takes the argument, and returns a bool. * * This function returns NULL on success, or errmsg on failure. */
| 179 | * This function returns NULL on success, or errmsg on failure. |
| 180 | */ |
| 181 | static const char *handle_percent(const char *buffer, |
| 182 | const jsmntok_t *tok, |
| 183 | va_list *ap) |
| 184 | { |
| 185 | void *ctx; |
| 186 | const char *fmtname; |
| 187 | |
| 188 | /* This is set to (dummy) json_scan if it's a non-tal fmt */ |
| 189 | ctx = va_arg(*ap, void *); |
| 190 | fmtname = va_arg(*ap, const char *); |
| 191 | if (ctx != json_scan) { |
| 192 | void *(*talfmt)(void *, const char *, const jsmntok_t *); |
| 193 | void **p; |
| 194 | p = va_arg(*ap, void **); |
| 195 | talfmt = va_arg(*ap, void *(*)(void *, const char *, const jsmntok_t *)); |
| 196 | *p = talfmt(ctx, buffer, tok); |
| 197 | if (*p != NULL) |
| 198 | return NULL; |
| 199 | } else { |
| 200 | bool (*fmt)(const char *, const jsmntok_t *, void *); |
| 201 | void *p; |
| 202 | |
| 203 | p = va_arg(*ap, void *); |
| 204 | fmt = va_arg(*ap, bool (*)(const char *, const jsmntok_t *, void *)); |
| 205 | if (fmt(buffer, tok, p)) |
| 206 | return NULL; |
| 207 | } |
| 208 | |
| 209 | return tal_fmt(tmpctx, "%s could not parse %.*s", |
| 210 | fmtname, |
| 211 | json_tok_full_len(tok), |
| 212 | json_tok_full(buffer, tok)); |
| 213 | } |
| 214 | |
| 215 | /* GUIDE := OBJ | ARRAY | '%' |
| 216 | * OBJ := '{' FIELDLIST '}' |
no test coverage detected