--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 5B71A6DE02D0\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:33 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.029\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.029 tagged_above=-999 required=5\r
+ tests=[AWL=-0.018, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id V9GhVDEPHTXP for <notmuch@notmuchmail.org>;\r
+ Tue, 22 Mar 2016 03:55:24 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id DC6646DE02A5\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:16 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1aiJya-00014J-C8; Tue, 22 Mar 2016 06:55:52 -0400\r
+Received: (nullmailer pid 14073 invoked by uid 1000);\r
+ Tue, 22 Mar 2016 10:55:11 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 04/13] lib/cli: add library API / CLI for compile time options\r
+Date: Tue, 22 Mar 2016 07:54:45 -0300\r
+Message-Id: <1458644094-13951-5-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.7.0\r
+In-Reply-To: <1458644094-13951-1-git-send-email-david@tethera.net>\r
+References: <1458644094-13951-1-git-send-email-david@tethera.net>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 22 Mar 2016 10:55:33 -0000\r
+\r
+This is intentionally low tech; if we have more than two options it may\r
+make sense to build up what infrastructure is provided.\r
+---\r
+ lib/Makefile.local | 1 +\r
+ lib/notmuch.h | 10 ++++++++++\r
+ lib/options.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch-config.c | 20 ++++++++++++++++++++\r
+ test/T030-config.sh | 6 ++++--\r
+ test/T040-setup.sh | 6 ++++--\r
+ test/test-lib.sh | 6 ++++++\r
+ 7 files changed, 95 insertions(+), 4 deletions(-)\r
+ create mode 100644 lib/options.c\r
+\r
+diff --git a/lib/Makefile.local b/lib/Makefile.local\r
+index 3a07090..4ad0158 100644\r
+--- a/lib/Makefile.local\r
++++ b/lib/Makefile.local\r
+@@ -39,6 +39,7 @@ libnotmuch_c_srcs = \\r
+ $(dir)/message-file.c \\r
+ $(dir)/messages.c \\r
+ $(dir)/sha1.c \\r
++ $(dir)/options.c \\r
+ $(dir)/tags.c\r
+ \r
+ libnotmuch_cxx_srcs = \\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index cb46fc0..b29dd5f 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -1838,6 +1838,16 @@ notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);\r
+ void\r
+ notmuch_filenames_destroy (notmuch_filenames_t *filenames);\r
+ \r
++typedef enum {\r
++ NOTMUCH_OPTION_COMPACT = 1,\r
++ NOTMUCH_OPTION_FIELD_PROCESSOR = 2\r
++} notmuch_option_t;\r
++\r
++notmuch_bool_t\r
++notmuch_options_present (notmuch_option_t mask);\r
++\r
++notmuch_bool_t\r
++notmuch_options_get (const char *name);\r
+ /* @} */\r
+ \r
+ NOTMUCH_END_DECLS\r
+diff --git a/lib/options.c b/lib/options.c\r
+new file mode 100644\r
+index 0000000..4e15d92\r
+--- /dev/null\r
++++ b/lib/options.c\r
+@@ -0,0 +1,50 @@\r
++/* notmuch - Not much of an email program, (just index and search)\r
++ *\r
++ * Copyright © 2016 David Bremner\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program. If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: David Bremner <david@tethera.net>\r
++ */\r
++\r
++#include "notmuch.h"\r
++#include "notmuch-private.h"\r
++\r
++notmuch_bool_t\r
++notmuch_options_present (notmuch_option_t mask)\r
++{\r
++ notmuch_option_t present = 0;\r
++\r
++#if HAVE_XAPIAN_COMPACT\r
++ present |= NOTMUCH_OPTION_COMPACT;\r
++#endif\r
++\r
++#if HAVE_XAPIAN_COMPACT\r
++ present |= NOTMUCH_OPTION_FIELD_PROCESSOR;\r
++#endif\r
++\r
++ return (mask & present) != 0;\r
++\r
++}\r
++\r
++notmuch_bool_t\r
++notmuch_options_get (const char *name) {\r
++ if (STRNCMP_LITERAL (name, "compact") == 0) {\r
++ return notmuch_options_present (NOTMUCH_OPTION_COMPACT);\r
++ } else if (STRNCMP_LITERAL (name, "field_processor") == 0) {\r
++ return notmuch_options_present (NOTMUCH_OPTION_FIELD_PROCESSOR);\r
++ } else {\r
++ return FALSE;\r
++ }\r
++}\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index d252bb2..cfc549d 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -750,6 +750,8 @@ _item_split (char *item, char **group, char **key)\r
+ return 0;\r
+ }\r
+ \r
++#define OPTION_PREFIX "options."\r
++\r
+ static int\r
+ notmuch_config_command_get (notmuch_config_t *config, char *item)\r
+ {\r
+@@ -773,6 +775,9 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)\r
+ tags = notmuch_config_get_new_tags (config, &length);\r
+ for (i = 0; i < length; i++)\r
+ printf ("%s\n", tags[i]);\r
++ } else if (STRNCMP_LITERAL (item, OPTION_PREFIX) == 0) {\r
++ printf ("%s\n",\r
++ notmuch_options_get (item + strlen (OPTION_PREFIX)) ? "true" : "false");\r
+ } else {\r
+ char **value;\r
+ size_t i, length;\r
+@@ -804,6 +809,11 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char\r
+ {\r
+ char *group, *key;\r
+ \r
++ if (STRNCMP_LITERAL (item, OPTION_PREFIX) == 0) {\r
++ fprintf (stderr, "Error: read only option: %s\n", item);\r
++ return 1;\r
++ }\r
++\r
+ if (_item_split (item, &group, &key))\r
+ return 1;\r
+ \r
+@@ -830,6 +840,15 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char\r
+ return notmuch_config_save (config);\r
+ }\r
+ \r
++static\r
++void\r
++_notmuch_config_list_options () {\r
++ printf("options.compact=%s\n",\r
++ notmuch_options_present(NOTMUCH_OPTION_COMPACT) ? "true" : "false");\r
++ printf("options.field_processor=%s\n",\r
++ notmuch_options_present(NOTMUCH_OPTION_FIELD_PROCESSOR) ? "true" : "false");\r
++}\r
++\r
+ static int\r
+ notmuch_config_command_list (notmuch_config_t *config)\r
+ {\r
+@@ -865,6 +884,7 @@ notmuch_config_command_list (notmuch_config_t *config)\r
+ \r
+ g_strfreev (groups);\r
+ \r
++ _notmuch_config_list_options ();\r
+ return 0;\r
+ }\r
+ \r
+diff --git a/test/T030-config.sh b/test/T030-config.sh\r
+index f404908..c37ba21 100755\r
+--- a/test/T030-config.sh\r
++++ b/test/T030-config.sh\r
+@@ -44,7 +44,7 @@ test_expect_equal "$(notmuch config get foo.nonexistent)" ""\r
+ \r
+ test_begin_subtest "List all items"\r
+ notmuch config set database.path "/canonical/path"\r
+-output=$(notmuch config list)\r
++output=$(notmuch config list | notmuch_options_sanitize)\r
+ test_expect_equal "$output" "\\r
+ database.path=/canonical/path\r
+ user.name=Notmuch Test Suite\r
+@@ -56,7 +56,9 @@ search.exclude_tags=\r
+ maildir.synchronize_flags=true\r
+ crypto.gpg_path=gpg\r
+ foo.string=this is another string value\r
+-foo.list=this;is another;list value;"\r
++foo.list=this;is another;list value;\r
++options.compact=something\r
++options.field_processor=something"\r
+ \r
+ test_begin_subtest "Top level --config=FILE option"\r
+ cp "${NOTMUCH_CONFIG}" alt-config\r
+diff --git a/test/T040-setup.sh b/test/T040-setup.sh\r
+index cf0c00b..5db03a6 100755\r
+--- a/test/T040-setup.sh\r
++++ b/test/T040-setup.sh\r
+@@ -19,7 +19,7 @@ another.suite@example.com\r
+ foo bar\r
+ baz\r
+ EOF\r
+-output=$(notmuch --config=new-notmuch-config config list)\r
++output=$(notmuch --config=new-notmuch-config config list | notmuch_options_sanitize)\r
+ test_expect_equal "$output" "\\r
+ database.path=/path/to/maildir\r
+ user.name=Test Suite\r
+@@ -29,6 +29,8 @@ new.tags=foo;bar;\r
+ new.ignore=\r
+ search.exclude_tags=baz;\r
+ maildir.synchronize_flags=true\r
+-crypto.gpg_path=gpg"\r
++crypto.gpg_path=gpg\r
++options.compact=something\r
++options.field_processor=something"\r
+ \r
+ test_done\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index cc08a98..49e6f40 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -733,6 +733,12 @@ notmuch_uuid_sanitize ()\r
+ {\r
+ 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
+ }\r
++\r
++notmuch_options_sanitize ()\r
++{\r
++ sed 's/^options[.]\(.*\)=.*$/options.\1=something/'\r
++}\r
++\r
+ # End of notmuch helper functions\r
+ \r
+ # Use test_set_prereq to tell that a particular prerequisite is available.\r
+-- \r
+2.7.0\r
+\r