diff options
author | schnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-09-26 03:16:42 +0000 |
---|---|---|
committer | schnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-09-26 03:16:42 +0000 |
commit | f229ce08ca3956fd7ecbe2b9a83067eeb55d0afb (patch) | |
tree | 15ee1e1d2c05708018c35b9f52107c6a7950cfd8 /src | |
parent | 6088cd914c9e75fa2a2e88a463528594c50d710d (diff) |
Print run time warnings while setting parameters with CCTK_WARN
instead of with fprintf (stderr, ...).
Correct critical error in looking at the values of cctk_full_warnings,
highlight_warning_messages, and cctk_strong_param_check.
Handle the empty regular expression specially in CCTK_RegexMatch,
since regcomp may treat it as illegal expression. In Cactus, an empty
regular expression matches everything.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4150 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r-- | src/main/Parameters.c | 15 | ||||
-rw-r--r-- | src/main/WarnLevel.c | 85 | ||||
-rw-r--r-- | src/util/Misc.c | 29 |
3 files changed, 86 insertions, 43 deletions
diff --git a/src/main/Parameters.c b/src/main/Parameters.c index d662f92e..4b78264f 100644 --- a/src/main/Parameters.c +++ b/src/main/Parameters.c @@ -1978,8 +1978,9 @@ static int ParameterSetKeyword (t_param *param, const char *value) if (*(char **) param->data == NULL) { - fprintf (stderr, "Since this was the default value, " - "setting anyway - please fix!\n"); + CCTK_VWarn (1, __LINE__, __FILE__, "Cactus", + "Since this was the default value, " + "setting anyway - please fix!"); CCTK_SetString (param->data, value); } } @@ -2021,8 +2022,9 @@ static int ParameterSetString (t_param *param, const char *value) if (*(char **) param->data == NULL) { - fprintf (stderr, "Since this was the default value, " - "setting anyway - please fix!\n"); + CCTK_VWarn (1, __LINE__, __FILE__, "Cactus", + "Since this was the default value, " + "setting anyway - please fix!"); CCTK_SetString (param->data, value); } } @@ -2064,8 +2066,9 @@ static int ParameterSetSentence (t_param *param, const char *value) if (*(char **) param->data == NULL) { - fprintf (stderr, "Since this was the default value, " - "setting anyway - please fix!\n"); + CCTK_VWarn (1, __LINE__, __FILE__, "Cactus", + "Since this was the default value, " + "setting anyway - please fix!"); CCTK_SetString (param->data, value); } } diff --git a/src/main/WarnLevel.c b/src/main/WarnLevel.c index f5baeab7..c3db295e 100644 --- a/src/main/WarnLevel.c +++ b/src/main/WarnLevel.c @@ -389,7 +389,8 @@ int CCTK_VWarn (int level, const char *format, ...) { - const CCTK_INT *cctk_full_warnings, *highlight_warning_messages; + const CCTK_INT *cctk_full_warnings_ptr, *highlight_warning_messages_ptr; + CCTK_INT cctk_full_warnings, highlight_warning_messages; int param_type; int myproc; va_list ap, aq; @@ -399,10 +400,17 @@ int CCTK_VWarn (int level, myproc = CCTK_MyProc(NULL); - cctk_full_warnings = + cctk_full_warnings_ptr = CCTK_ParameterGet ("cctk_full_warnings", "Cactus", ¶m_type); - highlight_warning_messages = + // Default to yes + cctk_full_warnings = + cctk_full_warnings_ptr && *cctk_full_warnings_ptr; + + highlight_warning_messages_ptr = CCTK_ParameterGet ("highlight_warning_messages", "Cactus", ¶m_type); + // Default to no + highlight_warning_messages = + ! highlight_warning_messages_ptr || *highlight_warning_messages_ptr; va_start (ap, format); #ifdef HAVE_VA_COPY @@ -415,7 +423,7 @@ int CCTK_VWarn (int level, if (level <= warning_level) { - if (*highlight_warning_messages) + if (highlight_warning_messages) { fprintf (stderr, BOLD_ON); } @@ -433,7 +441,7 @@ int CCTK_VWarn (int level, level, myproc, thorn); } - if (*highlight_warning_messages) + if (highlight_warning_messages) { fprintf (stderr, BOLD_OFF); } @@ -448,7 +456,7 @@ int CCTK_VWarn (int level, if (level <= logging_level || (myproc && level <= warning_level)) { - if (*highlight_warning_messages) + if (highlight_warning_messages) { fprintf (stdout, BOLD_ON); } @@ -466,7 +474,7 @@ int CCTK_VWarn (int level, level, myproc, thorn); } - if (*highlight_warning_messages) + if (highlight_warning_messages) { fprintf (stdout, BOLD_OFF); } @@ -537,22 +545,31 @@ int CCTK_ParameterLevel (void) @@*/ int CCTK_ParamWarn (const char *thorn, const char *message) { - const CCTK_INT *cctk_strong_param_check, *highlight_warning_messages; + const CCTK_INT *cctk_strong_param_check_ptr, *highlight_warning_messages_ptr; + CCTK_INT cctk_strong_param_check, highlight_warning_messages; int param_type; - cctk_strong_param_check = CCTK_ParameterGet ("cctk_strong_param_check", - "Cactus", ¶m_type); - highlight_warning_messages = CCTK_ParameterGet ("highlight_warning_messages", - "Cactus", ¶m_type); - if (*highlight_warning_messages) + cctk_strong_param_check_ptr = + CCTK_ParameterGet ("cctk_strong_param_check", "Cactus", ¶m_type); + // Default to yes + cctk_strong_param_check = + cctk_strong_param_check_ptr && *cctk_strong_param_check_ptr; + + highlight_warning_messages_ptr = + CCTK_ParameterGet ("highlight_warning_messages", "Cactus", ¶m_type); + // Default to no + highlight_warning_messages = + ! highlight_warning_messages_ptr || *highlight_warning_messages_ptr; + + if (highlight_warning_messages) { fprintf (stderr, BOLD_ON "PARAM %s (%s):" BOLD_OFF " %s\n", - *cctk_strong_param_check ? "ERROR" : "WARNING", thorn, message); + cctk_strong_param_check ? "ERROR" : "WARNING", thorn, message); } else { fprintf (stderr, "PARAM %s (%s): %s\n", - *cctk_strong_param_check ? "ERROR" : "WARNING", thorn, message); + cctk_strong_param_check ? "ERROR" : "WARNING", thorn, message); } param_errors++; @@ -605,22 +622,31 @@ int CCTK_VParamWarn (const char *thorn, ...) { va_list ap; - const CCTK_INT *cctk_strong_param_check, *highlight_warning_messages; + const CCTK_INT *cctk_strong_param_check_ptr, *highlight_warning_messages_ptr; + CCTK_INT cctk_strong_param_check, highlight_warning_messages; int param_type; - cctk_strong_param_check = CCTK_ParameterGet ("cctk_strong_param_check", - "Cactus", ¶m_type); - highlight_warning_messages = CCTK_ParameterGet ("highlight_warning_messages", - "Cactus", ¶m_type); - if (*highlight_warning_messages) + cctk_strong_param_check_ptr = + CCTK_ParameterGet ("cctk_strong_param_check", "Cactus", ¶m_type); + // Default to yes + cctk_strong_param_check = + cctk_strong_param_check_ptr && *cctk_strong_param_check_ptr; + + highlight_warning_messages_ptr = + CCTK_ParameterGet ("highlight_warning_messages", "Cactus", ¶m_type); + // Default to no + highlight_warning_messages = + ! highlight_warning_messages_ptr || *highlight_warning_messages_ptr; + + if (highlight_warning_messages) { fprintf (stderr, BOLD_ON "PARAM %s (%s)" BOLD_OFF ": ", - *cctk_strong_param_check ? "ERROR" : "WARNING", thorn); + cctk_strong_param_check ? "ERROR" : "WARNING", thorn); } else { fprintf (stderr, "PARAM %s (%s): ", - *cctk_strong_param_check ? "ERROR" : "WARNING", thorn); + cctk_strong_param_check ? "ERROR" : "WARNING", thorn); } va_start (ap, format); @@ -877,14 +903,19 @@ int CCTKi_SetErrorLevel (int level) void CCTKi_FinaliseParamWarn (void) { int param_type; - const CCTK_INT *cctk_strong_param_check; + const CCTK_INT *cctk_strong_param_check_ptr; + CCTK_INT cctk_strong_param_check; if (param_errors) { - cctk_strong_param_check = CCTK_ParameterGet ("cctk_strong_param_check", - "Cactus", ¶m_type); - if (*cctk_strong_param_check) + cctk_strong_param_check_ptr = + CCTK_ParameterGet ("cctk_strong_param_check", "Cactus", ¶m_type); + // Default to yes + cctk_strong_param_check = + cctk_strong_param_check_ptr && *cctk_strong_param_check_ptr; + + if (cctk_strong_param_check) { fprintf (stderr, "\nFailed parameter check (%d errors)\n\n", param_errors); CCTK_Abort (NULL, 99); diff --git a/src/util/Misc.c b/src/util/Misc.c index 9d92a447..f4418799 100644 --- a/src/util/Misc.c +++ b/src/util/Misc.c @@ -1151,23 +1151,32 @@ int CCTK_RegexMatch(const char *string, int status; regex_t re; - if (regcomp(&re, pattern, REG_EXTENDED) == 0) + /* BSD says: an empty string is not a legal regular expression. + Handle this case specially. */ + if (strcmp(pattern, "") == 0) { - status = regexec(&re, string, (size_t)nmatch, pmatch, 0); - regfree(&re); - if (status != 0) + retval = 1; /* report success */ + } + else + { + if (regcomp(&re, pattern, REG_EXTENDED) == 0) { - retval = 0; /* report error */ + status = regexec(&re, string, (size_t)nmatch, pmatch, 0); + regfree(&re); + if (status != 0) + { + retval = 0; /* report error */ + } + else + { + retval = 1; + } } else { - retval = 1; + retval = 0; } } - else - { - retval = 0; - } return retval; } |