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