mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Merge pull request #144 from pcc/config-section-name
Match user input against config section names if pattern matching was…
This commit is contained in:
commit
2e0b0386dc
2 changed files with 35 additions and 6 deletions
|
|
@ -182,6 +182,9 @@ Sections can be used to group settings and their names are only used for readabi
|
||||||
.TP
|
.TP
|
||||||
tio will try to match the user input to a section pattern to get the tty and other options.
|
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
|
.TP
|
||||||
Options without any section name sets the default options.
|
Options without any section name sets the default options.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
* 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
|
* This will look for the pattern element of each section and try to match it
|
||||||
* with the user input.
|
* with the user input.
|
||||||
*/
|
*/
|
||||||
static int section_search_handler(void *user, const char *section, const char
|
static int section_pattern_search_handler(void *user, const char *section, const char *varname,
|
||||||
*varname, const char *varval)
|
const char *varval)
|
||||||
{
|
{
|
||||||
UNUSED(user);
|
UNUSED(user);
|
||||||
|
|
||||||
|
|
@ -190,6 +190,28 @@ static int section_search_handler(void *user, const char *section, const char
|
||||||
return 0;
|
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)
|
static int resolve_config_file(void)
|
||||||
{
|
{
|
||||||
asprintf(&c->path, "%s/tio/tiorc", getenv("XDG_CONFIG_HOME"));
|
asprintf(&c->path, "%s/tio/tiorc", getenv("XDG_CONFIG_HOME"));
|
||||||
|
|
@ -237,12 +259,16 @@ void config_file_parse(const int argc, char *argv[])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ini_parse(c->path, section_search_handler, NULL);
|
ret = ini_parse(c->path, section_pattern_search_handler, NULL);
|
||||||
|
if (!c->section_name)
|
||||||
|
{
|
||||||
|
ret = ini_parse(c->path, section_name_search_handler, NULL);
|
||||||
if (!c->section_name)
|
if (!c->section_name)
|
||||||
{
|
{
|
||||||
debug_printf("unable to match user input to configuration section (%d)\n", ret);
|
debug_printf("unable to match user input to configuration section (%d)\n", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = ini_parse(c->path, data_handler, NULL);
|
ret = ini_parse(c->path, data_handler, NULL);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue