From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 47BDF431FAE for ; Sat, 16 Jun 2012 03:22:05 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 4PvYuAL2QCtf for ; Sat, 16 Jun 2012 03:22:04 -0700 (PDT) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A023B431FB6 for ; Sat, 16 Jun 2012 03:22:04 -0700 (PDT) Received: by wibhr14 with SMTP id hr14so238325wib.2 for ; Sat, 16 Jun 2012 03:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=ba2TXiOJxZGeViEVJJ/ucZP1tFS2i3Nle6Yh8ac+HJk=; b=C2Qso/piHzdXf9qMEk6by0vVYXG01JFkonPwYDwzSCoxPrgLNh9ktKlQxKhWj4tdB3 2vmI/u3qtVVsQjGhg74cpTlkjfY2bLWIgmAvllfJSBWMfX1vqHYHerh3p68HbZcGQSUf 1jAMNfg+CrIrEfgpFgu4v3Ai70JaW22qonknf5FWK9gixxbsPd/J4GQcjsFpznIK4Lur 4NfvbyAA/SvK42yGx4GH5PaISGzz1CSvvQBfYmIPh6+NP1f45eJ4I4gvSUndvhT1vXDs pn/FuZ1wX/zMCdmwM4/IogiDYnhg2GdaYZhV6dsWrWJg83Wc55g6fPCQhGejNXYLqDLW pYRg== Received: by 10.216.213.143 with SMTP id a15mr5157705wep.156.1339842123201; Sat, 16 Jun 2012 03:22:03 -0700 (PDT) Received: from localhost (94-192-233-223.zone6.bethere.co.uk. [94.192.233.223]) by mx.google.com with ESMTPS id hv7sm16617138wib.0.2012.06.16.03.22.01 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 16 Jun 2012 03:22:02 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [Patch v8 1/6] cli: command line parsing: allow default for keyword options Date: Sat, 16 Jun 2012 11:21:42 +0100 Message-Id: <1339842107-10632-2-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1339842107-10632-1-git-send-email-markwalters1009@gmail.com> References: <1339842107-10632-1-git-send-email-markwalters1009@gmail.com> 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: Sat, 16 Jun 2012 10:22:05 -0000 This changes the parsing for "keyword" options so that if the option is specified with no argument the argument is parsed as if it were passed an empty string. This make it easier to add options to existing boolean arguments (the existing --option can default to TRUE). --- command-line-arguments.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diff --git a/command-line-arguments.c b/command-line-arguments.c index 76b185f..b0a0dab 100644 --- a/command-line-arguments.c +++ b/command-line-arguments.c @@ -11,10 +11,15 @@ */ static notmuch_bool_t -_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) { +_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { const notmuch_keyword_t *keywords = arg_desc->keywords; + if (next == 0) { + /* No keyword given */ + arg_str = ""; + } + while (keywords->name) { if (strcmp (arg_str, keywords->name) == 0) { if (arg_desc->output_var) { @@ -24,7 +29,10 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) { } keywords++; } - fprintf (stderr, "unknown keyword: %s\n", arg_str); + if (next != 0) + fprintf (stderr, "unknown keyword: %s\n", arg_str); + else + fprintf (stderr, "option %s needs a keyword\n", arg_desc->name); return FALSE; } @@ -99,7 +107,8 @@ parse_option (const char *arg, */ if (next != '=' && next != ':' && next != 0) return FALSE; if (next == 0) { - if (try->opt_type != NOTMUCH_OPT_BOOLEAN) + if (try->opt_type != NOTMUCH_OPT_BOOLEAN && + try->opt_type != NOTMUCH_OPT_KEYWORD) return FALSE; } else { if (value[0] == 0) return FALSE; @@ -110,7 +119,7 @@ parse_option (const char *arg, switch (try->opt_type) { case NOTMUCH_OPT_KEYWORD: - return _process_keyword_arg (try, value); + return _process_keyword_arg (try, next, value); break; case NOTMUCH_OPT_BOOLEAN: return _process_boolean_arg (try, next, value); -- 1.7.9.1