diff options
author | Carl Worth <cworth@cworth.org> | 2009-10-31 16:40:47 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2009-10-31 16:40:47 -0700 |
commit | 2405b45a06b5c9a596324c81e65fae31e2bcfab0 (patch) | |
tree | dbdfa3e7cfa3ece123450c731bb4061cdba5ad58 /notmuch.c | |
parent | c96021a47705bdb2ac189d52825a8edc033d35dd (diff) |
notmuch: Add a talloc context argument to each top-level command function.
I had noticed several times earlier that having a talloc context
passed in would make things more convenient. I'm not exercising
that convenience yet, but the context is there now, (and there's
one fewer item on our TODO list).
Diffstat (limited to 'notmuch.c')
-rw-r--r-- | notmuch.c | 33 |
1 files changed, 18 insertions, 15 deletions
@@ -60,7 +60,7 @@ #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0])) -typedef int (*command_function_t) (int argc, char *argv[]); +typedef int (*command_function_t) (void *ctx, int argc, char *argv[]); typedef struct command { const char *name; @@ -471,7 +471,7 @@ count_files (const char *path, int *count) } static int -setup_command (unused (int argc), unused (char *argv[])) +setup_command (unused (void *ctx), unused (int argc), unused (char *argv[])) { notmuch_database_t *notmuch = NULL; char *default_path, *mail_directory = NULL; @@ -629,7 +629,7 @@ tag_inbox_and_unread (notmuch_message_t *message) } static int -new_command (unused (int argc), unused (char *argv[])) +new_command (unused (void *ctx), unused (int argc), unused (char *argv[])) { notmuch_database_t *notmuch; const char *mail_directory; @@ -807,9 +807,9 @@ _format_relative_date (void *ctx, time_t then) #undef DAY static int -search_command (int argc, char *argv[]) +search_command (void *ctx, int argc, char *argv[]) { - void *local = talloc_new (NULL); + void *local = talloc_new (ctx); notmuch_database_t *notmuch = NULL; notmuch_query_t *query; notmuch_threads_t *threads; @@ -897,9 +897,9 @@ _get_one_line_summary (void *ctx, notmuch_message_t *message) } static int -show_command (unused (int argc), unused (char *argv[])) +show_command (void *ctx, unused (int argc), unused (char *argv[])) { - void *local = talloc_new (NULL); + void *local = talloc_new (ctx); char *query_string; notmuch_database_t *notmuch = NULL; notmuch_query_t *query = NULL; @@ -997,7 +997,7 @@ show_command (unused (int argc), unused (char *argv[])) } static int -tag_command (unused (int argc), unused (char *argv[])) +tag_command (void *ctx, unused (int argc), unused (char *argv[])) { void *local; int *add_tags, *remove_tags; @@ -1011,7 +1011,7 @@ tag_command (unused (int argc), unused (char *argv[])) int ret = 0; int i; - local = talloc_new (NULL); + local = talloc_new (ctx); if (local == NULL) { ret = 1; goto DONE; @@ -1102,7 +1102,7 @@ tag_command (unused (int argc), unused (char *argv[])) } static int -dump_command (int argc, char *argv[]) +dump_command (unused (void *ctx), int argc, char *argv[]) { FILE *output = NULL; notmuch_database_t *notmuch = NULL; @@ -1178,7 +1178,7 @@ dump_command (int argc, char *argv[]) } static int -restore_command (int argc, char *argv[]) +restore_command (unused (void *ctx), int argc, char *argv[]) { FILE *input = NULL; notmuch_database_t *notmuch = NULL; @@ -1287,7 +1287,7 @@ restore_command (int argc, char *argv[]) } static int -help_command (int argc, char *argv[]); +help_command (void *ctx, int argc, char *argv[]); command_t commands[] = { { "setup", setup_command, @@ -1404,7 +1404,7 @@ usage (void) } static int -help_command (int argc, char *argv[]) +help_command (unused (void *ctx), int argc, char *argv[]) { command_t *command; unsigned int i; @@ -1435,17 +1435,18 @@ help_command (int argc, char *argv[]) int main (int argc, char *argv[]) { + void *local = talloc_new (NULL); command_t *command; unsigned int i; if (argc == 1) - return setup_command (0, NULL); + return setup_command (local, 0, NULL); for (i = 0; i < ARRAY_SIZE (commands); i++) { command = &commands[i]; if (strcmp (argv[1], command->name) == 0) - return (command->function) (argc - 2, &argv[2]); + return (command->function) (local, argc - 2, &argv[2]); } /* Don't complain about "help" being an unknown command when we're @@ -1453,5 +1454,7 @@ main (int argc, char *argv[]) fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n", argv[1]); + talloc_free (local); + return 1; } |