X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-config.c;h=48312e3f913dda58151efbe591415f875751bb05;hp=247fbe4ba1e394c0d4dc34b7142dd2c2f9da3f57;hb=4ef2106792439f5ade157b3ba3b8f7fa86fcb3ed;hpb=e76f6517de020783d828be59f461f1d4f465c4b4 diff --git a/notmuch-config.c b/notmuch-config.c index 247fbe4b..48312e3f 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -705,14 +705,8 @@ _item_split (char *item, char **group, char **key) } static int -notmuch_config_command_get (void *ctx, char *item) +notmuch_config_command_get (notmuch_config_t *config, char *item) { - notmuch_config_t *config; - - config = notmuch_config_open (ctx, NULL, FALSE); - if (config == NULL) - return 1; - if (strcmp(item, "database.path") == 0) { printf ("%s\n", notmuch_config_get_database_path (config)); } else if (strcmp(item, "user.name") == 0) { @@ -756,25 +750,17 @@ notmuch_config_command_get (void *ctx, char *item) g_strfreev (value); } - notmuch_config_close (config); - return 0; } static int -notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[]) +notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char *argv[]) { - notmuch_config_t *config; char *group, *key; - int ret; if (_item_split (item, &group, &key)) return 1; - config = notmuch_config_open (ctx, NULL, FALSE); - if (config == NULL) - return 1; - /* With only the name of an item, we clear it from the * configuration file. * @@ -795,23 +781,15 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[]) break; } - ret = notmuch_config_save (config); - notmuch_config_close (config); - - return ret; + return notmuch_config_save (config); } static int -notmuch_config_command_list (void *ctx) +notmuch_config_command_list (notmuch_config_t *config) { - notmuch_config_t *config; char **groups; size_t g, groups_length; - config = notmuch_config_open (ctx, NULL, FALSE); - if (config == NULL) - return 1; - groups = g_key_file_get_groups (config->key_file, &groups_length); if (groups == NULL) return 1; @@ -841,13 +819,11 @@ notmuch_config_command_list (void *ctx) g_strfreev (groups); - notmuch_config_close (config); - return 0; } int -notmuch_config_command (void *ctx, int argc, char *argv[]) +notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]) { argc--; argv++; /* skip subcommand argument */ @@ -862,16 +838,16 @@ notmuch_config_command (void *ctx, int argc, char *argv[]) "one argument.\n"); return 1; } - return notmuch_config_command_get (ctx, argv[1]); + return notmuch_config_command_get (config, argv[1]); } else if (strcmp (argv[0], "set") == 0) { if (argc < 2) { fprintf (stderr, "Error: notmuch config set requires at least " "one argument.\n"); return 1; } - return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2); + return notmuch_config_command_set (config, argv[1], argc - 2, argv + 2); } else if (strcmp (argv[0], "list") == 0) { - return notmuch_config_command_list (ctx); + return notmuch_config_command_list (config); } fprintf (stderr, "Unrecognized argument for notmuch config: %s\n",