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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3224 - (hide annotations)
Wed Sep 29 05:19:37 2010 UTC (9 years, 4 months ago) by jfenwick
Original Path: branches/domexper/dudley/src/TagMap.c
File MIME type: text/plain
File size: 2527 byte(s)
indent -linux -nce -i4 -bl -bli0 -l120

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

  ViewVC Help
Powered by ViewVC 1.1.26