diff options
author | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2006-08-31 16:54:40 +0000 |
---|---|---|
committer | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2006-08-31 16:54:40 +0000 |
commit | f679cb6f669f123caadd5429413e53ce4f7ee34c (patch) | |
tree | ab40b6edab57a19be924c1d9ed355b0ae58d6300 /src/util | |
parent | c2114cf17fce2cb7400e7138f3a732e21e7a3a83 (diff) |
Make the parameter file parser preserve newlines in multi-line string parameter
values. This makes its behaviour consistent with the flesh API routine
CCTK_ParameterSet().
This closes PR Cactus/2050: preserve newlines in quoted string parameter values.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4371 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/ParseFile.c | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/src/util/ParseFile.c b/src/util/ParseFile.c index 6258798d..86172217 100644 --- a/src/util/ParseFile.c +++ b/src/util/ParseFile.c @@ -236,6 +236,8 @@ int ParseFile(FILE *ifp, if (c == '"') { + int startline = lineno; + /* Just handle the thing. */ int p = 0; if (ntokens > 1) @@ -254,21 +256,61 @@ int ParseFile(FILE *ifp, #ifdef DEBUG printf("%c",c); #endif - /* Make an important decision NOT to include - * line feeds in the string parameters - */ - if (c != '\n') value[p++] = (char)c; + value[p++] = (char)c; + CheckBuf(p,lineno); if (c == '\n') { - printf ("Warning: Quoted string contains newline for token %s\n", - tokens); - printf ("This could indicate a parameter file error or missing quote\n"); #ifdef DEBUG printf ("LINE %d\n",lineno); #endif lineno++; } - CheckBuf(p,lineno); + else if (c == EOF) + { + break; + } + } + /* ignore all extra spaces or a trailing comment in this line */ + if (c == '"') + { + int is_comment = 0; + while ((c = fgetc(ifp)) != '\n') + { + if (c == EOF) + { + break; + } + if (c == '#') + { + is_comment = 1; + } + else if (! (is_comment || c == ' ' || c == '\t' || c == '\r')) + { + fprintf (stderr, "ERROR: extra characters found after closing " + "quote for value of parameter '%s' starting " + "in line %d\n", + tokens, startline); + fprintf(stderr, "This is a fatal error.\n"); + free (tokens); + return 1; + } + } + if (c == '\n' || c == EOF) + { + if (c == '\n') lineno++; + /* mark it as properly quoted string value */ + c = '"'; + } + } + /* fail if the quoted string did not terminate with a quote */ + if (c != '"') + { + fprintf (stderr, "ERROR: no closing quote found for quoted value " + "of parameter '%s' starting in line %d\n", + tokens, startline); + fprintf(stderr, "This is a fatal error.\n"); + free (tokens); + return 1; } value[p] = '\0'; #ifdef DEBUG |