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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1044 - (hide annotations)
Mon Mar 19 07:29:31 2007 UTC (12 years, 10 months ago) by gross
File MIME type: text/plain
File size: 2904 byte(s)
clear name tagging is supported now.
1 gross 1044 /*
2     ************************************************************
3     * Copyright 2006 by ACcESS MNRF *
4     * *
5     * http://www.access.edu.au *
6     * Primary Business: Queensland, Australia *
7     * Licensed under the Open Software License version 3.0 *
8     * http://www.opensource.org/licenses/osl-3.0.php *
9     * *
10     ************************************************************
11     */
12    
13     /**************************************************************/
14    
15     /* Finley: simple mapping fram names to tag keys via a linked list */
16    
17     /**************************************************************/
18    
19     /* Author: gross@access.edu.au */
20     /* Version: $Id:$ */
21    
22     /**************************************************************/
23    
24     #include "TagMap.h"
25    
26     /**************************************************************/
27    
28     void Finley_TagMap_insert(Finley_TagMap** tag_map,
29     const char* name,
30     index_t tag_key)
31     {
32     Finley_TagMap* map=NULL;
33     if (strlen(name)<1) {
34     Finley_setError(VALUE_ERROR,"empty tag name.");
35     return;
36     }
37     if (strchr(name,32) != NULL) { /* check for space */
38     Finley_setError(VALUE_ERROR,"tag name may not contain a space.");
39     return;
40     }
41     if (*tag_map == NULL) {
42     map=MEMALLOC(1,Finley_TagMap);
43     if (Finley_checkPtr(map)) return;
44     map->name=MEMALLOC(strlen(name)+1,char);
45     if (Finley_checkPtr(map->name) ) {
46     MEMFREE(map);
47     } else {
48     strcpy(map->name,name);
49     map->tag_key=tag_key;
50     map->next=NULL;
51     *tag_map=map;
52     }
53     } else {
54     if (strcmp((*tag_map)->name,name)==0) {
55     (*tag_map)->tag_key=tag_key;
56     } else {
57     Finley_TagMap_insert(&((*tag_map)->next),name,tag_key);
58     }
59     }
60     }
61    
62     index_t Finley_TagMap_getTag(Finley_TagMap* tag_map,const char* name)
63     {
64     char error_msg[LenErrorMsg_MAX];
65     if (tag_map == NULL) {
66     sprintf(error_msg,"Finley_TagMap_getTag: unknown tag name %s.",name);
67     Finley_setError(VALUE_ERROR,error_msg);
68     return -1;
69     } else {
70     if (strcmp(tag_map->name,name)==0) {
71     return tag_map->tag_key;
72     } else {
73     return Finley_TagMap_getTag(tag_map->next,name);
74     }
75     }
76     }
77     bool_t Finley_TagMap_isValidTagName(Finley_TagMap* tag_map, const char* name)
78     {
79     if (tag_map == NULL) {
80     return FALSE;
81     } else {
82     if (strcmp(tag_map->name,name)==0) {
83     return TRUE;
84     } else {
85     return Finley_TagMap_isValidTagName(tag_map->next,name);
86     }
87     }
88     }
89     /* deallocates the Finley_TagMap in by recursive calls */
90    
91     void Finley_TagMap_free(Finley_TagMap* in) {
92     if (in!=NULL) {
93     Finley_TagMap_free(in->next);
94     MEMFREE(in->name);
95     MEMFREE(in);
96     }
97     }
98    

  ViewVC Help
Powered by ViewVC 1.1.26