From f679cb6f669f123caadd5429413e53ce4f7ee34c Mon Sep 17 00:00:00 2001 From: tradke Date: Thu, 31 Aug 2006 16:54:40 +0000 Subject: 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 --- src/util/ParseFile.c | 58 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) (limited to 'src/util') 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 -- cgit v1.2.3