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 7D4E2429E2E for ; Mon, 3 Nov 2014 15:51:13 -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 7UorYG236elN for ; Mon, 3 Nov 2014 15:51:07 -0800 (PST) Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) by olra.theworths.org (Postfix) with ESMTP id 90424429E32 for ; Mon, 3 Nov 2014 15:50:51 -0800 (PST) Received: from localhost (unknown [192.168.200.7]) by max.feld.cvut.cz (Postfix) with ESMTP id 124975CD008; Tue, 4 Nov 2014 00:50:51 +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 TXyKONql-BxH; Tue, 4 Nov 2014 00:50:46 +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 E3BB05CD00C; Tue, 4 Nov 2014 00:50:40 +0100 (CET) Received: from wsh by steelpick.2x.cz with local (Exim 4.84) (envelope-from ) id 1XlROM-0005Wc-4p; Tue, 04 Nov 2014 00:50:34 +0100 From: Michal Sojka To: notmuch@notmuchmail.org Subject: [PATCH v2 05/10] cli: add support for hierarchical command line option arrays Date: Tue, 4 Nov 2014 00:50:17 +0100 Message-Id: <1415058622-21162-6-git-send-email-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1415058622-21162-1-git-send-email-sojkam1@fel.cvut.cz> References: <1415058622-21162-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: Mon, 03 Nov 2014 23:51:14 -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