/[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 3086 - (show annotations)
Thu Aug 5 05:07:58 2010 UTC (9 years, 3 months ago) by jfenwick
File MIME type: text/plain
File size: 2630 byte(s)
Another pass at removing finley

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
17 /* Dudley: simple mapping fram names to tag keys via a linked list */
18
19 /**************************************************************/
20
21 #include "TagMap.h"
22
23 /**************************************************************/
24
25 void Dudley_TagMap_insert(Dudley_TagMap** tag_map,
26 const char* name,
27 index_t tag_key)
28 {
29 Dudley_TagMap* map=NULL;
30 if (strlen(name)<1) {
31 Dudley_setError(VALUE_ERROR,"empty tag name.");
32 return;
33 }
34 if (strchr(name,32) != NULL) { /* check for space */
35 Dudley_setError(VALUE_ERROR,"tag name may not contain a space.");
36 return;
37 }
38 if (*tag_map == NULL) {
39 map=MEMALLOC(1,Dudley_TagMap);
40 if (Dudley_checkPtr(map)) return;
41 map->name=MEMALLOC(strlen(name)+1,char);
42 if (Dudley_checkPtr(map->name) ) {
43 MEMFREE(map);
44 } else {
45 strcpy(map->name,name);
46 map->tag_key=tag_key;
47 map->next=NULL;
48 *tag_map=map;
49 }
50 } else {
51 if (strcmp((*tag_map)->name,name)==0) {
52 (*tag_map)->tag_key=tag_key;
53 } else {
54 Dudley_TagMap_insert(&((*tag_map)->next),name,tag_key);
55 }
56 }
57 }
58
59 index_t Dudley_TagMap_getTag(Dudley_TagMap* tag_map,const char* name)
60 {
61 char error_msg[LenErrorMsg_MAX];
62 if (tag_map == NULL) {
63 sprintf(error_msg,"Dudley_TagMap_getTag: unknown tag name %s.",name);
64 Dudley_setError(VALUE_ERROR,error_msg);
65 return -1;
66 } else {
67 if (strcmp(tag_map->name,name)==0) {
68 return tag_map->tag_key;
69 } else {
70 return Dudley_TagMap_getTag(tag_map->next,name);
71 }
72 }
73 }
74 bool_t Dudley_TagMap_isValidTagName(Dudley_TagMap* tag_map, const char* name)
75 {
76 if (tag_map == NULL) {
77 return FALSE;
78 } else {
79 if (strcmp(tag_map->name,name)==0) {
80 return TRUE;
81 } else {
82 return Dudley_TagMap_isValidTagName(tag_map->next,name);
83 }
84 }
85 }
86 /* deallocates the Dudley_TagMap in by recursive calls */
87
88 void Dudley_TagMap_free(Dudley_TagMap* in) {
89 if (in!=NULL) {
90 Dudley_TagMap_free(in->next);
91 MEMFREE(in->name);
92 MEMFREE(in);
93 }
94 return;
95 }
96

  ViewVC Help
Powered by ViewVC 1.1.26