Improve whitespace handling

Ignore blank lines which consist of whitespace. Per issue #71 in
GitHub.

This fix also improves comment handling and will treat lines with
whitespace before the '#' character as whitespace.
This commit is contained in:
Ian Barwick
2015-06-04 11:42:38 +09:00
parent a54478a045
commit ff7b4d3f02

View File

@@ -149,13 +149,17 @@ parse_config(const char *config_file, t_configuration_options *options)
{
bool known_parameter = true;
/* Skip blank lines and comments */
if (buff[0] == '\n' || buff[0] == '#')
continue;
/* Parse name/value pair from line */
parse_line(buff, name, value);
/* Skip blank lines */
if(!strlen(name))
continue;
/* Skip comments */
if (name[0] == '#')
continue;
/* Copy into correct entry in parameters struct */
if (strcmp(name, "cluster") == 0)
strncpy(options->cluster_name, value, MAXLEN);
@@ -335,10 +339,21 @@ parse_line(char *buff, char *name, char *value)
*/
for (; i < MAXLEN; ++i)
{
if (buff[i] != '=')
name[j++] = buff[i];
else
if (buff[i] == '=')
break;
switch(buff[i])
{
/* Ignore whitespace */
case ' ':
case '\n':
case '\r':
case '\t':
continue;
default:
name[j++] = buff[i];
}
}
name[j] = '\0';