diff options
author | Emanuele Giaquinta <exg@irssi.org> | 2007-06-05 12:03:18 +0000 |
---|---|---|
committer | exg <exg@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2007-06-05 12:03:18 +0000 |
commit | 51ab0c135035b3748b6ceb8fa1033f08310bd57b (patch) | |
tree | 9bd62019f7ba48798570132967a4e972574e7171 /src/fe-common/core | |
parent | 1e5554a20312775a8773328fc81552c8e1eb0064 (diff) | |
download | irssi-51ab0c135035b3748b6ceb8fa1033f08310bd57b.zip |
Cleanup cmd_set by moving the code to print the settings matching a
pattern in its own function and using settings_get_record for exact
matching.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4540 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-common/core')
-rw-r--r-- | src/fe-common/core/fe-settings.c | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c index 57e8f7da..a2881630 100644 --- a/src/fe-common/core/fe-settings.c +++ b/src/fe-common/core/fe-settings.c @@ -41,6 +41,29 @@ static void set_print(SETTINGS_REC *rec) g_free(value); } +static void set_print_pattern(const char *pattern) +{ + GSList *sets, *tmp; + const char *last_section; + + last_section = ""; + sets = settings_get_sorted(); + for (tmp = sets; tmp != NULL; tmp = tmp->next) { + SETTINGS_REC *rec = tmp->data; + + if (stristr(rec->key, pattern) == NULL) + continue; + if (strcmp(last_section, rec->section) != 0) { + /* print section */ + printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, + TXT_SET_TITLE, rec->section); + last_section = rec->section; + } + set_print(rec); + } + g_slist_free(sets); +} + static void set_boolean(const char *key, const char *value) { if (g_strcasecmp(value, "ON") == 0) @@ -57,11 +80,10 @@ static void set_boolean(const char *key, const char *value) static void cmd_set(char *data) { GHashTable *optlist; - GSList *sets, *tmp; - const char *last_section; char *key, *value; void *free_arg; - int found, clear, set_default; + int clear, set_default; + SETTINGS_REC *rec; if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, "set", &optlist, &key, &value)) @@ -73,23 +95,11 @@ static void cmd_set(char *data) if (*key == '\0') clear = set_default = FALSE; - last_section = ""; found = 0; - sets = settings_get_sorted(); - for (tmp = sets; tmp != NULL; tmp = tmp->next) { - SETTINGS_REC *rec = tmp->data; - - if (((clear || set_default || *value != '\0') && g_strcasecmp(rec->key, key) != 0) || - (*value == '\0' && *key != '\0' && stristr(rec->key, key) == NULL)) - continue; - - if (strcmp(last_section, rec->section) != 0) { - /* print section */ - printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, - TXT_SET_TITLE, rec->section); - last_section = rec->section; - } - - if (clear || set_default || *value != '\0') { + if (!(clear || set_default || *value != '\0')) + set_print_pattern(key); + else { + rec = settings_get_record(key); + if (rec != NULL) { /* change the setting */ switch (rec->type) { case SETTING_TYPE_BOOLEAN: @@ -130,20 +140,13 @@ static void cmd_set(char *data) break; } signal_emit("setup changed", 0); - } - - set_print(rec); - found = TRUE; - - if (clear || *value != '\0') - break; + printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, + TXT_SET_TITLE, rec->section); + set_print(rec); + } else + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_SET_UNKNOWN, key); } - g_slist_free(sets); - - if (!found) { - printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, - TXT_SET_UNKNOWN, key); - } cmd_params_free(free_arg); } |