[PATCH v2 03/14] cli/reply: reuse show_reply_headers() in headers-only format
[notmuch-archives.git] / 31 / 1f8b6df665fb152bffc23b8e3120a851dc6ebd
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
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 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
27         :references;\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
34         Mplg==\r
35 X-Gm-Message-State:\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
40         [88.195.111.91])\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
54 Precedence: list\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
65 \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
68 \r
69 ---\r
70 \r
71 This might be a bit too tricky for some people's tastes... let's see!\r
72 ;)\r
73 ---\r
74  notmuch-config.c |  141 ++++++++++++++----------------------------------------\r
75  1 file changed, 37 insertions(+), 104 deletions(-)\r
76 \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
82      *field = NULL;\r
83  }\r
84  \r
85 +#define DEFINE_CONFIG_GET(group, key) \\r
86 +    const char *                                                       \\r
87 +    notmuch_config_get_ ## group ## _ ## key (notmuch_config_t *config) { \\r
88 +       return _config_get (config, &config->group ## _ ## key, #group, #key); \\r
89 +    }\r
90 +\r
91 +#define DEFINE_CONFIG_SET(group, key)                          \\r
92 +    void                                                               \\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
95 +    }\r
96 +\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
102  }\r
103  \r
104 -const char *\r
105 -notmuch_config_get_database_path (notmuch_config_t *config)\r
106 -{\r
107 -    return _config_get (config, &config->database_path, "database", "path");\r
108 -}\r
109 -\r
110 -void\r
111 -notmuch_config_set_database_path (notmuch_config_t *config,\r
112 -                                 const char *database_path)\r
113 -{\r
114 -    _config_set (config, &config->database_path, "database", "path", database_path);\r
115 -}\r
116 -\r
117 -const char *\r
118 -notmuch_config_get_user_name (notmuch_config_t *config)\r
119 -{\r
120 -    return _config_get (config, &config->user_name, "user", "name");\r
121 -}\r
122 -\r
123 -void\r
124 -notmuch_config_set_user_name (notmuch_config_t *config,\r
125 -                             const char *user_name)\r
126 -{\r
127 -    _config_set (config, &config->user_name, "user", "name", user_name);\r
128 -}\r
129 -\r
130 -const char *\r
131 -notmuch_config_get_user_primary_email (notmuch_config_t *config)\r
132 -{\r
133 -    return _config_get (config, &config->user_primary_email, "user", "primary_email");\r
134 -}\r
135 -\r
136 -void\r
137 -notmuch_config_set_user_primary_email (notmuch_config_t *config,\r
138 -                                      const char *primary_email)\r
139 -{\r
140 -    _config_set (config, &config->user_primary_email, "user", "primary_email", primary_email);\r
141 -}\r
142 -\r
143 -const char **\r
144 -notmuch_config_get_user_other_email (notmuch_config_t *config,   size_t *length)\r
145 -{\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
149 -}\r
150 -\r
151 -const char **\r
152 -notmuch_config_get_new_tags (notmuch_config_t *config,   size_t *length)\r
153 -{\r
154 -    return _config_get_list (config, "new", "tags",\r
155 -                            &(config->new_tags),\r
156 -                            &(config->new_tags_length), length);\r
157 -}\r
158 -\r
159 -const char **\r
160 -notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)\r
161 -{\r
162 -    return _config_get_list (config, "new", "ignore",\r
163 -                            &(config->new_ignore),\r
164 -                            &(config->new_ignore_length), length);\r
165 -}\r
166 -\r
167 -void\r
168 -notmuch_config_set_user_other_email (notmuch_config_t *config,\r
169 -                                    const char *list[],\r
170 -                                    size_t length)\r
171 -{\r
172 -    _config_set_list (config, "user", "other_email", list, length,\r
173 -                    &(config->user_other_email));\r
174 -}\r
175 -\r
176 -void\r
177 -notmuch_config_set_new_tags (notmuch_config_t *config,\r
178 -                                    const char *list[],\r
179 -                                    size_t length)\r
180 -{\r
181 -    _config_set_list (config, "new", "tags", list, length,\r
182 -                    &(config->new_tags));\r
183 -}\r
184 -\r
185 -void\r
186 -notmuch_config_set_new_ignore (notmuch_config_t *config,\r
187 -                              const char *list[],\r
188 -                              size_t length)\r
189 -{\r
190 -    _config_set_list (config, "new", "ignore", list, length,\r
191 -                    &(config->new_ignore));\r
192 -}\r
193 +#define DEFINE_CONFIG_GET_LIST(group, key)                             \\r
194 +    const char **                                                      \\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
197 +    }\r
198  \r
199 -const char **\r
200 -notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)\r
201 -{\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
205 -}\r
206 +#define DEFINE_CONFIG_SET_LIST(group, key)                             \\r
207 +    void                                                               \\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
210 +    }\r
211  \r
212 -void\r
213 -notmuch_config_set_search_exclude_tags (notmuch_config_t *config,\r
214 -                                     const char *list[],\r
215 -                                     size_t length)\r
216 -{\r
217 -    _config_set_list (config, "search", "exclude_tags", list, length,\r
218 -                     &(config->search_exclude_tags));\r
219 -}\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
226 +\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
235  \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
238 -- \r
239 1.7.10.4\r
240 \r