--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\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 81B08429E25\r
+ for <notmuch@notmuchmail.org>; Thu, 8 Mar 2012 14:16:12 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] 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 Cd8ez-OCKQWr for <notmuch@notmuchmail.org>;\r
+ Thu, 8 Mar 2012 14:16:12 -0800 (PST)\r
+Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
+ [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ CEEC8431FAE for <notmuch@notmuchmail.org>; Thu, 8 Mar 2012 14:16:11 -0800\r
+ (PST)\r
+Received: by mail-ww0-f45.google.com with SMTP id ds10so878463wgb.2\r
+ for <notmuch@notmuchmail.org>; Thu, 08 Mar 2012 14:16:11 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=UvY+VtrS18qmXIzo8Z6w8CC6EqsYraJnjzcaJkKkMoI=;\r
+ b=Yu/b4aTB/6TkxVXo4OTvVTZvY/tDDEhwsDQi9o9Y7sz4zeorXTSS45QVOY/Vur2wXy\r
+ sKsT4hmeKLIftlvGKwARFkGDGQlfadU36rJ79owAOvA2PCF9ivO/COcV9FiseGiw7hX4\r
+ 8mT20dg5S45UigL/u9njgtdiLygKabfho9/OqkUDrMr8I9pO6hmjcygcyhBTetx8z8GY\r
+ p0Ue2CIRwly52jh/eGnd3mYqMacPznNI1TsPiOMGWIMATpeKvgE7J0tcNdpDn476wVRY\r
+ hpND6JSSfagQskTQQfFoOExEvA4jmPImm8WoVOcghPpawEv5gk3+MQiGdB6Pgbq9xOO1\r
+ JJWQ==\r
+Received: by 10.216.132.98 with SMTP id n76mr4124246wei.101.1331244971342;\r
+ Thu, 08 Mar 2012 14:16:11 -0800 (PST)\r
+Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
+ [94.192.233.223]) by mx.google.com with ESMTPS id\r
+ fl2sm14898801wib.4.2012.03.08.14.16.10 (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Thu, 08 Mar 2012 14:16:10 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] cli: Parsing. Add option NOTMUCH_OPT_INT_OR_BOOLEAN\r
+Date: Thu, 8 Mar 2012 22:15:43 +0000\r
+Message-Id: <1331244944-7960-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1331244944-7960-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1331244944-7960-1-git-send-email-markwalters1009@gmail.com>\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, 08 Mar 2012 22:16:12 -0000\r
+\r
+Allow the option NOTMUCH_OPT_INT_OR_BOOLEAN for command line parsing\r
+which accepts --verbose=3 and --verbose with the latter setting\r
+verbose to 1. It also allows --verbose=0 so (with a little caller\r
+support) user can turn off boolean options.\r
+\r
+This means that extra options can be added to the command line\r
+programs in a backwards compatible manner.\r
+---\r
+ command-line-arguments.c | 29 +++++++++++++++++++++++++++--\r
+ command-line-arguments.h | 3 +++\r
+ 2 files changed, 30 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/command-line-arguments.c b/command-line-arguments.c\r
+index e711414..99e13c6 100644\r
+--- a/command-line-arguments.c\r
++++ b/command-line-arguments.c\r
+@@ -4,6 +4,22 @@\r
+ #include "error_util.h"\r
+ #include "command-line-arguments.h"\r
+ \r
++/* A helper for parsing an int to a boolean */\r
++notmuch_bool_t\r
++notmuch_int_to_boolean (int i)\r
++{\r
++ switch (i) {\r
++ case 1:\r
++ return TRUE;\r
++ case 0:\r
++ return FALSE;\r
++ default:\r
++ INTERNAL_ERROR ("Non-boolean value %d", i);\r
++ /* UNREACHED */\r
++ return FALSE;\r
++ }\r
++}\r
++\r
+ /*\r
+ Search the array of keywords for a given argument, assigning the\r
+ output variable to the corresponding value. Return FALSE if nothing\r
+@@ -72,6 +88,7 @@ parse_option (const char *arg,\r
+ if (try->name && strncmp (arg, try->name, strlen (try->name)) == 0) {\r
+ char next = arg[strlen (try->name)];\r
+ const char *value= arg+strlen(try->name)+1;\r
++ enum notmuch_opt_type opt_type = try->opt_type;\r
+ \r
+ char *endptr;\r
+ \r
+@@ -79,7 +96,14 @@ parse_option (const char *arg,\r
+ * delimiter, and a non-zero length value\r
+ */\r
+ \r
+- if (try->opt_type != NOTMUCH_OPT_BOOLEAN) {\r
++ if (opt_type == NOTMUCH_OPT_INT_OR_BOOLEAN) {\r
++ if (next != 0)\r
++ opt_type = NOTMUCH_OPT_INT;\r
++ else\r
++ opt_type = NOTMUCH_OPT_BOOLEAN;\r
++ }\r
++\r
++ if (opt_type != NOTMUCH_OPT_BOOLEAN) {\r
+ if (next != '=' && next != ':') return FALSE;\r
+ if (value[0] == 0) return FALSE;\r
+ } else {\r
+@@ -89,7 +113,7 @@ parse_option (const char *arg,\r
+ if (try->output_var == NULL)\r
+ INTERNAL_ERROR ("output pointer NULL for option %s", try->name);\r
+ \r
+- switch (try->opt_type) {\r
++ switch (opt_type) {\r
+ case NOTMUCH_OPT_KEYWORD:\r
+ return _process_keyword_arg (try, value);\r
+ break;\r
+@@ -107,6 +131,7 @@ parse_option (const char *arg,\r
+ break;\r
+ case NOTMUCH_OPT_POSITION:\r
+ case NOTMUCH_OPT_END:\r
++ case NOTMUCH_OPT_INT_OR_BOOLEAN: /* should be dealt with above */\r
+ default:\r
+ INTERNAL_ERROR ("unknown or unhandled option type %d", try->opt_type);\r
+ /*UNREACHED*/\r
+diff --git a/command-line-arguments.h b/command-line-arguments.h\r
+index de1734a..a2fc545 100644\r
+--- a/command-line-arguments.h\r
++++ b/command-line-arguments.h\r
+@@ -6,6 +6,7 @@\r
+ enum notmuch_opt_type {\r
+ NOTMUCH_OPT_END = 0,\r
+ NOTMUCH_OPT_BOOLEAN, /* --verbose */\r
++ NOTMUCH_OPT_INT_OR_BOOLEAN, /* --verbose or --verbose=1 */\r
+ NOTMUCH_OPT_INT, /* --frob=8 */\r
+ NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */\r
+ NOTMUCH_OPT_STRING, /* --file=/tmp/gnarf.txt */\r
+@@ -76,5 +77,7 @@ parse_position_arg (const char *arg,\r
+ int position_arg_index,\r
+ const notmuch_opt_desc_t* options);\r
+ \r
++notmuch_bool_t\r
++notmuch_int_to_boolean (int i);\r
+ \r
+ #endif\r
+-- \r
+1.7.9.1\r
+\r