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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (10 years ago) by jfenwick
Original Path: trunk/finley/src/TagMap.c
File MIME type: text/plain
File size: 2630 byte(s)
Don't panic.
Updating copyright stamps

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 ksteube 1312 /* Finley: simple mapping fram names to tag keys via a linked list */
18 gross 1044
19     /**************************************************************/
20    
21     #include "TagMap.h"
22    
23     /**************************************************************/
24    
25     void Finley_TagMap_insert(Finley_TagMap** tag_map,
26     const char* name,
27     index_t tag_key)
28     {
29     Finley_TagMap* map=NULL;
30     if (strlen(name)<1) {
31     Finley_setError(VALUE_ERROR,"empty tag name.");
32     return;
33     }
34     if (strchr(name,32) != NULL) { /* check for space */
35     Finley_setError(VALUE_ERROR,"tag name may not contain a space.");
36     return;
37     }
38     if (*tag_map == NULL) {
39     map=MEMALLOC(1,Finley_TagMap);
40     if (Finley_checkPtr(map)) return;
41     map->name=MEMALLOC(strlen(name)+1,char);
42     if (Finley_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     Finley_TagMap_insert(&((*tag_map)->next),name,tag_key);
55     }
56     }
57     }
58    
59     index_t Finley_TagMap_getTag(Finley_TagMap* tag_map,const char* name)
60     {
61     char error_msg[LenErrorMsg_MAX];
62     if (tag_map == NULL) {
63     sprintf(error_msg,"Finley_TagMap_getTag: unknown tag name %s.",name);
64     Finley_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 Finley_TagMap_getTag(tag_map->next,name);
71     }
72     }
73     }
74     bool_t Finley_TagMap_isValidTagName(Finley_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 Finley_TagMap_isValidTagName(tag_map->next,name);
83     }
84     }
85     }
86     /* deallocates the Finley_TagMap in by recursive calls */
87    
88     void Finley_TagMap_free(Finley_TagMap* in) {
89     if (in!=NULL) {
90     Finley_TagMap_free(in->next);
91     MEMFREE(in->name);
92     MEMFREE(in);
93     }
94 gross 1804 return;
95 gross 1044 }
96    

  ViewVC Help
Powered by ViewVC 1.1.26