X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=sprinter-text.c;h=648b54b1e886553cd839ca24f4f5f0a9378aa47b;hp=b208840be72df7d0b2431737abb0f0c28b760eac;hb=b23902a61158ecdbca2d9d96c6eaf509d6e3d205;hpb=36522fca1cac6ca23c2c4c0280e3e20e96f7bfbb diff --git a/sprinter-text.c b/sprinter-text.c index b208840b..648b54b1 100644 --- a/sprinter-text.c +++ b/sprinter-text.c @@ -21,18 +21,26 @@ struct sprinter_text { /* A flag to indicate if this is the first tag. Used in list of tags * for summary. */ - notmuch_bool_t first_tag; + bool first_tag; }; static void -text_string (struct sprinter *sp, const char *val) +text_string_len (struct sprinter *sp, const char *val, size_t len) { struct sprinter_text *sptxt = (struct sprinter_text *) sp; if (sptxt->current_prefix != NULL) fprintf (sptxt->stream, "%s:", sptxt->current_prefix); - fputs(val, sptxt->stream); + fwrite (val, len, 1, sptxt->stream); +} + +static void +text_string (struct sprinter *sp, const char *val) +{ + if (val == NULL) + val = ""; + text_string_len (sp, val, strlen (val)); } static void @@ -44,7 +52,7 @@ text_integer (struct sprinter *sp, int val) } static void -text_boolean (struct sprinter *sp, notmuch_bool_t val) +text_boolean (struct sprinter *sp, bool val) { struct sprinter_text *sptxt = (struct sprinter_text *) sp; @@ -59,6 +67,14 @@ text_separator (struct sprinter *sp) fputc ('\n', sptxt->stream); } +static void +text0_separator (struct sprinter *sp) +{ + struct sprinter_text *sptxt = (struct sprinter_text *) sp; + + fputc ('\0', sptxt->stream); +} + static void text_set_prefix (struct sprinter *sp, const char *prefix) { @@ -105,13 +121,14 @@ sprinter_text_create (const void *ctx, FILE *stream) .begin_list = text_begin_list, .end = text_end, .string = text_string, + .string_len = text_string_len, .integer = text_integer, .boolean = text_boolean, .null = text_null, .map_key = text_map_key, .separator = text_separator, .set_prefix = text_set_prefix, - .is_text_printer = TRUE, + .is_text_printer = true, }, }; struct sprinter_text *res; @@ -124,3 +141,17 @@ sprinter_text_create (const void *ctx, FILE *stream) res->stream = stream; return &res->vtable; } + +struct sprinter * +sprinter_text0_create (const void *ctx, FILE *stream) +{ + struct sprinter *sp; + + sp = sprinter_text_create (ctx, stream); + if (! sp) + return NULL; + + sp->separator = text0_separator; + + return sp; +}