/[escript]/branches/domexper/dudley/src/TagMap.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/TagMap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3227 - (show annotations)
Thu Sep 30 06:07:08 2010 UTC (9 years, 6 months ago) by jfenwick
File MIME type: text/plain
File size: 2574 byte(s)
Pass1 or moving MPI stuff out of paso

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * 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
14 /**************************************************************/
15
16 /* Dudley: simple mapping fram names to tag keys via a linked list */
17
18 /**************************************************************/
19
20 #include "TagMap.h"
21 #include "esysUtils/mem.h"
22 #include "string.h"
23
24 /**************************************************************/
25
26 void Dudley_TagMap_insert(Dudley_TagMap ** tag_map, const char *name, index_t tag_key)
27 {
28 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 }
69
70 index_t Dudley_TagMap_getTag(Dudley_TagMap * tag_map, const char *name)
71 {
72 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 }
91
92 bool_t Dudley_TagMap_isValidTagName(Dudley_TagMap * tag_map, const char *name)
93 {
94 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 }
110
111 /* deallocates the Dudley_TagMap in by recursive calls */
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 }

  ViewVC Help
Powered by ViewVC 1.1.26