[PATCH v2 11/20] insert: parse command-line tag operations
Reuse the parser in notmuch-tag.c to parse +tag and -tag operations on the 'insert' command-line. --- notmuch-insert.c | 23 +++ 1 file changed, 23 insertions(+) diff --git a/notmuch-insert.c b/notmuch-insert.c index 362da66..e4631a2 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -262,6 +262,8 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) const char **new_tags; size_t new_tags_length; const char *folder = NULL; +notmuch_tag_operation_t *tag_ops; +int tag_ops_count; char *maildir; int opt_index; notmuch_bool_t ret; @@ -279,6 +281,27 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) return 1; } +/* Array of tagging operations (add or remove), terminated with an + * empty element. */ +tag_ops = talloc_array (ctx, notmuch_tag_operation_t, argc - opt_index + 1); +if (tag_ops == NULL) { + fprintf (stderr, "Out of memory.\n"); + return 1; +} + +opt_index = parse_tag_operations (opt_index, argc, argv, + tag_ops, _ops_count); +if (opt_index < 0) + return 1; + +tag_ops[tag_ops_count].tag = NULL; + +if (opt_index != argc) { + fprintf (stderr, "Error: bad argument to notmuch insert: %s\n", +argv[opt_index]); + return 1; +} + config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; -- 1.7.12.1
[PATCH v2 11/20] insert: parse command-line tag operations
Reuse the parser in notmuch-tag.c to parse +tag and -tag operations on the 'insert' command-line. --- notmuch-insert.c | 23 +++ 1 file changed, 23 insertions(+) diff --git a/notmuch-insert.c b/notmuch-insert.c index 362da66..e4631a2 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -262,6 +262,8 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) const char **new_tags; size_t new_tags_length; const char *folder = NULL; +notmuch_tag_operation_t *tag_ops; +int tag_ops_count; char *maildir; int opt_index; notmuch_bool_t ret; @@ -279,6 +281,27 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) return 1; } +/* Array of tagging operations (add or remove), terminated with an + * empty element. */ +tag_ops = talloc_array (ctx, notmuch_tag_operation_t, argc - opt_index + 1); +if (tag_ops == NULL) { + fprintf (stderr, Out of memory.\n); + return 1; +} + +opt_index = parse_tag_operations (opt_index, argc, argv, + tag_ops, tag_ops_count); +if (opt_index 0) + return 1; + +tag_ops[tag_ops_count].tag = NULL; + +if (opt_index != argc) { + fprintf (stderr, Error: bad argument to notmuch insert: %s\n, +argv[opt_index]); + return 1; +} + config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; -- 1.7.12.1 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch