/[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

temp/finley/src/TagMap.c revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC trunk/dudley/src/TagMap.c revision 3259 by jfenwick, Mon Oct 11 01:48:14 2010 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2010 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14  /**************************************************************/  /**************************************************************/
15    
16  /* Finley: simple mapping fram names to tag keys via a linked list */  /* Dudley: simple mapping fram names to tag keys via a linked list */
17    
18  /**************************************************************/  /**************************************************************/
19    
20  #include "TagMap.h"  #include "TagMap.h"
21    #include "esysUtils/mem.h"
22    #include "string.h"
23    
24  /**************************************************************/  /**************************************************************/
25    
26  void Finley_TagMap_insert(Finley_TagMap** tag_map,  void Dudley_TagMap_insert(Dudley_TagMap ** tag_map, const char *name, index_t tag_key)
                           const char* name,  
                           index_t tag_key)  
27  {  {
28    Finley_TagMap* map=NULL;      Dudley_TagMap *map = NULL;
29    if (strlen(name)<1) {      if (strlen(name) < 1)
30       Finley_setError(VALUE_ERROR,"empty tag name.");      {
31       return;      Dudley_setError(VALUE_ERROR, "empty tag name.");
32    }      return;
33    if (strchr(name,32) != NULL) {   /* check for space */      }
34       Finley_setError(VALUE_ERROR,"tag name may not contain a space.");      if (strchr(name, 32) != NULL)
35       return;      {               /* check for space */
36    }      Dudley_setError(VALUE_ERROR, "tag name may not contain a space.");
37    if (*tag_map == NULL) {      return;
38         map=MEMALLOC(1,Finley_TagMap);      }
39         if (Finley_checkPtr(map)) return;      if (*tag_map == NULL)
40         map->name=MEMALLOC(strlen(name)+1,char);      {
41         if (Finley_checkPtr(map->name) ) {      map = MEMALLOC(1, Dudley_TagMap);
42              MEMFREE(map);      if (Dudley_checkPtr(map))
43          } else {          return;
44              strcpy(map->name,name);      map->name = MEMALLOC(strlen(name) + 1, char);
45              map->tag_key=tag_key;      if (Dudley_checkPtr(map->name))
46              map->next=NULL;      {
47              *tag_map=map;          MEMFREE(map);
48          }      }
49    } else {      else
50        if (strcmp((*tag_map)->name,name)==0) {      {
51           (*tag_map)->tag_key=tag_key;          strcpy(map->name, name);
52        } else {          map->tag_key = tag_key;
53           Finley_TagMap_insert(&((*tag_map)->next),name,tag_key);          map->next = NULL;
54        }          *tag_map = map;
55    }      }
56        }
57        else
58        {
59        if (strcmp((*tag_map)->name, name) == 0)
60        {
61            (*tag_map)->tag_key = tag_key;
62        }
63        else
64        {
65            Dudley_TagMap_insert(&((*tag_map)->next), name, tag_key);
66        }
67        }
68  }  }
69    
70  index_t Finley_TagMap_getTag(Finley_TagMap* tag_map,const char* name)  index_t Dudley_TagMap_getTag(Dudley_TagMap * tag_map, const char *name)
71  {  {
72    char error_msg[LenErrorMsg_MAX];      char error_msg[LenErrorMsg_MAX];
73    if (tag_map == NULL) {      if (tag_map == NULL)
74          sprintf(error_msg,"Finley_TagMap_getTag: unknown tag name %s.",name);      {
75          Finley_setError(VALUE_ERROR,error_msg);      sprintf(error_msg, "Dudley_TagMap_getTag: unknown tag name %s.", name);
76          return -1;      Dudley_setError(VALUE_ERROR, error_msg);
77    } else {      return -1;
78        if (strcmp(tag_map->name,name)==0) {      }
79           return tag_map->tag_key;      else
80        } else {      {
81           return Finley_TagMap_getTag(tag_map->next,name);      if (strcmp(tag_map->name, name) == 0)
82        }      {
83    }          return tag_map->tag_key;
84        }
85        else
86        {
87            return Dudley_TagMap_getTag(tag_map->next, name);
88        }
89        }
90  }  }
91  bool_t Finley_TagMap_isValidTagName(Finley_TagMap* tag_map, const char* name)  
92    bool_t Dudley_TagMap_isValidTagName(Dudley_TagMap * tag_map, const char *name)
93  {  {
94    if (tag_map == NULL) {      if (tag_map == NULL)
95          return FALSE;      {
96    } else {      return FALSE;
97        if (strcmp(tag_map->name,name)==0) {      }
98           return TRUE;      else
99        } else {      {
100           return Finley_TagMap_isValidTagName(tag_map->next,name);      if (strcmp(tag_map->name, name) == 0)
101        }      {
102    }          return TRUE;
103        }
104        else
105        {
106            return Dudley_TagMap_isValidTagName(tag_map->next, name);
107        }
108        }
109  }  }
 /* deallocates the Finley_TagMap in by recursive calls */  
110    
111  void Finley_TagMap_free(Finley_TagMap* in) {  /* deallocates the Dudley_TagMap in by recursive calls */
   if (in!=NULL) {  
     Finley_TagMap_free(in->next);  
     MEMFREE(in->name);  
     MEMFREE(in);  
   }  
 }  
112    
113    void Dudley_TagMap_free(Dudley_TagMap * in)
114    {
115        if (in != NULL)
116        {
117        Dudley_TagMap_free(in->next);
118        MEMFREE(in->name);
119        MEMFREE(in);
120        }
121        return;
122    }

Legend:
Removed from v.1387  
changed lines
  Added in v.3259

  ViewVC Help
Powered by ViewVC 1.1.26