[PATCH 2/3] notmuch-dump: convert to notmuch-opts option-parsing.
authorDavid Bremner <bremner@debian.org>
Thu, 1 Dec 2011 01:15:29 +0000 (17:15 +1600)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:40:31 +0000 (09:40 -0800)
e4/266f42ae08ca05ead78b6cb1b735f59db16436 [new file with mode: 0644]

diff --git a/e4/266f42ae08ca05ead78b6cb1b735f59db16436 b/e4/266f42ae08ca05ead78b6cb1b735f59db16436
new file mode 100644 (file)
index 0000000..e6992ec
--- /dev/null
@@ -0,0 +1,134 @@
+Return-Path: <bremner@unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 5D181429E27\r
+       for <notmuch@notmuchmail.org>; Wed, 30 Nov 2011 17:15:54 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 02hxuyNPe0xe for <notmuch@notmuchmail.org>;\r
+       Wed, 30 Nov 2011 17:15:53 -0800 (PST)\r
+Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id AA7ED431FD0\r
+       for <notmuch@notmuchmail.org>; Wed, 30 Nov 2011 17:15:53 -0800 (PST)\r
+Received: from rocinante.cs.unb.ca (m3.kereda.com [207.194.238.3] (may be\r
+       forged)) (authenticated bits=0)\r
+       by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pB11FnmK008709\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
+       Wed, 30 Nov 2011 21:15:50 -0400\r
+Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.76)\r
+       (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+       id 1RVvFd-0006qU-9e; Wed, 30 Nov 2011 17:15:49 -0800\r
+From: David Bremner <bremner@debian.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] notmuch-dump: convert to notmuch-opts option-parsing.\r
+Date: Wed, 30 Nov 2011 17:15:29 -0800\r
+Message-Id: <1322702130-26068-2-git-send-email-bremner@debian.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1322702130-26068-1-git-send-email-bremner@debian.org>\r
+References:\r
+ <7574621578db9bbfc88348c87e2f5431f4cb2296.1321223343.git.jani@nikula.org>\r
+       <1322702130-26068-1-git-send-email-bremner@debian.org>\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 01 Dec 2011 01:15:54 -0000\r
+\r
+This is actually a bit of a tricky case because of the treating of the\r
+first non-option as a filename. On the other hand, we don't do any\r
+"normal" argument parsing yet.\r
+---\r
+ notmuch-dump.c |   46 +++++++++++++++++++++++++++++++---------------\r
+ 1 files changed, 31 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+index 0475eb9..8a8d6ec 100644\r
+--- a/notmuch-dump.c\r
++++ b/notmuch-dump.c\r
+@@ -19,6 +19,7 @@\r
+  */\r
\r
+ #include "notmuch-client.h"\r
++#include "notmuch-opts.h"\r
\r
+ int\r
+ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+@@ -41,27 +42,42 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+     if (notmuch == NULL)\r
+       return 1;\r
\r
+-    argc--; argv++; /* skip subcommand argument */\r
++    notmuch_opt_desc_t options[] = {\r
++      { 0, 0, 0, 0 }\r
++    };\r
\r
+-    if (argc && strcmp (argv[0], "--") != 0) {\r
+-      fprintf (stderr, "Warning: the output file argument of dump is deprecated.\n");\r
+-      output = fopen (argv[0], "w");\r
+-      if (output == NULL) {\r
+-          fprintf (stderr, "Error opening %s for writing: %s\n",\r
+-                   argv[0], strerror (errno));\r
++    notmuch_opt_t result;\r
++    int opt_index;\r
++    notmuch_bool_t more_args=TRUE;\r
++\r
++    for (opt_index = 1; more_args && opt_index < argc; opt_index++) {\r
++\r
++      more_args=parse_argument (argv[0], argv[opt_index], options, &result);\r
++\r
++      switch (result.arg_id) {\r
++      case '?':\r
+           return 1;\r
++          break;\r
++      case '*':\r
++          fprintf (stderr, "Warning: the output file argument of dump is deprecated.\n");\r
++          output = fopen (result.string, "w");\r
++          if (output == NULL) {\r
++              fprintf (stderr, "Error opening %s for writing: %s\n",\r
++                       result.string, strerror (errno));\r
++              return 1;\r
++          }\r
++      case '-':\r
++          /* fall through */\r
++          more_args=FALSE;\r
++          break;\r
+       }\r
+-      argc--;\r
+-      argv++;\r
+     }\r
\r
+-    if (argc && strcmp (argv[0], "--") == 0){\r
+-      argc--;\r
+-      argv++;\r
+-    }\r
++    if (opt_index < argc && strcmp(argv[opt_index],"--") == 0)\r
++      opt_index++;\r
\r
+-    if (argc) {\r
+-      query_str = query_string_from_args (notmuch, argc, argv);\r
++    if (opt_index < argc) {\r
++      query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);\r
+       if (query_str == NULL) {\r
+           fprintf (stderr, "Out of memory.\n");\r
+           return 1;\r
+-- \r
+1.7.5.4\r
+\r