2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * File: Symbolic.h $XConsortium: Symbolic.h /main/3 1995/10/26 15:45:51 rswiston $
27 * (c) Copyright 1988, Hewlett-Packard Company, all rights reserved.
29 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
30 * (c) Copyright 1993, 1994 International Business Machines Corp. *
31 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
32 * (c) Copyright 1993, 1994 Novell, Inc. *
40 /* -------------------------------------------- */
42 #ifdef __recursive_includes
45 /* -------------------------------------------- */
47 /****************************************************************************/
48 /* Symbol (hash) Tables */
52 There are two types of symbol (hash) tables. The common case is where the
53 key (index) is ascii string. The Xe_intern() and XeRegisterSymbol()
54 routines assume this type of table. In these cases an "XeSymbol" entry is
55 created in the symbol table (see type below). After it is created a COPY of
56 the string is made and stored in the "name" field. The "value" field is
57 free for the user to fill in on his own.
61 typedef struct _XeSymbol {
67 This type is used for the XeRegisterFunction() routine.
70 typedef void (*XeAnyFunction) ();
74 The second type of table is where the user defines his own type of
75 data, hash functions, compare functions, etc.
78 /* The following types for the the user configurable functions that */
79 /* are set with the Xe_set_syms_fns() routine. */
80 /* ---------------------------------------------------------------- */
85 /* Any user defined function should return "0" for a "match" */
87 /* Used for Xe_intern() and XeRegisterSymbol() */
89 /* If NO "cmp_fn", strcmp("next_table_entry"->name, "name") */
90 /* If "cmp_fn", cmp_fn("next_table_entry"->name, "name") */
92 /* Used for Xe_intern_anysym() */
94 /* If NO "cmp_fn", strcmp("next_table_entry"->name, "data"->name) */
95 /* If "cmp_fn", cmp_fn("next_table_entry", "data") */
96 /* -------------------------------------------------------------------- */
98 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
99 typedef int (*XeSymFn_cmp) (void *, void *); /* 0 mean match */
101 typedef int (*XeSymFn_cmp) ();
107 /* Note, the internal hash function in not user accesable. */
109 /* Used for Xe_intern() and XeRegisterSymbol() */
111 /* If NO "hash_fn", internal_hash("next_table_entry"->name, "name") */
112 /* If "hash_fn", hash_fn("next_table_entry"->name, "name") */
114 /* Used for Xe_intern_anysym() */
116 /* If NO "hash_fn", internal_hash("next_table_entry"->name, "data"->name)*/
117 /* If "hash_fn", hash_fn("next_table_entry" , "data") */
118 /* ----------------------------------------------------------------------- */
120 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
121 typedef unsigned int (*XeSymFn_hash) (void *, unsigned int);
123 typedef unsigned int (*XeSymFn_hash) ();
128 /* Used for Xe_intern() and XeRegisterSymbol() */
130 /* 1) A XeSymbol entry is created, */
131 /* - XeSymbol->name = strdup("name"), */
132 /* - XeSymbol->value = NULL */
133 /* 2) If a "init_fn" is configured, */
134 /* - XeSymbol->value = init_fn( XeSymbol, 0 ) */
136 /* Used for Xe_intern_anysym() */
138 /* 1) If "size" != 0, */
139 /* - malloc "size" bytes, */
140 /* - copy "size" bytes from "data" into malloced space, */
141 /* - Save pointer to malloc space as user's data pointer */
143 /* - Save "data" as pointer to user's data */
144 /* 3) If a "init_fn" is configured, */
145 /* - call init_fn( user's data pointer, "size" ) */
146 /* - set user's data pointer to return value of init_fn */
147 /* ONLY if "size" was zero. */
149 /* If size is non zero AND there is a user's malloc function, */
150 /* beware that the return value from the malloc function is not */
151 /* save anywhere by these routines. If size was zero, the */
152 /* return value of the user's function is kept. */
154 /* -------------------------------------------------------------------- */
156 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
157 typedef void * (*XeSymFn_init)(void *, unsigned int);
159 typedef void * (*XeSymFn_init)();
164 /* If created by Xe_intern() or XeRegisterSymbol() */
166 /* 1) free(XeSymbol->name) */
167 /* 2) If a "clean_fn" is configured, */
168 /* - clean_fn(XeSymbol->value), */
169 /* - the XeSymbol entry is deleted. */
171 /* If created by Xe_intern_anysym() */
173 /* 1) If a "clean_fn" is configured, */
174 /* - init_fn( user's data pointer, "size" ) */
175 /* 2) If "size" != 0 during at creation time, */
176 /* - free( user's data pointer ) */
178 /* Take note of the what happens during creation with "size" is */
179 /* non-zero and there is a user's malloc function. The result of */
180 /* the user's malloc function will be passed to this clean function */
181 /* only if "size" was zero at creation time. Otherwise, the memory */
182 /* malloc'ed by this routine due to the non-zero size parameter is */
183 /* what is passed to the user's clean function. */
184 /* -------------------------------------------------------------------- */
186 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
187 typedef void (*XeSymFn_clean) (void *);
189 typedef void (*XeSymFn_clean) ();
192 /* This is what an internal symbol table entry looks like: */
193 /* ------------------------------------------------------- */
194 typedef struct _XeSymtabList {
195 struct _XeSymtabList *rest;
197 Boolean data_is_XeSymbol;
198 Boolean data_is_malloc_mem;
202 /* This is the master record for a symbol table */
203 /* -------------------------------------------- */
205 typedef struct _XeSymTable
207 unsigned int hashsize; /* # of hash buckets. */
208 XeSymtabList *list; /* Hash buckets. */
210 XeSymtabList curr_list; /* Used to dump/traver the table. */
211 unsigned int curr_hash;
213 XeSymFn_cmp cmp_fn; /* Read above description with each */
214 XeSymFn_hash hash_fn; /* function typedef for more info. */
215 XeSymFn_init init_fn;
216 XeSymFn_clean clean_fn;
220 /* Create a new hashtable. "hashsize must be power of 2 if using default */
221 /* hash function (no checking is done to ensure this). */
222 /* --------------------------------------------------------------------- */
223 XeSymTable Xe_new_symtab
224 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
225 (unsigned int hashsize);
231 /* Create the default symbol table. If already created, just */
232 /* return the symtable pointer. */
233 /* ---------------------------------------------------------- */
234 XeSymTable Xe_default_symtab
235 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
242 /* Configure user defined function for use with symtab routines. */
243 /* NOTE: Be sure you understand the interaction of these functions */
244 /* Read the decriptions with each of the typdef's above. A */
245 /* null function pointer will overwrite any previously */
246 /* installed value. */
247 /* --------------------------------------------------------------- */
248 XeSymTable Xe_set_sym_fns
249 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
252 XeSymFn_init init_fn,
253 XeSymFn_clean clean_fn,
254 XeSymFn_hash hash_fn);
260 /* Find or create a symbol for "name". Its "value" is set to NULL. */
261 /* None of the user defined init/cmp, etc functions are honored by */
263 /* WARNING: Read the notes for the function typedef's above. */
264 /* ----------------------------------------------------------------- */
266 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
267 (XeSymTable t, ConstXeString const name);
273 /* Find the symbol for "name". NULL is returned if not found. */
274 /* None of the user defined init/cmp, etc functions are honored by */
276 /* WARNING: Read the notes for the function typedef's above. */
277 /* ----------------------------------------------------------------- */
279 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
280 (XeSymTable t, ConstXeString const name);
286 /****************************************************************************/
289 typedef struct _XeList {
290 struct _XeList *rest;
294 /* make a list from data and rest */
295 /* ------------------------------ */
297 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
298 (void *data, XeList rest);
304 /****************************************************************************/
307 typedef struct _XeQueue {
313 /* for static or auto struct queues */
314 /* -------------------------------- */
315 XeQueue Xe_init_queue
316 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
317 (XeQueue q, void * nullval);
322 XeQueue Xe_make_queue
323 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
329 void Xe_release_queue
330 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
336 /* nullval returned if queue empty */
337 /* ------------------------------- */
339 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
345 /* nullval returned if not found */
346 /* ------------------------------- */
347 void * Xe_delete_queue_element
348 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
349 (XeQueue q, void * val);
355 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
356 (XeQueue q, void * val);
361 /* user declares his own "type var" */
362 /* -------------------------------- */
363 #define Xe_for_queue(type,var,q) \
364 XeList q_next, q_list; \
365 for(q_list = q->head; \
366 q_list && (var = (type) q_list->data, q_next = q_list->rest , 1);\
370 /* PUT NOTHING AFTER THIS endif */
371 #endif /* _Symbolic_h_ */