]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/clients/xzwrite/associate.c
Initial revision
[1ts-debian.git] / zephyr / clients / xzwrite / associate.c
1 /*
2  * This is a string-associative array abstraction with really lousy
3  * semantics.  But it does what I need at the moment.
4  */
5
6 #include "associate.h"
7
8 AArray AACreate()
9 {
10      return (DynCreate(sizeof(AElementRec), 0));
11 }
12
13 void AADestroy(array)
14    AArray array;
15 {
16      DynDestroy(array);
17 }
18
19 int AAInsert(array, index, value)
20    AArray array;
21    char *index, *value;
22 {
23      AElementRec temp;
24      int ret;
25
26      temp.index = index;
27      temp.value = value;
28
29      ret = DynAdd(array, &temp);
30      if (ret != DYN_OK)
31           return AA_FAILED;
32      else
33           return AA_OK;
34 }
35
36 char *AALookup(array, index)
37    AArray array;
38    char *index;
39 {
40      AElementRec *a;
41      int i;
42
43      a = (AElementRec *) DynGet((char *) array, 0);
44      for (i=0; i < DynSize(array); i++)
45           if (strcmp(a[i].index, index) == 0)
46                return (a[i].value);
47
48      return NULL;
49 }
50
51