Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / d1 / 63f35ca6587e1892ddea323b0004271e61970b
1 Return-Path: <bremner@tethera.net>\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 arlo.cworth.org (Postfix) with ESMTP id 5B71A6DE02D0\r
6  for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:33 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.029\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.029 tagged_above=-999 required=5\r
12  tests=[AWL=-0.018, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
13  autolearn=disabled\r
14 Received: from arlo.cworth.org ([127.0.0.1])\r
15  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
16  with ESMTP id V9GhVDEPHTXP for <notmuch@notmuchmail.org>;\r
17  Tue, 22 Mar 2016 03:55:24 -0700 (PDT)\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id DC6646DE02A5\r
20  for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:16 -0700 (PDT)\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
22  (envelope-from <bremner@tethera.net>)\r
23  id 1aiJya-00014J-C8; Tue, 22 Mar 2016 06:55:52 -0400\r
24 Received: (nullmailer pid 14073 invoked by uid 1000);\r
25  Tue, 22 Mar 2016 10:55:11 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 04/13] lib/cli: add library API / CLI for compile time options\r
29 Date: Tue, 22 Mar 2016 07:54:45 -0300\r
30 Message-Id: <1458644094-13951-5-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.7.0\r
32 In-Reply-To: <1458644094-13951-1-git-send-email-david@tethera.net>\r
33 References: <1458644094-13951-1-git-send-email-david@tethera.net>\r
34 MIME-Version: 1.0\r
35 Content-Type: text/plain; charset=UTF-8\r
36 Content-Transfer-Encoding: 8bit\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.20\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41  <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
43  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
48  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Tue, 22 Mar 2016 10:55:33 -0000\r
50 \r
51 This is intentionally low tech; if we have more than two options it may\r
52 make sense to build up what infrastructure is provided.\r
53 ---\r
54  lib/Makefile.local  |  1 +\r
55  lib/notmuch.h       | 10 ++++++++++\r
56  lib/options.c       | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
57  notmuch-config.c    | 20 ++++++++++++++++++++\r
58  test/T030-config.sh |  6 ++++--\r
59  test/T040-setup.sh  |  6 ++++--\r
60  test/test-lib.sh    |  6 ++++++\r
61  7 files changed, 95 insertions(+), 4 deletions(-)\r
62  create mode 100644 lib/options.c\r
63 \r
64 diff --git a/lib/Makefile.local b/lib/Makefile.local\r
65 index 3a07090..4ad0158 100644\r
66 --- a/lib/Makefile.local\r
67 +++ b/lib/Makefile.local\r
68 @@ -39,6 +39,7 @@ libnotmuch_c_srcs =           \\r
69         $(dir)/message-file.c   \\r
70         $(dir)/messages.c       \\r
71         $(dir)/sha1.c           \\r
72 +       $(dir)/options.c        \\r
73         $(dir)/tags.c\r
74  \r
75  libnotmuch_cxx_srcs =          \\r
76 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
77 index cb46fc0..b29dd5f 100644\r
78 --- a/lib/notmuch.h\r
79 +++ b/lib/notmuch.h\r
80 @@ -1838,6 +1838,16 @@ notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);\r
81  void\r
82  notmuch_filenames_destroy (notmuch_filenames_t *filenames);\r
83  \r
84 +typedef enum {\r
85 +    NOTMUCH_OPTION_COMPACT = 1,\r
86 +    NOTMUCH_OPTION_FIELD_PROCESSOR = 2\r
87 +} notmuch_option_t;\r
88 +\r
89 +notmuch_bool_t\r
90 +notmuch_options_present (notmuch_option_t mask);\r
91 +\r
92 +notmuch_bool_t\r
93 +notmuch_options_get (const char *name);\r
94  /* @} */\r
95  \r
96  NOTMUCH_END_DECLS\r
97 diff --git a/lib/options.c b/lib/options.c\r
98 new file mode 100644\r
99 index 0000000..4e15d92\r
100 --- /dev/null\r
101 +++ b/lib/options.c\r
102 @@ -0,0 +1,50 @@\r
103 +/* notmuch - Not much of an email program, (just index and search)\r
104 + *\r
105 + * Copyright © 2016 David Bremner\r
106 + *\r
107 + * This program is free software: you can redistribute it and/or modify\r
108 + * it under the terms of the GNU General Public License as published by\r
109 + * the Free Software Foundation, either version 3 of the License, or\r
110 + * (at your option) any later version.\r
111 + *\r
112 + * This program is distributed in the hope that it will be useful,\r
113 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
115 + * GNU General Public License for more details.\r
116 + *\r
117 + * You should have received a copy of the GNU General Public License\r
118 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
119 + *\r
120 + * Author: David Bremner <david@tethera.net>\r
121 + */\r
122 +\r
123 +#include "notmuch.h"\r
124 +#include "notmuch-private.h"\r
125 +\r
126 +notmuch_bool_t\r
127 +notmuch_options_present (notmuch_option_t mask)\r
128 +{\r
129 +    notmuch_option_t present = 0;\r
130 +\r
131 +#if HAVE_XAPIAN_COMPACT\r
132 +    present |= NOTMUCH_OPTION_COMPACT;\r
133 +#endif\r
134 +\r
135 +#if HAVE_XAPIAN_COMPACT\r
136 +    present |= NOTMUCH_OPTION_FIELD_PROCESSOR;\r
137 +#endif\r
138 +\r
139 +    return (mask & present) != 0;\r
140 +\r
141 +}\r
142 +\r
143 +notmuch_bool_t\r
144 +notmuch_options_get (const char *name) {\r
145 +    if (STRNCMP_LITERAL (name, "compact") == 0) {\r
146 +       return notmuch_options_present (NOTMUCH_OPTION_COMPACT);\r
147 +    } else if (STRNCMP_LITERAL (name, "field_processor") == 0) {\r
148 +       return notmuch_options_present (NOTMUCH_OPTION_FIELD_PROCESSOR);\r
149 +    } else {\r
150 +       return FALSE;\r
151 +    }\r
152 +}\r
153 diff --git a/notmuch-config.c b/notmuch-config.c\r
154 index d252bb2..cfc549d 100644\r
155 --- a/notmuch-config.c\r
156 +++ b/notmuch-config.c\r
157 @@ -750,6 +750,8 @@ _item_split (char *item, char **group, char **key)\r
158      return 0;\r
159  }\r
160  \r
161 +#define OPTION_PREFIX "options."\r
162 +\r
163  static int\r
164  notmuch_config_command_get (notmuch_config_t *config, char *item)\r
165  {\r
166 @@ -773,6 +775,9 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)\r
167         tags = notmuch_config_get_new_tags (config, &length);\r
168         for (i = 0; i < length; i++)\r
169             printf ("%s\n", tags[i]);\r
170 +    } else if (STRNCMP_LITERAL (item, OPTION_PREFIX) == 0) {\r
171 +       printf ("%s\n",\r
172 +              notmuch_options_get (item + strlen (OPTION_PREFIX)) ? "true" : "false");\r
173      } else {\r
174         char **value;\r
175         size_t i, length;\r
176 @@ -804,6 +809,11 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char\r
177  {\r
178      char *group, *key;\r
179  \r
180 +    if (STRNCMP_LITERAL (item, OPTION_PREFIX) == 0) {\r
181 +       fprintf (stderr, "Error: read only option: %s\n", item);\r
182 +       return 1;\r
183 +    }\r
184 +\r
185      if (_item_split (item, &group, &key))\r
186         return 1;\r
187  \r
188 @@ -830,6 +840,15 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char\r
189      return notmuch_config_save (config);\r
190  }\r
191  \r
192 +static\r
193 +void\r
194 +_notmuch_config_list_options () {\r
195 +    printf("options.compact=%s\n",\r
196 +          notmuch_options_present(NOTMUCH_OPTION_COMPACT) ? "true" : "false");\r
197 +    printf("options.field_processor=%s\n",\r
198 +          notmuch_options_present(NOTMUCH_OPTION_FIELD_PROCESSOR) ? "true" : "false");\r
199 +}\r
200 +\r
201  static int\r
202  notmuch_config_command_list (notmuch_config_t *config)\r
203  {\r
204 @@ -865,6 +884,7 @@ notmuch_config_command_list (notmuch_config_t *config)\r
205  \r
206      g_strfreev (groups);\r
207  \r
208 +    _notmuch_config_list_options ();\r
209      return 0;\r
210  }\r
211  \r
212 diff --git a/test/T030-config.sh b/test/T030-config.sh\r
213 index f404908..c37ba21 100755\r
214 --- a/test/T030-config.sh\r
215 +++ b/test/T030-config.sh\r
216 @@ -44,7 +44,7 @@ test_expect_equal "$(notmuch config get foo.nonexistent)" ""\r
217  \r
218  test_begin_subtest "List all items"\r
219  notmuch config set database.path "/canonical/path"\r
220 -output=$(notmuch config list)\r
221 +output=$(notmuch config list | notmuch_options_sanitize)\r
222  test_expect_equal "$output" "\\r
223  database.path=/canonical/path\r
224  user.name=Notmuch Test Suite\r
225 @@ -56,7 +56,9 @@ search.exclude_tags=\r
226  maildir.synchronize_flags=true\r
227  crypto.gpg_path=gpg\r
228  foo.string=this is another string value\r
229 -foo.list=this;is another;list value;"\r
230 +foo.list=this;is another;list value;\r
231 +options.compact=something\r
232 +options.field_processor=something"\r
233  \r
234  test_begin_subtest "Top level --config=FILE option"\r
235  cp "${NOTMUCH_CONFIG}" alt-config\r
236 diff --git a/test/T040-setup.sh b/test/T040-setup.sh\r
237 index cf0c00b..5db03a6 100755\r
238 --- a/test/T040-setup.sh\r
239 +++ b/test/T040-setup.sh\r
240 @@ -19,7 +19,7 @@ another.suite@example.com\r
241  foo bar\r
242  baz\r
243  EOF\r
244 -output=$(notmuch --config=new-notmuch-config config list)\r
245 +output=$(notmuch --config=new-notmuch-config config list | notmuch_options_sanitize)\r
246  test_expect_equal "$output" "\\r
247  database.path=/path/to/maildir\r
248  user.name=Test Suite\r
249 @@ -29,6 +29,8 @@ new.tags=foo;bar;\r
250  new.ignore=\r
251  search.exclude_tags=baz;\r
252  maildir.synchronize_flags=true\r
253 -crypto.gpg_path=gpg"\r
254 +crypto.gpg_path=gpg\r
255 +options.compact=something\r
256 +options.field_processor=something"\r
257  \r
258  test_done\r
259 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
260 index cc08a98..49e6f40 100644\r
261 --- a/test/test-lib.sh\r
262 +++ b/test/test-lib.sh\r
263 @@ -733,6 +733,12 @@ notmuch_uuid_sanitize ()\r
264  {\r
265      sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'\r
266  }\r
267 +\r
268 +notmuch_options_sanitize ()\r
269 +{\r
270 +    sed 's/^options[.]\(.*\)=.*$/options.\1=something/'\r
271 +}\r
272 +\r
273  # End of notmuch helper functions\r
274  \r
275  # Use test_set_prereq to tell that a particular prerequisite is available.\r
276 -- \r
277 2.7.0\r
278 \r