1 Return-Path: <jani@nikula.org>
\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 F037B421177
\r
6 for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 08:20:11 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 LJ-9KPbXPW4G for <notmuch@notmuchmail.org>;
\r
16 Sun, 18 Aug 2013 08:20:06 -0700 (PDT)
\r
17 Received: from mail-bk0-f51.google.com (mail-bk0-f51.google.com
\r
18 [209.85.214.51]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 25838429E59
\r
21 for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 08:20:06 -0700 (PDT)
\r
22 Received: by mail-bk0-f51.google.com with SMTP id mx10so1111067bkb.38
\r
23 for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 08:20:04 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
\r
28 bh=dX/jB0P4THWXkMen1TrH0kki1cbjh3Wg7fyJpyBuGWA=;
\r
29 b=IYbdtoUmwccyBn7SFM/Xi0ns+bkrtEvfdFRF1j+ssosy4xjHFQya2sQherIy9U8pX/
\r
30 oja6zKhPB6O0ozpyY6FOmUKA/cY4ZC+h2TmYpoiNcq8M67p7ObTDt525DVEc+RlH9YxX
\r
31 MA7m6zNuKGJmhOps4W+ne8fk2ZkiGRBMLqfOeueqswpC/VLRft2w6adUPWUM8LKybXw0
\r
32 1dOqOgY9dwjR+MLAtNKXcB2xvL5p3oOwGkKsIy+z159JupVIq9ivigW/tlZ8jkALYQcF
\r
33 oIIbMDz3Cnyszv3nRG1o7Tn0bbllmHlK7RfHqvinjPY7hMRY9n6J64JVw0sQTo5bQqK/
\r
36 ALoCoQnLCgoZfghpOR3oXcPaw/+CHM9oMNr1BX5I/kUOLOP14X0XhKkhbs4AdGH5hP8CvhKs87MF
\r
37 X-Received: by 10.205.10.132 with SMTP id pa4mr6969943bkb.15.1376839204800;
\r
38 Sun, 18 Aug 2013 08:20:04 -0700 (PDT)
\r
39 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.
\r
41 by mx.google.com with ESMTPSA id nv4sm949614bkb.3.1969.12.31.16.00.00
\r
42 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
43 Sun, 18 Aug 2013 08:20:04 -0700 (PDT)
\r
44 From: Jani Nikula <jani@nikula.org>
\r
45 To: notmuch@notmuchmail.org
\r
46 Subject: [PATCH 2/2] cli: define config getters and setters using a macro
\r
47 Date: Sun, 18 Aug 2013 18:20:05 +0300
\r
48 Message-Id: <1376839205-5115-2-git-send-email-jani@nikula.org>
\r
49 X-Mailer: git-send-email 1.7.10.4
\r
50 In-Reply-To: <1376839205-5115-1-git-send-email-jani@nikula.org>
\r
51 References: <1376839205-5115-1-git-send-email-jani@nikula.org>
\r
52 X-BeenThere: notmuch@notmuchmail.org
\r
53 X-Mailman-Version: 2.1.13
\r
55 List-Id: "Use and development of the notmuch mail system."
\r
56 <notmuch.notmuchmail.org>
\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
60 List-Post: <mailto:notmuch@notmuchmail.org>
\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
63 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
64 X-List-Received-Date: Sun, 18 Aug 2013 15:20:12 -0000
\r
66 There's plenty of duplicated code in defining the functions for config
\r
67 get/set. Add macros to define the functions.
\r
71 This might be a bit too tricky for some people's tastes... let's see!
\r
74 notmuch-config.c | 141 ++++++++++++++----------------------------------------
\r
75 1 file changed, 37 insertions(+), 104 deletions(-)
\r
77 diff --git a/notmuch-config.c b/notmuch-config.c
\r
78 index 305d213..fcee0fc 100644
\r
79 --- a/notmuch-config.c
\r
80 +++ b/notmuch-config.c
\r
81 @@ -520,6 +520,18 @@ _config_set (notmuch_config_t *config, char **field,
\r
85 +#define DEFINE_CONFIG_GET(group, key) \
\r
87 + notmuch_config_get_ ## group ## _ ## key (notmuch_config_t *config) { \
\r
88 + return _config_get (config, &config->group ## _ ## key, #group, #key); \
\r
91 +#define DEFINE_CONFIG_SET(group, key) \
\r
93 + notmuch_config_set_ ## group ## _ ## key (notmuch_config_t *config, const char *value) { \
\r
94 + _config_set (config, &config->group ## _ ## key, #group, #key, value); \
\r
97 static const char **
\r
98 _config_get_list (notmuch_config_t *config,
\r
99 const char *section, const char *key,
\r
100 @@ -562,112 +574,33 @@ _config_set_list (notmuch_config_t *config,
\r
101 *config_var = NULL;
\r
105 -notmuch_config_get_database_path (notmuch_config_t *config)
\r
107 - return _config_get (config, &config->database_path, "database", "path");
\r
111 -notmuch_config_set_database_path (notmuch_config_t *config,
\r
112 - const char *database_path)
\r
114 - _config_set (config, &config->database_path, "database", "path", database_path);
\r
118 -notmuch_config_get_user_name (notmuch_config_t *config)
\r
120 - return _config_get (config, &config->user_name, "user", "name");
\r
124 -notmuch_config_set_user_name (notmuch_config_t *config,
\r
125 - const char *user_name)
\r
127 - _config_set (config, &config->user_name, "user", "name", user_name);
\r
131 -notmuch_config_get_user_primary_email (notmuch_config_t *config)
\r
133 - return _config_get (config, &config->user_primary_email, "user", "primary_email");
\r
137 -notmuch_config_set_user_primary_email (notmuch_config_t *config,
\r
138 - const char *primary_email)
\r
140 - _config_set (config, &config->user_primary_email, "user", "primary_email", primary_email);
\r
144 -notmuch_config_get_user_other_email (notmuch_config_t *config, size_t *length)
\r
146 - return _config_get_list (config, "user", "other_email",
\r
147 - &(config->user_other_email),
\r
148 - &(config->user_other_email_length), length);
\r
152 -notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
154 - return _config_get_list (config, "new", "tags",
\r
155 - &(config->new_tags),
\r
156 - &(config->new_tags_length), length);
\r
160 -notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
\r
162 - return _config_get_list (config, "new", "ignore",
\r
163 - &(config->new_ignore),
\r
164 - &(config->new_ignore_length), length);
\r
168 -notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
169 - const char *list[],
\r
172 - _config_set_list (config, "user", "other_email", list, length,
\r
173 - &(config->user_other_email));
\r
177 -notmuch_config_set_new_tags (notmuch_config_t *config,
\r
178 - const char *list[],
\r
181 - _config_set_list (config, "new", "tags", list, length,
\r
182 - &(config->new_tags));
\r
186 -notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
187 - const char *list[],
\r
190 - _config_set_list (config, "new", "ignore", list, length,
\r
191 - &(config->new_ignore));
\r
193 +#define DEFINE_CONFIG_GET_LIST(group, key) \
\r
195 + notmuch_config_get_ ## group ## _ ## key (notmuch_config_t *config, size_t *length) { \
\r
196 + return _config_get_list (config, #group, #key, &config->group ## _ ## key, &config->group ## _ ## key ## _ ## length, length); \
\r
200 -notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
\r
202 - return _config_get_list (config, "search", "exclude_tags",
\r
203 - &(config->search_exclude_tags),
\r
204 - &(config->search_exclude_tags_length), length);
\r
206 +#define DEFINE_CONFIG_SET_LIST(group, key) \
\r
208 + notmuch_config_set_ ## group ## _ ## key (notmuch_config_t *config, const char *list[], size_t length) { \
\r
209 + _config_set_list (config, #group, #key, list, length, &config->group ## _ ## key); \
\r
213 -notmuch_config_set_search_exclude_tags (notmuch_config_t *config,
\r
214 - const char *list[],
\r
217 - _config_set_list (config, "search", "exclude_tags", list, length,
\r
218 - &(config->search_exclude_tags));
\r
220 +DEFINE_CONFIG_GET(database, path);
\r
221 +DEFINE_CONFIG_SET(database, path);
\r
222 +DEFINE_CONFIG_GET(user, name);
\r
223 +DEFINE_CONFIG_SET(user, name);
\r
224 +DEFINE_CONFIG_GET(user, primary_email);
\r
225 +DEFINE_CONFIG_SET(user, primary_email);
\r
227 +DEFINE_CONFIG_GET_LIST(user, other_email);
\r
228 +DEFINE_CONFIG_SET_LIST(user, other_email);
\r
229 +DEFINE_CONFIG_GET_LIST(new, tags);
\r
230 +DEFINE_CONFIG_SET_LIST(new, tags);
\r
231 +DEFINE_CONFIG_GET_LIST(new, ignore);
\r
232 +DEFINE_CONFIG_SET_LIST(new, ignore);
\r
233 +DEFINE_CONFIG_GET_LIST(search, exclude_tags);
\r
234 +DEFINE_CONFIG_SET_LIST(search, exclude_tags);
\r
236 /* Given a configuration item of the form <group>.<key> return the
\r
237 * component group and key. If any error occurs, print a message on
\r