[PATCH 8/8] cli: use notmuch_exclude_t in option parser

Peter Wang novalazy at gmail.com
Wed Jun 20 06:29:07 PDT 2012


Use notmuch_exclude_t constants directly instead of a redundant
enumeration while parsing search --exclude keyword arguments.
---
 notmuch-search.c |   28 +++++++++-------------------
 1 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/notmuch-search.c b/notmuch-search.c
index 027923d..23cf342 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -416,13 +416,6 @@ do_search_tags (notmuch_database_t *notmuch,
     return 0;
 }
 
-enum {
-    EXCLUDE_TRUE,
-    EXCLUDE_FALSE,
-    EXCLUDE_FLAG,
-    EXCLUDE_ALL
-};
-
 int
 notmuch_search_command (void *ctx, int argc, char *argv[])
 {
@@ -436,7 +429,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
     output_t output = OUTPUT_SUMMARY;
     int offset = 0;
     int limit = -1; /* unlimited */
-    int exclude = EXCLUDE_TRUE;
+    notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE;
     unsigned int i;
 
     enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }
@@ -459,10 +452,10 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 				  { "tags", OUTPUT_TAGS },
 				  { 0, 0 } } },
         { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
-          (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
-                                  { "false", EXCLUDE_FALSE },
-                                  { "flag", EXCLUDE_FLAG },
-                                  { "all", EXCLUDE_ALL },
+          (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
+                                  { "false", NOTMUCH_EXCLUDE_FALSE },
+                                  { "flag", NOTMUCH_EXCLUDE_FLAG },
+                                  { "all", NOTMUCH_EXCLUDE_ALL },
                                   { 0, 0 } } },
 	{ NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },
 	{ NOTMUCH_OPT_INT, &limit, "limit", 'L', 0  },
@@ -510,15 +503,15 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 
     notmuch_query_set_sort (query, sort);
 
-    if (exclude == EXCLUDE_FLAG && output != OUTPUT_SUMMARY) {
+    if (exclude == NOTMUCH_EXCLUDE_FLAG && output != OUTPUT_SUMMARY) {
 	/* If we are not doing summary output there is nowhere to
 	 * print the excluded flag so fall back on including the
 	 * excluded messages. */
 	fprintf (stderr, "Warning: this output format cannot flag excluded messages.\n");
-	exclude = EXCLUDE_FALSE;
+	exclude = NOTMUCH_EXCLUDE_FALSE;
     }
 
-    if (exclude != EXCLUDE_FALSE) {
+    if (exclude != NOTMUCH_EXCLUDE_FALSE) {
 	const char **search_exclude_tags;
 	size_t search_exclude_tags_length;
 
@@ -526,10 +519,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 	    (config, &search_exclude_tags_length);
 	for (i = 0; i < search_exclude_tags_length; i++)
 	    notmuch_query_add_tag_exclude (query, search_exclude_tags[i]);
-	if (exclude == EXCLUDE_FLAG)
-	    notmuch_query_set_omit_excluded (query, NOTMUCH_EXCLUDE_FLAG);
-	if (exclude == EXCLUDE_ALL)
-	    notmuch_query_set_omit_excluded (query, NOTMUCH_EXCLUDE_ALL);
+	notmuch_query_set_omit_excluded (query, exclude);
     }
 
     switch (output) {
-- 
1.7.4.4



More information about the notmuch mailing list