From f61d82db344793d3c30ec5bfd06fca6e169f38a6 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Mon, 24 Feb 2014 23:36:58 +0200 Subject: [PATCH] [PATCH] cli: command line option parser cleanup --- f4/433b73177b2091bc52580042359b97a570fedf | 156 ++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 f4/433b73177b2091bc52580042359b97a570fedf diff --git a/f4/433b73177b2091bc52580042359b97a570fedf b/f4/433b73177b2091bc52580042359b97a570fedf new file mode 100644 index 000000000..3b410c466 --- /dev/null +++ b/f4/433b73177b2091bc52580042359b97a570fedf @@ -0,0 +1,156 @@ +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 70D44431FD9 + for ; Mon, 24 Feb 2014 13:37:09 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[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 DVPXWLzJqU6K for ; + Mon, 24 Feb 2014 13:37:04 -0800 (PST) +Received: from mail-ea0-f182.google.com (mail-ea0-f182.google.com + [209.85.215.182]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id BA332431FCF + for ; Mon, 24 Feb 2014 13:37:03 -0800 (PST) +Received: by mail-ea0-f182.google.com with SMTP id r15so3383638ead.41 + for ; Mon, 24 Feb 2014 13:37:01 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id; + bh=wSbr8duGCT9hvlRony3ddtM4SvxrXYoLxxMQb2NDEGM=; + b=GYo+SLt4N7R0d1SqSAd2OIMDo1Y6207azxmY3xfFVlFpBoB3DXh3frTaU6SXCqMWED + fnTkDn/lUEAVqZGgFvgzDnYUB6BvDzK1r0eJG8oQK8G1gtVRKdGlJCKmf2u5TMXyNiOa + U9+/3BeWDlvWklh8/7aIrjaBaztSf4cnNCbnigdZgi4WUEanDGGWagikhwoU7KQQOv7D + QYGmz0r7cJUp6iZkcQqgOlBrvAS0ZLYoTtid/zIwtB+NVT72aE5Qh5cwEFn+EEV+4RUH + FD1l68gh/Q3rXKIDznx3ezabAAkC2ZWQbvu5Zws/PwwnUVN1uv6q8TYvEbLFcjKWIE5Y + PDFw== +X-Gm-Message-State: + ALoCoQk0tqOcpb3qeXLo+MfPO9M+3FYU+6/xhZ6PbE8T7yIqVx8B1fP8iycUeODBg56o95L+rYW8 +X-Received: by 10.14.1.68 with SMTP id 44mr27323853eec.0.1393277821014; + Mon, 24 Feb 2014 13:37:01 -0800 (PST) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) + by mx.google.com with ESMTPSA id n48sm47572595eew.0.2014.02.24.13.36.59 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Mon, 24 Feb 2014 13:37:00 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH] cli: command line option parser cleanup +Date: Mon, 24 Feb 2014 23:36:58 +0200 +Message-Id: <1393277818-8430-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 1.8.5.3 +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, 24 Feb 2014 21:37:09 -0000 + +Reduce the indentation for clarity. No functional changes. + +--- + +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 + -- 2.26.2