[PATCH v2 06/11] sprinter: add unsigned_long printer function

Jani Nikula jani at nikula.org
Tue May 23 09:53:12 PDT 2017


On Fri, 19 May 2017, Ioan-Adrian Ratiu <adi at adirat.com> wrote:
> We need to output unsigned long values for message and thread
> (sum of all message's) file sizes.

The sprinter types should be about the types that can be represented
using the format being output, i.e. JSON and S-Expressions, *not* about
the C types. I'd rather see the integer sprinter functions expanded to a
bigger type.

BR,
Jani.


>
> Signed-off-by: Ioan-Adrian Ratiu <adi at adirat.com>
> ---
>  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 0a077907..de1dbec2 100644
> --- a/sprinter-json.c
> +++ b/sprinter-json.c
> @@ -132,6 +132,14 @@ json_integer (struct sprinter *sp, int val)
>  }
>  
>  static void
> +json_unsigned_long (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, notmuch_bool_t val)
>  {
>      struct sprinter_json *spj = json_begin_value (sp);
> @@ -181,6 +189,7 @@ sprinter_json_create (const void *ctx, FILE *stream)
>  	    .string = json_string,
>  	    .string_len = json_string_len,
>  	    .integer = json_integer,
> +	    .unsigned_long = json_unsigned_long,
>  	    .boolean = json_boolean,
>  	    .null = json_null,
>  	    .map_key = json_map_key,
> diff --git a/sprinter-sexp.c b/sprinter-sexp.c
> index 08783e11..3162ad9c 100644
> --- a/sprinter-sexp.c
> +++ b/sprinter-sexp.c
> @@ -169,6 +169,14 @@ sexp_integer (struct sprinter *sp, int val)
>  }
>  
>  static void
> +sexp_unsigned_long (struct sprinter *sp, unsigned long val)
> +{
> +    struct sprinter_sexp *sps = sexp_begin_value (sp);
> +
> +    fprintf (sps->stream, "%lu", val);
> +}
> +
> +static void
>  sexp_boolean (struct sprinter *sp, notmuch_bool_t val)
>  {
>      struct sprinter_sexp *sps = sexp_begin_value (sp);
> @@ -216,6 +224,7 @@ sprinter_sexp_create (const void *ctx, FILE *stream)
>  	    .string = sexp_string,
>  	    .string_len = sexp_string_len,
>  	    .integer = sexp_integer,
> +	    .unsigned_long = sexp_unsigned_long,
>  	    .boolean = sexp_boolean,
>  	    .null = sexp_null,
>  	    .map_key = sexp_map_key,
> diff --git a/sprinter-text.c b/sprinter-text.c
> index 7779488f..5d1607e9 100644
> --- a/sprinter-text.c
> +++ b/sprinter-text.c
> @@ -52,6 +52,14 @@ text_integer (struct sprinter *sp, int val)
>  }
>  
>  static void
> +text_unsigned_long (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, notmuch_bool_t val)
>  {
>      struct sprinter_text *sptxt = (struct sprinter_text *) sp;
> @@ -123,6 +131,7 @@ sprinter_text_create (const void *ctx, FILE *stream)
>  	    .string = text_string,
>  	    .string_len = text_string_len,
>  	    .integer = text_integer,
> +	    .unsigned_long = text_unsigned_long,
>  	    .boolean = text_boolean,
>  	    .null = text_null,
>  	    .map_key = text_map_key,
> diff --git a/sprinter.h b/sprinter.h
> index f859672f..2495a7d1 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 (*unsigned_long) (struct sprinter *, unsigned long);
>      void (*boolean) (struct sprinter *, notmuch_bool_t);
>      void (*null) (struct sprinter *);
>  
> -- 
> 2.13.0
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list