Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id CA721431FB6 for ; Fri, 27 Jul 2012 21:29:42 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YGlnSlrBPbQ8 for ; Fri, 27 Jul 2012 21:29:40 -0700 (PDT) Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU [18.9.25.12]) by olra.theworths.org (Postfix) with ESMTP id 3A49F431FBD for ; Fri, 27 Jul 2012 21:29:28 -0700 (PDT) X-AuditID: 1209190c-b7f806d000006b87-71-50136aa76963 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id 13.00.27527.7AA63105; Sat, 28 Jul 2012 00:29:28 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q6S4TRP1017258; Sat, 28 Jul 2012 00:29:27 -0400 Received: from drake.dyndns.org (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6S4TK8k027350 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 28 Jul 2012 00:29:22 -0400 (EDT) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1SuyeW-0002Wj-81; Sat, 28 Jul 2012 00:29:20 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2 00/13] Convert notmuch show to use structure printers Date: Sat, 28 Jul 2012 00:29:01 -0400 Message-Id: <1343449754-9010-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrBIsWRmVeSWpSXmKPExsUixCmqrLsiSzjA4MIhRou9De2MFqvn8lhc vzmT2eLNynmsDiweO2fdZfdYvGk/m8fhrwtZPJ6tusUcwBLFZZOSmpNZllqkb5fAlXH8wEHG gifiFQd3fmBvYPwm1MXIySEhYCKxseUvG4QtJnHh3nogm4tDSGAfo8TdJ8eZIZwNjBJ3Os8w QjiPmCQO3LjNDuHMZZRoPDSXBaSfTUBDYtv+5YwgtoiAtMTOu7NZQWxmAUeJu78PA83l4BAW 8JBYOzkHJMwioCqxd9M6sHJeAXuJRZ82skKcIS/x9H4f2wRG3gWMDKsYZVNyq3RzEzNzilOT dYuTE/PyUot0DfVyM0v0UlNKNzGCA0iSZwfjm4NKhxgFOBiVeHiVrwsFCLEmlhVX5h5ilORg UhLljQoXDhDiS8pPqcxILM6ILyrNSS0+xCjBwawkwrtTECjHm5JYWZValA+TkuZgURLnvZxy 019IID2xJDU7NbUgtQgmK8PBoSTBuz0TqFGwKDU9tSItM6cEIc3EwQkynAdo+BqQGt7igsTc 4sx0iPwpRkUpcd5JIAkBkERGaR5cLyzCXzGKA70izHsNpIoHmBzgul8BDWYCGmwRLQQyuCQR ISXVwLj1X2fYhBl3j4RuXP9Dge/jJtdwfUm+So95pV2TF8s9NLq7++H3NVK/XG58YZww/Zel PpvAqbYT0usWKicJPd2boVXcx+VqeEC8f8OtJXfNgzXZxXXym2IWf9WumuvqW+c9z7xRU+fP 1uzQbZfeJH7tOvg1/K9FzJuaPVN2FEbPswk+tSSEuVGJpTgj0VCLuag4EQAusRsKywIAAA== Cc: tomi.ollila@iki.fi X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Jul 2012 04:29:43 -0000 This is version 2 of [0]. It adds some comments explaining handling of NUL bytes in strings and moves a few variable assignments closer to their uses. [0] id:1343183693-17134-1-git-send-email-amdragon@mit.edu The diff from version 1 follows. (Note that date was already assigned where it was used in version 1, in addition to being assigned at the beginning of format_message_json; hence the diff diff only shows it being removed). diff --git a/notmuch-show.c b/notmuch-show.c index f5bc098..3556293 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -105,6 +105,8 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message) from, relative_date, tags); } +/* Emit a sequence of key/value pairs for the metadata of message. + * The caller should begin a map before calling this. */ static void format_message_json (sprinter_t *sp, notmuch_message_t *message) { @@ -113,9 +115,6 @@ format_message_json (sprinter_t *sp, notmuch_message_t *message) time_t date; const char *relative_date; - date = notmuch_message_get_date (message); - relative_date = notmuch_time_relative_date (local, date); - sp->map_key (sp, "id"); sp->string (sp, notmuch_message_get_message_id (message)); @@ -133,6 +132,7 @@ format_message_json (sprinter_t *sp, notmuch_message_t *message) sp->integer (sp, date); sp->map_key (sp, "date_relative"); + relative_date = notmuch_time_relative_date (local, date); sp->string (sp, relative_date); sp->map_key (sp, "tags"); diff --git a/sprinter-json.c b/sprinter-json.c index 2587ca6..c9b6835 100644 --- a/sprinter-json.c +++ b/sprinter-json.c @@ -88,6 +88,11 @@ json_end (struct sprinter *sp) fputc ('\n', spj->stream); } +/* This implementation supports embedded NULs as allowed by the JSON + * specification and Unicode. Support for *parsing* embedded NULs + * varies, but is generally not a problem outside of C-based parsers + * (Python's json module and Emacs' json.el take embedded NULs in + * stride). */ static void json_string_len (struct sprinter *sp, const char *val, size_t len) { diff --git a/sprinter.h b/sprinter.h index 826a852..5f43175 100644 --- a/sprinter.h +++ b/sprinter.h @@ -23,9 +23,11 @@ typedef struct sprinter { */ void (*end) (struct sprinter *); - /* Print one string/integer/boolean/null element (possibly inside a - * list or map, followed or preceded by separators). - * For string, the char * must be UTF-8 encoded. + /* Print one string/integer/boolean/null element (possibly inside + * a list or map, followed or preceded by separators). For string + * and string_len, the char * must be UTF-8 encoded. string_len + * allows non-terminated strings and strings with embedded NULs + * (though the handling of the latter is format-dependent). */ void (*string) (struct sprinter *, const char *); void (*string_len) (struct sprinter *, const char *, size_t);