mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Match user input against config section names if pattern matching was unsuccessful.
This allows for better config file ergonomics if the user has a diverse set of serial devices as the name does not need to be specified in the config file twice.
This commit is contained in:
parent
b882827b97
commit
a81c43a01a
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
|
||||
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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue