From 3abd66b09008b065c9dc815462261b910a6180ae Mon Sep 17 00:00:00 2001 From: schnetter Date: Tue, 28 Dec 2004 19:03:14 +0000 Subject: Revert accidental changes from the last commit. Sorry. git-svn-id: http://svn.cactuscode.org/flesh/trunk@3945 17b73243-c579-4c4c-a9d2-2d5706c11dac --- src/util/CactusTimers.c | 23 +++-------- src/util/Misc.c | 7 ++-- src/util/ParseFile.c | 73 +++++++++++++++------------------- src/util/Table.c | 101 ++++++++++++------------------------------------ 4 files changed, 66 insertions(+), 138 deletions(-) (limited to 'src') diff --git a/src/util/CactusTimers.c b/src/util/CactusTimers.c index 6ad254d3..7c630dac 100644 --- a/src/util/CactusTimers.c +++ b/src/util/CactusTimers.c @@ -405,13 +405,12 @@ static int CCTKi_TimerCreate (const char *timername) { int retval; t_Timer *timer; - void *tmp; const cClockFuncs *funcs; int this_timer; int handle; - if (Util_GetHandle (timers, timername, &tmp) >= 0) + if (Util_GetHandle (timers, timername, (void **) &timer) >= 0) { /* Handle already exists */ retval = -1; @@ -477,13 +476,11 @@ static int CCTKi_TimerCreate (const char *timername) @@*/ int CCTK_TimerDestroy (const char *timername) { - void *tmp; t_Timer *timer; int this_timer; - this_timer = Util_GetHandle (timers, timername, &tmp); - timer = tmp; + this_timer = Util_GetHandle (timers, timername, (void **) &timer); if (this_timer >= 0) { CCTKi_TimerDestroy (this_timer, timer); @@ -615,13 +612,11 @@ static void CCTKi_TimerDestroy (int this_timer, t_Timer *timer) @@*/ int CCTK_TimerStart (const char *timername) { - void *tmp; t_Timer *timer; int this_timer; - this_timer = Util_GetHandle (timers, timername, &tmp); - timer = tmp; + this_timer = Util_GetHandle (timers, timername, (void **) &timer); if (this_timer >= 0) { CCTKi_TimerStart (this_timer, timer); @@ -749,13 +744,11 @@ static void CCTKi_TimerStart (int this_timer, t_Timer *timer) @@*/ int CCTK_TimerStop (const char *timername) { - void *tmp; t_Timer *timer; int this_timer; - this_timer = Util_GetHandle (timers, timername, &tmp); - timer = tmp; + this_timer = Util_GetHandle (timers, timername, (void **)&timer); if (this_timer >= 0) { CCTKi_TimerStop (this_timer, timer); @@ -882,13 +875,11 @@ static void CCTKi_TimerStop (int this_timer, t_Timer *timer) @@*/ int CCTK_TimerReset (const char *timername) { - void *tmp; t_Timer *timer; int this_timer; - this_timer = Util_GetHandle (timers, timername, &tmp); - timer = tmp; + this_timer = Util_GetHandle (timers, timername, (void **) &timer); if (this_timer >= 0) { CCTKi_TimerReset (this_timer, timer); @@ -1021,13 +1012,11 @@ static void CCTKi_TimerReset (int this_timer, t_Timer *timer) @@*/ int CCTK_Timer (const char *timername, cTimerData *info) { - void *tmp; t_Timer *timer; int this_timer; - this_timer = Util_GetHandle (timers, timername, &tmp); - timer = tmp; + this_timer = Util_GetHandle (timers, timername, (void **) &timer); if (this_timer >= 0) { CCTKi_Timer (this_timer, timer, info); diff --git a/src/util/Misc.c b/src/util/Misc.c index 2b351fc1..e08285b9 100644 --- a/src/util/Misc.c +++ b/src/util/Misc.c @@ -457,7 +457,7 @@ int Util_IntInRange(int inval, const char *range) if(inval >= start + !start_closed && inval <= end - !end_closed && - ! (((unsigned int)inval - (unsigned int)start) % step)) + ! ((inval-start) % step)) { retval = 1; } @@ -1221,9 +1221,10 @@ void CCTK_FCALL CCTK_FNAME(CCTK_PrintString) @@*/ int CCTK_FortranString (const char *c_string, char *fortran_string, - int fortran_length) + size_t fortran_length) { - int nchars, c_strlen; + int nchars; + size_t c_strlen; nchars = c_strlen = strlen (c_string); diff --git a/src/util/ParseFile.c b/src/util/ParseFile.c index ca886201..9c483ced 100644 --- a/src/util/ParseFile.c +++ b/src/util/ParseFile.c @@ -51,6 +51,14 @@ int ParseFile(FILE *ifp, ********************* Local Data ***************************** ********************************************************************/ +#ifndef WIN32 +#define BOLDON "\033[1m" +#define BOLDOFF "\033[0m" +#else +#define BOLDON "" +#define BOLDOFF "" +#endif + /* parse buffer size */ #define BUF_SZ (8 * 1024) @@ -260,8 +268,8 @@ int ParseFile(FILE *ifp, if (c != '\n') value[p++] = c; if (c == '\n') { - printf ("Warning: Quoted string contains newline for token %s\n", - tokens); + printf ("%sWarning:%s Quoted string contains newline for token %s\n", + BOLDON, BOLDOFF, tokens); printf ("This could indicated a parameter file error or missing quote\n"); #ifdef DEBUG printf ("LINE %d\n",lineno); @@ -280,52 +288,35 @@ int ParseFile(FILE *ifp, else if (c == '$') { /* We got a define */ - char buf[1000]; - char * p = buf; + /* FIXME: Assume it is a parameter file for now */ + char path[500]; + char *parfile; - /* read name */ - do + CCTK_ParameterFilename(500,path); + parfile = strrchr (path, '/'); + if (parfile == NULL) { - c = fgetc(ifp); -#ifdef DEBUG - printf("%c",c); -#endif - *p++ = c; + parfile = path; } - while (!(c==' ' || c=='\t' || c == '\n' || c == '\r' || c == EOF)); - *--p = 0; - - if (strcmp (buf, "parfile") == 0) + else { - char path[1000]; - char *parfile; - char *dot; - - CCTK_ParameterFilename(sizeof path,path); - /* remove the leading directory part */ - parfile = strrchr (path, '/'); - if (parfile == NULL) - { - parfile = path; - } - else - { - parfile++; - } - /* skip the parameter file extension */ - dot = strrchr (parfile, '.'); - if (dot) - { - *dot = 0; - } - - set_function(tokens,parfile,lineno); + parfile++; } - else + /* skip the parameter file extension */ + if (strcmp (parfile + strlen (parfile) - 4, ".par") == 0) { - fprintf(stderr, "Error at line %d. Unknown define '%s'.\n", lineno, buf); - num_errors++; + parfile[strlen (parfile) - 4] = 0; + } + + /* ignore everything else on the line */ + while (!(c==' ' || c=='\t' || c == '\n' || c == '\r' || c == EOF)) + { + c = fgetc(ifp); +#ifdef DEBUG + printf("%c",c); +#endif } + set_function(tokens,parfile,lineno); } else { diff --git a/src/util/Table.c b/src/util/Table.c index 7a2c4b29..0aa20d75 100644 --- a/src/util/Table.c +++ b/src/util/Table.c @@ -1114,18 +1114,19 @@ void CCTK_FCALL CCTK_FNAME(Util_TableCreateFromString) In more detail, the strings recognized are defined by the following BNF:
- string -> whitespace* assign*
- assign -> key whitespace* '=' whitespace* value delimiter
+ string -> assign*
+ assign -> whitespace*
+ assign -> whitespace* key whitespace* = + whitespace* value delimiter
key -> any string not containing '/' or '=' or whitespace
value -> array | int_value | real_value | string_value
- array -> { whitespace* (int_value whitespace* [',' whitespace*])* } - | { whitespace* (real_value whitespace* [',' whitespace*])* }
+ array -> { int_value* } | { real_value* }
int_value -> anything recognized as a valid integer - by strtol(3) in base 10
+ by strdol(3) in base 10
real_value -> anything not recognized as a valid integer by strtol(3) but recognized as valid by - strtod(3)
+ strdod(3)
string_value -> a C-style string enclosed in "double quotes" (C-style character escape codes are allowed ie. '\a', '\b', '\f', '\n', '\r', '\t', @@ -1134,14 +1135,10 @@ void CCTK_FCALL CCTK_FNAME(Util_TableCreateFromString) (C-style character escape codes are *not* allowed, ie. every character within the string is interpreted literally)
- delimiter -> end-of-string | whitespace+ - | whitespace* ',' whitespace*
+ delimiter -> end-of-string | whitespace
whitespace --> ' ' | '\t' | '\n' | '\r' | '\f' | '\v'
- where * denotes 0 or more repetitions, - + denotes 1 or more repetitions, - [] denotes 0 or 1 repetitions (i.e. an optional part), - and | denotes logical or. + where * denotes 0 or more repetitions and | denotes logical or.

Notice also that the keys allowed by this function are somewhat more restricted than those allowed by the other @@ -1183,7 +1180,7 @@ void CCTK_FCALL CCTK_FNAME(Util_TableCreateFromString) @@*/ int Util_TableSetFromString(int handle, const char string[]) { -#define WHITESPACE " \t\n\r\f\v" +#define WHITESPACE " \t\n\r\f\v" struct scalar_value scalar; #ifdef UTIL_TABLE_DEBUG @@ -1203,9 +1200,6 @@ int Util_TableSetFromString(int handle, const char string[]) int Set_count = 0, status = 0; char *p = buffer; - /* skip leading whitespace */ - p += strspn(p, WHITESPACE); - while (*p != '\0' && status >= 0) { /* @@ -1213,6 +1207,9 @@ int Util_TableSetFromString(int handle, const char string[]) * assignment starting at p, creating a table entry for it */ + /* skip leading whitespaces */ + p += strspn(p, WHITESPACE); + #ifdef UTIL_TABLE_DEBUG2 printf(" skipped over delimiters to p-buffer=%d\n", (int) (p-buffer)); #endif @@ -1228,7 +1225,6 @@ int Util_TableSetFromString(int handle, const char string[]) p = q + strspn (q, WHITESPACE); /* p -> "= value..." */ if (*p != '=') { - assert (status >= 0); status = UTIL_ERROR_BAD_INPUT; /* no '=" in "key=value" string */ break; } @@ -1238,7 +1234,6 @@ int Util_TableSetFromString(int handle, const char string[]) p += strspn (p, WHITESPACE); /* p -> "value..." */ if (*p == '\0') { - assert (status >= 0); status = UTIL_ERROR_BAD_INPUT; /* no value supplied */ break; } @@ -1248,10 +1243,9 @@ int Util_TableSetFromString(int handle, const char string[]) /* split "value..." into "value" and "..." */ - /* - * check the type of value which is either + /* check the type of value which is either * - a string enclosed in single or double quotes - * - an array of scalars enclosed in curly braces + * - an array of scalars enclosed in round brackets * - a scalar (integer or real) */ if (*value == '\'' || *value == '"' || *value == '{') @@ -1274,7 +1268,6 @@ int Util_TableSetFromString(int handle, const char string[]) if (*p != *q) { - assert (status >= 0); status = UTIL_ERROR_BAD_INPUT; /* no closing delimiter found */ break; /* in string or array value */ } @@ -1303,11 +1296,10 @@ int Util_TableSetFromString(int handle, const char string[]) } } q++; - } /* while */ + } if (p != q) { - assert (status >= 0); status = UTIL_ERROR_BAD_INPUT; /* invalid escape code found */ break; } @@ -1320,7 +1312,7 @@ int Util_TableSetFromString(int handle, const char string[]) /* * this block handles numbers */ - p += strcspn (value, WHITESPACE ","); + p += strcspn (value, WHITESPACE); q = value; } @@ -1338,7 +1330,6 @@ int Util_TableSetFromString(int handle, const char string[]) */ if (*q == '\'' || *q == '"') { - assert (status >= 0); status = Util_TableSetString(handle, value, key); } else @@ -1346,17 +1337,14 @@ int Util_TableSetFromString(int handle, const char string[]) convert_string_to_number (value, &scalar); if (scalar.datatype == CCTK_VARIABLE_INT) { - assert (status >= 0); status = Util_TableSetInt(handle, scalar.value.int_scalar, key); } else if (scalar.datatype == CCTK_VARIABLE_REAL) { - assert (status >= 0); status = Util_TableSetReal(handle, scalar.value.real_scalar, key); } else { - assert (status >= 0); status = UTIL_ERROR_BAD_INPUT; /* can't parse scalar value */ } } @@ -1382,8 +1370,6 @@ int Util_TableSetFromString(int handle, const char string[]) int datatypesize = 0; char *array = NULL; - /* skip leading whitespace */ - value += strspn (value, WHITESPACE); while (*value) { @@ -1394,8 +1380,11 @@ int Util_TableSetFromString(int handle, const char string[]) * and pushing it to the resulting generic array buffer */ + /* skip leading whitespaces */ + value += strspn (value, WHITESPACE); + /* split "value..." into "value" and "..." */ - q = value + strcspn (value, WHITESPACE ","); + q = value + strcspn (value, WHITESPACE); if (*q != '\0') /* if we're already at the end of the list */ /* we don't want to advance further */ { @@ -1406,7 +1395,6 @@ int Util_TableSetFromString(int handle, const char string[]) if (scalar.datatype == -1) { datatype = scalar.datatype; - assert (status >= 0); status = UTIL_ERROR_BAD_INPUT; /* can't parse array value */ break; } @@ -1419,7 +1407,6 @@ int Util_TableSetFromString(int handle, const char string[]) { /* all array values must have the same datatype */ datatype = -1; - assert (status >= 0); status = UTIL_ERROR_TABLE_NO_MIXED_TYPE_ARRAY; break; } @@ -1440,7 +1427,6 @@ int Util_TableSetFromString(int handle, const char string[]) } if (array == NULL) { - assert (status >= 0); status = UTIL_ERROR_NO_MEMORY; break; } @@ -1455,20 +1441,10 @@ int Util_TableSetFromString(int handle, const char string[]) nvals++; value = q; - - /* skip whitespace* [',' whitespace*] */ - value += strspn (value, WHITESPACE); - if (*p == ',') - { - ++p; - value += strspn (value, WHITESPACE); - } - - } /* while (*value) */ + } if (datatype == CCTK_VARIABLE_INT || datatype == CCTK_VARIABLE_REAL) { - assert (status >= 0); status = Util_TableSetGenericArray(handle, datatype, nvals, array, key); } @@ -1476,21 +1452,12 @@ int Util_TableSetFromString(int handle, const char string[]) { free (array); } - } /* if this block handles array values */ + } ++Set_count; } } - - /* skip whitespace* [',' whitespace*] */ - p += strspn (p, WHITESPACE); - if (*p == ',') - { - ++p; - p += strspn (p, WHITESPACE); - } - - } /* loop over all assignments */ + } #ifdef UTIL_TABLE_DEBUG2 printf(" returning with code %d\n", status >= 0 ? Set_count : status); @@ -6400,7 +6367,6 @@ static assert( Util_TableSetFromString(handle, "foo/" ) == UTIL_ERROR_BAD_INPUT ); assert( Util_TableCreateFromString("foo" ) == UTIL_ERROR_BAD_INPUT ); - assert( Util_TableCreateFromString("foo," ) == UTIL_ERROR_BAD_INPUT ); assert( Util_TableCreateFromString("foo/" ) == UTIL_ERROR_BAD_INPUT ); assert( Util_TableCreateFromString("foo=" ) == UTIL_ERROR_BAD_INPUT ); assert( Util_TableCreateFromString("foo/=12" ) == UTIL_ERROR_TABLE_BAD_KEY ); @@ -6416,16 +6382,8 @@ static assert( Util_TableCreateFromString("foo={bar}" ) == UTIL_ERROR_BAD_INPUT ); assert( Util_TableCreateFromString(" foo = { \"\r\t\n\v\" } " ) == UTIL_ERROR_BAD_INPUT ); - assert( Util_TableCreateFromString(" foo = { \"\r\t\n\v\", } " ) == - UTIL_ERROR_BAD_INPUT ); assert( Util_TableCreateFromString("foo={0 1.0}" ) == UTIL_ERROR_TABLE_NO_MIXED_TYPE_ARRAY ); - assert( Util_TableCreateFromString("foo={0, 1.0}" ) == - UTIL_ERROR_TABLE_NO_MIXED_TYPE_ARRAY ); - assert( Util_TableCreateFromString("foo={0, 1.0,}" ) == - UTIL_ERROR_TABLE_NO_MIXED_TYPE_ARRAY ); - assert( Util_TableCreateFromString("foo={0 1.0 ,}" ) == - UTIL_ERROR_TABLE_NO_MIXED_TYPE_ARRAY ); /* * Test some "good" strings with single values @@ -6480,23 +6438,12 @@ static assert( int_array[0] == -1 && int_array[1] == 2 && int_array[2] == -3 && int_array[3] == 4 ); - assert( Util_TableSetFromString(handle, " foo = {\t-1, +2, -3, +4,\t} " ) == 1 ); - assert( Util_TableGetIntArray (handle, 5, int_array, "foo") == 4 ); - assert( int_array[0] == -1 && int_array[1] == 2 && - int_array[2] == -3 && int_array[3] == 4 ); - assert( Util_TableSetFromString(handle, " foo = {\t-1.1\t+2.2\t-3.3\t+4.4\t} ") == 1); assert( Util_TableGetRealArray (handle, 100, real_array, "foo") == 4 ); assert( real_array[0] == -1.1 && real_array[1] == 2.2 && real_array[2] == -3.3 && real_array[3] == 4.4 ); - assert( Util_TableSetFromString(handle, - " foo = {\t-1.1,\t+2.2\t,-3.3\t+4.4\t,\t} ") == 1); - assert( Util_TableGetRealArray (handle, 100, real_array, "foo") == 4 ); - assert( real_array[0] == -1.1 && real_array[1] == 2.2 && - real_array[2] == -3.3 && real_array[3] == 4.4 ); - assert( Util_TableDeleteKey (handle, "foo") == 0 ); assert( Util_TableQueryNKeys (handle) == 0 ); } -- cgit v1.2.3