Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / df / ea1c70b51ab15fe794e5191e21347e6eb7c754
1 Return-Path: <peter.feigl@gmx.at>\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 8EC86431FC0\r
6         for <notmuch@notmuchmail.org>; Tue, 10 Jul 2012 11:56:14 -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.001\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.001 tagged_above=-999 required=5\r
12         tests=[FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001]\r
13         autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id Rdh+vVmivbtq for <notmuch@notmuchmail.org>;\r
17         Tue, 10 Jul 2012 11:56:13 -0700 (PDT)\r
18 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.23])\r
19         by olra.theworths.org (Postfix) with SMTP id 4C6AA431FBF\r
20         for <notmuch@notmuchmail.org>; Tue, 10 Jul 2012 11:56:13 -0700 (PDT)\r
21 Received: (qmail invoked by alias); 10 Jul 2012 18:56:10 -0000\r
22 Received: from www.nexoid.at (EHLO mail.nexoid.at) [178.79.130.240]\r
23         by mail.gmx.net (mp031) with SMTP; 10 Jul 2012 20:56:10 +0200\r
24 X-Authenticated: #4563876\r
25 X-Provags-ID: V01U2FsdGVkX19Vb2BisVBVkwwxE2kmexZLYEysiJVDAUaGlOF67S\r
26         B+XR9dIoYuJIEG\r
27 Received: from nexoid (localhost [127.0.0.1])\r
28         by mail.nexoid.at (Postfix) with ESMTP id 4C6AAE00C\r
29         for <notmuch@notmuchmail.org>; Tue, 10 Jul 2012 20:56:09 +0200 (CEST)\r
30 From: <craven@gmx.net>\r
31 To: notmuch@notmuchmail.org\r
32 Subject: [PATCH v3 1/3] Add support for structured output formatters.\r
33 User-Agent: Notmuch/0.11+77~gad6d0d5 (http://notmuchmail.org) Emacs/24.1.50.2\r
34         (i686-pc-linux-gnu)\r
35 Date: Tue, 10 Jul 2012 20:56:09 +0200\r
36 Message-ID: <87394zv41i.fsf@nexoid.at>\r
37 MIME-Version: 1.0\r
38 Content-Type: text/plain; charset=utf-8\r
39 Content-Transfer-Encoding: quoted-printable\r
40 X-Y-GMX-Trusted: 0\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Tue, 10 Jul 2012 18:56:14 -0000\r
54 \r
55 This patch adds a new type structure_printer, which is used for structured =\r
56 formatting, e.g. JSON or S-Expressions.\r
57 \r
58 The structure contains the following function pointers:\r
59 \r
60 - initial_state: is called to create a state object, that is passed to all =\r
61 invocations. This should be used to keep track of the output file and every=\r
62 thing else necessary to correctly format output.\r
63 - map: is called when a new map (associative array, dictionary) is started.=\r
64  map_key and the primitives (string, number, bool) are used alternatingly t=\r
65 o add key/value pairs. pop is used to close the map (see there). This funct=\r
66 ion must return a nesting level identifier that can be used to close all ne=\r
67 sted structures (maps and lists), backing out to the returned nesting level.\r
68 - list: is called when a new list (array, vector) is started. the primitive=\r
69 s (string, number, bool) are used consecutively to add values to the list. =\r
70 pop is used to close the list. This function must return a nesting level id=\r
71 entifier that can be used to close all nested structures (maps and lists), =\r
72 backing out to the returned nesting level.\r
73 - pop: is called to return to a given nesting level. All lists and maps wit=\r
74 h a deeper nesting level must be closed.\r
75 - number, string, bool: output one element of the specific type.\r
76 \r
77 All functions should use state to insert delimiters etc. automatically when=\r
78  appropriate.\r
79 \r
80 Example:\r
81 int top, one;\r
82 top =3D map(state);\r
83 map_key(state, "foo");\r
84 one =3D list(state);\r
85 number(state, 1);\r
86 number(state, 2);\r
87 number(state, 3);\r
88 pop(state, one);\r
89 map_key(state, "bar");\r
90 map(state);\r
91 map_key(state, "baaz");\r
92 string(state, "hello world");\r
93 pop(state, top);\r
94 \r
95 would output JSON as follows:\r
96 \r
97 {"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}\r
98 ---\r
99  Makefile.local      |    1 +\r
100  structured-output.h |   64 +++++++++++++++++++++++++++++++++++++++++++++++=\r
101 ++++\r
102  2 files changed, 65 insertions(+)\r
103  create mode 100644 structured-output.h\r
104 \r
105 diff --git a/Makefile.local b/Makefile.local\r
106 index a890df2..9b3db5e 100644\r
107 --- a/Makefile.local\r
108 +++ b/Makefile.local\r
109 @@ -286,6 +286,7 @@ notmuch_client_srcs =3D             \\r
110         notmuch-reply.c         \\r
111         notmuch-restore.c       \\r
112         notmuch-search.c        \\r
113 +       structured-output.c     \\r
114         notmuch-setup.c         \\r
115         notmuch-show.c          \\r
116         notmuch-tag.c           \\r
117 diff --git a/structured-output.h b/structured-output.h\r
118 new file mode 100644\r
119 index 0000000..b43afe0\r
120 --- /dev/null\r
121 +++ b/structured-output.h\r
122 @@ -0,0 +1,64 @@\r
123 +/* notmuch - Not much of an email program, (just index and search)\r
124 + *\r
125 + * Copyright =C2=A9 2009 Carl Worth\r
126 + *\r
127 + * This program is free software: you can redistribute it and/or modify\r
128 + * it under the terms of the GNU General Public License as published by\r
129 + * the Free Software Foundation, either version 3 of the License, or\r
130 + * (at your option) any later version.\r
131 + *\r
132 + * This program is distributed in the hope that it will be useful,\r
133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
135 + * GNU General Public License for more details.\r
136 + *\r
137 + * You should have received a copy of the GNU General Public License\r
138 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
139 + *\r
140 + * Author: Carl Worth <cworth@cworth.org>\r
141 + */\r
142 +\r
143 +#include "notmuch-client.h"\r
144 +\r
145 +/* structured formatting, useful for JSON, S-Expressions, ...\r
146 +\r
147 +- initial_state: is called to create a state object, that is passed to all=\r
148  invocations. This should be used to keep track of the output file and ever=\r
149 ything else necessary to correctly format output.\r
150 +- map: is called when a new map (associative array, dictionary) is started=\r
151 . map_key and the primitives (string, number, bool) are used alternatingly =\r
152 to add key/value pairs. pop is used to close the map (see there). This func=\r
153 tion must return a nesting level identifier that can be used to close all n=\r
154 ested structures (maps and lists), backing out to the returned nesting leve=\r
155 l.\r
156 +- list: is called when a new list (array, vector) is started. the primitiv=\r
157 es (string, number, bool) are used consecutively to add values to the list.=\r
158  pop is used to close the list. This function must return a nesting level i=\r
159 dentifier that can be used to close all nested structures (maps and lists),=\r
160  backing out to the returned nesting level.\r
161 +- pop: is called to return to a given nesting level. All lists and maps wi=\r
162 th a deeper nesting level must be closed.\r
163 +- number, string, bool: output one element of the specific type.\r
164 +\r
165 +All functions should use state to insert delimiters etc. automatically whe=\r
166 n appropriate.\r
167 +\r
168 +Example:\r
169 +int top, one;\r
170 +top =3D map(state);\r
171 +map_key(state, "foo");\r
172 +one =3D list(state);\r
173 +number(state, 1);\r
174 +number(state, 2);\r
175 +number(state, 3);\r
176 +pop(state, one);\r
177 +map_key(state, "bar");\r
178 +map(state);\r
179 +map_key(state, "baaz");\r
180 +string(state, "hello world");\r
181 +pop(state, top);\r
182 +\r
183 +would output JSON as follows:\r
184 +\r
185 +{"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}\r
186 +\r
187 + */\r
188 +typedef struct structure_printer {\r
189 +    int (*map)(void *state);\r
190 +    int (*list)(void *state);\r
191 +    void (*pop)(void *state, int level);\r
192 +    void (*map_key)(void *state, const char *key);\r
193 +    void (*number)(void *state, int val);\r
194 +    void (*string)(void *state, const char *val);\r
195 +    void (*bool)(void *state, notmuch_bool_t val);\r
196 +    void *(*initial_state)(const struct structure_printer *sp, FILE *outpu=\r
197 t);\r
198 +} structure_printer_t;\r
199 +\r
200 +\r
201 --=20\r
202 1.7.10.4\r