X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=sprinter-json.c;h=273bdeca3d736dcb16f90acdf4ee6377efb281d0;hp=0a077907cd83368c339c320968ef2b8a5e91f7d8;hb=HEAD;hpb=94c3b40d41f1ad98719d411ef28b69075fda0579 diff --git a/sprinter-json.c b/sprinter-json.c index 0a077907..502f89fb 100644 --- a/sprinter-json.c +++ b/sprinter-json.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -13,14 +14,14 @@ struct sprinter_json { /* A flag to signify that a separator should be inserted in the * output as soon as possible. */ - notmuch_bool_t insert_separator; + bool insert_separator; }; struct json_state { struct json_state *parent; /* True if nothing has been printed in this aggregate yet. * Suppresses the comma before a value. */ - notmuch_bool_t first; + bool first; /* The character that closes the current aggregate. */ char close; }; @@ -37,12 +38,12 @@ json_begin_value (struct sprinter *sp) fputc (',', spj->stream); if (spj->insert_separator) { fputc ('\n', spj->stream); - spj->insert_separator = FALSE; + spj->insert_separator = false; } else { fputc (' ', spj->stream); } } else { - spj->state->first = FALSE; + spj->state->first = false; } } return spj; @@ -58,7 +59,7 @@ json_begin_aggregate (struct sprinter *sp, char open, char close) fputc (open, spj->stream); state->parent = spj->state; - state->first = TRUE; + state->first = true; state->close = close; spj->state = state; } @@ -124,15 +125,15 @@ json_string (struct sprinter *sp, const char *val) } static void -json_integer (struct sprinter *sp, int val) +json_integer (struct sprinter *sp, int64_t val) { struct sprinter_json *spj = json_begin_value (sp); - fprintf (spj->stream, "%d", val); + fprintf (spj->stream, "%" PRId64, val); } static void -json_boolean (struct sprinter *sp, notmuch_bool_t val) +json_boolean (struct sprinter *sp, bool val) { struct sprinter_json *spj = json_begin_value (sp); @@ -154,7 +155,7 @@ json_map_key (struct sprinter *sp, const char *key) json_string (sp, key); fputs (": ", spj->stream); - spj->state->first = TRUE; + spj->state->first = true; } static void @@ -167,11 +168,11 @@ json_separator (struct sprinter *sp) { struct sprinter_json *spj = (struct sprinter_json *) sp; - spj->insert_separator = TRUE; + spj->insert_separator = true; } struct sprinter * -sprinter_json_create (const void *ctx, FILE *stream) +sprinter_json_create (notmuch_database_t *db, FILE *stream) { static const struct sprinter_json template = { .vtable = { @@ -186,16 +187,17 @@ sprinter_json_create (const void *ctx, FILE *stream) .map_key = json_map_key, .separator = json_separator, .set_prefix = json_set_prefix, - .is_text_printer = FALSE, + .is_text_printer = false, } }; struct sprinter_json *res; - res = talloc (ctx, struct sprinter_json); + res = talloc (db, struct sprinter_json); if (! res) return NULL; *res = template; + res->vtable.notmuch = db; res->stream = stream; return &res->vtable; }