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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (11 years, 11 months ago) by ksteube
File MIME type: text/plain
File size: 2655 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

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

  ViewVC Help
Powered by ViewVC 1.1.26