You must write a parser that splits each line into it's elements:
The title, the assignment character, and a comma separated list of values.
You can for example use
strchr
or
string::find
to locate the assignment character and get the title and the parameters.
Then extract multiple parameters using
strtok
or do it like above but using the comma now. Then remove leading and trailing (white) spaces from each substring and convert to lower.
Once you have a single parameter you should use lookup tables to determine the type and value. With mixed boolean and integers value I would check for boolean values first with a function returning three states (not a boolean, false, and true):
int getBoolean(const char *s)
{
if (0 == strcmp(s, "false") || 0 == strcmp(s, "no"))
return 0;
if (0 == strcmp(s, "true") || 0 == strcmp(s, "yes"))
return 1;
return -1;
}
If the above fails (returns -1), check for an integer:
typedef struct {
const char *name;
int value;
} lookup_t;
int getInteger(const char *s)
{
static const lookup_t lookup[] = {
{ "pause", VK_PAUSE },
{ NULL, -1 }
};
int i = 0;
while (lookup[i].name)
{
if (0 == strcmp(s, lookup[i].name))
break;
i++;
}
return lookup[i].value;
}