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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3086 - (hide annotations)
Thu Aug 5 05:07:58 2010 UTC (9 years, 6 months ago) by jfenwick
Original Path: branches/domexper/dudley/src/TagMap.c
File MIME type: text/plain
File size: 2630 byte(s)
Another pass at removing finley

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

  ViewVC Help
Powered by ViewVC 1.1.26