#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;
}
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;
}
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;
#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;
}
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;
}
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;
int ret = 0;
int i;
- local = talloc_new (NULL);
+ local = talloc_new (ctx);
if (local == NULL) {
ret = 1;
goto DONE;
}
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;
}
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;
}
static int
-help_command (int argc, char *argv[]);
+help_command (void *ctx, int argc, char *argv[]);
command_t commands[] = {
{ "setup", setup_command,
}
static int
-help_command (int argc, char *argv[])
+help_command (unused (void *ctx), int argc, char *argv[])
{
command_t *command;
unsigned int i;
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
fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
argv[1]);
+ talloc_free (local);
+
return 1;
}