# HG changeset patch # User markus schnalke # Date 1329589960 -3600 # Node ID c8e3d1a79313c90f700c392d4abfadda0e2e9072 # Parent 5e728dd64c1ba308be29afda9fc961b8994571b3 Refactoring in conf.c: read_rval(). diff -r 5e728dd64c1b -r c8e3d1a79313 src/conf.c --- a/src/conf.c Sat Feb 18 18:48:19 2012 +0100 +++ b/src/conf.c Sat Feb 18 19:32:40 2012 +0100 @@ -256,22 +256,6 @@ return FALSE; } -/* -** after parsing, eat trailing characters until and including the Newline -*/ -static gboolean -eat_line_trailing(FILE *in) -{ - gint c; - - while ((c = fgetc(in)) != EOF) { - if (c == '\n') { - return TRUE; - } - } - return FALSE; -} - static gboolean eat_spaces(FILE *in) { @@ -332,38 +316,48 @@ } c = fgetc(in); - if (c != '\"') { - while ((isalnum(c) || c == '_' || c == '-' || c == '.' - || c == '/' || c == '@' || c == ';' || c == ':') - && (ptr < buf + size - 1) - && (c != EOF)) { - *ptr = c; - ptr++; - c = fgetc(in); + if (c != '"') { + /* unquoted rval */ + ungetc(c, in); + while ((c = fgetc(in)) != EOF) { + if (ptr >= buf+size-1) { + /* rval too long */ + break; + } + if (!isalnum(c) && c != '_' && c != '-' && + c != '.' && c != '/' && c != '@' && + c != ';' && c != ':') { + break; + } + *ptr++ = c; } *ptr = '\0'; ungetc(c, in); } else { + /* quoted rval */ gboolean escape = FALSE; - c = fgetc(in); - while (((c != '\"') || escape) && (ptr < buf + size - 1)) { - if (c != '\n') { /* ignore line breaks */ - if ((c == '\\') && (!escape)) { - escape = TRUE; - } else { - *ptr = c; - ptr++; - escape = FALSE; - } + while ((c = fgetc(in)) != EOF) { + if (ptr >= buf+size-1) { + /* rval too long */ + break; } - c = fgetc(in); + if (!escape && c == '"') { + break; + } + if (!escape && c == '\\') { + escape = TRUE; + continue; + } + *ptr++ = c; + escape = FALSE; } *ptr = '\0'; } - - eat_line_trailing(in); - DEBUG(9) fprintf(stderr, "rval = %s\n", buf); + /* eat trailing of line */ + while ((c = fgetc(in)) != EOF && c != '\n') { + continue; + } return TRUE; }