1 Return-Path: <bremner@pivot.cs.unb.ca>
\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 2B13241733A
\r
6 for <notmuch@notmuchmail.org>; Sat, 24 Apr 2010 04:45:32 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9] autolearn=ham
\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 Y0BwFBsn-rMo for <notmuch@notmuchmail.org>;
\r
16 Sat, 24 Apr 2010 04:45:29 -0700 (PDT)
\r
17 Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 6B4C741733F
\r
19 for <notmuch@notmuchmail.org>; Sat, 24 Apr 2010 04:45:29 -0700 (PDT)
\r
21 fctnnbsc30w-142167190087.pppoe-dynamic.high-speed.nb.bellaliant.net
\r
22 ([142.167.190.87] helo=rocinante.cs.unb.ca)
\r
23 by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)
\r
24 (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)
\r
25 id 1O5dnc-00030i-Vj; Sat, 24 Apr 2010 08:45:29 -0300
\r
26 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.71)
\r
27 (envelope-from <bremner@rocinante.cs.unb.ca>)
\r
28 id 1O5dn6-0005Qi-Ja; Sat, 24 Apr 2010 08:44:56 -0300
\r
29 From: david@tethera.net
\r
30 To: notmuch@notmuchmail.org
\r
31 Subject: [PATCH 2/3] notmuch-output.[ch]: initial implementation of output
\r
32 selection argument handling.
\r
33 Date: Sat, 24 Apr 2010 08:44:37 -0300
\r
34 Message-Id: <1272109478-20686-3-git-send-email-david@tethera.net>
\r
35 X-Mailer: git-send-email 1.7.0
\r
36 In-Reply-To: <1272109478-20686-1-git-send-email-david@tethera.net>
\r
37 References: <1272109478-20686-1-git-send-email-david@tethera.net>
\r
38 X-Sender-Verified: bremner@pivot.cs.unb.ca
\r
39 Cc: David Bremner <bremner@unb.ca>
\r
40 X-BeenThere: notmuch@notmuchmail.org
\r
41 X-Mailman-Version: 2.1.13
\r
43 List-Id: "Use and development of the notmuch mail system."
\r
44 <notmuch.notmuchmail.org>
\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
48 List-Post: <mailto:notmuch@notmuchmail.org>
\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
52 X-List-Received-Date: Sat, 24 Apr 2010 11:45:32 -0000
\r
54 From: David Bremner <bremner@unb.ca>
\r
56 These two files provide a more or less "object oriented" approach to
\r
57 parsing output selection arguments. The use of a struct to track
\r
58 which output pieces are selected is intended to hide the
\r
59 implementation, which currently uses bitmasks.
\r
61 Makefile.local | 1 +
\r
62 notmuch-output.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
63 notmuch-output.h | 49 ++++++++++++++++++++++++++++
\r
64 3 files changed, 145 insertions(+), 0 deletions(-)
\r
65 create mode 100644 notmuch-output.c
\r
66 create mode 100644 notmuch-output.h
\r
68 diff --git a/Makefile.local b/Makefile.local
\r
69 index 5bb570b..eb78679 100644
\r
70 --- a/Makefile.local
\r
71 +++ b/Makefile.local
\r
72 @@ -240,6 +240,7 @@ notmuch_client_srcs = \
\r
76 + notmuch-output.c \
\r
80 diff --git a/notmuch-output.c b/notmuch-output.c
\r
81 new file mode 100644
\r
82 index 0000000..a84bbe1
\r
84 +++ b/notmuch-output.c
\r
86 +/* notmuch-output.h --- encapsulate handling of output selection.
\r
88 + * Copyright 2010 © David Bremner
\r
90 + * This file is part of Notmuch.
\r
92 + * Notmuch is free software: you can redistribute it and/or modify it
\r
93 + * under the terms of the GNU General Public License as published by the
\r
94 + * Free Software Foundation, either version 3 of the License, or (at
\r
95 + * your option) any later version.
\r
97 + * Notmuch is distributed in the hope that it will be useful, but
\r
98 + * WITHOUT ANY WARRANTY; without even the implied warranty of
\r
99 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
100 + * General Public License for more details.
\r
102 + * You should have received a copy of the GNU General Public License
\r
103 + * along with Notmuch. If not, see <http:www.gnu.org/licenses/>.
\r
105 + * Authors: David Bremner <david@tethera.net>
\r
108 +#include "notmuch-client.h"
\r
109 +#include "notmuch-output.h"
\r
111 +notmuch_output_options_t *
\r
112 +output_init(void *ctx){
\r
113 + notmuch_output_options_t *output_opts;
\r
115 + output_opts = talloc (ctx, notmuch_output_options_t);
\r
116 + output_opts->output_all=TRUE;
\r
117 + output_opts->mask=0;
\r
118 + return output_opts;
\r
122 +output_parse_arg(notmuch_output_options_t *output_opts, const char *arg){
\r
126 + struct { const char *name; notmuch_output_t key; } parse_try[]={
\r
127 + {"bcc", NOTMUCH_OUTPUT_BCC},
\r
128 + {"body", NOTMUCH_OUTPUT_BODY},
\r
129 + {"cc", NOTMUCH_OUTPUT_CC},
\r
130 + {"date",NOTMUCH_OUTPUT_DATE},
\r
131 + {"from",NOTMUCH_OUTPUT_FROM},
\r
132 + {"message-id",NOTMUCH_OUTPUT_MESSAGE_ID},
\r
133 + {"subject",NOTMUCH_OUTPUT_SUBJECT},
\r
134 + {"to", NOTMUCH_OUTPUT_TO},
\r
137 + opt = strchr(arg, '=');
\r
143 + output_opts->output_all=FALSE;
\r
147 + notmuch_bool_t found = FALSE;
\r
148 + notmuch_output_t key = 0;
\r
150 + for (i = 0; i<ARRAY_SIZE(parse_try) ; i++){
\r
151 + if (strncmp(opt, parse_try[i].name,
\r
152 + strlen(parse_try[i].name)) == 0){
\r
153 + key = parse_try[i].key;
\r
159 + fprintf (stderr, "Unrecognized output selection: %s\n", opt);
\r
163 + output_opts->mask |= (1<<key);
\r
165 + opt = strchr(opt, ',');
\r
173 +output_get_flag(notmuch_output_options_t *opts,
\r
174 + notmuch_output_t flag){
\r
176 + if (opts->output_all)
\r
179 + return (opts->mask & (1<<flag));
\r
181 diff --git a/notmuch-output.h b/notmuch-output.h
\r
182 new file mode 100644
\r
183 index 0000000..1216499
\r
185 +++ b/notmuch-output.h
\r
187 +/* notmuch-output.h --- encapsulate handling of output selection.
\r
189 + * Copyright 2010 © David Bremner
\r
191 + * This file is part of Notmuch.
\r
193 + * Notmuch is free software: you can redistribute it and/or modify it
\r
194 + * under the terms of the GNU General Public License as published by the
\r
195 + * Free Software Foundation, either version 3 of the License, or (at
\r
196 + * your option) any later version.
\r
198 + * Notmuch is distributed in the hope that it will be useful, but
\r
199 + * WITHOUT ANY WARRANTY; without even the implied warranty of
\r
200 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
201 + * General Public License for more details.
\r
203 + * You should have received a copy of the GNU General Public License
\r
204 + * along with Notmuch. If not, see <http:www.gnu.org/licenses/>.
\r
206 + * Authors: David Bremner <david@tethera.net>
\r
209 +#ifndef NOTMUCH_OUTPUT_H
\r
210 +#define NOTMUCH_OUTPUT_H
\r
212 +typedef struct notmuch_output_struct {
\r
213 + notmuch_bool_t output_all;
\r
215 +} notmuch_output_options_t;
\r
217 +typedef enum notmuch_output_enum {
\r
218 + NOTMUCH_OUTPUT_BCC,
\r
219 + NOTMUCH_OUTPUT_BODY,
\r
220 + NOTMUCH_OUTPUT_CC,
\r
221 + NOTMUCH_OUTPUT_DATE,
\r
222 + NOTMUCH_OUTPUT_FROM,
\r
223 + NOTMUCH_OUTPUT_MESSAGE_ID,
\r
224 + NOTMUCH_OUTPUT_SUBJECT,
\r
225 + NOTMUCH_OUTPUT_TO
\r
226 +} notmuch_output_t;
\r
228 +notmuch_output_options_t *output_init(void *ctx);
\r
230 +int output_parse_arg(notmuch_output_options_t *opts,
\r
231 + const char* arg);
\r
233 +notmuch_bool_t output_get_flag(notmuch_output_options_t *opts,
\r
234 + notmuch_output_t flag);
\r