1 Return-Path: <tomi.ollila@iki.fi>
\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 95822431FDD
\r
6 for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 11:09:25 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 A8itxHlr638i for <notmuch@notmuchmail.org>;
\r
16 Sun, 18 Aug 2013 11:09:21 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id D198A431FDB
\r
19 for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 11:09:20 -0700 (PDT)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id 07228100086;
\r
22 Sun, 18 Aug 2013 21:09:16 +0300 (EEST)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org
\r
25 Subject: Re: [PATCH 2/2] cli: define config getters and setters using a macro
\r
26 In-Reply-To: <1376839205-5115-2-git-send-email-jani@nikula.org>
\r
27 References: <1376839205-5115-1-git-send-email-jani@nikula.org>
\r
28 <1376839205-5115-2-git-send-email-jani@nikula.org>
\r
29 User-Agent: Notmuch/0.16+3~g340c058 (http://notmuchmail.org) Emacs/24.3.1
\r
30 (x86_64-unknown-linux-gnu)
\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
32 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
33 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
34 Date: Sun, 18 Aug 2013 21:09:15 +0300
\r
35 Message-ID: <m2zjse7tx0.fsf@guru.guru-group.fi>
\r
37 Content-Type: text/plain
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Sun, 18 Aug 2013 18:09:25 -0000
\r
52 On Sun, Aug 18 2013, Jani Nikula <jani@nikula.org> wrote:
\r
54 > There's plenty of duplicated code in defining the functions for config
\r
55 > get/set. Add macros to define the functions.
\r
59 > This might be a bit too tricky for some people's tastes... let's see!
\r
62 Yes, a bit tricky. Nevertheless I like these...
\r
64 Additionally id:1376839205-5115-1-git-send-email-jani@nikula.org LGTM.
\r
70 > notmuch-config.c | 141 ++++++++++++++----------------------------------------
\r
71 > 1 file changed, 37 insertions(+), 104 deletions(-)
\r
73 > diff --git a/notmuch-config.c b/notmuch-config.c
\r
74 > index 305d213..fcee0fc 100644
\r
75 > --- a/notmuch-config.c
\r
76 > +++ b/notmuch-config.c
\r
77 > @@ -520,6 +520,18 @@ _config_set (notmuch_config_t *config, char **field,
\r
81 > +#define DEFINE_CONFIG_GET(group, key) \
\r
83 > + notmuch_config_get_ ## group ## _ ## key (notmuch_config_t *config) { \
\r
84 > + return _config_get (config, &config->group ## _ ## key, #group, #key); \
\r
87 > +#define DEFINE_CONFIG_SET(group, key) \
\r
89 > + notmuch_config_set_ ## group ## _ ## key (notmuch_config_t *config, const char *value) { \
\r
90 > + _config_set (config, &config->group ## _ ## key, #group, #key, value); \
\r
93 > static const char **
\r
94 > _config_get_list (notmuch_config_t *config,
\r
95 > const char *section, const char *key,
\r
96 > @@ -562,112 +574,33 @@ _config_set_list (notmuch_config_t *config,
\r
97 > *config_var = NULL;
\r
101 > -notmuch_config_get_database_path (notmuch_config_t *config)
\r
103 > - return _config_get (config, &config->database_path, "database", "path");
\r
107 > -notmuch_config_set_database_path (notmuch_config_t *config,
\r
108 > - const char *database_path)
\r
110 > - _config_set (config, &config->database_path, "database", "path", database_path);
\r
114 > -notmuch_config_get_user_name (notmuch_config_t *config)
\r
116 > - return _config_get (config, &config->user_name, "user", "name");
\r
120 > -notmuch_config_set_user_name (notmuch_config_t *config,
\r
121 > - const char *user_name)
\r
123 > - _config_set (config, &config->user_name, "user", "name", user_name);
\r
127 > -notmuch_config_get_user_primary_email (notmuch_config_t *config)
\r
129 > - return _config_get (config, &config->user_primary_email, "user", "primary_email");
\r
133 > -notmuch_config_set_user_primary_email (notmuch_config_t *config,
\r
134 > - const char *primary_email)
\r
136 > - _config_set (config, &config->user_primary_email, "user", "primary_email", primary_email);
\r
140 > -notmuch_config_get_user_other_email (notmuch_config_t *config, size_t *length)
\r
142 > - return _config_get_list (config, "user", "other_email",
\r
143 > - &(config->user_other_email),
\r
144 > - &(config->user_other_email_length), length);
\r
148 > -notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
150 > - return _config_get_list (config, "new", "tags",
\r
151 > - &(config->new_tags),
\r
152 > - &(config->new_tags_length), length);
\r
156 > -notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
\r
158 > - return _config_get_list (config, "new", "ignore",
\r
159 > - &(config->new_ignore),
\r
160 > - &(config->new_ignore_length), length);
\r
164 > -notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
165 > - const char *list[],
\r
168 > - _config_set_list (config, "user", "other_email", list, length,
\r
169 > - &(config->user_other_email));
\r
173 > -notmuch_config_set_new_tags (notmuch_config_t *config,
\r
174 > - const char *list[],
\r
177 > - _config_set_list (config, "new", "tags", list, length,
\r
178 > - &(config->new_tags));
\r
182 > -notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
183 > - const char *list[],
\r
186 > - _config_set_list (config, "new", "ignore", list, length,
\r
187 > - &(config->new_ignore));
\r
189 > +#define DEFINE_CONFIG_GET_LIST(group, key) \
\r
190 > + const char ** \
\r
191 > + notmuch_config_get_ ## group ## _ ## key (notmuch_config_t *config, size_t *length) { \
\r
192 > + return _config_get_list (config, #group, #key, &config->group ## _ ## key, &config->group ## _ ## key ## _ ## length, length); \
\r
196 > -notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
\r
198 > - return _config_get_list (config, "search", "exclude_tags",
\r
199 > - &(config->search_exclude_tags),
\r
200 > - &(config->search_exclude_tags_length), length);
\r
202 > +#define DEFINE_CONFIG_SET_LIST(group, key) \
\r
204 > + notmuch_config_set_ ## group ## _ ## key (notmuch_config_t *config, const char *list[], size_t length) { \
\r
205 > + _config_set_list (config, #group, #key, list, length, &config->group ## _ ## key); \
\r
209 > -notmuch_config_set_search_exclude_tags (notmuch_config_t *config,
\r
210 > - const char *list[],
\r
213 > - _config_set_list (config, "search", "exclude_tags", list, length,
\r
214 > - &(config->search_exclude_tags));
\r
216 > +DEFINE_CONFIG_GET(database, path);
\r
217 > +DEFINE_CONFIG_SET(database, path);
\r
218 > +DEFINE_CONFIG_GET(user, name);
\r
219 > +DEFINE_CONFIG_SET(user, name);
\r
220 > +DEFINE_CONFIG_GET(user, primary_email);
\r
221 > +DEFINE_CONFIG_SET(user, primary_email);
\r
223 > +DEFINE_CONFIG_GET_LIST(user, other_email);
\r
224 > +DEFINE_CONFIG_SET_LIST(user, other_email);
\r
225 > +DEFINE_CONFIG_GET_LIST(new, tags);
\r
226 > +DEFINE_CONFIG_SET_LIST(new, tags);
\r
227 > +DEFINE_CONFIG_GET_LIST(new, ignore);
\r
228 > +DEFINE_CONFIG_SET_LIST(new, ignore);
\r
229 > +DEFINE_CONFIG_GET_LIST(search, exclude_tags);
\r
230 > +DEFINE_CONFIG_SET_LIST(search, exclude_tags);
\r
232 > /* Given a configuration item of the form <group>.<key> return the
\r
233 > * component group and key. If any error occurs, print a message on
\r
237 > _______________________________________________
\r
238 > notmuch mailing list
\r
239 > notmuch@notmuchmail.org
\r
240 > http://notmuchmail.org/mailman/listinfo/notmuch
\r