Fix copyright date.
[become] / src / sym.h
CommitLineData
c4f2d992 1/* -*-c-*-
2 *
c758e654 3 * $Id: sym.h,v 1.3 1998/01/12 16:46:30 mdw Exp $
c4f2d992 4 *
5 * Symbol table management
6 *
c758e654 7 * (c) 1998 Straylight
c4f2d992 8 */
9
03f996bd 10/*----- Licensing notice --------------------------------------------------*
c4f2d992 11 *
12 * This file is part of `become'
13 *
14 * `Become' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * `Become' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
03f996bd 25 * along with `become'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
c4f2d992 27 */
28
29/*----- Revision history --------------------------------------------------*
30 *
31 * $Log: sym.h,v $
c758e654 32 * Revision 1.3 1998/01/12 16:46:30 mdw
33 * Fix copyright date.
34 *
03f996bd 35 * Revision 1.2 1997/08/04 10:24:25 mdw
36 * Sources placed under CVS control.
37 *
38 * Revision 1.1 1997/07/21 13:47:43 mdw
c4f2d992 39 * Initial revision
40 *
41 */
42
43#ifndef SYM_H
44#define SYM_H
45
46#ifdef __cplusplus
47 extern "C" {
48#endif
49
50/*----- Required headers --------------------------------------------------*/
51
52#include <stddef.h>
53
54/*----- Type definitions --------------------------------------------------*/
55
56/* --- Symbol table --- *
57 *
58 * A @sym_table@ contains the information needed to manage a symbol table.
59 * Users shouldn't fiddle with this information directly, but it needs to be
60 * here so that objects of the correct type can be created.
61 */
62
63typedef struct sym_table {
64 unsigned long mask; /* Bit mask for hashing purposes */
65 size_t c; /* Down counter for growing table */
66 struct sym_base **a; /* Array of hash bins */
67} sym_table;
68
69/* --- A symbol table entry --- *
70 *
71 * I don't care what actually gets stored in symbol entries because I don't
72 * create them: that's the responsibility of my client. All I care about
73 * here is that whatever gets passed to me is a structure whose first member
74 * is a @sym_base@. The ANSI guarantees about structure layout are
75 * sufficient to allow me to manipulate such objects.
76 */
77
78typedef struct sym_base {
79 struct sym_base *next; /* Next symbol in hash bin */
80 unsigned long hash; /* Hash value for symbol's name */
81 char *name; /* Name of this symbol */
82 size_t len; /* Length of the symbol's name */
83} sym_base;
84
85/* --- An iterator block --- */
86
87typedef struct sym_iter {
88 sym_table *t; /* Symbol table being iterated */
89 sym_base *n; /* Address of next item to return */
90 size_t i; /* Index of next hash bin to use */
91} sym_iter;
92
93/*----- External functions ------------------------------------------------*/
94
95/* --- @sym_createTable@ --- *
96 *
97 * Arguments: @sym_table *t@ = symbol table to initialise
98 *
99 * Returns: ---
100 *
101 * Use: Initialises the given symbol table.
102 */
103
104extern void sym_createTable(sym_table */*t*/);
105
106/* --- @sym_destroyTable@ --- *
107 *
108 * Arguments: @sym_table *t@ = pointer to symbol table in question
109 *
110 * Returns: ---
111 *
112 * Use: Destroys a symbol table, freeing all the memory it used to
113 * occupy.
114 */
115
116extern void sym_destroyTable(sym_table */*t*/);
117
118/* --- @sym_find@ --- *
119 *
120 * Arguments: @sym_table *t@ = pointer to symbol table in question
121 * @const char *n@ = pointer to symbol table to look up
122 * @long l@ = length of the name string or negative to measure
123 * @size_t sz@ = size of desired symbol object, or zero
124 * @unsigned *f@ = pointer to a flag, or null.
125 *
126 * Returns: The address of a @sym_base@ structure, or null if not found
127 * and @sz@ is zero.
128 *
129 * Use: Looks up a symbol in a given symbol table. The name is
130 * passed by the address of its first character. The length
131 * may be given, in which case the name may contain arbitrary
132 * binary data, or it may be given as a negative number, in
133 * which case the length of the name is calculated as
134 * @strlen(n)@.
135 *
136 * The return value is the address of a pointer to a @sym_base@
137 * block (which may have other things on the end, as above). If
138 * the symbol could be found, the return value points to the
139 * symbol block. If the symbol wasn't there, then if @sz@ is
140 * nonzero, a new symbol is created and its address is returned;
141 * otherwise a null pointer is returned.
142 *
143 * The value of @*f@ indicates whether a new symbol entry was
144 * created: a nonzero value indicates that an old value was
145 * found.
146 */
147
148extern void *sym_find(sym_table */*t*/, const char */*n*/, long /*l*/,
149 size_t /*sz*/, unsigned */*f*/);
150
151/* --- @sym_remove@ --- *
152 *
153 * Arguments: @sym_table *i@ = pointer to a symbol table object
154 * @void *b@ = pointer to symbol table entry
155 *
156 * Returns: ---
157 *
158 * Use: Removes the object from the symbol table. The space occupied
159 * by the object and its name is freed; anything else attached
160 * to the entry should already be gone by this point.
161 */
162
163extern void sym_remove(sym_table */*t*/, void */*b*/);
164
165/* --- @sym_createIter@ --- *
166 *
167 * Arguments: @sym_iter *i@ = pointer to an iterator object
168 * @sym_table *t@ = pointer to a symbol table object
169 *
170 * Returns: ---
171 *
172 * Use: Creates a new symbol table iterator which may be used to
173 * iterate through a symbol table.
174 */
175
176extern void sym_createIter(sym_iter */*i*/, sym_table */*t*/);
177
178/* --- @sym_next@ --- *
179 *
180 * Arguments: @sym_iter *i@ = pointer to iterator object
181 *
182 * Returns: Pointer to the next symbol found, or null when finished.
183 *
184 * Use: Returns the next symbol from the table. Symbols are not
185 * returned in any particular order.
186 */
187
188extern void *sym_next(sym_iter */*i*/);
189
190/*----- That's all, folks -------------------------------------------------*/
191
192#ifdef __cplusplus
193 }
194#endif
195
196#endif