Mercurial > hg > index.cgi
comparison lwbasic/symtab.c @ 29:bc96cd02fbf4
Added basic symbol table structure
author | lost@l-w.ca |
---|---|
date | Fri, 28 Jan 2011 22:35:04 -0700 |
parents | |
children | 49d608aecc4d |
comparison
equal
deleted
inserted
replaced
28:9ac1c97d01db | 29:bc96cd02fbf4 |
---|---|
1 /* | |
2 symtab.c | |
3 | |
4 Copyright © 2011 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 /* | |
23 Symbol table handling | |
24 */ | |
25 | |
26 #include <stdlib.h> | |
27 #include <string.h> | |
28 | |
29 #include <lw_alloc.h> | |
30 #include <lw_string.h> | |
31 | |
32 #define __symtab_c_seen__ | |
33 #include "symtab.h" | |
34 | |
35 symtab_t *symtab_init(void) | |
36 { | |
37 symtab_t *st; | |
38 | |
39 st = lw_alloc(sizeof(symtab_t)); | |
40 st -> head = NULL; | |
41 return st; | |
42 } | |
43 | |
44 void symtab_destroy(symtab_t *st) | |
45 { | |
46 symtab_entry_t *se; | |
47 | |
48 while (st -> head) | |
49 { | |
50 se = st -> head; | |
51 st -> head = se -> next; | |
52 lw_free(se -> name); | |
53 lw_free(se); | |
54 } | |
55 lw_free(st); | |
56 } | |
57 | |
58 symtab_entry_t *symtab_find(symtab_t *st, char *name) | |
59 { | |
60 symtab_entry_t *se; | |
61 | |
62 for (se = st -> head; se; se = se -> next) | |
63 { | |
64 if (strcmp(se -> name, name) == 0) | |
65 return se; | |
66 } | |
67 return NULL; | |
68 } | |
69 | |
70 void symtab_register(symtab_t *st, char *name, int addr, int symtype) | |
71 { | |
72 symtab_entry_t *se; | |
73 | |
74 se = lw_alloc(sizeof(symtab_entry_t)); | |
75 se -> name = lw_strdup(name); | |
76 se -> addr = addr; | |
77 se -> symtype = symtype; | |
78 se -> next = st -> head; | |
79 st -> head = se; | |
80 } |