mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
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
This commit is contained in:
parent
1e5554a203
commit
51ab0c1350
@ -41,6 +41,29 @@ static void set_print(SETTINGS_REC *rec)
|
|||||||
g_free(value);
|
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)
|
static void set_boolean(const char *key, const char *value)
|
||||||
{
|
{
|
||||||
if (g_strcasecmp(value, "ON") == 0)
|
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)
|
static void cmd_set(char *data)
|
||||||
{
|
{
|
||||||
GHashTable *optlist;
|
GHashTable *optlist;
|
||||||
GSList *sets, *tmp;
|
|
||||||
const char *last_section;
|
|
||||||
char *key, *value;
|
char *key, *value;
|
||||||
void *free_arg;
|
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,
|
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS,
|
||||||
"set", &optlist, &key, &value))
|
"set", &optlist, &key, &value))
|
||||||
@ -73,23 +95,11 @@ static void cmd_set(char *data)
|
|||||||
if (*key == '\0')
|
if (*key == '\0')
|
||||||
clear = set_default = FALSE;
|
clear = set_default = FALSE;
|
||||||
|
|
||||||
last_section = ""; found = 0;
|
if (!(clear || set_default || *value != '\0'))
|
||||||
sets = settings_get_sorted();
|
set_print_pattern(key);
|
||||||
for (tmp = sets; tmp != NULL; tmp = tmp->next) {
|
else {
|
||||||
SETTINGS_REC *rec = tmp->data;
|
rec = settings_get_record(key);
|
||||||
|
if (rec != NULL) {
|
||||||
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') {
|
|
||||||
/* change the setting */
|
/* change the setting */
|
||||||
switch (rec->type) {
|
switch (rec->type) {
|
||||||
case SETTING_TYPE_BOOLEAN:
|
case SETTING_TYPE_BOOLEAN:
|
||||||
@ -130,17 +140,10 @@ static void cmd_set(char *data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
signal_emit("setup changed", 0);
|
signal_emit("setup changed", 0);
|
||||||
}
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
|
||||||
|
TXT_SET_TITLE, rec->section);
|
||||||
set_print(rec);
|
set_print(rec);
|
||||||
found = TRUE;
|
} else
|
||||||
|
|
||||||
if (clear || *value != '\0')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_slist_free(sets);
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
|
||||||
TXT_SET_UNKNOWN, key);
|
TXT_SET_UNKNOWN, key);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user