config: do not require option value

Now setting a value with "=" is not required anymore in config files.
This should work analogous to command line arguments. Putting an entry
"opt=value" into the config file is like "--opt=value" on the command
line, and "opt" is like "--opt=" and "--opt".
This commit is contained in:
wm4 2012-09-20 03:33:57 +02:00
parent 830560979c
commit 5412993724
1 changed files with 38 additions and 54 deletions

View File

@ -144,67 +144,51 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile)
while (isspace(line[line_pos]))
++line_pos;
param_pos = 0;
/* check '=' */
if (line[line_pos++] != '=') {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"option %s needs a parameter\n", opt);
ret = -1;
errors++;
continue;
}
if (line[line_pos] == '=') {
line_pos++;
/* whitespaces... */
while (isspace(line[line_pos]))
++line_pos;
/* whitespaces... */
while (isspace(line[line_pos]))
++line_pos;
/* read the parameter */
if (line[line_pos] == '"' || line[line_pos] == '\'') {
c = line[line_pos];
++line_pos;
for (param_pos = 0; line[line_pos] != c; /* NOTHING */) {
param[param_pos++] = line[line_pos++];
if (param_pos >= MAX_PARAM_LEN) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"option %s has a too long parameter\n", opt);
ret = -1;
errors++;
goto nextline;
}
}
line_pos++; /* skip the closing " or ' */
} else {
for (param_pos = 0; isprint(line[line_pos])
&& !isspace(line[line_pos])
&& line[line_pos] != '#'; /* NOTHING */) {
param[param_pos++] = line[line_pos++];
if (param_pos >= MAX_PARAM_LEN) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too long parameter\n");
ret = -1;
errors++;
goto nextline;
/* read the parameter */
if (line[line_pos] == '"' || line[line_pos] == '\'') {
c = line[line_pos];
++line_pos;
for (param_pos = 0; line[line_pos] != c; /* NOTHING */) {
param[param_pos++] = line[line_pos++];
if (param_pos >= MAX_PARAM_LEN) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"option %s has a too long parameter\n", opt);
ret = -1;
errors++;
goto nextline;
}
}
line_pos++; /* skip the closing " or ' */
} else {
for (param_pos = 0; isprint(line[line_pos])
&& !isspace(line[line_pos])
&& line[line_pos] != '#'; /* NOTHING */) {
param[param_pos++] = line[line_pos++];
if (param_pos >= MAX_PARAM_LEN) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too long parameter\n");
ret = -1;
errors++;
goto nextline;
}
}
}
while (isspace(line[line_pos]))
++line_pos;
}
param[param_pos] = '\0';
/* did we read a parameter? */
if (param_pos == 0) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"option %s needs a parameter\n", opt);
ret = -1;
errors++;
continue;
}
/* now, check if we have some more chars on the line */
/* whitespace... */
while (isspace(line[line_pos]))
++line_pos;
/* EOL / comment */
if (line[line_pos] != '\0' && line[line_pos] != '#') {
PRINT_LINENUM;