From: Tomi Ollila Date: Tue, 25 Feb 2014 19:24:58 +0000 (+0200) Subject: Re: [PATCH] cli: command line option parser cleanup X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9e13e67927a0eb48e449b6b2adf4bf5b6343724f;p=notmuch-archives.git Re: [PATCH] cli: command line option parser cleanup --- diff --git a/a3/b391007c6f6d51fbb0407f27b3e911025a4544 b/a3/b391007c6f6d51fbb0407f27b3e911025a4544 new file mode 100644 index 000000000..3f82ea777 --- /dev/null +++ b/a3/b391007c6f6d51fbb0407f27b3e911025a4544 @@ -0,0 +1,155 @@ +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 1940F429E49 + for ; Tue, 25 Feb 2014 11:25:15 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 a3gJ5zM1S6h4 for ; + Tue, 25 Feb 2014 11:25:07 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id CACFA429E43 + for ; Tue, 25 Feb 2014 11:25:06 -0800 (PST) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 5F985100064; + Tue, 25 Feb 2014 21:24:59 +0200 (EET) +From: Tomi Ollila +To: Jani Nikula , notmuch@notmuchmail.org +Subject: Re: [PATCH] cli: command line option parser cleanup +In-Reply-To: <1393277818-8430-1-git-send-email-jani@nikula.org> +References: <1393277818-8430-1-git-send-email-jani@nikula.org> +User-Agent: Notmuch/0.17+108~gb327c11 (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +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: Tue, 25 Feb 2014 19:25:15 -0000 + +On Mon, Feb 24 2014, Jani Nikula wrote: + +> Reduce the indentation for clarity. No functional changes. +> +> --- + +LGTM. I like the style. + +Tomi + + +> +> I've had this around for a while now, in preparation for something +> else that was never needed... +> --- +> command-line-arguments.c | 69 ++++++++++++++++++++++++------------------------ +> 1 file changed, 35 insertions(+), 34 deletions(-) +> +> diff --git a/command-line-arguments.c b/command-line-arguments.c +> index bf9aecabe869..844d6c3d18bf 100644 +> --- a/command-line-arguments.c +> +++ b/command-line-arguments.c +> @@ -129,40 +129,41 @@ parse_option (const char *arg, +> +> const notmuch_opt_desc_t *try; +> for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) { +> - if (try->name && strncmp (arg, try->name, strlen (try->name)) == 0) { +> - char next = arg[strlen (try->name)]; +> - const char *value= arg+strlen(try->name)+1; +> - +> - /* If we have not reached the end of the argument +> - (i.e. the next character is not a space or delimiter) +> - then the argument could still match a longer option +> - name later in the option table. +> - */ +> - if (next != '=' && next != ':' && next != '\0') +> - continue; +> - +> - if (try->output_var == NULL) +> - INTERNAL_ERROR ("output pointer NULL for option %s", try->name); +> - +> - switch (try->opt_type) { +> - case NOTMUCH_OPT_KEYWORD: +> - return _process_keyword_arg (try, next, value); +> - break; +> - case NOTMUCH_OPT_BOOLEAN: +> - return _process_boolean_arg (try, next, value); +> - break; +> - case NOTMUCH_OPT_INT: +> - return _process_int_arg (try, next, value); +> - break; +> - case NOTMUCH_OPT_STRING: +> - return _process_string_arg (try, next, value); +> - break; +> - case NOTMUCH_OPT_POSITION: +> - case NOTMUCH_OPT_END: +> - default: +> - INTERNAL_ERROR ("unknown or unhandled option type %d", try->opt_type); +> - /*UNREACHED*/ +> - } +> + if (! try->name) +> + continue; +> + +> + if (strncmp (arg, try->name, strlen (try->name)) != 0) +> + continue; +> + +> + char next = arg[strlen (try->name)]; +> + const char *value = arg + strlen(try->name) + 1; +> + +> + /* +> + * If we have not reached the end of the argument (i.e. the +> + * next character is not a space or delimiter) then the +> + * argument could still match a longer option name later in +> + * the option table. +> + */ +> + if (next != '=' && next != ':' && next != '\0') +> + continue; +> + +> + if (try->output_var == NULL) +> + INTERNAL_ERROR ("output pointer NULL for option %s", try->name); +> + +> + switch (try->opt_type) { +> + case NOTMUCH_OPT_KEYWORD: +> + return _process_keyword_arg (try, next, value); +> + case NOTMUCH_OPT_BOOLEAN: +> + return _process_boolean_arg (try, next, value); +> + case NOTMUCH_OPT_INT: +> + return _process_int_arg (try, next, value); +> + case NOTMUCH_OPT_STRING: +> + return _process_string_arg (try, next, value); +> + case NOTMUCH_OPT_POSITION: +> + case NOTMUCH_OPT_END: +> + default: +> + INTERNAL_ERROR ("unknown or unhandled option type %d", try->opt_type); +> + /*UNREACHED*/ +> } +> } +> fprintf (stderr, "Unrecognized option: --%s\n", arg); +> -- +> 1.8.5.3 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch