[WIP2 05/12] cli: add two sprinter utility functions
David Bremner
david at tethera.net
Sun Apr 5 15:59:07 PDT 2015
These are called directly, rather than via a vtable. They will
help add common metadata to search/show/reply
---
devel/schemata | 1 +
sprinter-utils.c | 41 +++++++++++++++++++++++++++++++++++++++++
sprinter.h | 7 +++++++
3 files changed, 49 insertions(+)
create mode 100644 sprinter-utils.c
diff --git a/devel/schemata b/devel/schemata
index 41dc4a6..98a1b2b 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -147,6 +147,7 @@ search_files = [string*]
search_tags = [string*]
thread_summary = {
+ database: database_metadata
thread: threadid,
timestamp: unix_time,
date_relative: string, # user-friendly timestamp
diff --git a/sprinter-utils.c b/sprinter-utils.c
new file mode 100644
index 0000000..2ba588e
--- /dev/null
+++ b/sprinter-utils.c
@@ -0,0 +1,41 @@
+#include "notmuch-client.h"
+#include "sprinter.h"
+
+notmuch_status_t
+sprinter_start_output (sprinter_t *sp,
+ const notmuch_query_t *query,
+ const char *query_type)
+{
+ long int rev;
+ const char *uuid;
+ notmuch_database_t *notmuch;
+
+ sp->begin_list (sp);
+
+ if (sp->type != NOTMUCH_SPRINTER_TEXT && notmuch_format_version >= 3) {
+ notmuch = notmuch_query_get_database (query);
+
+ rev = notmuch_database_get_revision (notmuch, &uuid);
+
+ sp->begin_map (sp);
+ sp->map_key (sp, "query_type");
+ sp->string (sp, query_type);
+
+ sp->map_key (sp, "uuid");
+ sp->string (sp, uuid);
+
+ sp->map_key (sp, "lastmod");
+ sp->integer (sp, rev);
+
+ sp->end (sp);
+
+ }
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
+notmuch_status_t
+sprinter_finish_output (sprinter_t *sp)
+{
+ sp->end (sp); /* map */
+ return NOTMUCH_STATUS_SUCCESS;
+}
diff --git a/sprinter.h b/sprinter.h
index 7e58f69..4873f69 100644
--- a/sprinter.h
+++ b/sprinter.h
@@ -91,4 +91,11 @@ sprinter_json_create (const void *ctx, FILE *stream);
struct sprinter *
sprinter_sexp_create (const void *ctx, FILE *stream);
+notmuch_status_t
+sprinter_start_output (struct sprinter *sp,
+ const notmuch_query_t *query,
+ const char *query_type);
+
+notmuch_status_t
+sprinter_finish_output (struct sprinter *sp);
#endif // NOTMUCH_SPRINTER_H
--
2.1.4
More information about the notmuch
mailing list