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 710FC431FBD for ; Sat, 9 Mar 2013 07:12:42 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" 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 fDo0HiKAkIXU for ; Sat, 9 Mar 2013 07:12:41 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com [209.85.215.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id F015F431FC3 for ; Sat, 9 Mar 2013 07:12:39 -0800 (PST) Received: by mail-la0-f48.google.com with SMTP id fq13so2568074lab.21 for ; Sat, 09 Mar 2013 07:12:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:x-gm-message-state; bh=0J6jsAbnii4LrMwbBNnf/7MJgkQV9xH0Nm1qFiQY0zc=; b=dr76RrNpdGi2LNPcD99+w8AWDpSVPNFr+cUmtwSQt8rXbxyIaRoM+xQ5XlnNvAO0V7 vZOzAYT7iUZn99vkKIFAjkjW8SzL7leyjsXMUaNxBmK0zj8jmxqyBhE6DA+GXL0O8k6V ugODq/4wiSQere/N/pU2qP6nmpoQzUKifk636qPZUSdc/+fbKcArIC3lUxvTbHNlTo/X S7y4u1KB/wW+RTc4xtHEwq+53oupgI9oyZ314mdaX3qE29HAFBN9uC5qUo4sZ3HgClnF uSBGiAQ//mNWC4k8WJ8iJvyX8NJmsCVphLIymR6GVH9okDHvLgGHfgl6u+W00KSMbGoy pZjg== X-Received: by 10.112.10.102 with SMTP id h6mr2316951lbb.75.1362841958399; Sat, 09 Mar 2013 07:12:38 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id e9sm2696962lbz.1.2013.03.09.07.12.36 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 09 Mar 2013 07:12:37 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v2 2/6] cli: extract count printing to a separate function in notmuch count Date: Sat, 9 Mar 2013 17:12:22 +0200 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQnFJFx96AXW8BZVe+HtO2VGlYkO+CAM8/q/QxsV/Xu/qETK5zfQwXTXVLyLWpZh+YVIsBF1 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: Sat, 09 Mar 2013 15:12:42 -0000 Make count printing on a query string reusable. No functional changes. --- notmuch-count.c | 59 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index c2f1b7d..630f036 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -32,16 +32,47 @@ enum { EXCLUDE_FALSE, }; +static int +print_count (notmuch_database_t *notmuch, const char *query_str, + const char **exclude_tags, size_t exclude_tags_length, int output) +{ + notmuch_query_t *query; + size_t i; + + query = notmuch_query_create (notmuch, query_str); + if (query == NULL) { + fprintf (stderr, "Out of memory\n"); + return 1; + } + + for (i = 0; i < exclude_tags_length; i++) + notmuch_query_add_tag_exclude (query, exclude_tags[i]); + + switch (output) { + case OUTPUT_MESSAGES: + printf ("%u\n", notmuch_query_count_messages (query)); + break; + case OUTPUT_THREADS: + printf ("%u\n", notmuch_query_count_threads (query)); + break; + } + + notmuch_query_destroy (query); + + return 0; +} + int notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) { notmuch_database_t *notmuch; - notmuch_query_t *query; char *query_str; int opt_index; int output = OUTPUT_MESSAGES; int exclude = EXCLUDE_TRUE; - unsigned int i; + const char **search_exclude_tags = NULL; + size_t search_exclude_tags_length = 0; + int ret; notmuch_opt_desc_t options[] = { { NOTMUCH_OPT_KEYWORD, &output, "output", 'o', @@ -71,33 +102,15 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) return 1; } - query = notmuch_query_create (notmuch, query_str); - if (query == NULL) { - fprintf (stderr, "Out of memory\n"); - return 1; - } - if (exclude == EXCLUDE_TRUE) { - const char **search_exclude_tags; - size_t search_exclude_tags_length; - search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_length); - for (i = 0; i < search_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); } - switch (output) { - case OUTPUT_MESSAGES: - printf ("%u\n", notmuch_query_count_messages (query)); - break; - case OUTPUT_THREADS: - printf ("%u\n", notmuch_query_count_threads (query)); - break; - } + ret = print_count (notmuch, query_str, search_exclude_tags, + search_exclude_tags_length, output); - notmuch_query_destroy (query); notmuch_database_destroy (notmuch); - return 0; + return ret; } -- 1.7.10.4