Re: [PATCH] notmuch-emacs-mua: make --auto-daemon imply --create-frame
[notmuch-archives.git] / 4e / 024ce6281551912a6e058076ff8c03fb0cac76
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id BD101429E3A\r
6         for <notmuch@notmuchmail.org>; Thu,  2 Aug 2012 18:15:10 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id HuF7U1DehA9G for <notmuch@notmuchmail.org>;\r
16         Thu,  2 Aug 2012 18:15:09 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
18         [18.7.68.37])\r
19         by olra.theworths.org (Postfix) with ESMTP id 1B500431E64\r
20         for <notmuch@notmuchmail.org>; Thu,  2 Aug 2012 18:15:08 -0700 (PDT)\r
21 X-AuditID: 12074425-b7f9b6d0000008c4-ba-501b261b242f\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id D8.BD.02244.B162B105; Thu,  2 Aug 2012 21:15:07 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q731F6dw012765; \r
27         Thu, 2 Aug 2012 21:15:06 -0400\r
28 Received: from drake.dyndns.org\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q731F4Hj002786\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Thu, 2 Aug 2012 21:15:05 -0400 (EDT)\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
36         (envelope-from <amdragon@mit.edu>)\r
37         id 1Sx6To-0003wE-3m; Thu, 02 Aug 2012 21:15:04 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v3 03/13] sprinter: Add a string_len method\r
41 Date: Thu,  2 Aug 2012 21:14:49 -0400\r
42 Message-Id: <1343956499-14543-4-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.10\r
44 In-Reply-To: <1343956499-14543-1-git-send-email-amdragon@mit.edu>\r
45 References: <1343956499-14543-1-git-send-email-amdragon@mit.edu>\r
46 X-Brightmail-Tracker:\r
47  H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrCutJh1g8GGPrMXquTwW12/OZLZ4\r
48         s3IeqwOzx85Zd9k9Dn9dyOLxbNUt5gDmKC6blNSczLLUIn27BK6MWU39jAWbFCq2TL3N0sA4\r
49         UbKLkZNDQsBE4vrdT2wQtpjEhXvrgWwuDiGBfYwSh570MIEkhATWM0o8mW8CkXjIJLHl2Guo\r
50         qrmMEp+nvgdrZxPQkNi2fzkjiC0iIC2x8+5sVhCbWSBOYsuU/2BxYQFriVc7L4BNZRFQlZiy\r
51         6jtQDQcHr4CDxNP+IIgr5CWe3u8DG8kp4Cjx+u0rRogjHCSWt3WzTmDkX8DIsIpRNiW3Sjc3\r
52         MTOnODVZtzg5MS8vtUjXQi83s0QvNaV0EyMotNhdVHcwTjikdIhRgINRiYfXSFI6QIg1say4\r
53         MvcQoyQHk5IoL7MSUIgvKT+lMiOxOCO+qDQntfgQowQHs5IIb9USqQAh3pTEyqrUonyYlDQH\r
54         i5I4742Um/5CAumJJanZqakFqUUwWRkODiUJXllVoKGCRanpqRVpmTklCGkmDk6Q4TxAw+1B\r
55         aniLCxJzizPTIfKnGBWlxHnZQRICIImM0jy4Xljsv2IUB3pFmPeCClAVDzBtwHW/AhrMBDTY\r
56         zgzk6uKSRISUVANj7tqWCXVL/zCqaHrcUz/gLvzTMjqj68EmbcemWwWtUufc+h9p7ruTW3Zb\r
57         fmvRQ7OFF1p4bO/lN3qIpGR7Cy/Q6pM7tn3xi2VRsndLb+gI759YGvxPR/BHhJ2OsAyzTfkt\r
58         l8PnjX0sCz6tK5si6/E8cFVNdZ57Iu+2N/7s39j1I/7sP7Vk91UlluKMREMt5qLiRAA73IiM\r
59         2AIAAA==\r
60 Cc: tomi.ollila@iki.fi\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65         <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Fri, 03 Aug 2012 01:15:11 -0000\r
74 \r
75 This method allows callers to output strings with specific lengths.\r
76 It's useful both for strings with embedded NULs (which JSON can\r
77 represent, though parser support is apparently spotty), and\r
78 non-terminated strings.\r
79 ---\r
80  sprinter-json.c |   16 ++++++++++++++--\r
81  sprinter-text.c |   11 +++++++++--\r
82  sprinter.h      |    9 ++++++---\r
83  3 files changed, 29 insertions(+), 7 deletions(-)\r
84 \r
85 diff --git a/sprinter-json.c b/sprinter-json.c\r
86 index 4649655..c9b6835 100644\r
87 --- a/sprinter-json.c\r
88 +++ b/sprinter-json.c\r
89 @@ -88,8 +88,13 @@ json_end (struct sprinter *sp)\r
90         fputc ('\n', spj->stream);\r
91  }\r
92  \r
93 +/* This implementation supports embedded NULs as allowed by the JSON\r
94 + * specification and Unicode.  Support for *parsing* embedded NULs\r
95 + * varies, but is generally not a problem outside of C-based parsers\r
96 + * (Python's json module and Emacs' json.el take embedded NULs in\r
97 + * stride). */\r
98  static void\r
99 -json_string (struct sprinter *sp, const char *val)\r
100 +json_string_len (struct sprinter *sp, const char *val, size_t len)\r
101  {\r
102      static const char *const escapes[] = {\r
103         ['\"'] = "\\\"", ['\\'] = "\\\\", ['\b'] = "\\b",\r
104 @@ -98,7 +103,7 @@ json_string (struct sprinter *sp, const char *val)\r
105      struct sprinter_json *spj = json_begin_value (sp);\r
106  \r
107      fputc ('"', spj->stream);\r
108 -    for (; *val; ++val) {\r
109 +    for (; len; ++val, --len) {\r
110         unsigned char ch = *val;\r
111         if (ch < ARRAY_SIZE (escapes) && escapes[ch])\r
112             fputs (escapes[ch], spj->stream);\r
113 @@ -111,6 +116,12 @@ json_string (struct sprinter *sp, const char *val)\r
114  }\r
115  \r
116  static void\r
117 +json_string (struct sprinter *sp, const char *val)\r
118 +{\r
119 +    json_string_len (sp, val, strlen (val));\r
120 +}\r
121 +\r
122 +static void\r
123  json_integer (struct sprinter *sp, int val)\r
124  {\r
125      struct sprinter_json *spj = json_begin_value (sp);\r
126 @@ -166,6 +177,7 @@ sprinter_json_create (const void *ctx, FILE *stream)\r
127             .begin_list = json_begin_list,\r
128             .end = json_end,\r
129             .string = json_string,\r
130 +           .string_len = json_string_len,\r
131             .integer = json_integer,\r
132             .boolean = json_boolean,\r
133             .null = json_null,\r
134 diff --git a/sprinter-text.c b/sprinter-text.c\r
135 index b208840..dfa54b5 100644\r
136 --- a/sprinter-text.c\r
137 +++ b/sprinter-text.c\r
138 @@ -25,14 +25,20 @@ struct sprinter_text {\r
139  };\r
140  \r
141  static void\r
142 -text_string (struct sprinter *sp, const char *val)\r
143 +text_string_len (struct sprinter *sp, const char *val, size_t len)\r
144  {\r
145      struct sprinter_text *sptxt = (struct sprinter_text *) sp;\r
146  \r
147      if (sptxt->current_prefix != NULL)\r
148         fprintf (sptxt->stream, "%s:", sptxt->current_prefix);\r
149  \r
150 -    fputs(val, sptxt->stream);\r
151 +    fwrite (val, len, 1, sptxt->stream);\r
152 +}\r
153 +\r
154 +static void\r
155 +text_string (struct sprinter *sp, const char *val)\r
156 +{\r
157 +    text_string_len (sp, val, strlen (val));\r
158  }\r
159  \r
160  static void\r
161 @@ -105,6 +111,7 @@ sprinter_text_create (const void *ctx, FILE *stream)\r
162             .begin_list = text_begin_list,\r
163             .end = text_end,\r
164             .string = text_string,\r
165 +           .string_len = text_string_len,\r
166             .integer = text_integer,\r
167             .boolean = text_boolean,\r
168             .null = text_null,\r
169 diff --git a/sprinter.h b/sprinter.h\r
170 index 6680d41..5f43175 100644\r
171 --- a/sprinter.h\r
172 +++ b/sprinter.h\r
173 @@ -23,11 +23,14 @@ typedef struct sprinter {\r
174       */\r
175      void (*end) (struct sprinter *);\r
176  \r
177 -    /* Print one string/integer/boolean/null element (possibly inside a\r
178 -     * list or map, followed or preceded by separators).\r
179 -     * For string, the char * must be UTF-8 encoded.\r
180 +    /* Print one string/integer/boolean/null element (possibly inside\r
181 +     * a list or map, followed or preceded by separators).  For string\r
182 +     * and string_len, the char * must be UTF-8 encoded.  string_len\r
183 +     * allows non-terminated strings and strings with embedded NULs\r
184 +     * (though the handling of the latter is format-dependent).\r
185       */\r
186      void (*string) (struct sprinter *, const char *);\r
187 +    void (*string_len) (struct sprinter *, const char *, size_t);\r
188      void (*integer) (struct sprinter *, int);\r
189      void (*boolean) (struct sprinter *, notmuch_bool_t);\r
190      void (*null) (struct sprinter *);\r
191 -- \r
192 1.7.10\r
193 \r