+/* The following is to allow future options to be added more easily */
+enum {
+ EXCLUDE_TRUE,
+ EXCLUDE_FALSE,
+};
+
+static int
+print_count (notmuch_database_t *notmuch, const char *query_str,
+ const char **exclude_tags, size_t exclude_tags_length, int output)
+{
+ notmuch_query_t *query;
+ size_t i;
+
+ query = notmuch_query_create (notmuch, query_str);
+ if (query == NULL) {
+ fprintf (stderr, "Out of memory\n");
+ return 1;
+ }
+
+ for (i = 0; i < exclude_tags_length; i++)
+ notmuch_query_add_tag_exclude (query, exclude_tags[i]);
+
+ switch (output) {
+ case OUTPUT_MESSAGES:
+ printf ("%u\n", notmuch_query_count_messages (query));
+ break;
+ case OUTPUT_THREADS:
+ printf ("%u\n", notmuch_query_count_threads (query));
+ break;
+ }
+
+ notmuch_query_destroy (query);
+
+ return 0;
+}
+
+static int
+count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,
+ size_t exclude_tags_length, int output)
+{
+ char *line = NULL;
+ ssize_t line_len;
+ size_t line_size;
+ int ret = 0;
+
+ while (!ret && (line_len = getline (&line, &line_size, input)) != -1) {
+ chomp_newline (line);
+ ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,
+ output);
+ }
+
+ if (line)
+ free (line);
+
+ return ret;
+}
+