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