summaryrefslogtreecommitdiff
path: root/src/main/Groups.c
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2001-09-03 10:25:13 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2001-09-03 10:25:13 +0000
commitd77d4624d62303d581a20f934fe27644ae22baa1 (patch)
tree9d7f1a8c022fce56e8a1bb7e95f9d76c171a13ea /src/main/Groups.c
parentbc050398375a56670626fa689be722a64a6776fd (diff)
Extended parsing of SIZE option for ARRAY variables.
Now this can be a comma-separated list of positive integer constants or parameter names (optionally with an integer constant added/substracted to/from it). git-svn-id: http://svn.cactuscode.org/flesh/trunk@2327 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main/Groups.c')
-rw-r--r--src/main/Groups.c122
1 files changed, 75 insertions, 47 deletions
diff --git a/src/main/Groups.c b/src/main/Groups.c
index ca122b8c..a56c7e07 100644
--- a/src/main/Groups.c
+++ b/src/main/Groups.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include <regex.h>
#include "cctk_Constants.h"
#include "cctk_WarnLevel.h"
@@ -95,6 +96,14 @@ void CCTK_FCALL CCTK_FNAME (CCTK_GroupDimFromVarI)
/********************************************************************
+ *********************** Other Routines ************************
+ ********************************************************************/
+int CCTK_RegexMatch(const char *string,
+ const char *pattern,
+ const int nmatch,
+ regmatch_t *pmatch);
+
+/********************************************************************
******************** Internal Typedefs ************************
********************************************************************/
typedef struct
@@ -2042,8 +2051,9 @@ static cGroupDefinition *CCTKi_SetupGroup (const char *implementation,
@date Sun Nov 28 12:38:38 1999
@author Tom Goodale
@desc
- Extracts the size array from a comma-separated list
- of parameter names.
+ Extracts the size array from a comma-separated list of
+ positive integer constants or parameter names (which can
+ have an optional integer constant added/substracted to/from it).
@enddesc
@returntype CCTK_INT **
@@ -2055,82 +2065,100 @@ static CCTK_INT **CCTKi_ExtractSize (int dimension,
const char *this_thorn,
const char *sizestring)
{
- int i,
- type;
- CCTK_INT *this_size,
- **size_array;
- const char *last_comma,
- *next_comma,
- *thorn;
- char *thorn_impl,
- *param,
- tmp[200];
+ int dim, type;
+ CCTK_INT *this_size, **size_array;
+ const char *last_comma, *next_comma;
+ char *thorn, *param, *tmp;
+ regmatch_t pmatch[5];
if (strlen (sizestring))
{
-
size_array = (CCTK_INT **) malloc (dimension * sizeof (CCTK_INT *));
next_comma = sizestring;
if (size_array)
{
- for (i=0; i < dimension; i++)
+ for (dim = 0; dim < dimension; dim++)
{
+ /* find the comma as a delimiter for different dimension sizes */
last_comma = next_comma[0] == ',' ? next_comma+1 : next_comma;
next_comma = strstr (last_comma, ",");
+ /* copy dimension size token into a work string buffer */
+ tmp = strdup (last_comma);
if (next_comma)
{
- strncpy (tmp, last_comma, next_comma-last_comma);
tmp[next_comma-last_comma] = '\0';
}
- else
+
+ /* now execute the regex parser on that token
+ This should always succeed since the perl parser did the same
+ check already when creating the variable bindings. */
+ if (CCTK_RegexMatch (tmp, "(^[0-9]+)|([A-Za-z][A-Za-z0-9_]*)"
+ "(::[A-Za-z][A-Za-z0-9_]*)?([+-][0-9]+)?",
+ 5, pmatch) <= 0)
{
- strcpy (tmp, last_comma);
+ CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
+ "CCTKi_ExtractSize: invalid syntax in size specification "
+ "'%s'", tmp);
}
- /* check whether the parameter was given with its full name */
- thorn_impl = param = NULL;
- if (Util_SplitString (&thorn_impl, &param, tmp, "::") == 0)
+ /* check for constant size */
+ if (pmatch[1].rm_so >= 0)
{
- thorn = thorn_impl;
+ size_array[dim] = (CCTK_INT *) malloc (sizeof (CCTK_INT));
+ *size_array[dim] = (CCTK_INT) atoi (tmp + pmatch[0].rm_so);
}
else
{
- thorn = this_thorn;
- param = tmp;
- }
+ /* it's a parameter name, either given as basename or fullname */
+ if (pmatch[3].rm_so >= 0)
+ {
+ thorn = strdup (tmp + pmatch[2].rm_so);
+ thorn[pmatch[2].rm_eo - pmatch[2].rm_so] = 0;
+ param = strdup (tmp + pmatch[3].rm_so + 2);
+ param[pmatch[3].rm_eo - pmatch[3].rm_so - 2] = 0;
+ }
+ else
+ {
+ thorn = strdup (this_thorn);
+ param = strdup (tmp + pmatch[2].rm_so);
+ param[pmatch[2].rm_eo - pmatch[2].rm_so] = 0;
+ }
- /* check if such a parameter exists at all */
- this_size = (CCTK_INT *) CCTK_ParameterGet (param, thorn, &type);
- if (! this_size)
- {
- CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
- "CCTKi_ExtractSize: '%s::%s' is not a parameter",
- thorn, param);
- }
+ /* check if such a parameter exists at all */
+ this_size = (CCTK_INT *) CCTK_ParameterGet (param, thorn, &type);
+ if (! this_size)
+ {
+ CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
+ "CCTKi_ExtractSize: '%s::%s' is not a parameter",
+ thorn, param);
+ }
- /* check if the parameter is of type INTEGER */
- if (type != PARAMETER_INTEGER)
- {
- CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
- "CCTKi_ExtractSize: parameter '%s::%s' is not of type "
- "INTEGER", thorn, param);
- }
+ /* check if the parameter is of type INTEGER */
+ if (type != PARAMETER_INTEGER)
+ {
+ CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
+ "CCTKi_ExtractSize: parameter '%s::%s' is not of "
+ "type INTEGER", thorn, param);
+ }
- /* okay, store the size value */
- size_array[i] = this_size;
+ /* okay, store the size value */
+ size_array[dim] = this_size;
- if (thorn_impl)
- {
- free (thorn_impl);
- }
- if (param != tmp)
- {
+ /* check for an optional constant (includes sign character) */
+ if (pmatch[4].rm_so >= 0)
+ {
+ *size_array[dim] += atoi (tmp + pmatch[2].rm_so);
+ }
+
+ free (thorn);
free (param);
}
+
+ free (tmp);
}
}
}