diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-08-26 15:34:20 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-08-26 15:34:20 +0000 |
commit | 5e90d4682484a0b9cbc232d0005bcda3895f6c9f (patch) | |
tree | d14c7ec57f48fd431663326f9c7b55900846aa47 /src | |
parent | 9a643dc37c6334abd06d70688d2e1494c435bbf2 (diff) |
New parameter stuff.
Now a non-active thorn's extensions to parameters shouldn't be valid,
range checking is now done, even for strings, which must conform to
a regular expression.
Tom
git-svn-id: http://svn.cactuscode.org/flesh/trunk@859 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ActiveThorns.h | 5 | ||||
-rw-r--r-- | src/include/ParameterBindings.h | 21 | ||||
-rw-r--r-- | src/include/cctk_ActiveThorns.h | 7 | ||||
-rw-r--r-- | src/main/ActiveThorns.c | 110 | ||||
-rw-r--r-- | src/main/CommandLine.c | 18 | ||||
-rw-r--r-- | src/main/InitialiseDataStructures.c | 6 | ||||
-rw-r--r-- | src/main/Parameters.c | 580 | ||||
-rw-r--r-- | src/main/SetParams.c | 103 | ||||
-rw-r--r-- | src/main/Subsystems.c | 2 | ||||
-rw-r--r-- | src/main/WarnLevel.c | 76 | ||||
-rw-r--r-- | src/main/make.code.defn | 1 | ||||
-rw-r--r-- | src/util/Misc.c | 233 |
12 files changed, 924 insertions, 238 deletions
diff --git a/src/include/ActiveThorns.h b/src/include/ActiveThorns.h index 69e54e66..eb1f2f60 100644 --- a/src/include/ActiveThorns.h +++ b/src/include/ActiveThorns.h @@ -21,6 +21,11 @@ int CCTK_IsThornActive(const char *name); int CCTK_IsImplementationActive(const char *name); int CCTKi_ListThorns(FILE *file, const char *format, int active); int CCTKi_ListImplementations(FILE *file, const char *format, int active); +const char *CCTK_ActivatingThorn(const char *imp); + + /* FIXME - should return a list or something */ +t_sktree *CCTK_ImpThornList(const char *imp); + #ifdef __cplusplus } diff --git a/src/include/ParameterBindings.h b/src/include/ParameterBindings.h index 97612df2..1f5da613 100644 --- a/src/include/ParameterBindings.h +++ b/src/include/ParameterBindings.h @@ -10,9 +10,30 @@ #ifndef _PARAMETERBINDINGS_H_ #define _PARAMETERBINDINGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int ParameterCreate(const char *name, /* The parameter name */ + const char *thorn, /* The thorn */ + const char *type, /* The parameter type */ + const char *scope, /* The scoping block */ + int steerable, /* Is it steerable ? */ + const char *description, /* The description */ + const char *defval, /* The default value */ + void *datapointer, /* The actual data */ + int n_ranges, /* How many allowed ranges it has */ + ...); + +#ifdef __cplusplus +} +#endif + #define PARAMETER_KEYWORD 1 #define PARAMETER_STRING 2 #define PARAMETER_SENTENCE 3 +#define PARAMETER_INT 4 #define PARAMETER_INTEGER 4 #define PARAMETER_REAL 5 #define PARAMETER_LOGICAL 6 diff --git a/src/include/cctk_ActiveThorns.h b/src/include/cctk_ActiveThorns.h index bfc6a6ba..eb1f2f60 100644 --- a/src/include/cctk_ActiveThorns.h +++ b/src/include/cctk_ActiveThorns.h @@ -1,5 +1,5 @@ /*@@ - @header cctk_ActiveThorns.h + @header ActiveThorns.h @date Sun Jul 4 17:39:50 1999 @author Tom Goodale @desc @@ -21,6 +21,11 @@ int CCTK_IsThornActive(const char *name); int CCTK_IsImplementationActive(const char *name); int CCTKi_ListThorns(FILE *file, const char *format, int active); int CCTKi_ListImplementations(FILE *file, const char *format, int active); +const char *CCTK_ActivatingThorn(const char *imp); + + /* FIXME - should return a list or something */ +t_sktree *CCTK_ImpThornList(const char *imp); + #ifdef __cplusplus } diff --git a/src/main/ActiveThorns.c b/src/main/ActiveThorns.c index 3793b537..943958e3 100644 --- a/src/main/ActiveThorns.c +++ b/src/main/ActiveThorns.c @@ -11,13 +11,12 @@ #include <stdlib.h> #include <string.h> -#include "cctk_ActiveThorns.h" #include "SKBinTree.h" +#include "cctk_ActiveThorns.h" static char *rcsid = "$Header$"; - /* Local routine */ static int CCTK_RegisterImp(const char *name, const char *thorn); @@ -39,6 +38,8 @@ struct IMPLEMENTATION static t_sktree *thornlist = NULL; static t_sktree *implist = NULL; +static int n_thorns = 0; +static int n_imps = 0; /*@@ @routine CCTKi_RegisterThorn @@ -62,14 +63,14 @@ int CCTKi_RegisterThorn(const char *name, const char *imp) struct THORN *thorn; - printf("Registering thorn %s, which provides %s\n", name, imp); + /* printf("Registering thorn %s, which provides %s\n", name, imp);*/ /* Does the thorn already exist ? */ node = SKTreeFindNode(thornlist, name); if(!node) { - + n_thorns++; /* Create the structure to hold thorn info. */ thorn = (struct THORN *)malloc(sizeof(struct THORN)); @@ -146,6 +147,8 @@ static int CCTK_RegisterImp(const char *name, const char *thorn) if(!node) { + n_imps++; + /* Create the structure to hold info about it. */ imp = (struct IMPLEMENTATION *)malloc(sizeof(struct IMPLEMENTATION)); @@ -425,3 +428,102 @@ int CCTKi_ListImplementations(FILE *file, const char *format, int active) return retval; } + +int CCTK_ImpList(int active, char ***list, int *n_implementations) +{ + int retval; + t_sktree *node; + + struct IMPLEMENTATION *imp; + + retval = 0; + + + *list = (char **)malloc(n_imps*sizeof(char *)); + + for(node= SKTreeFindFirst(implist), *n_implementations = 0; + node; + node = node->next, retval++) + { + imp = (struct IMPLEMENTATION *)(node->data); + + if(imp->active || !active) + { + (*list)[*n_implementations] = (char *) malloc(strlen(node->key)+1); + strcpy((*list)[*n_implementations], node->key); + (*n_implementations)++; + } + } + + return retval; +} + +const char *CCTK_ActivatingThorn(const char *name) +{ + const char *retval; + + t_sktree *node; + + struct IMPLEMENTATION *imp; + + /* Find the implementation */ + node = SKTreeFindNode(implist, name); + + retval = NULL; + + if(node) + { + imp = (struct IMPLEMENTATION *)(node->data); + + if(imp->active) + { + retval = imp->activating_thorn; + } + } + + return retval; +} + + + + /*@@ + @routine CCTK_ImpThornList + @date Tue Jul 27 09:15:58 1999 + @author Tom Goodale + @desc + Return the thorns for an implementation. + For now return an sktree - FIXME + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +t_sktree *CCTK_ImpThornList(const char *name) +{ + t_sktree *retval; + + t_sktree *node; + + struct IMPLEMENTATION *imp; + + + /* Find the implementation */ + node = SKTreeFindNode(implist, name); + + + if(node) + { + imp = (struct IMPLEMENTATION *)(node->data); + + retval = imp->thornlist; + } + else + { + retval = NULL; + } + + return retval; +} diff --git a/src/main/CommandLine.c b/src/main/CommandLine.c index 7cd0d45b..273bd344 100644 --- a/src/main/CommandLine.c +++ b/src/main/CommandLine.c @@ -14,9 +14,11 @@ #include "CommandLine.h" #include "cctk_Flesh.h" #include "cGH.h" + #include "cctk_Comm.h" #include "cctk_WarnLevel.h" #include "cctk_Bindings.h" +#include "cctk_Misc.h" /* FIXME. This shouldn't be here !*/ #include "thornlist.h" @@ -75,7 +77,23 @@ void CCTKi_CommandLineDescribeAllParameters(void) void CCTKi_CommandLineDescribeParameter(const char *optarg) { + char *thorn; + char *param; + + /* CCTKi_BindingsParameterHelp(optarg,"%s",stdout); + */ + + Util_SplitString(þ, ¶m, optarg, "::"); + + ParameterPrintDescription(param, + thorn, /*const char *thorn,*/ + "..%s..%s\n",/* const char *format,*/ + stdout); + + free(thorn); + free(param); + exit(1); } diff --git a/src/main/InitialiseDataStructures.c b/src/main/InitialiseDataStructures.c index 3f822530..c153cc4b 100644 --- a/src/main/InitialiseDataStructures.c +++ b/src/main/InitialiseDataStructures.c @@ -12,6 +12,10 @@ #include <string.h> #include "cctk_Flesh.h" + +/* FIXME - remove this when ActiveThorns doesn't need it */ +#include "SKBinTree.h" + #include "cctk_ActiveThorns.h" static char *rcsid = "$Id$"; @@ -46,7 +50,7 @@ int InitialiseDataStructures(tFleshConfig *ConfigData) /* Initialise appropriate subsystems. */ CCTKi_BindingsImplementationsInitialise(); - CCTKi_BindingsParametersInitialise(); + /* CCTKi_BindingsParametersInitialise();*/ CCTKi_BindingsVariablesInitialise(); CCTKi_BindingsScheduleInitialise(); diff --git a/src/main/Parameters.c b/src/main/Parameters.c index 7abd9650..c7760bc3 100644 --- a/src/main/Parameters.c +++ b/src/main/Parameters.c @@ -7,13 +7,19 @@ @enddesc @@*/ +#include "config.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <stdarg.h> + +#include "SKBinTree.h" + +#include "ActiveThorns.h" #include "ParameterBindings.h" -#include "SKBinTree.h" const char *rcsid="$Header$"; @@ -25,6 +31,7 @@ int STR_cmpi(const char *string1, const char *string2); #define SCOPE_RESTRICTED 2 #define SCOPE_PRIVATE 3 #define SCOPE_NOT_GLOBAL 4 +#define SCOPE_ANY 5 typedef struct RANGE { @@ -40,7 +47,6 @@ typedef struct PARAMETER { char *name; char *thorn; - char *implementation; int scope; char *description; @@ -72,21 +78,18 @@ typedef struct PARAMTREENODE static t_parameter *ParameterFind(const char *name, const char *thorn, - const char *implementation, int scope); -static int ParameterNew(const char *thorn, - const char *implementation, - const char *name, - const char *type, - const char *scope, - int steerable, - const char *description, - const char *defval, - void *data); +static t_parameter *ParameterNew(const char *thorn, + const char *name, + const char *type, + const char *scope, + int steerable, + const char *description, + const char *defval, + void *data); static int ParameterCheck(const char *thorn, - const char *implementation, const char *name, const char *type, const char *scope, @@ -125,6 +128,16 @@ static int ParameterExtend(t_parameter *parameter, static int ParameterListAddParam(t_paramlist **paramlist, t_parameter *newparam); + +static int ParameterSetKeyword(t_parameter *param, const char *value); +static int ParameterSetString(t_parameter *param, const char *value); +static int ParameterSetSentence(t_parameter *param, const char *value); +static int ParameterSetInteger(t_parameter *param, const char *value); +static int ParameterSetReal(t_parameter *param, const char *value); +static int ParameterSetLogical(t_parameter *param, const char *value); + + + static t_sktree *paramtree=NULL; @@ -156,13 +169,7 @@ static t_sktree *paramtree=NULL; @vcomment @endvar - @var implementation - @vdesc The originating implementation - @vtype const char * - @vio in - @vcomment - - @endvar + @var scope @vdesc The scope of the parameter @vtype const char * @@ -209,34 +216,56 @@ static t_sktree *paramtree=NULL; @@*/ int ParameterCreate(const char *name, const char *thorn, - const char *implementation, const char *type, const char *scope, int steerable, const char *description, const char *defval, - void *data) + void *data, + int n_ranges, + ...) { int retval; int iscope; + int i; t_parameter *parameter; + va_list ranges; + const char *rangeval; + const char *rangedesc; iscope = ParameterGetScope(scope); - parameter = ParameterFind(name, thorn, implementation, iscope); + parameter = ParameterFind(name, thorn, iscope); if(!parameter) { - retval = ParameterNew(thorn, implementation, name, - type, scope, steerable, description, defval, data); + parameter = ParameterNew(thorn, name, + type, scope, steerable, description, defval, data); + + if(n_ranges) + { + va_start(ranges, n_ranges); + + for(i=0; i < n_ranges; i++) + { + rangeval = (const char *)va_arg(ranges, const char *); + rangedesc = (const char *)va_arg(ranges, const char *); + + ParameterExtend(parameter, thorn, rangeval, rangedesc); + } + va_end(ranges); + + } + + retval = ParameterSetSimple(parameter, defval); + } else { - retval = ParameterCheck(thorn, implementation, name, + retval = ParameterCheck(thorn, name, type, scope, steerable, description, defval, data); } - return retval; } @@ -295,7 +324,7 @@ int ParameterCreate(const char *name, @endreturndesc @@*/ -int ParameterAddRange(const char *origin, +int ParameterAddRange(const char *implementation, const char *name, const char *range_origin, const char *range, @@ -304,26 +333,36 @@ int ParameterAddRange(const char *origin, int retval; t_parameter *parameter; - if(!STR_CMP(origin, range_origin)) - { - parameter = ParameterFind(name, origin, NULL, SCOPE_PRIVATE); - if(!parameter) parameter = ParameterFind(name, origin, NULL, SCOPE_RESTRICTED); - if(!parameter) parameter = ParameterFind(name, origin, NULL, SCOPE_GLOBAL); - } - else - { - parameter = ParameterFind(name, NULL, origin, SCOPE_RESTRICTED); - } + /* For the moment do this in the quick and dirty way 8-( FIXME */ + t_sktree *thornlist; - if(parameter) - { - retval = ParameterExtend(parameter, range_origin, range, range_description); - } - else + t_sktree *node; + + /*printf("Extending parameter %s::%s from thorn %s\n", implementation, name, range_origin);*/ + + thornlist = CCTK_ImpThornList(implementation); + + retval = -1; + + if(thornlist) { - retval = -1; + for(node= SKTreeFindFirst(thornlist); + node; + node = node->next) + { + parameter = ParameterFind(name, node->key, SCOPE_RESTRICTED); + + if(parameter) + { + retval = ParameterExtend(parameter, range_origin, range, range_description); + } + else + { + retval = -1; + } + } } - + return retval; } @@ -376,44 +415,13 @@ int ParameterAddRange(const char *origin, @@*/ int ParameterSet(const char *name, const char *thorn, - const char *implementation, const char *value) { int retval; int iscope; t_parameter *param; - t_parameter *param2; - param = NULL; - param2 = NULL; - - /* See what info we have */ - if(!thorn && !implementation) - { - /* No info, so must be a global parameter. */ - iscope = SCOPE_GLOBAL; - param = ParameterFind(name, NULL, NULL, iscope); - } - else - { - iscope = SCOPE_NOT_GLOBAL; - if(thorn && implementation) - { - /* Have both thorn and implementation so check both. */ - param = ParameterFind(name, NULL, implementation, iscope); - param2 = ParameterFind(name, thorn, NULL, iscope); - if(param2 && ! param) - { - /* Only one found, so put into primary setting mode */ - param = param2; - } - } - else - { - /* Only have one of thorn or imp, so look for it */ - param = ParameterFind(name, thorn, implementation, iscope); - } - } + param = ParameterFind(name, thorn, SCOPE_ANY); if(param) { @@ -424,12 +432,6 @@ int ParameterSet(const char *name, retval = -1; } - /* Should produce a warning for this case. */ - if(param2) - { - retval = ParameterSetSimple(param2, value); - } - return retval; } @@ -492,45 +494,16 @@ int ParameterSet(const char *name, @@*/ int ParameterPrintDescription(const char *name, const char *thorn, - const char *implementation, const char *format, FILE *file) { int retval; int iscope; t_parameter *param; - t_parameter *param2; param = NULL; - param2 = NULL; - /* See what info we have */ - if(!thorn && !implementation) - { - /* No info, so must be a global parameter. */ - iscope = SCOPE_GLOBAL; - param = ParameterFind(name, NULL, NULL, iscope); - } - else - { - iscope = SCOPE_NOT_GLOBAL; - if(thorn && implementation) - { - /* Have both thorn and implementation so check both. */ - param = ParameterFind(name, NULL, implementation, iscope); - param2 = ParameterFind(name, thorn, NULL, iscope); - if(param2 && ! param) - { - /* Only one found, so put into primary setting mode */ - param = param2; - } - } - else - { - /* Only have one of thorn or imp, so look for it */ - param = ParameterFind(name, thorn, implementation, iscope); - } - } + param = ParameterFind(name, thorn, SCOPE_ANY); if(param) { @@ -541,12 +514,6 @@ int ParameterPrintDescription(const char *name, retval = -1; } - /* Should produce a warning for this case. */ - if(param2) - { - retval = ParameterPrintSimple(param2, format, file); - } - return retval; } @@ -600,44 +567,15 @@ int ParameterPrintDescription(const char *name, @@*/ void *ParameterGet(const char *name, const char *thorn, - const char *implementation, int *type) { void *retval; int iscope; t_parameter *param; - t_parameter *param2; param = NULL; - param2 = NULL; - /* See what info we have */ - if(!thorn && !implementation) - { - /* No info, so must be a global parameter. */ - iscope = SCOPE_GLOBAL; - param = ParameterFind(name, NULL, NULL, iscope); - } - else - { - iscope = SCOPE_NOT_GLOBAL; - if(thorn && implementation) - { - /* Have both thorn and implementation so check both. */ - param = ParameterFind(name, NULL, implementation, iscope); - param2 = ParameterFind(name, thorn, NULL, iscope); - if(param2 && ! param) - { - /* Only one found, so put into primary setting mode */ - param = param2; - } - } - else - { - /* Only have one of thorn or imp, so look for it */ - param = ParameterFind(name, thorn, implementation, iscope); - } - } + param = ParameterFind(name, thorn, SCOPE_ANY); if(param) { @@ -648,11 +586,6 @@ void *ParameterGet(const char *name, retval = NULL; } - if(param2) - { - fprintf(stderr, "Ambiguous parameter name %s\n", name); - retval = NULL; - } return retval; @@ -704,7 +637,6 @@ const char *ParameterWalk(int first, static t_parameter *ParameterFind(const char *name, const char *thorn, - const char *implementation, int scope) { t_parameter *retval; @@ -715,40 +647,27 @@ static t_parameter *ParameterFind(const char *name, node = NULL; list = NULL; - if(scope == SCOPE_NOT_GLOBAL && thorn && implementation) - { - fprintf(stderr, "Calling error\n"); - retval = NULL; - } - else - { - node = ParameterPTreeNodeFind(paramtree, name); + node = ParameterPTreeNodeFind(paramtree, name); - if(node) + if(node) + { + for(list = node->paramlist; list; list = list->next) { - for(list = node->paramlist; list; list = list->next) + if(! thorn) { - if(scope == SCOPE_GLOBAL ) - { - if(scope == list->param->scope) - { - break; - } - } - else if(scope == SCOPE_NOT_GLOBAL) + if(list->param->scope == SCOPE_GLOBAL) { - if(thorn && ! STR_CMP(thorn, list->param->thorn)) break; - if(implementation && ! STR_CMP(implementation, list->param->implementation)) break; + break; } - else if(scope == SCOPE_RESTRICTED) - { - if(implementation && ! STR_CMP(implementation, list->param->implementation) && scope == list->param->scope) break; - } - else - { - if(thorn && ! STR_CMP(thorn, list->param->thorn) && scope == list->param->scope) break; - } } + else if(scope == SCOPE_ANY) + { + if(thorn && ! STR_CMP(thorn, list->param->thorn)) break; + } + else if(!STR_CMP(thorn, list->param->thorn) && list->param->scope == scope) + { + break; + } } } @@ -764,18 +683,32 @@ static t_parameter *ParameterFind(const char *name, return retval; } -static int ParameterNew(const char *thorn, - const char *implementation, - const char *name, - const char *type, - const char *scope, - int steerable, - const char *description, - const char *defval, - void *data) + /*@@ + @routine ParameterNew + @date Mon Jul 26 10:59:42 1999 + @author Tom Goodale + @desc + + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +static t_parameter *ParameterNew(const char *thorn, + const char *name, + const char *type, + const char *scope, + int steerable, + const char *description, + const char *defval, + void *data) { int retval; t_parameter *newparam; + char ** stringdata; retval = -1; @@ -784,7 +717,6 @@ static int ParameterNew(const char *thorn, if(newparam) { newparam->thorn = (char *)malloc(sizeof(char)*(1+strlen(thorn))); - newparam->implementation = (char *)malloc(sizeof(char)*(1+strlen(implementation))); newparam->name = (char *)malloc(sizeof(char)*(1+strlen(name))); newparam->scope = ParameterGetScope(scope); newparam->type = ParameterGetType(type); @@ -792,16 +724,23 @@ static int ParameterNew(const char *thorn, newparam->description = (char *)malloc(sizeof(char)*(1+strlen(description))); newparam->defval = (char *)malloc(sizeof(char)*(1+strlen(defval))); newparam->data = data; + newparam->range = NULL; + + if(newparam->type == PARAMETER_STRING || + newparam->type == PARAMETER_SENTENCE || + newparam->type == PARAMETER_KEYWORD) + { + stringdata = (char **)data; + *stringdata = NULL; + } if(newparam->thorn && - newparam->implementation && newparam->name && newparam->description && newparam->defval) { strcpy(newparam->name, name); strcpy(newparam->thorn, thorn); - strcpy(newparam->implementation, implementation); strcpy(newparam->description, description); strcpy(newparam->defval, defval); @@ -809,11 +748,10 @@ static int ParameterNew(const char *thorn, } } - return retval; + return newparam; } static int ParameterCheck(const char *thorn, - const char *implementation, const char *name, const char *type, const char *scope, @@ -903,11 +841,15 @@ static int ParameterGetType(const char *type) PTYPE(KEYWORD); PTYPE(STRING); PTYPE(SENTENCE); - PTYPE(INTEGER); + PTYPE(INT); PTYPE(REAL); PTYPE(LOGICAL); #undef PTYPE + if(retval == -1) + { + fprintf(stderr, "What on earth kind of a paramter is %s ? \n",type); + } return retval; } @@ -1077,20 +1019,30 @@ static int ParameterExtend(t_parameter *parameter, static int ParameterSetSimple(t_parameter *param, const char *value) { + int retval; + + retval = -2; + + /* fprintf(stdout, "Setting value of parameter %s::%s\n", param->thorn, param->name);*/ switch(param->type) { case PARAMETER_KEYWORD : + retval = ParameterSetKeyword(param, value); break; case PARAMETER_STRING : + retval = ParameterSetString(param, value); break; case PARAMETER_SENTENCE : - case PARAMETER_INTEGER : + retval = ParameterSetSentence(param, value); break; + case PARAMETER_INT : + retval = ParameterSetInteger(param, value); break; case PARAMETER_REAL : + retval = ParameterSetReal(param, value); break; case PARAMETER_LOGICAL : - fprintf(stderr, "Setting value of parameter %s::%s", param->thorn, param->name); + retval = ParameterSetLogical(param, value); break; default : fprintf(stderr, "Unknown parameter type %d\n", param->type); } - return 0; + return retval; } static int ParameterPrintSimple(t_parameter *param, @@ -1101,7 +1053,6 @@ static int ParameterPrintSimple(t_parameter *param, fprintf(file, format, "Parameter", param->name); fprintf(file, format, "Thorn", param->thorn); - fprintf(file, format, "Imp", param->implementation); fprintf(file, format, "Desc", param->description); fprintf(file, format, "Def", param->defval); @@ -1116,7 +1067,230 @@ static int ParameterPrintSimple(t_parameter *param, static int ParameterListAddParam(t_paramlist **paramlist, t_parameter *newparam) { - return 0; + int retval; + t_paramlist *node; + node = (t_paramlist *)malloc(sizeof(t_paramlist)); + + if(node) + { + node->param = newparam; + + /* Place at beginning of list for now. */ + node->next = *paramlist; + node->last = NULL; + (*paramlist)->last = node; + + *paramlist = node; + + retval = 0; + } + else + { + retval = 1; + } + + return retval; +} + + +static int ParameterSetKeyword(t_parameter *param, const char *value) +{ + int retval; + t_range *range; + + retval = -1; + for(range = param->range; range ; range = range->next) + { + if(CCTK_IsThornActive(range->origin)||CCTK_Equals(param->thorn, range->origin)) + { + if(!STR_CMP(value, range->range)) + { + retval = CCTK_SetString(param->data, value); + break; + } + } + } + + if(retval == -1) + { + fprintf(stderr, + "Unable to set keyword %s::%s - %s not in any active range\n", + param->thorn, + param->name, + value); + if(*((char **)param->data) == NULL) + { + fprintf(stderr, "Since this was the default value, setting anyway - please fix!\n"); + + CCTK_SetString(param->data, value); + } + } + + return retval; +} + +static int ParameterSetString(t_parameter *param, const char *value) +{ + int retval; + t_range *range; + + retval = -1; + for(range = param->range; range ; range = range->next) + { + if(CCTK_IsThornActive(range->origin)||CCTK_Equals(param->thorn, range->origin)) + { + if(CCTK_RegexMatch(value, range->range, 0, NULL)) + { + retval = CCTK_SetString(param->data, value); + } + break; + } + } + + if(retval == -1) + { + fprintf(stderr, + "Unable to set string %s::%s - %s not in any active range\n", + param->thorn, + param->name, + value); + + if(*((char **)param->data) == NULL) + { + fprintf(stderr, "Since this was the default value, setting anyway - please fix!\n"); + + CCTK_SetString(param->data, value); + } + + } + + return retval; +} + +static int ParameterSetSentence(t_parameter *param, const char *value) +{ + int retval; + t_range *range; + + retval = -1; + for(range = param->range; range ; range = range->next) + { + if(CCTK_IsThornActive(range->origin)||CCTK_Equals(param->thorn, range->origin)) + { + if(CCTK_RegexMatch(value, range->range, 0, NULL)) + { + retval = CCTK_SetString(param->data, value); + } + break; + } + } + + if(retval == -1) + { + fprintf(stderr, + "Unable to set sentence %s::%s - %s not in any active range\n", + param->thorn, + param->name, + value); + + if(*((char **)param->data) == NULL) + { + fprintf(stderr, "Since this was the default value, setting anyway - please fix!\n"); + + CCTK_SetString(param->data, value); + } + } + + return retval; +} + +static int ParameterSetInteger(t_parameter *param, const char *value) +{ + int retval; + t_range *range; + int inval; + int *val; + + inval = atoi(value); + val = (int *)param->data; + retval = -1; + for(range = param->range; range ; range = range->next) + { + if(CCTK_IsThornActive(range->origin)||CCTK_Equals(param->thorn, range->origin)) + { + if(Util_IntInRange(inval, range->range)) + { + *val = inval; + retval = 0; + } + break; + } + } + + if(retval == -1) + { + fprintf(stderr, + "Unable to set integer %s::%s - %s not in any active range\n", + param->thorn, + param->name, + value); + } + + return retval; +} + +static int ParameterSetReal(t_parameter *param, const char *value) +{ + int retval; + t_range *range; + double inval; + CCTK_REAL *val; + + inval = atof(value); + val = (CCTK_REAL *)param->data; + retval = -1; + for(range = param->range; range ; range = range->next) + { + if(CCTK_IsThornActive(range->origin)||CCTK_Equals(param->thorn, range->origin)) + { + if(Util_DoubleInRange(inval, range->range)||CCTK_Equals(param->thorn, range->origin)) + { + *val = inval; + retval = 0; + } + break; + } + } + + if(retval == -1) + { + fprintf(stderr, + "Unable to set real %s::%s - %s not in any active range\n", + param->thorn, + param->name, + value); + } + + return retval; +} + +static int ParameterSetLogical(t_parameter *param, const char *value) +{ + int retval; + + retval = -1; + retval = CCTK_SetLogical(param->data, value); + + if(retval == -1) + { + fprintf(stderr, + "Unable to set logical %s::%s - %s not recognised\n", + param->thorn, + param->name, + value); + } + + return retval; } /*#define TEST_PARAMETERS*/ diff --git a/src/main/SetParams.c b/src/main/SetParams.c index 074e638d..2a32c775 100644 --- a/src/main/SetParams.c +++ b/src/main/SetParams.c @@ -11,7 +11,14 @@ #include "cctk.h" +/* FIXME - remove this when ActiveThorns doesn't need it */ +#include "SKBinTree.h" + +#include "cctk_ActiveThorns.h" +#include "ParameterBindings.h" + #include "cctk_WarnLevel.h" +#include "cctk_Misc.h" static char *rcsid = "$Id$"; @@ -36,9 +43,9 @@ int CCTKi_SetParameter(const char *parameter, const char *value) const char *position; int length; int n_errors; - + retval = 0; - + if(CCTK_Equals(parameter, "ActiveThorns")) { n_errors = 0; @@ -47,18 +54,18 @@ int CCTKi_SetParameter(const char *parameter, const char *value) while(*position) { length=0; - + for(;*position && *position != ' ';position++) { thornname[length] = *position; if(length < 100) length++; } - + thornname[length] = '\0'; n_errors += CCTKi_ActivateThorn(thornname) != 0; if(*position) position++; } - + if(n_errors) { CCTK_WARN(0, "Errors while activating thorns\n"); @@ -66,25 +73,89 @@ int CCTKi_SetParameter(const char *parameter, const char *value) } else { - retval = CCTKi_BindingsParameterSet(parameter, value); + /* retval = CCTKi_BindingsParameterSet(parameter, value);*/ + retval = CCTKi_ReallySetParameter(parameter, value); } - + if(retval) { -#if 0 if(retval == -1) { -#endif - char *msg = (char *) malloc (strlen (parameter) + 30); - - sprintf(msg, "Unknown parameter %s", parameter); - CCTK_PARAMWARN (msg); - free (msg); -#if 0 + fprintf(stderr, "Unknown parameter %s\n", parameter); + } + else + { + fprintf(stderr, "Error setting parameter %s to %s\n", parameter, value); } -#endif } return retval; } +int CCTKi_ReallySetParameter(const char *parameter, const char *value) +{ + int retval; + const char *thorn; + char *param; + char *imp; + + int retval_imp; + int retval_thorn; + + + /* + CCTKi_BindingsParameterHelp(optarg,"%s",stdout); + */ + + Util_SplitString(&imp, ¶m, parameter, "::"); + + retval = -1; + /* If param is null, there were no colons in the input */ + + if(!param) + { + retval = ParameterSet(parameter, imp, value); + } + else + { + /* Set if this is an implementation one */ + if(CCTK_IsImplementationActive(imp)) + { + thorn = CCTK_ActivatingThorn(imp); + retval_imp = ParameterSet(param, thorn, value); + } + else + { + thorn = NULL; + retval_imp = -1; + } + + + /* Set if this is a thorn one. */ + if(!thorn || !CCTK_Equals(thorn,imp)) + { + retval_thorn = ParameterSet(param, imp, value); + } + else + { + /* Don't need to set it twice if the name of the imp is the same as the thorn providing it */ + retval_thorn = retval_imp; + } + + if(!retval_imp || !retval_thorn) + { + retval = 0; + } + else + { + retval = retval_imp ? retval_imp : retval_thorn; + } + } + + /* Free any allocated memory. */ + free(imp); + free(param); + + return retval; + +} diff --git a/src/main/Subsystems.c b/src/main/Subsystems.c index f2ad3cc7..1274c1d9 100644 --- a/src/main/Subsystems.c +++ b/src/main/Subsystems.c @@ -30,6 +30,8 @@ int InitialiseSubsystemDefaults(void) SetupCommFunctions(); SetupIOFunctions(); + CCTKi_BindingsParametersInitialise(); + return 0; } diff --git a/src/main/WarnLevel.c b/src/main/WarnLevel.c index b6b64ae9..b8af4b1c 100644 --- a/src/main/WarnLevel.c +++ b/src/main/WarnLevel.c @@ -12,10 +12,14 @@ #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> + +#include "StoreKeyedData.h" #include "cctk_Misc.h" #include "cctk_WarnLevel.h" #include "cctk_FortranString.h" + #include "cctk_parameters.h" static char *rcsid = "$Header$"; @@ -37,6 +41,13 @@ static int warning_level = 1; static int error_level = 0; + +/* Store a list of format strings */ + +static n_formats = 0; +static pKeyedData *formatlist = NULL; + + /*@@ @routine CCTKi_SetWarnLevel @date Wed Feb 17 00:42:16 1999 @@ -309,6 +320,71 @@ void CCTKi_FinaliseParamWarn(void) } /*@@ + @routine CCTK_MessageFormat + @date Mon Jul 26 19:51:26 1999 + @author Tom Goodale + @desc + Stores a format for messages from Fortran. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int FMODIFIER FORTRAN_NAME(CCTK_MessageFormat)(ONE_FORTSTRING_ARG) +{ + ONE_FORTSTRING_CREATE(format) + + StoreKeyedData(&formatlist, n_formats++ , (void *)format); + + return n_formats-1; +} + +void FMODIFIER FORTRAN_NAME(CCTK_VInfo)(int format_number, ...) +{ + char *format_string; + char *message; + char format[100]; + int message_length; + int current_place; + va_list args; + + if(format_number < n_formats) + { + format_string = (char *)GetKeyedData(formatlist, format_number); + + /* Pick an aribitrary starting length for the message */ + message_length=5*strlen(format_string); + + message = (char *)malloc(message_length); + + /* Loop through the format string */ + for(current_place=0; format_string; format_string++) + { + if(*format_string != '%') + { + message[current_place] = *format_string; + current_place++; + if(current_place >= message_length) + { + message = (char *)realloc(message, message_length*2); + message_length *=2; + } + } + else + { + + } + } + + } + +} + + /*@@ + @routine CCTK_NotYetImplemented @routine CCTKi_NotYetImplemented @date July 1999 @author Gabrielle Allen diff --git a/src/main/make.code.defn b/src/main/make.code.defn index 8d60eed9..efdda784 100644 --- a/src/main/make.code.defn +++ b/src/main/make.code.defn @@ -15,7 +15,6 @@ InitialiseDataStructures.c\ ProcessCommandLine.c\ ProcessEnvironment.c\ ProcessParameterDatabase.c\ -RecordImplementation.c\ SetParams.c\ ShutdownCactus.c\ Startup.c\ diff --git a/src/util/Misc.c b/src/util/Misc.c index 5bda1e6b..0a2e34fa 100644 --- a/src/util/Misc.c +++ b/src/util/Misc.c @@ -9,12 +9,16 @@ /*#define DEBUG_MISC*/ -#include <stdlib.h> +/*#include "cctk.h"*/ + #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <ctype.h> #include <stdarg.h> #include <assert.h> +#include <limits.h> +#include <math.h> #include "gnu_regex.h" @@ -251,7 +255,113 @@ int Util_InList(const char *string1, int n_elements, ...) @@*/ int Util_IntInRange(int inval, const char *range) { - return 1; + int retval; + int matched; + regmatch_t pmatch[6]; + int start_closed, end_closed; + int start, end, step; + + retval = 0; + + /* Valid ranges are of the form start:end:step + * possibly preceeded by a [ or ( and ended by a ) or ] to indicate + * closure. The end and step are optional. A * can also be used + * to indicate any value. + * + * The following regular expression may match five substrings: + * + * 1 - [ or ( + * 2 - start + * 3 - end + * 4 - step + * 5 - ) or ] + */ + + if(matched = CCTK_RegexMatch(range, + "(\\[|\\()?([^]):]*):?([^]):]*)?:?([^]):]*)?(\\]|\\))?", + 6, pmatch)) + { + /* First work out if the range is closed at the lower end. */ + if(pmatch[1].rm_so != -1) + { + switch(range[pmatch[1].rm_so]) + { + case '(' : start_closed = 0; break; + case '[' : + default : start_closed = 1; + } + } + else + { + start_closed = 1; + } + + /* Next find the start of the range */ + if(pmatch[2].rm_so != -1 && + (pmatch[2].rm_eo-pmatch[2].rm_so > 0) && + range[pmatch[2].rm_so] != '*') + { + start = atoi(range+pmatch[2].rm_so); + } + else + { + /* No start range given, so use the smallest integer available. */ + start = INT_MIN; + } + + /* Next find the end of the range */ + if(pmatch[3].rm_so != -1 && + (pmatch[3].rm_eo-pmatch[3].rm_so > 0) && + range[pmatch[3].rm_so] != '*') + { + end = atoi(range+pmatch[3].rm_so); + } + else + { + /* No end range given, so use the largest integer available. */ + end = INT_MAX; + } + + /* Next find the step of the range */ + if(pmatch[4].rm_so != -1 && (pmatch[4].rm_eo-pmatch[4].rm_so > 0)) + { + step = atoi(range+pmatch[4].rm_so); + } + else + { + /* No step given, so default to 1. */ + step = 1; + } + + /* Finally work out if the range is closed at the upper end. */ + if(pmatch[5].rm_so != -1) + { + switch(range[pmatch[5].rm_so]) + { + case ')' : end_closed = 0; break; + case ']' : + default : end_closed = 1; + } + } + else + { + end_closed = 1; + } + + if(inval >= start + !start_closed && + inval <= end - !end_closed && + ! ((inval-start) % step)) + { + retval = 1; + } + + } + else + { + CCTK_Warn(1, __LINE__, __FILE__, "Flesh", "Invalid range"); + } + + return retval; } /*@@ @@ -271,7 +381,115 @@ int Util_IntInRange(int inval, const char *range) @@*/ int Util_DoubleInRange(double inval, const char *range) { - return 1; + int retval; + int matched; + regmatch_t pmatch[6]; + int start_closed, end_closed; + double start, end, step; + + retval = 0; + + /* Valid ranges are of the form start:end:step + * possibly preceeded by a [ or ( and ended by a ) or ] to indicate + * closure. The end and step are optional. A * can also be used + * to indicate any value. + * + * The following regular expression may match five substrings: + * + * 1 - [ or ( + * 2 - start + * 3 - end + * 4 - step + * 5 - ) or ] + */ + + if(matched = CCTK_RegexMatch(range, + "(\\[|\\()?([^]):]*):?([^]):]*)?:?([^]):]*)?(\\]|\\))?", + 6, pmatch)) + { + /* First work out if the range is closed at the lower end. */ + if(pmatch[1].rm_so != -1) + { + switch(range[pmatch[1].rm_so]) + { + case '(' : start_closed = 0; break; + case '[' : + default : start_closed = 1; + } + } + else + { + start_closed = 1; + } + + /* Next find the start of the range */ + if(pmatch[2].rm_so != -1 && + (pmatch[2].rm_eo-pmatch[2].rm_so > 0) && + range[pmatch[2].rm_so] != '*') + { + start = atof(range+pmatch[2].rm_so); + } + else + { + /* No start range given, so use the smallest integer available. */ + start = INT_MIN; + } + + /* Next find the end of the range */ + if(pmatch[3].rm_so != -1 && + (pmatch[3].rm_eo-pmatch[3].rm_so > 0) && + range[pmatch[3].rm_so] != '*') + { + end = atof(range+pmatch[3].rm_so); + } + else + { + /* No end range given, so use the largest integer available. */ + end = FLT_MAX; + } + +#if 0 + /* Next find the step of the range */ + if(pmatch[4].rm_so != -1 && (pmatch[4].rm_eo-pmatch[4].rm_so > 0)) + { + step = atof(range+pmatch[4].rm_so); + } + else + { + /* No step given, so default to 1. */ + step = 1; + } +#endif + + /* Finally work out if the range is closed at the upper end. */ + if(pmatch[5].rm_so != -1) + { + switch(range[pmatch[5].rm_so]) + { + case ')' : end_closed = 0; break; + case ']' : + default : end_closed = 1; + } + } + else + { + end_closed = 1; + } + + if(inval > start /*+ !start_closed */&& + inval < end /* - !end_closed */ /* && + ! ((inval-start) % step)*/) + { + retval = 1; + } + + } + else + { + CCTK_Warn(1, __LINE__, __FILE__, "Flesh", "Invalid range"); + } + + return retval; } @@ -727,12 +945,3 @@ int CCTK_RegexMatch(const char *string, return(1); } - - - - - - - - - |