diff --git a/man/tio.1.in b/man/tio.1.in index db2c5e9..93ff593 100644 --- a/man/tio.1.in +++ b/man/tio.1.in @@ -182,6 +182,9 @@ Sections can be used to group settings and their names are only used for readabi .TP tio will try to match the user input to a section pattern to get the tty and other options. +.TP +If pattern matching fails, tio will try to match the user input to a section name. + .TP Options without any section name sets the default options. diff --git a/src/configfile.c b/src/configfile.c index 392ad46..25eccb0 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -162,14 +162,14 @@ static int data_handler(void *user, const char *section, const char *name, } /** - * section_search_handler() - walk config file to find section matching user input + * section_pattern_search_handler() - walk config file to find section matching user input * * INIH handler used to resolve the section matching the user's input. * This will look for the pattern element of each section and try to match it * with the user input. */ -static int section_search_handler(void *user, const char *section, const char - *varname, const char *varval) +static int section_pattern_search_handler(void *user, const char *section, const char *varname, + const char *varval) { UNUSED(user); @@ -190,6 +190,28 @@ static int section_search_handler(void *user, const char *section, const char return 0; } +/** + * section_pattern_search_handler() - walk config file to find section matching user input + * + * INIH handler used to resolve the section matching the user's input. + * This will try to match the user input against a section with the name of the user input. + */ +static int section_name_search_handler(void *user, const char *section, const char *varname, + const char *varval) +{ + UNUSED(user); + UNUSED(varname); + UNUSED(varval); + + if (!strcmp(section, c->user)) + { + /* section name matches as plain text */ + asprintf(&c->section_name, "%s", section); + } + + return 0; +} + static int resolve_config_file(void) { asprintf(&c->path, "%s/tio/tiorc", getenv("XDG_CONFIG_HOME")); @@ -237,11 +259,15 @@ void config_file_parse(const int argc, char *argv[]) return; } - ret = ini_parse(c->path, section_search_handler, NULL); + ret = ini_parse(c->path, section_pattern_search_handler, NULL); if (!c->section_name) { - debug_printf("unable to match user input to configuration section (%d)\n", ret); - return; + ret = ini_parse(c->path, section_name_search_handler, NULL); + if (!c->section_name) + { + debug_printf("unable to match user input to configuration section (%d)\n", ret); + return; + } } ret = ini_parse(c->path, data_handler, NULL);