From fc1289389a047ef7f3e6b9d98124cfdf3437d005 Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Mon, 28 May 2012 23:31:52 +1000 Subject: [PATCH] Re: [PATCH v6 1/6] cli: command line parsing: allow default for keyword options --- c9/d30a7e9cd671b05518c066bdb6e534bfbae9d1 | 117 ++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 c9/d30a7e9cd671b05518c066bdb6e534bfbae9d1 diff --git a/c9/d30a7e9cd671b05518c066bdb6e534bfbae9d1 b/c9/d30a7e9cd671b05518c066bdb6e534bfbae9d1 new file mode 100644 index 000000000..c0d489066 --- /dev/null +++ b/c9/d30a7e9cd671b05518c066bdb6e534bfbae9d1 @@ -0,0 +1,117 @@ +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 A5B78431FAF + for ; Mon, 28 May 2012 06:32:00 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.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 WdEA05QfPXlf for ; + Mon, 28 May 2012 06:32:00 -0700 (PDT) +Received: from mail-pz0-f53.google.com (mail-pz0-f53.google.com + [209.85.210.53]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 22794431FAE + for ; Mon, 28 May 2012 06:32:00 -0700 (PDT) +Received: by dadg9 with SMTP id g9so5241732dad.26 + for ; Mon, 28 May 2012 06:31:58 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=date:message-id:from:to:subject:in-reply-to:references:mime-version + :content-type:content-disposition:content-transfer-encoding; + bh=UgTQwJanb1bgx2Hjg0aaMK0wv7oJj6K8eWJv308CGsg=; + b=NrJIUws8kYTEDYEP4YLy+5bK8G8eYbII5VgDQko+Y1J+RcMGC0FACyoV91B9G/sZ/Y + 681Ht5tq34eFkaTIARvMtmLxGysfmh0ansFibsDaAH8slT+C12sTiRWX3OEviIq7CkDY + zAQBdt/vufCgJkh2HbOtFwqeu4qwbsOrS8suImVHSx1ecuKZVTUMDhC/9PgPJwi52cmW + KvVToiMI2FaatFlhCVv+wTy4j+RgNwSu/uvJpppM+pqqtjiA0vQ+IynQU8XU3eluCqiF + q+gBOUX3QhcGTO/hwjWIAIGgLanIhYlp0dqYuQSuKUCvyYbFdtlQrC43a9bAu5qM32dI + hwDQ== +Received: by 10.68.233.102 with SMTP id tv6mr27313781pbc.153.1338211918235; + Mon, 28 May 2012 06:31:58 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id rv5sm19298330pbc.56.2012.05.28.06.31.55 + (version=TLSv1/SSLv3 cipher=OTHER); + Mon, 28 May 2012 06:31:56 -0700 (PDT) +Date: Mon, 28 May 2012 23:31:52 +1000 +Message-ID: <20120528233152.GD2331@hili.localdomain> +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: Re: [PATCH v6 1/6] cli: command line parsing: allow default for + keyword options +In-Reply-To: <1338106946-7611-2-git-send-email-markwalters1009@gmail.com> +References: <1338106946-7611-1-git-send-email-markwalters1009@gmail.com> + <1338106946-7611-2-git-send-email-markwalters1009@gmail.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +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, 28 May 2012 13:32:00 -0000 + +On Sun, 27 May 2012 09:22:21 +0100, Mark Walters wrote: +> 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..2fb8a1b 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=""; +> + } +> + + +Whitespace. + +> 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) + +Whitespace. + +> + fprintf (stderr, "unknown keyword: %s\n", arg_str); +> + else +> + fprintf (stderr, "option %s needs a keyword\n", arg_desc->name); + +I think "keyword argument" is clearer. + +Peter -- 2.26.2