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 74824431FD6 for ; Thu, 24 Jan 2013 04:09:26 -0800 (PST) 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 lSVwp4Wmo950 for ; Thu, 24 Jan 2013 04:09:25 -0800 (PST) Received: from mail-da0-f54.google.com (mail-da0-f54.google.com [209.85.210.54]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 63318431FCF for ; Thu, 24 Jan 2013 04:09:20 -0800 (PST) Received: by mail-da0-f54.google.com with SMTP id n2so4258646dad.41 for ; Thu, 24 Jan 2013 04:09:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=VP7cZ2RmGU8gvZ3Iw4FhGlvKPM5YnlMkTxsxbZt0fQo=; b=sfA0Yuvf0qiH7JLtAAnjL1faOZaTKVxSWg+01HRaJ6aszRet7hgKEOg3eELhYzHLtl wLO3a+I9AA5HPaJ4rBzsWE3SUYQRX7XczL6EchO2y95EkTLME9ZcfB0Dp0dUwX/WIGgz sDU9WkuF3RFMf3ULY7dQsOPjlclTpqQJoJbQEmR+RBhH2KVd0YDR62jMzqEuTHEYvKRC H3dppbVoTnDOps5xnDQ/OWDJilHcorxjjyJCqYim+6ctsbQ/W84PO3bR0aLR473BA0TR 8R7kOSGTpFejVfboij418pakOledYn2qhYdgKJSFOi7/GhyutD1LOs9q0rAXpR4v75Ci 1TpQ== X-Received: by 10.68.220.6 with SMTP id ps6mr4191667pbc.80.1359029359643; Thu, 24 Jan 2013 04:09:19 -0800 (PST) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id o6sm15590382paw.37.2013.01.24.04.09.17 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 24 Jan 2013 04:09:18 -0800 (PST) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH v4 01/12] tag-util: move out 'tag' command-line checks Date: Thu, 24 Jan 2013 23:07:57 +1100 Message-Id: <1359029288-12132-2-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1359029288-12132-1-git-send-email-novalazy@gmail.com> References: <1359029288-12132-1-git-send-email-novalazy@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: Thu, 24 Jan 2013 12:09:26 -0000 parse_tag_command_line checked for two error conditions which are specific to the 'tag' command. It can be reused for the forthcoming notmuch 'insert' command if we move the checks out, into notmuch-tag.c. --- notmuch-tag.c | 10 ++++++++++ tag-util.c | 11 +++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/notmuch-tag.c b/notmuch-tag.c index d9daf8f..a901dad 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -234,6 +234,16 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index, &query_string, tag_ops)) return 1; + + if (tag_op_list_size (tag_ops) == 0) { + fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n"); + return 1; + } + + if (*query_string == '\0') { + fprintf (stderr, "Error: notmuch tag requires at least one search term.\n"); + return 1; + } } config = notmuch_config_open (ctx, NULL, NULL); diff --git a/tag-util.c b/tag-util.c index 701d329..743d591 100644 --- a/tag-util.c +++ b/tag-util.c @@ -188,16 +188,11 @@ parse_tag_command_line (void *ctx, int argc, char **argv, tag_op_list_append (tag_ops, argv[i] + 1, is_remove); } - if (tag_op_list_size (tag_ops) == 0) { - fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n"); - return TAG_PARSE_INVALID; - } - *query_str = query_string_from_args (ctx, argc - i, &argv[i]); - if (*query_str == NULL || **query_str == '\0') { - fprintf (stderr, "Error: notmuch tag requires at least one search term.\n"); - return TAG_PARSE_INVALID; + if (*query_str == NULL) { + fprintf (stderr, "Out of memory.\n"); + return TAG_PARSE_OUT_OF_MEMORY; } return TAG_PARSE_SUCCESS; -- 1.7.12.1