[PATCH v4 2/5] sprinter: add text0 formatter for null character separated text
Same as the text formatter, but with each field separated by a null character rather than a newline character. --- sprinter-text.c | 22 ++ sprinter.h |6 ++ 2 files changed, 28 insertions(+) diff --git a/sprinter-text.c b/sprinter-text.c index 10343be..7779488 100644 --- a/sprinter-text.c +++ b/sprinter-text.c @@ -68,6 +68,14 @@ text_separator (struct sprinter *sp) } 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) { struct sprinter_text *sptxt = (struct sprinter_text *) sp; @@ -133,3 +141,17 @@ sprinter_text_create (const void *ctx, FILE *stream) res->stream = stream; return >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; +} diff --git a/sprinter.h b/sprinter.h index f43a844..f859672 100644 --- a/sprinter.h +++ b/sprinter.h @@ -67,6 +67,12 @@ typedef struct sprinter { struct sprinter * sprinter_text_create (const void *ctx, FILE *stream); +/* Create a new unstructured printer that emits the text format for + * "notmuch search", with each field separated by a null character + * instead of the newline character. */ +struct sprinter * +sprinter_text0_create (const void *ctx, FILE *stream); + /* Create a new structure printer that emits JSON. */ struct sprinter * sprinter_json_create (const void *ctx, FILE *stream); -- 1.7.10.4
[PATCH v4 2/5] sprinter: add text0 formatter for null character separated text
Same as the text formatter, but with each field separated by a null character rather than a newline character. --- sprinter-text.c | 22 ++ sprinter.h |6 ++ 2 files changed, 28 insertions(+) diff --git a/sprinter-text.c b/sprinter-text.c index 10343be..7779488 100644 --- a/sprinter-text.c +++ b/sprinter-text.c @@ -68,6 +68,14 @@ text_separator (struct sprinter *sp) } 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) { struct sprinter_text *sptxt = (struct sprinter_text *) sp; @@ -133,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; +} diff --git a/sprinter.h b/sprinter.h index f43a844..f859672 100644 --- a/sprinter.h +++ b/sprinter.h @@ -67,6 +67,12 @@ typedef struct sprinter { struct sprinter * sprinter_text_create (const void *ctx, FILE *stream); +/* Create a new unstructured printer that emits the text format for + * notmuch search, with each field separated by a null character + * instead of the newline character. */ +struct sprinter * +sprinter_text0_create (const void *ctx, FILE *stream); + /* Create a new structure printer that emits JSON. */ struct sprinter * sprinter_json_create (const void *ctx, FILE *stream); -- 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch