[cig-commits] r18463 - seismo/3D/SPECFEM3D/trunk/src/shared
dkomati1 at geodynamics.org
dkomati1 at geodynamics.org
Wed May 25 13:10:42 PDT 2011
Author: dkomati1
Date: 2011-05-25 13:10:42 -0700 (Wed, 25 May 2011)
New Revision: 18463
Modified:
seismo/3D/SPECFEM3D/trunk/src/shared/param_reader.c
Log:
updated param_reader.c to allow for multi words when reading a string
Modified: seismo/3D/SPECFEM3D/trunk/src/shared/param_reader.c
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/shared/param_reader.c 2011-05-25 19:57:02 UTC (rev 18462)
+++ seismo/3D/SPECFEM3D/trunk/src/shared/param_reader.c 2011-05-25 20:10:42 UTC (rev 18463)
@@ -31,6 +31,7 @@
by Dennis McRitchie (Princeton University, USA)
January 7, 2010 - par_file parsing
+ May 25, 2011 - Updated to support multi-word values
..
You'll notice that the heart of the parser is a complex regular
expression that is compiled within the C code, and then used to split
@@ -140,13 +141,15 @@
}
/* Regular expression for parsing lines from param file.
** Good luck reading this regular expression. Basically, the lines of
- ** the parameter file should be of the form 'parameter = value'. Blank
+ ** the parameter file should be of the form 'parameter = value',
+ ** optionally followed by a #-delimited comment.
+ ** 'value' can be any number of space- or tab-separated words. Blank
** lines, lines containing only white space and lines whose first non-
** whitespace character is '#' are ignored. White space is generally
** ignored. As you will see later in the code, if both parameter and
** value are not specified the line is ignored.
*/
- char pattern[] = "^[ \t]*([^# \t]*)[ \t]*=[ \t]*([^# \t]*)[ \t]*(#.*){0,1}$";
+ char pattern[] = "^[ \t]*([^# \t]+)[ \t]*=[ \t]*([^# \t]+([ \t]+[^# \t]+)*)";
// Compile the regular expression.
status = regcomp(&compiled_pattern, pattern, REG_EXTENDED);
@@ -196,13 +199,14 @@
// Clear out the return string with blanks, copy the value into it, and return.
memset(string_read, ' ', *string_read_len);
strncpy(string_read, value, strlen(value));
+ // printf("'%s'='%s'\n", namecopy2, value);
free(value);
free(namecopy);
*ierr = 0;
return;
}
// If no keyword matches, print out error and die.
- printf("No match in parameter file for keyword %s\n", namecopy);
+ printf("No match in parameter file for keyword '%s'\n", namecopy);
free(namecopy);
regfree(&compiled_pattern);
*ierr = 1;
More information about the CIG-COMMITS
mailing list