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 0AA05429E42 for ; Mon, 10 Oct 2011 06:50:07 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[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 kWL95MxcYxtM for ; Mon, 10 Oct 2011 06:50:06 -0700 (PDT) Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 230EA429E57 for ; Mon, 10 Oct 2011 06:49:59 -0700 (PDT) Received: from zancas.localnet (fctnnbsc36w-156034064058.pppoe-dynamic.High-Speed.nb.bellaliant.net [156.34.64.58]) (authenticated bits=0) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id p9ADntqg010828 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Mon, 10 Oct 2011 10:49:56 -0300 Received: from bremner by zancas.localnet with local (Exim 4.76) (envelope-from ) id 1RDGEq-0006fr-92; Mon, 10 Oct 2011 10:49:52 -0300 From: david@tethera.net To: notmuch@notmuchmail.org Subject: [PATCH 3/6] notmuch-dump: update handling of file name argument Date: Mon, 10 Oct 2011 10:49:18 -0300 Message-Id: <1318254561-25386-4-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.6.3 In-Reply-To: <1318254561-25386-1-git-send-email-david@tethera.net> References: <8739f2qhla.fsf@zancas.localnet> <1318254561-25386-1-git-send-email-david@tethera.net> Cc: David Bremner 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, 10 Oct 2011 13:50:07 -0000 From: David Bremner We permit -- as an "option processing terminator". Currently this does not do anything useful, but we plan to add search terms after the --. --- notmuch-dump.c | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-) diff --git a/notmuch-dump.c b/notmuch-dump.c index 7e7bc17..610144e 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -26,7 +26,7 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) notmuch_config_t *config; notmuch_database_t *notmuch; notmuch_query_t *query; - FILE *output; + FILE *output = stdout; notmuch_messages_t *messages; notmuch_message_t *message; notmuch_tags_t *tags; @@ -40,23 +40,28 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) if (notmuch == NULL) return 1; - query = notmuch_query_create (notmuch, ""); - if (query == NULL) { - fprintf (stderr, "Out of memory\n"); - return 1; - } - notmuch_query_set_sort (query, NOTMUCH_SORT_MESSAGE_ID); - - if (argc) { + if (argc && strcmp (argv[0], "--") != 0) { output = fopen (argv[0], "w"); if (output == NULL) { fprintf (stderr, "Error opening %s for writing: %s\n", argv[0], strerror (errno)); return 1; } - } else { - output = stdout; + argc--; + argv++; + } + + if (argc && strcmp (argv[0], "--") == 0){ + argc--; + argv++; + } + + query = notmuch_query_create (notmuch, ""); + if (query == NULL) { + fprintf (stderr, "Out of memory\n"); + return 1; } + notmuch_query_set_sort (query, NOTMUCH_SORT_MESSAGE_ID); for (messages = notmuch_query_search_messages (query); notmuch_messages_valid (messages); -- 1.7.6.3