diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-07-05 09:01:57 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-07-05 09:01:57 +0000 |
commit | 27101c7b64409abfa493e64bed5de72ac84bb1ce (patch) | |
tree | 4bfaf0a5b0fcc4d7119325d665f06165380c72b5 /src | |
parent | 287abd55c7e41b10718810c7dec8b3bf939d8cf6 (diff) |
Latest changes for the ActiveThorns.
Tom
git-svn-id: http://svn.cactuscode.org/flesh/trunk@649 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ActiveThorns.h | 3 | ||||
-rw-r--r-- | src/include/SKBinTree.h | 2 | ||||
-rw-r--r-- | src/main/ActiveThorns.c | 91 | ||||
-rw-r--r-- | src/main/SetParams.c | 9 | ||||
-rw-r--r-- | src/util/SKBinTree.c | 42 |
5 files changed, 145 insertions, 2 deletions
diff --git a/src/include/ActiveThorns.h b/src/include/ActiveThorns.h index 0abdd287..9794f612 100644 --- a/src/include/ActiveThorns.h +++ b/src/include/ActiveThorns.h @@ -19,7 +19,8 @@ int CCTK_RegisterThorn(const char *name, const char *imp); int CCTK_ActivateThorn(const char *name); int CCTK_IsThornActive(const char *name); int CCTK_IsImplementationActive(const char *name); - +int CCTK_ListThorns(FILE *file, const char *format, int active); +int CCTK_ListImplementations(FILE *file, const char *format, int active); #ifdef __cplusplus } diff --git a/src/include/SKBinTree.h b/src/include/SKBinTree.h index 6ff6153b..482219be 100644 --- a/src/include/SKBinTree.h +++ b/src/include/SKBinTree.h @@ -40,6 +40,8 @@ void SKTreePrintNodes(t_sktree *root, int depth, void (*print_node)(void *, int) t_sktree *SKTreeFindNode(t_sktree *root, const char *key); +t_sktree *SKTreeFindFirst(t_sktree *root); + #ifdef _cplusplus } #endif diff --git a/src/main/ActiveThorns.c b/src/main/ActiveThorns.c index 00db62c3..b7d90a68 100644 --- a/src/main/ActiveThorns.c +++ b/src/main/ActiveThorns.c @@ -30,6 +30,8 @@ struct THORN struct IMPLEMENTATION { int active; + t_sktree *thornlist; + char *activating_thorn; }; @@ -150,6 +152,9 @@ static int CCTKi_RegisterImp(const char *name, const char *thorn) { imp->active = 0; + /* Store the name of this thorn in a tree */ + imp->thornlist = SKTreeStoreData(NULL,NULL, thorn, NULL); + /* Store the info in the tree. */ temp = SKTreeStoreData(implist, implist, name, imp); @@ -171,6 +176,9 @@ static int CCTKi_RegisterImp(const char *name, const char *thorn) } else { + imp = (struct IMPLEMENTATION *)(node->data); + SKTreeStoreData(imp->thornlist,imp->thornlist, thorn, NULL); + retval = -1; } @@ -226,11 +234,14 @@ int CCTK_ActivateThorn(const char *name) printf("Success -> active implementation %s\n", name, thorn->implementation); thorn->active = 1; imp->active = 1; + /* Remember which thorn activated this imp. */ + imp->activating_thorn = (char *)malloc(sizeof(char)*(strlen(name)+1)); + strcpy(imp->activating_thorn, name); retval = 0; } else { - printf("Failure -> Implementation %s already active\n", thorn->implementation); + printf("Failure -> Implementation %s already activated by %s\n", thorn->implementation, imp->activating_thorn); retval = -4; } } @@ -335,3 +346,81 @@ int CCTK_IsImplementationActive(const char *name) return retval; } + + /*@@ + @routine CCTK_ListThorns + @date Mon Jul 5 10:02:15 1999 + @author Tom Goodale + @desc + Prints a list of thorns. + Only lists active ones if the 'active' parameter is true. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int CCTK_ListThorns(FILE *file, const char *format, int active) +{ + int retval; + t_sktree *node; + + struct THORN *thorn; + + retval = 0; + + for(node= SKTreeFindFirst(thornlist); + node; + node = node->next, retval++) + { + thorn = (struct THORN *)(node->data); + + if(thorn->active || !active) + { + fprintf(file, format, node->key); + } + } + + return retval; +} + + /*@@ + @routine CCTK_ListImplementations + @date Mon Jul 5 10:08:19 1999 + @author Tom Goodale + @desc + Prints a list of implementations. + Only lists active ones if the 'active' parameter is true. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int CCTK_ListImplementations(FILE *file, const char *format, int active) +{ + int retval; + t_sktree *node; + + struct IMPLEMENTATION *imp; + + retval = 0; + + for(node= SKTreeFindFirst(implist); + node; + node = node->next, retval++) + { + imp = (struct IMPLEMENTATION *)(node->data); + + if(imp->active || !active) + { + fprintf(file, format, node->key); + } + } + + return retval; +} diff --git a/src/main/SetParams.c b/src/main/SetParams.c index 4cf65490..34887124 100644 --- a/src/main/SetParams.c +++ b/src/main/SetParams.c @@ -9,6 +9,10 @@ #include <stdio.h> +#include "cctk.h" + +#include "WarnLevel.h" + static char *rcsid = "$Id$"; /*@@ @@ -52,6 +56,11 @@ int CCTK_SetParameter(const char *parameter, const char *value) n_errors += CCTK_ActivateThorn(thornname) != 0; if(*position) position++; } + + if(n_errors) + { + CCTK_WARN(0, "Errors while activating thorns\n"); + } } else { diff --git a/src/util/SKBinTree.c b/src/util/SKBinTree.c index 64834401..fb55d5bf 100644 --- a/src/util/SKBinTree.c +++ b/src/util/SKBinTree.c @@ -4,6 +4,8 @@ @author Tom Goodale @desc Routines to deal with binary trees keyed by strings. + The tree is a threaded tree, i.e. it can also be + traversed, inorder, like a linked list. @enddesc @@*/ @@ -47,6 +49,7 @@ t_sktree *SKTreeStoreData(t_sktree *root, t_sktree *subtree, { subtree->left=NULL; subtree->right=NULL; + subtree->next=NULL; subtree->data = data; @@ -57,10 +60,13 @@ t_sktree *SKTreeStoreData(t_sktree *root, t_sktree *subtree, if((order = STR_CMP(key, root->key)) < 0) { root->left = subtree; + subtree->next = root ; } else { root->right = subtree; + subtree->next = root->next; + root->next = subtree; } } } @@ -206,6 +212,20 @@ void SKTreePrintNodes(t_sktree *root, int depth, void (*print_node)(void *, int) } + /*@@ + @routine SKTreeFindNode + @date Mon Jul 5 10:09:30 1999 + @author Tom Goodale + @desc + Finds a given node in the tree. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ t_sktree *SKTreeFindNode(t_sktree *root, const char *key) { int order; @@ -237,6 +257,28 @@ t_sktree *SKTreeFindNode(t_sktree *root, const char *key) return node; } + /*@@ + @routine SKTreeFindFirst + @date Mon Jul 5 10:09:57 1999 + @author Tom Goodale + @desc + Finds the first node in the tree (the leftmost one). + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +t_sktree *SKTreeFindFirst(t_sktree *root) +{ + for(; root->left ; root = root->left); + + return root; +} + + /*@@ |