From ebd9d3057b889f2fe224c7cd7a0c539aa33a4d5c Mon Sep 17 00:00:00 2001 From: rhaas Date: Tue, 5 Jun 2012 01:21:05 +0000 Subject: have CCTK_RegexMatch return a distinct error code if patterns is invalid This patch changes the return value in the "does not compile" case to -1 and updates all source files that I could find that use it. Note that this patch changes behaviour of a routine. It used to return 0 for non-compiling patterns so thorns that test for C-like true would interpret invalid patterns as does-not-match, but will interpret the -1 return value as does-match. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4831 17b73243-c579-4c4c-a9d2-2d5706c11dac --- doc/ReferenceManual.pdf | Bin 1186265 -> 916133 bytes doc/ReferenceManual/CCTKReference.tex | 69 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) (limited to 'doc') diff --git a/doc/ReferenceManual.pdf b/doc/ReferenceManual.pdf index a90197c4..3e657e12 100644 Binary files a/doc/ReferenceManual.pdf and b/doc/ReferenceManual.pdf differ diff --git a/doc/ReferenceManual/CCTKReference.tex b/doc/ReferenceManual/CCTKReference.tex index 1908547b..e1b86845 100644 --- a/doc/ReferenceManual/CCTKReference.tex +++ b/doc/ReferenceManual/CCTKReference.tex @@ -659,6 +659,9 @@ from Fortran. \item[\code{CCTK\_ReductionHandle}] [\pageref{CCTK-ReductionHandle}] Get the handle for a registered reduction operator +\item[\code{CCTK\_RegexMatch}] [\pageref{CCTK-RegexMatch}] + Perform a regular expression match of string against pattern + \item[\code{CCTK\_RegisterBanner}] [\pageref{CCTK-RegisterBanner}] Register a banner for a thorn @@ -10647,6 +10650,72 @@ call CCTK_ReductionHandle(handle,"maximum") \end{ExampleSection} \end{FunctionDescription} +% Misc.c +\begin{FunctionDescription}{CCTK\_RegexMatch}{Perform a regular expression match of string against pattern} +\label{CCTK-RegexMatch} +\begin{SynopsisSection} +\begin{Synopsis}{C} +\begin{verbatim}success = CCTK_RegexMatch( const char *string, const char *pattern, + const int nmatch, regmatch_t *pmatch)\end{verbatim} +\end{Synopsis} +\end{SynopsisSection} +\begin{ParameterSection} +\begin{Parameter}{string} +String to match against +\end{Parameter} +\begin{Parameter}{pattern} +Regex pattern +\end{Parameter} +\begin{Parameter}{nmatch} +The size of the pmatch array +\end{Parameter} +\begin{Parameter}{pmatch} +Array in which to place the matches +\end{Parameter} +\end{ParameterSection} +\begin{ResultSection} +\begin{Result}{0} pattern does not match\end{Result} +\begin{Result}{1} pattern matches\end{Result} +\begin{Result}{< 0} indicates an error condition (pattern did not compile as a + regular expression) \end{Result} +\end{ResultSection} +\begin{Discussion} +Perform a regular expression match of string against pattern. +Also returns the specified number of matched substrings as +give by regexec. +This is a modified form of the example routine given in the SGI +man page for regcomp. +\end{Discussion} +\begin{ExampleSection} +\begin{Example}{C} +\begin{verbatim} +#define R_BEGIN "(\\[|\\()?" +#define R_VALUE "([^]):]*)" +#define R_SEP ":" +#define R_END "(\\]|\\))?" +#define R_MAYBE(x) "(" x ")?" + + int matched; + const char pattern[] = + R_BEGIN + R_VALUE + R_MAYBE(R_SEP R_VALUE R_MAYBE(R_SEP R_VALUE)) + R_END; + + if( (matched = CCTK_RegexMatch(range, pattern, 8, pmatch)) > 0) { + CCTK_VInfo(CCTK_THORNSTRING, "'%s' is a valid range specifier", + range); + } else if(!matched) { + CCTK_VInfo(CCTK_THORNSTRING, "'%s' is not a valid range specifier", + range); + } else { + CCTK_VInfo(CCTK_THORNSTRING, "invalid pattern '%s'", pattern); + } +\end{verbatim} +\end{Example} +\end{ExampleSection} +\end{FunctionDescription} + % Coord.c \begin{FunctionDescription}{CCTK\_RegisterBanner}{Register a banner for a thorn} \label{CCTK-RegisterBanner} -- cgit v1.2.3