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 0152E431FDC for ; Wed, 25 Jul 2012 06:44:10 -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 KwdukMViGVzD for ; Wed, 25 Jul 2012 06:44:09 -0700 (PDT) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8D937431FAE for ; Wed, 25 Jul 2012 06:44:09 -0700 (PDT) Received: by mail-pb0-f53.google.com with SMTP id rr13so1767731pbb.26 for ; Wed, 25 Jul 2012 06:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=znSJ6OY/HEngoNx3sDcCsFahxHQeS923hhE/P7Llewk=; b=XrHMAxzY6Z8ezbaBCaWCJGg0/5MaYWkZ/ztJxQ0iDdpIQPY4l/DP+voBeA0bBLWN4p QW9JXTI4t7PcB0xImio0GDqYtkxSNbiZnRreACp+YDCsc9lIMUPPs66FEnYNwvE03RYi la1XDnFbR1uk8MZhERd1n2Uu+yCruw1z6Rwnu08kYU8PXtsHKjH/7uah58e2SKsz8MJA FIAzjquErcufYkomhLHJj5ZwlfEd85OS4dpHkLSQ5op4zJgvER96zx8xPxYhLbF1S2wH iomXCzh2dK/PBGByWBkZwgzsMEvvXw5cDVZ6Dg8TTp6eMPsnalmPjiiMGa5HlLPew/50 Xv9w== Received: by 10.68.231.10 with SMTP id tc10mr53678564pbc.107.1343223849378; Wed, 25 Jul 2012 06:44:09 -0700 (PDT) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id ny4sm14408899pbb.57.2012.07.25.06.44.06 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jul 2012 06:44:08 -0700 (PDT) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH 10/18] insert: parse command-line tag operations Date: Wed, 25 Jul 2012 23:42:39 +1000 Message-Id: <1343223767-9812-10-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1343223767-9812-1-git-send-email-novalazy@gmail.com> References: <1343223767-9812-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: Wed, 25 Jul 2012 13:44:11 -0000 Parse +tag and -tag on the 'insert' command-line. Issue a warning about ambiguous -tag arguments which don't follow +tag nor an explicit option list terminator. --- notmuch-insert.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index 4fb3ea3..6db03e3 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -24,6 +24,11 @@ #include #include +typedef struct { + const char *tag; + notmuch_bool_t remove; +} tag_operation_t; + static notmuch_bool_t check_folder_name (const char *folder) { @@ -236,8 +241,11 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) const char **new_tags; size_t new_tags_length; const char *folder = NULL; + tag_operation_t *tag_ops; + int tag_ops_count = 0; char *maildir; int opt_index; + notmuch_bool_t warn_tag_rem; notmuch_bool_t ret; notmuch_opt_desc_t options[] = { @@ -253,6 +261,48 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) return 1; } + if (opt_index > 0 && strcmp (argv[opt_index - 1], "--") == 0) { + warn_tag_rem = FALSE; + } else { + warn_tag_rem = TRUE; + } + + /* Array of tagging operations (add or remove), terminated with an + * empty element. */ + tag_ops = talloc_array (ctx, tag_operation_t, argc - opt_index + 1); + if (tag_ops == NULL) { + fprintf (stderr, "Out of memory.\n"); + return 1; + } + + for (; opt_index < argc; opt_index++) { + if (argv[opt_index][0] == '+') { + tag_ops[tag_ops_count].tag = argv[opt_index] + 1; + tag_ops[tag_ops_count].remove = FALSE; + tag_ops_count++; + warn_tag_rem = FALSE; + } else if (argv[opt_index][0] == '-') { + if (warn_tag_rem) { + fprintf (stderr, + "Warning: ambiguous argument treated as tag removal: %s\n", + argv[opt_index]); + } + tag_ops[tag_ops_count].tag = argv[opt_index] + 1; + tag_ops[tag_ops_count].remove = TRUE; + tag_ops_count++; + } else { + break; + } + } + + tag_ops[tag_ops_count].tag = NULL; + + if (opt_index != argc) { + fprintf (stderr, "Error: bad argument to notmuch insert: %s\n", + argv[opt_index]); + return 1; + } + config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; -- 1.7.4.4