hirc

IRC client
Log | Files | Refs

commit c1000351f4e75dd5dc309558b7c9a2f5ce23166f
parent 2545314641e3f498d0aa6569e59689890b1f57f3
Author: hhvn <dev@hhvn.uk>
Date:   Tue, 12 Apr 2022 12:44:24 +0100

Use "true" and "false" for booleans (but allow nums too)

Diffstat:
Msrc/config.c | 16+++++++++++++---
Msrc/main.c | 4+++-
2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/config.c b/src/config.c @@ -1304,6 +1304,9 @@ config_get_print(char *name) { else if (config[i].valtype == Val_pair || config[i].valtype == Val_colourpair) hist_format(selected.history, Activity_status, HIST_UI, "SELF_UI :%s: {%ld, %ld}", config[i].name, config[i].pair[0], config[i].pair[1]); + else if (config[i].valtype == Val_bool) + hist_format(selected.history, Activity_status, HIST_UI, "SELF_UI :%s: %s", + config[i].name, config[i].num ? "true" : "false"); else hist_format(selected.history, Activity_status, HIST_UI, "SELF_UI :%s: %ld", config[i].name, config[i].num); @@ -1323,9 +1326,12 @@ config_gets(char *name) { return NULL; for (i=0; config[i].name; i++) { - if (strcmp(config[i].name, name) == 0 && - config[i].valtype == Val_string) - return config[i].str; + if (strcmp(config[i].name, name) == 0) { + if (config[i].valtype == Val_string) + return config[i].str; + else if (config[i].valtype == Val_bool) + return config[i].num ? "true" : "false"; + } } return NULL; @@ -1435,6 +1441,10 @@ config_set(char *name, char *val) { config_setr(name, strtol(tok[0], NULL, 10), strtol(tok[1], NULL, 10)); else if (strisnum(tok[0]) && !tok[1]) config_setl(name, strtol(tok[0], NULL, 10)); + else if (tok[0] && strcmp(tok[0], "true") == 0) + config_setl(name, 1); + else if (tok[0] && strcmp(tok[0], "false") == 0) + config_setl(name, 0); else if (tok[0]) config_sets(name, str); else diff --git a/src/main.c b/src/main.c @@ -384,8 +384,10 @@ main(int argc, char *argv[]) { printf("Default value: %s\n", config[i].str); else if (config[i].valtype == Val_pair || config[i].valtype == Val_colourpair) printf("Default value: {%02ld, %02ld}\n", config[i].pair[0], config[i].pair[1]); + else if (config[i].valtype == Val_bool) + printf("Default value: %s\n", config[i].num ? "true" : "false"); else - printf("Default value: %02ld\n", config[i].num); + printf("Default value: %ld\n", config[i].num); for (j=0; config[i].description[j]; j++) printf("%s\n", config[i].description[j]); printf(".Ed\n");