From ff7b4d3f028a427d2394d0432fc0a425210cbf9b Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 4 Jun 2015 11:42:38 +0900 Subject: [PATCH] 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. --- config.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/config.c b/config.c index 41fa4d7a..28a3fa07 100644 --- a/config.c +++ b/config.c @@ -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';