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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3227 - (hide annotations)
Thu Sep 30 06:07:08 2010 UTC (9 years, 5 months ago) by jfenwick
Original Path: branches/domexper/dudley/src/TagMap.c
File MIME type: text/plain
File size: 2574 byte(s)
Pass1 or moving MPI stuff out of paso

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 jfenwick 3227 #include "esysUtils/mem.h"
22     #include "string.h"
23 gross 1044
24     /**************************************************************/
25    
26 jfenwick 3224 void Dudley_TagMap_insert(Dudley_TagMap ** tag_map, const char *name, index_t tag_key)
27 gross 1044 {
28 jfenwick 3224 Dudley_TagMap *map = NULL;
29     if (strlen(name) < 1)
30     {
31     Dudley_setError(VALUE_ERROR, "empty tag name.");
32     return;
33     }
34     if (strchr(name, 32) != NULL)
35     { /* check for space */
36     Dudley_setError(VALUE_ERROR, "tag name may not contain a space.");
37     return;
38     }
39     if (*tag_map == NULL)
40     {
41     map = MEMALLOC(1, Dudley_TagMap);
42     if (Dudley_checkPtr(map))
43     return;
44     map->name = MEMALLOC(strlen(name) + 1, char);
45     if (Dudley_checkPtr(map->name))
46     {
47     MEMFREE(map);
48     }
49     else
50     {
51     strcpy(map->name, name);
52     map->tag_key = tag_key;
53     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 gross 1044 }
69    
70 jfenwick 3224 index_t Dudley_TagMap_getTag(Dudley_TagMap * tag_map, const char *name)
71 gross 1044 {
72 jfenwick 3224 char error_msg[LenErrorMsg_MAX];
73     if (tag_map == NULL)
74     {
75     sprintf(error_msg, "Dudley_TagMap_getTag: unknown tag name %s.", name);
76     Dudley_setError(VALUE_ERROR, error_msg);
77     return -1;
78     }
79     else
80     {
81     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 gross 1044 }
91 jfenwick 3224
92     bool_t Dudley_TagMap_isValidTagName(Dudley_TagMap * tag_map, const char *name)
93 gross 1044 {
94 jfenwick 3224 if (tag_map == NULL)
95     {
96     return FALSE;
97     }
98     else
99     {
100     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 gross 1044 }
110 jfenwick 3224
111 jfenwick 3086 /* deallocates the Dudley_TagMap in by recursive calls */
112 gross 1044
113 jfenwick 3224 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 gross 1044 }

  ViewVC Help
Powered by ViewVC 1.1.26