/[escript]/trunk/dudley/src/TagMap.c
ViewVC logotype

Diff of /trunk/dudley/src/TagMap.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3080 by jfenwick, Tue Aug 3 04:28:03 2010 UTC revision 3086 by jfenwick, Thu Aug 5 05:07:58 2010 UTC
# Line 14  Line 14 
14    
15  /**************************************************************/  /**************************************************************/
16    
17  /* Finley: simple mapping fram names to tag keys via a linked list */  /* Dudley: simple mapping fram names to tag keys via a linked list */
18    
19  /**************************************************************/  /**************************************************************/
20    
# Line 22  Line 22 
22    
23  /**************************************************************/  /**************************************************************/
24    
25  void Finley_TagMap_insert(Finley_TagMap** tag_map,  void Dudley_TagMap_insert(Dudley_TagMap** tag_map,
26                            const char* name,                            const char* name,
27                            index_t tag_key)                            index_t tag_key)
28  {  {
29    Finley_TagMap* map=NULL;    Dudley_TagMap* map=NULL;
30    if (strlen(name)<1) {    if (strlen(name)<1) {
31       Finley_setError(VALUE_ERROR,"empty tag name.");       Dudley_setError(VALUE_ERROR,"empty tag name.");
32       return;       return;
33    }    }
34    if (strchr(name,32) != NULL) {   /* check for space */    if (strchr(name,32) != NULL) {   /* check for space */
35       Finley_setError(VALUE_ERROR,"tag name may not contain a space.");       Dudley_setError(VALUE_ERROR,"tag name may not contain a space.");
36       return;       return;
37    }    }
38    if (*tag_map == NULL) {    if (*tag_map == NULL) {
39         map=MEMALLOC(1,Finley_TagMap);         map=MEMALLOC(1,Dudley_TagMap);
40         if (Finley_checkPtr(map)) return;         if (Dudley_checkPtr(map)) return;
41         map->name=MEMALLOC(strlen(name)+1,char);         map->name=MEMALLOC(strlen(name)+1,char);
42         if (Finley_checkPtr(map->name) ) {         if (Dudley_checkPtr(map->name) ) {
43              MEMFREE(map);              MEMFREE(map);
44          } else {          } else {
45              strcpy(map->name,name);              strcpy(map->name,name);
# Line 51  void Finley_TagMap_insert(Finley_TagMap* Line 51  void Finley_TagMap_insert(Finley_TagMap*
51        if (strcmp((*tag_map)->name,name)==0) {        if (strcmp((*tag_map)->name,name)==0) {
52           (*tag_map)->tag_key=tag_key;           (*tag_map)->tag_key=tag_key;
53        } else {        } else {
54           Finley_TagMap_insert(&((*tag_map)->next),name,tag_key);           Dudley_TagMap_insert(&((*tag_map)->next),name,tag_key);
55        }        }
56    }    }
57  }  }
58    
59  index_t Finley_TagMap_getTag(Finley_TagMap* tag_map,const char* name)  index_t Dudley_TagMap_getTag(Dudley_TagMap* tag_map,const char* name)
60  {  {
61    char error_msg[LenErrorMsg_MAX];    char error_msg[LenErrorMsg_MAX];
62    if (tag_map == NULL) {    if (tag_map == NULL) {
63          sprintf(error_msg,"Finley_TagMap_getTag: unknown tag name %s.",name);          sprintf(error_msg,"Dudley_TagMap_getTag: unknown tag name %s.",name);
64          Finley_setError(VALUE_ERROR,error_msg);          Dudley_setError(VALUE_ERROR,error_msg);
65          return -1;          return -1;
66    } else {    } else {
67        if (strcmp(tag_map->name,name)==0) {        if (strcmp(tag_map->name,name)==0) {
68           return tag_map->tag_key;           return tag_map->tag_key;
69        } else {        } else {
70           return Finley_TagMap_getTag(tag_map->next,name);           return Dudley_TagMap_getTag(tag_map->next,name);
71        }        }
72    }    }
73  }  }
74  bool_t Finley_TagMap_isValidTagName(Finley_TagMap* tag_map, const char* name)  bool_t Dudley_TagMap_isValidTagName(Dudley_TagMap* tag_map, const char* name)
75  {  {
76    if (tag_map == NULL) {    if (tag_map == NULL) {
77          return FALSE;          return FALSE;
# Line 79  bool_t Finley_TagMap_isValidTagName(Finl Line 79  bool_t Finley_TagMap_isValidTagName(Finl
79        if (strcmp(tag_map->name,name)==0) {        if (strcmp(tag_map->name,name)==0) {
80           return TRUE;           return TRUE;
81        } else {        } else {
82           return Finley_TagMap_isValidTagName(tag_map->next,name);           return Dudley_TagMap_isValidTagName(tag_map->next,name);
83        }        }
84    }    }
85  }  }
86  /* deallocates the Finley_TagMap in by recursive calls */  /* deallocates the Dudley_TagMap in by recursive calls */
87    
88  void Finley_TagMap_free(Finley_TagMap* in) {  void Dudley_TagMap_free(Dudley_TagMap* in) {
89    if (in!=NULL) {    if (in!=NULL) {
90      Finley_TagMap_free(in->next);      Dudley_TagMap_free(in->next);
91      MEMFREE(in->name);      MEMFREE(in->name);
92      MEMFREE(in);      MEMFREE(in);
93    }    }

Legend:
Removed from v.3080  
changed lines
  Added in v.3086

  ViewVC Help
Powered by ViewVC 1.1.26