From 4318a7d91141dbfd260aff0dfd7dd53db68e3537 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 5 Nov 2014 01:25:54 +0100 Subject: [PATCH] [PATCH v3 05/10] cli: add support for hierarchical command line option arrays --- 51/6d7ad3e79236f0501deda870a6d756bb1e85a9 | 128 ++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 51/6d7ad3e79236f0501deda870a6d756bb1e85a9 diff --git a/51/6d7ad3e79236f0501deda870a6d756bb1e85a9 b/51/6d7ad3e79236f0501deda870a6d756bb1e85a9 new file mode 100644 index 000000000..a5c576cc1 --- /dev/null +++ b/51/6d7ad3e79236f0501deda870a6d756bb1e85a9 @@ -0,0 +1,128 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 1A9F6431FD2 + for ; Tue, 4 Nov 2014 16:26:26 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id KtR01dhhAkKx for ; + Tue, 4 Nov 2014 16:26:18 -0800 (PST) +Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) + by olra.theworths.org (Postfix) with ESMTP id 8CA87431FAE + for ; Tue, 4 Nov 2014 16:26:18 -0800 (PST) +Received: from localhost (unknown [192.168.200.7]) + by max.feld.cvut.cz (Postfix) with ESMTP id 959D25CD1B3; + Wed, 5 Nov 2014 01:26:17 +0100 (CET) +X-Virus-Scanned: IMAP STYX AMAVIS +Received: from max.feld.cvut.cz ([192.168.200.1]) + by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new, + port 10044) + with ESMTP id ePLw06xGE8iN; Wed, 5 Nov 2014 01:26:13 +0100 (CET) +Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34]) + by max.feld.cvut.cz (Postfix) with ESMTP id 7A67A5CD1A9; + Wed, 5 Nov 2014 01:26:13 +0100 (CET) +Received: from wsh by steelpick.2x.cz with local (Exim 4.84) + (envelope-from ) + id 1XloQI-0005Cx-SD; Wed, 05 Nov 2014 01:26:06 +0100 +From: Michal Sojka +To: notmuch@notmuchmail.org +Subject: [PATCH v3 05/10] cli: add support for hierarchical command line + option arrays +Date: Wed, 5 Nov 2014 01:25:54 +0100 +Message-Id: <1415147159-19946-6-git-send-email-sojkam1@fel.cvut.cz> +X-Mailer: git-send-email 2.1.1 +In-Reply-To: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz> +References: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Wed, 05 Nov 2014 00:26:26 -0000 + +From: Jani Nikula + +NOTMUCH_OPT_INHERIT expects a notmuch_opt_desc_t * pointer in +output_var. + +The "Unrecognized option" message was moved out of parse_option() to +not be emitted twice or when parsing a non-inherited option. +--- + command-line-arguments.c | 16 +++++++++------- + command-line-arguments.h | 1 + + 2 files changed, 10 insertions(+), 7 deletions(-) + +diff --git a/command-line-arguments.c b/command-line-arguments.c +index c6f7269..de6b453 100644 +--- a/command-line-arguments.c ++++ b/command-line-arguments.c +@@ -122,16 +122,18 @@ parse_position_arg (const char *arg_str, int pos_arg_index, + */ + + notmuch_bool_t +-parse_option (const char *arg, +- const notmuch_opt_desc_t *options) { +- +- assert(arg); ++parse_option (const char *_arg, const notmuch_opt_desc_t *options) ++{ ++ assert(_arg); + assert(options); + +- arg += 2; +- ++ const char *arg = _arg + 2; /* _arg starts with -- */ + const notmuch_opt_desc_t *try; + for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) { ++ if (try->opt_type == NOTMUCH_OPT_INHERIT && ++ parse_option (_arg, try->output_var)) ++ return TRUE; ++ + if (! try->name) + continue; + +@@ -170,7 +172,6 @@ parse_option (const char *arg, + /*UNREACHED*/ + } + } +- fprintf (stderr, "Unrecognized option: --%s\n", arg); + return FALSE; + } + +@@ -201,6 +202,7 @@ parse_arguments (int argc, char **argv, + if (more_args) { + opt_index++; + } else { ++ fprintf (stderr, "Unrecognized option: %s\n", argv[opt_index]); + opt_index = -1; + } + +diff --git a/command-line-arguments.h b/command-line-arguments.h +index 6444129..309aaf2 100644 +--- a/command-line-arguments.h ++++ b/command-line-arguments.h +@@ -5,6 +5,7 @@ + + enum notmuch_opt_type { + NOTMUCH_OPT_END = 0, ++ NOTMUCH_OPT_INHERIT, /* another options table */ + NOTMUCH_OPT_BOOLEAN, /* --verbose */ + NOTMUCH_OPT_INT, /* --frob=8 */ + NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */ +-- +2.1.1 + -- 2.26.2