[PATCH 13/14] cli: sprinter should be able to print an unsigned long

Subject: [PATCH 13/14] cli: sprinter should be able to print an unsigned long

Date: Wed, 4 Dec 2019 00:52:01 -0500

To: Notmuch Mail

Cc:

From: Daniel Kahn Gillmor


In some circumstances, we will encounter an unsigned long, and need to
emit it textually.

For example, in GPGME, the gpgme_signature_t object has members
(`created` and `expires`) that are unsigned long integers.  notmuch
doesn't use GPGME directly, but subsequent changes will make it clear
why we need to do have this capability.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
---
 sprinter-json.c | 9 +++++++++
 sprinter-sexp.c | 9 +++++++++
 sprinter-text.c | 9 +++++++++
 sprinter.h      | 1 +
 4 files changed, 28 insertions(+)

diff --git a/sprinter-json.c b/sprinter-json.c
index c6ec8577..0fc734f7 100644
--- a/sprinter-json.c
+++ b/sprinter-json.c
@@ -131,6 +131,14 @@ json_integer (struct sprinter *sp, int val)
     fprintf (spj->stream, "%d", val);
 }
 
+static void
+json_ulong (struct sprinter *sp, unsigned long val)
+{
+    struct sprinter_json *spj = json_begin_value (sp);
+
+    fprintf (spj->stream, "%lu", val);
+}
+
 static void
 json_boolean (struct sprinter *sp, bool val)
 {
@@ -181,6 +189,7 @@ sprinter_json_create (const void *ctx, FILE *stream)
 	    .string = json_string,
 	    .string_len = json_string_len,
 	    .integer = json_integer,
+	    .ulong = json_ulong,
 	    .boolean = json_boolean,
 	    .null = json_null,
 	    .map_key = json_map_key,
diff --git a/sprinter-sexp.c b/sprinter-sexp.c
index 6891ea42..72f23f4d 100644
--- a/sprinter-sexp.c
+++ b/sprinter-sexp.c
@@ -168,6 +168,14 @@ sexp_integer (struct sprinter *sp, int val)
     fprintf (sps->stream, "%d", val);
 }
 
+static void
+sexp_ulong (struct sprinter *sp, unsigned long val)
+{
+    struct sprinter_sexp *sps = (struct sprinter_sexp *) sp;
+
+    fprintf (sps->stream, "%lu", val);
+}
+
 static void
 sexp_boolean (struct sprinter *sp, bool val)
 {
@@ -216,6 +224,7 @@ sprinter_sexp_create (const void *ctx, FILE *stream)
 	    .string = sexp_string,
 	    .string_len = sexp_string_len,
 	    .integer = sexp_integer,
+	    .ulong = sexp_ulong,
 	    .boolean = sexp_boolean,
 	    .null = sexp_null,
 	    .map_key = sexp_map_key,
diff --git a/sprinter-text.c b/sprinter-text.c
index 648b54b1..2c6f635e 100644
--- a/sprinter-text.c
+++ b/sprinter-text.c
@@ -51,6 +51,14 @@ text_integer (struct sprinter *sp, int val)
     fprintf (sptxt->stream, "%d", val);
 }
 
+static void
+text_ulong (struct sprinter *sp, unsigned long val)
+{
+    struct sprinter_text *sptxt = (struct sprinter_text *) sp;
+
+    fprintf (sptxt->stream, "%lu", val);
+}
+
 static void
 text_boolean (struct sprinter *sp, bool val)
 {
@@ -123,6 +131,7 @@ sprinter_text_create (const void *ctx, FILE *stream)
 	    .string = text_string,
 	    .string_len = text_string_len,
 	    .integer = text_integer,
+	    .ulong = text_ulong,
 	    .boolean = text_boolean,
 	    .null = text_null,
 	    .map_key = text_map_key,
diff --git a/sprinter.h b/sprinter.h
index 182b1a8b..3c23d718 100644
--- a/sprinter.h
+++ b/sprinter.h
@@ -34,6 +34,7 @@ typedef struct sprinter {
     void (*string)(struct sprinter *, const char *);
     void (*string_len)(struct sprinter *, const char *, size_t);
     void (*integer)(struct sprinter *, int);
+    void (*ulong)(struct sprinter *, unsigned long);
     void (*boolean)(struct sprinter *, bool);
     void (*null)(struct sprinter *);
 
-- 
2.24.0

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: