summaryrefslogtreecommitdiff
path: root/src/schedule
diff options
context:
space:
mode:
Diffstat (limited to 'src/schedule')
-rw-r--r--src/schedule/Schedule.h2
-rw-r--r--src/schedule/ScheduleCreater.c74
-rw-r--r--src/schedule/ScheduleTraverse.c137
3 files changed, 191 insertions, 22 deletions
diff --git a/src/schedule/Schedule.h b/src/schedule/Schedule.h
index 5074e87a..bea93775 100644
--- a/src/schedule/Schedule.h
+++ b/src/schedule/Schedule.h
@@ -55,6 +55,8 @@ typedef struct
int n_whiles;
char **whiles;
+ int n_ifs;
+ char **ifs;
void *attributes;
diff --git a/src/schedule/ScheduleCreater.c b/src/schedule/ScheduleCreater.c
index 7aef2a5a..ace2c9a7 100644
--- a/src/schedule/ScheduleCreater.c
+++ b/src/schedule/ScheduleCreater.c
@@ -48,6 +48,7 @@ static int ScheduleItemNumber(t_sched_group *group,
static int ScheduleSetupWhiles(t_sched_item *item);
+static int ScheduleSetupIfs(t_sched_item *item);
/********************************************************************
********************* Other Routine Prototypes *********************
@@ -533,8 +534,11 @@ static t_sched_item *ScheduleCreateItem(const char *name, t_sched_modifier *modi
this->n_whiles = 0;
this->whiles = NULL;
+ this->n_ifs = 0;
+ this->ifs = NULL;
ScheduleSetupWhiles(this);
+ ScheduleSetupIfs(this);
this->attributes = attributes;
@@ -676,6 +680,10 @@ static t_sched_modifier_type ScheduleTranslateModifierType(const char *modifier)
{
retval = sched_while;
}
+ else if(!strcmp(modifier, "if"))
+ {
+ retval = sched_if;
+ }
#ifdef DEBUG_SCHEDULAR
printf("Translated modifier type %s to %d\n", modifier, retval);
@@ -747,7 +755,7 @@ static int ScheduleSortGroup(t_sched_group *group)
#endif
for(modifier = group->scheditems[item].modifiers; modifier; modifier = modifier->next)
{
- if(modifier->type == sched_while)
+ if(modifier->type == sched_while || modifier->type == sched_if)
{
continue;
}
@@ -969,6 +977,70 @@ static int ScheduleSetupWhiles(t_sched_item *item)
return retval;
}
+ /*@@
+ @routine ScheduleSetupIfs
+ @date Dec 27, 2005
+ @author Erik Schnetter
+ @desc
+ Make an array of all the ifs in the modifier list for a schedule item.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+ @var item
+ @vdesc The schedule item to work on
+ @vtype t_sched_item *
+ @vio inout
+ @vcomment
+
+ @endvar
+ @returntype int
+ @returndesc
+ Number of whiles
+ @endreturndesc
+@@*/
+static int ScheduleSetupIfs(t_sched_item *item)
+{
+ int retval;
+ t_sched_modifier *modifier;
+ char **temp;
+
+ retval = 0;
+
+ for(modifier = item->modifiers; modifier; modifier = modifier->next)
+ {
+ if(modifier->type == sched_if)
+ {
+ item->n_ifs++;
+ temp = (char **)realloc(item->ifs, item->n_ifs*sizeof(char *));
+
+ if(temp)
+ {
+ item->ifs = temp;
+
+ temp[item->n_ifs-1] = (char *)malloc((strlen(modifier->argument)+1)*sizeof(char));
+ if(temp[item->n_ifs-1])
+ {
+ strcpy(temp[item->n_ifs-1], modifier->argument);
+ }
+ else
+ {
+ item->n_ifs--;
+ retval--;
+ }
+ }
+ else
+ {
+ retval--;
+ }
+ }
+ }
+
+ return retval;
+}
+
/********************************************************************
********************************************************************
********************************************************************/
diff --git a/src/schedule/ScheduleTraverse.c b/src/schedule/ScheduleTraverse.c
index 30908371..1baa0ad3 100644
--- a/src/schedule/ScheduleTraverse.c
+++ b/src/schedule/ScheduleTraverse.c
@@ -34,9 +34,12 @@ static int ScheduleTraverseGroup(cHandledData *schedule_groups,
void *attributes,
int n_whiles,
char **whiles,
+ int n_ifs,
+ char **ifs,
int (*item_entry)(void *, void *),
int (*item_exit)(void *, void *),
- int (*while_check)(int, char **, void *, void *, int),
+ int (*while_check)(int, char **, void *, void *, int),
+ int (*if_check)(int, char **, void *, void *),
int (*function_process)(void *, void *, void *),
void *data);
@@ -44,9 +47,12 @@ static int ScheduleTraverseFunction(void *function,
void *attributes,
int n_whiles,
char **whiles,
+ int n_ifs,
+ char **ifs,
int (*item_entry)(void *, void *),
int (*item_exit)(void *, void *),
- int (*while_check)(int, char **, void *, void *, int),
+ int (*while_check)(int, char **, void *, void *, int),
+ int (*if_check)(int, char **, void *, void *),
int (*function_process)(void *, void *, void *),
void *data);
@@ -102,6 +108,13 @@ static int ScheduleTraverseFunction(void *function,
@vcomment
@endvar
+ @var if_check
+ @vdesc function to be called to check an if statement
+ @vtype int (*)(int, char **, void *, void *, int)
+ @vio in
+ @vcomment
+
+ @endvar
@var function_process
@vdesc function to be called on any function
@vtype int (*)(void *, void *, void *)
@@ -126,7 +139,8 @@ static int ScheduleTraverseFunction(void *function,
int CCTKi_DoScheduleTraverse(const char *group_name,
int (*item_entry)(void *, void *),
int (*item_exit)(void *, void *),
- int (*while_check)(int, char **, void *, void *, int),
+ int (*while_check)(int, char **, void *, void *, int),
+ int (*if_check)(int, char **, void *, void *),
int (*function_process)(void *, void *, void *),
void *data)
{
@@ -146,9 +160,12 @@ int CCTKi_DoScheduleTraverse(const char *group_name,
NULL,
0,
NULL,
+ 0,
+ NULL,
item_entry,
item_exit,
while_check,
+ if_check,
function_process,
data);
}
@@ -211,6 +228,20 @@ int CCTKi_DoScheduleTraverse(const char *group_name,
@vcomment
@endvar
+ @var n_ifs
+ @vdesc number of ifs
+ @vtype int
+ @vio in
+ @vcomment
+
+ @endvar
+ @var ifs
+ @vdesc array of if strings
+ @vtype char **
+ @vio in
+ @vcomment
+
+ @endvar
@var item_entry
@vdesc function to be called on entry to an item
@vtype int (*)(void *, void *)
@@ -232,6 +263,13 @@ int CCTKi_DoScheduleTraverse(const char *group_name,
@vcomment
@endvar
+ @var if_check
+ @vdesc function to be called to check a if statement
+ @vtype int (*)(int, char **, void *, void *, int)
+ @vio in
+ @vcomment
+
+ @endvar
@var function_process
@vdesc function to be called on any function
@vtype int (*)(void *, void *, void *)
@@ -257,9 +295,12 @@ static int ScheduleTraverseGroup(cHandledData *schedule_groups,
void *attributes,
int n_whiles,
char **whiles,
+ int n_ifs,
+ char **ifs,
int (*item_entry)(void *, void *),
int (*item_exit)(void *, void *),
- int (*while_check)(int, char **, void *, void *, int),
+ int (*while_check)(int, char **, void *, void *, int),
+ int (*if_check)(int, char **, void *, void *),
int (*function_process)(void *, void *, void *),
void *data)
{
@@ -268,17 +309,35 @@ static int ScheduleTraverseGroup(cHandledData *schedule_groups,
int called_item_entry;
t_sched_group *newgroup;
- /* If there is a while-list associated with this item, check if the group should be
- * exectuted at all.
+ doit = 1;
+
+ /* If there is an if-list associated with this item, check if the
+ * group should be exectuted at all.
*/
- if(n_whiles > 0 && while_check)
+ if(n_ifs > 0 && if_check)
{
- doit = while_check(n_whiles, whiles, attributes, data,1);
+ doit = doit && if_check(n_ifs, ifs, attributes, data);
}
- else
+
+ /* If there is a while-list associated with this item, check if the
+ * group should be exectuted at all.
+ *
+ * If there are both an if-list and a while-list, then both are
+ * checked when the group is entered, but only the while-list is
+ * checked to determine whether the loop should continue. This
+ * means that the if-statement is outside the while-statement, as in
+ *
+ * IF (...)
+ * WHILE (...)
+ * schedule stuff
+ * END WHILE
+ * END IF
+ */
+
+ if(n_whiles > 0 && while_check)
{
- doit = 1;
+ doit = doit && while_check(n_whiles, whiles, attributes, data,1);
}
/* Call a item entry function if it is defined. */
@@ -297,7 +356,7 @@ static int ScheduleTraverseGroup(cHandledData *schedule_groups,
}
/* Now traverse the group. */
- while(doit )
+ while(doit)
{
/* Traverse in the sorted order - assumes group has been sorted ! */
@@ -310,9 +369,12 @@ static int ScheduleTraverseGroup(cHandledData *schedule_groups,
group->scheditems[group->order[item]].attributes,
group->scheditems[group->order[item]].n_whiles,
group->scheditems[group->order[item]].whiles,
+ group->scheditems[group->order[item]].n_ifs,
+ group->scheditems[group->order[item]].ifs,
item_entry,
- item_exit,
+ item_exit,
while_check,
+ if_check,
function_process,
data);
break;
@@ -324,9 +386,12 @@ static int ScheduleTraverseGroup(cHandledData *schedule_groups,
group->scheditems[group->order[item]].attributes,
group->scheditems[group->order[item]].n_whiles,
group->scheditems[group->order[item]].whiles,
+ group->scheditems[group->order[item]].n_ifs,
+ group->scheditems[group->order[item]].ifs,
item_entry,
item_exit,
while_check,
+ if_check,
function_process,
data);
break;
@@ -398,6 +463,20 @@ static int ScheduleTraverseGroup(cHandledData *schedule_groups,
@vcomment
@endvar
+ @var n_ifs
+ @vdesc number of ifs
+ @vtype int
+ @vio in
+ @vcomment
+
+ @endvar
+ @var ifs
+ @vdesc array of if strings
+ @vtype char **
+ @vio in
+ @vcomment
+
+ @endvar
@var item_entry
@vdesc function to be called on entry to an item
@vtype int (*)(void *, void *)
@@ -419,6 +498,13 @@ static int ScheduleTraverseGroup(cHandledData *schedule_groups,
@vcomment
@endvar
+ @var if_check
+ @vdesc function to be called to check a if statement
+ @vtype int (*)(int, char **, void *, void *, int)
+ @vio in
+ @vcomment
+
+ @endvar
@var function_process
@vdesc function to be called on any function
@vtype int (*)(void *, void *, void *)
@@ -443,26 +529,36 @@ static int ScheduleTraverseFunction(void *function,
void *attributes,
int n_whiles,
char **whiles,
+ int n_ifs,
+ char **ifs,
int (*item_entry)(void *, void *),
int (*item_exit)(void *, void *),
- int (*while_check)(int, char **, void *, void *, int),
+ int (*while_check)(int, char **, void *, void *, int),
+ int (*if_check)(int, char **, void *, void *),
int (*function_process)(void *, void *, void *),
void *data)
{
int doit;
int called_item_entry;
- /* If there is a while-list associated with this function, check if the function should be
- * executed at all.
+ doit = 1;
+
+ /* If there is an if-list associated with this function, check if
+ * the function should be executed at all.
*/
- if(n_whiles > 0 && while_check)
+ if(n_ifs > 0 && if_check)
{
- doit = while_check(n_whiles, whiles, attributes, data,1);
+ doit = doit && if_check(n_ifs, ifs, attributes, data);
}
- else
+
+ /* If there is a while-list associated with this function, check if
+ * the function should be executed at all.
+ */
+
+ if(n_whiles > 0 && while_check)
{
- doit = 1;
+ doit = doit && while_check(n_whiles, whiles, attributes, data,1);
}
/* Call a item entry function if it is defined. */
@@ -481,7 +577,7 @@ static int ScheduleTraverseFunction(void *function,
}
/* Now traverse the . */
- while(doit )
+ while(doit)
{
/* Now actually do something with the function. */
@@ -493,7 +589,6 @@ static int ScheduleTraverseFunction(void *function,
doit = while_check(n_whiles, whiles, attributes, data,0) ;
}
else
-
{
doit = 0;
}