* [PATCH 1/2] sprinter: add text0 formatter for null character separated text
@ 2012-12-06 22:29 Jani Nikula
2012-12-06 22:29 ` [PATCH 2/2] cli: add --format=text0 to notmuch search Jani Nikula
0 siblings, 1 reply; 2+ messages in thread
From: Jani Nikula @ 2012-12-06 22:29 UTC (permalink / raw)
To: notmuch
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 912a526..74e7fec 100644
--- a/sprinter.h
+++ b/sprinter.h
@@ -66,6 +66,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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] cli: add --format=text0 to notmuch search
2012-12-06 22:29 [PATCH 1/2] sprinter: add text0 formatter for null character separated text Jani Nikula
@ 2012-12-06 22:29 ` Jani Nikula
0 siblings, 0 replies; 2+ messages in thread
From: Jani Nikula @ 2012-12-06 22:29 UTC (permalink / raw)
To: notmuch
Add new format text0, which is otherwise the same as text, but use the
null character as separator instead of the newline character. This is
similar to find(1) -print0 option, and works together with the
xargs(1) -0 option.
---
notmuch-search.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/notmuch-search.c b/notmuch-search.c
index 830c4e4..cd02b1d 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -305,8 +305,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
int exclude = EXCLUDE_TRUE;
unsigned int i;
- enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }
- format_sel = NOTMUCH_FORMAT_TEXT;
+ enum {
+ NOTMUCH_FORMAT_JSON,
+ NOTMUCH_FORMAT_TEXT,
+ NOTMUCH_FORMAT_TEXT0,
+ } format_sel = NOTMUCH_FORMAT_TEXT;
notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, &sort, "sort", 's',
@@ -316,6 +319,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
{ NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
(notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
{ "text", NOTMUCH_FORMAT_TEXT },
+ { "text0", NOTMUCH_FORMAT_TEXT0 },
{ 0, 0 } } },
{ NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
(notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
@@ -344,6 +348,9 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
case NOTMUCH_FORMAT_TEXT:
format = sprinter_text_create (ctx, stdout);
break;
+ case NOTMUCH_FORMAT_TEXT0:
+ format = sprinter_text0_create (ctx, stdout);
+ break;
case NOTMUCH_FORMAT_JSON:
format = sprinter_json_create (ctx, stdout);
break;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-12-06 22:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-06 22:29 [PATCH 1/2] sprinter: add text0 formatter for null character separated text Jani Nikula
2012-12-06 22:29 ` [PATCH 2/2] cli: add --format=text0 to notmuch search Jani Nikula
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).