X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-count.c;h=20ce33426c7072cf3bf6688a07083d5c89b1f328;hp=97242abaa778b00764264a0c396e65f6be75e188;hb=d4c598dc9ed3af0d38fde9b9f0dcf6fa8dd62351;hpb=b15a03fafc2e313264519f030e45ea203af508e2 diff --git a/notmuch-count.c b/notmuch-count.c index 97242aba..20ce3342 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -29,45 +29,26 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) notmuch_query_t *query; char *query_str; int i; -#if 0 - char *opt, *end; - int i, first = 0, max_threads = -1; - notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST; -#endif + notmuch_bool_t output_messages = TRUE; + + argc--; argv++; /* skip subcommand argument */ for (i = 0; i < argc && argv[i][0] == '-'; i++) { if (strcmp (argv[i], "--") == 0) { i++; break; } -#if 0 - if (STRNCMP_LITERAL (argv[i], "--first=") == 0) { - opt = argv[i] + sizeof ("--first=") - 1; - first = strtoul (opt, &end, 10); - if (*opt == '\0' || *end != '\0') { - fprintf (stderr, "Invalid value for --first: %s\n", opt); - return 1; - } - } else if (STRNCMP_LITERAL (argv[i], "--max-threads=") == 0) { - opt = argv[i] + sizeof ("--max-threads=") - 1; - max_threads = strtoul (opt, &end, 10); - if (*opt == '\0' || *end != '\0') { - fprintf (stderr, "Invalid value for --max-threads: %s\n", opt); - return 1; - } - } else if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) { - opt = argv[i] + sizeof ("--sort=") - 1; - if (strcmp (opt, "oldest-first") == 0) { - sort = NOTMUCH_SORT_OLDEST_FIRST; - } else if (strcmp (opt, "newest-first") == 0) { - sort = NOTMUCH_SORT_NEWEST_FIRST; + if (STRNCMP_LITERAL (argv[i], "--output=") == 0) { + const char *opt = argv[i] + sizeof ("--output=") - 1; + if (strcmp (opt, "threads") == 0) { + output_messages = FALSE; + } else if (strcmp (opt, "messages") == 0) { + output_messages = TRUE; } else { - fprintf (stderr, "Invalid value for --sort: %s\n", opt); + fprintf (stderr, "Invalid value for --output: %s\n", opt); return 1; } - } else -#endif - { + } else { fprintf (stderr, "Unrecognized option: %s\n", argv[i]); return 1; } @@ -90,7 +71,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) fprintf (stderr, "Out of memory.\n"); return 1; } - if (*query_str == '\0' || (*query_str == '*' && *(query_str+1) == '\0')) { + + if (*query_str == '\0') { query_str = talloc_strdup (ctx, ""); } @@ -100,7 +82,10 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) return 1; } - printf ("%u\n", notmuch_query_count_messages(query)); + if (output_messages) + printf ("%u\n", notmuch_query_count_messages (query)); + else + printf ("%u\n", notmuch_query_count_threads (query)); notmuch_query_destroy (query); notmuch_database_close (notmuch);