From 731a3ce5e1db052db0230d7a2533a83282f2998c Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Sun, 25 Nov 2012 16:13:14 +0000 Subject: [PATCH] Re: [PATCH v2 01/20] tag: factor out tag operation parsing --- 34/dc75ab90defb700e78ee34c9ea4e340a08e891 | 180 ++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 34/dc75ab90defb700e78ee34c9ea4e340a08e891 diff --git a/34/dc75ab90defb700e78ee34c9ea4e340a08e891 b/34/dc75ab90defb700e78ee34c9ea4e340a08e891 new file mode 100644 index 000000000..80fb503c2 --- /dev/null +++ b/34/dc75ab90defb700e78ee34c9ea4e340a08e891 @@ -0,0 +1,180 @@ +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 E6708431FAF + for ; Sun, 25 Nov 2012 08:13:13 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, 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 TN9ObLkNZQy9 for ; + Sun, 25 Nov 2012 08:13:13 -0800 (PST) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 4021E431FAE + for ; Sun, 25 Nov 2012 08:13:13 -0800 (PST) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1TcepT-00051s-RF; Sun, 25 Nov 2012 16:13:12 +0000 +Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1TcepT-0001Tm-G2; Sun, 25 Nov 2012 16:13:11 +0000 +From: Mark Walters +To: Peter Wang , notmuch@notmuchmail.org +Subject: Re: [PATCH v2 01/20] tag: factor out tag operation parsing +In-Reply-To: <1353806206-29133-2-git-send-email-novalazy@gmail.com> +References: <1353806206-29133-1-git-send-email-novalazy@gmail.com> + <1353806206-29133-2-git-send-email-novalazy@gmail.com> +User-Agent: Notmuch/0.14+81~g9730584 (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Sun, 25 Nov 2012 16:13:14 +0000 +Message-ID: <878v9pk6ed.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 93.97.24.31 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: 3fe47295da988fc873e6072d710fbab1 (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +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: Sun, 25 Nov 2012 16:13:14 -0000 + + +On Sun, 25 Nov 2012, Peter Wang wrote: +> Factor out parsing of +tag, -tag operations from argv +> into a separate function. +> --- +> notmuch-tag.c | 66 +++++++++++++++++++++++++++++++++++++---------------------- +> 1 file changed, 41 insertions(+), 25 deletions(-) +> +> diff --git a/notmuch-tag.c b/notmuch-tag.c +> index 88d559b..35a76db 100644 +> --- a/notmuch-tag.c +> +++ b/notmuch-tag.c +> @@ -167,11 +167,48 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string, +> return interrupted; +> } +> +> +/* Parse +tag and -tag operations between argv[i] and argv[argc-1]. +> + * The array tag_ops must be at least argc - i elements long. +> + * Returns the index into argv where parsing stopped, or -1 on error. */ + +Perhaps mention tag_ops_count (as the number of tags parsed or +something)? + +> +static int +> +parse_tag_operations (int i, int argc, char *argv[], +> + tag_operation_t *tag_ops, int *tag_ops_count) +> +{ +> + *tag_ops_count = 0; +> + +> + for (; i < argc; i++) { +> + if (strcmp (argv[i], "--") == 0) { +> + i++; +> + break; +> + } +> + if (argv[i][0] == '+' || argv[i][0] == '-') { +> + if (argv[i][0] == '+' && argv[i][1] == '\0') { +> + fprintf (stderr, "Error: tag names cannot be empty.\n"); +> + return -1; +> + } +> + if (argv[i][0] == '+' && argv[i][1] == '-') { +> + /* This disallows adding the non-removable tag "-" and +> + * enables notmuch tag to take long options in the +> + * future. */ +> + fprintf (stderr, "Error: tag names must not start with '-'.\n"); +> + return -1; +> + } +> + tag_ops[*tag_ops_count].tag = argv[i] + 1; +> + tag_ops[*tag_ops_count].remove = (argv[i][0] == '-'); +> + (*tag_ops_count)++; +> + } else { +> + break; +> + } +> + } +> + +> + return i; +> +} +> + +> int +> notmuch_tag_command (void *ctx, int argc, char *argv[]) +> { +> tag_operation_t *tag_ops; +> - int tag_ops_count = 0; +> + int tag_ops_count; +> char *query_string; +> notmuch_config_t *config; +> notmuch_database_t *notmuch; +> @@ -197,30 +234,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) +> return 1; +> } +> +> - for (i = 0; i < argc; i++) { +> - if (strcmp (argv[i], "--") == 0) { +> - i++; +> - break; +> - } +> - if (argv[i][0] == '+' || argv[i][0] == '-') { +> - if (argv[i][0] == '+' && argv[i][1] == '\0') { +> - fprintf (stderr, "Error: tag names cannot be empty.\n"); +> - return 1; +> - } +> - if (argv[i][0] == '+' && argv[i][1] == '-') { +> - /* This disallows adding the non-removable tag "-" and +> - * enables notmuch tag to take long options in the +> - * future. */ +> - fprintf (stderr, "Error: tag names must not start with '-'.\n"); +> - return 1; +> - } +> - tag_ops[tag_ops_count].tag = argv[i] + 1; +> - tag_ops[tag_ops_count].remove = (argv[i][0] == '-'); +> - tag_ops_count++; +> - } else { +> - break; +> - } +> - } +> + i = parse_tag_operations (0, argc, argv, tag_ops, &tag_ops_count); +> + if (i < 0) +> + return 1; +> +> tag_ops[tag_ops_count].tag = NULL; +> +> -- +> 1.7.12.1 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2