variable.c
1016 Bytes
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
52
53
54
55
56
#include <stdio.h>
#include <malloc.h>
#include <ident.h>
#include <expValue.h>
#include <variable.h>
#include <identList.h>
s_ident *
getVariable (s_identList * iList, char * id)
{
return identListSeekKey (iList, id);
}
s_ident *
getArray (s_ident * var, s_expVal * eVal)
{
s_ident * ret = NULL;
/* generate new idl if ident isn't, discard prev val */
if (identGetType (var) != ID_TYP_IDL)
identSetIdl (var, identListNew ());
/* now seek or generate the actual ident */
switch (expValueGetType (eVal))
{
case EXP_TYP_INT:
{
int idx = expValueInt (eVal);
ret = identListSeekIdx (identIdl (var), idx);
if (ret == NULL)
ret = identListPutVal (
identIdl (var), identUndefNew (idx, NULL));
break;
}
case EXP_TYP_STRING:
{
char * key = expValueString (eVal);
ret = identListSeekKey (identIdl (var), key);
if (ret == NULL)
ret = identListPutVal (
identIdl (var), identUndefNew (-1, key));
free (key);
}
}
return ret;
}