1/* *****************************************************************************
2
3libcsc:  Symbol Table Subsystem
4
5	----------------------------------------------------------------
6
7Copyright (c) 1999, 2000, 2002 Douglas R. Jerome, Peoria, AZ USA
8
9	This program is free software; you can redistribute it and/or modify
10	it under the terms of the GNU Library General Public License as
11	published by the Free Software Foundation; either version 2 of the
12	License, or (at your option) any later version.
13
14	This program is distributed in the hope that it will be useful,
15	but WITHOUT ANY WARRANTY; without even the implied warranty of
16	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17	GNU General Public License for more details.
18
19	You should have received a copy of the GNU Library General Public
20	License along with this program; if not, write to the Free Software
21	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23	----------------------------------------------------------------
24
25FILE NAME
26
27	$RCSfile: csc_symtab.c,v $
28	$Revision: 1.3 $
29	$Date: 2003/03/24 04:27:02 $
30
31
32PROGRAM INFORMATION
33
34	Developed by:	libcsc project
35	Developer:	Douglas R. Jerome, drj, <jerome@primenet.com>
36
37
38FILE DESCRIPTION
39
40<SUBSYSTEM NAME="csc_symtab">
41
42NAME
43        csc_symtab
44
45DESCRIPTION
46        Symbol Table Subsystem
47
48FUNCTIONS
49        CSCsymtabNew       - create a new libcsc hash table
50        CSCsymtabDel       - remove a libcsc symbol table
51        CSCsymtabStat      - retrieve statistics for a libcsc symbol table
52        CSCsymtabEntryPut  - add a symbol to a libcsc symbol table
53        CSCsymtabEntryGet  - get a symbol in a libcsc symbol table
54        CSCsymtabEntryDel  - remove a symbol from a libcsc symbol table
55        CSCsymtabEntryNext - find next entry in a libcsc symbol table
56</SUBSYSTEM>
57
58CHANGE LOG
59
60	23mar03	drj	Added a CSCmemListType argument to CSCsymtabEntryGet().
61
62	29apr02	drj	Added internal documentation.
63
64	18apr02	drj	Converted to libcsc: renamed everything from rt to csc,
65			removed some debug message printing code.
66
67	11may00	drj	Tracked changes to rtsMemDup().
68
69	23apr00	drj	Simplified the data types and function prototypes.
70			Fixed bugs with symbol usage.  Removed the useless
71			function rtsSymTabClr().
72
73	05dec99	drj	Added symbol duplication in rtsSymTabEntryPut().
74			Added more housekeeping for dynamically allocated
75			symbol fields to avoid memory leaks.
76
77	04dec99	drj	Fixed rtsSymTabEntryPut() bug that sent string, not
78			string's address, to rtsHashEntryPut(); removed debug
79			errors when adding duplicate symbol.
80			Removed rtsSymTabEntryNext() debug errors when at the
81			end of symbol table.
82			Fixed rtsSymTabEntryGet() bug that sent string, not
83			string's address, to rtsHashEntryGet(); removed debug
84			errors when getting non-existing symbol.
85
86	29apr99	drj	Rebaselined from librt version 0.3.1.
87
88***************************************************************************** */
89
90
91/* ************************************************************************* */
92/*                                                                           */
93/*      F e a t u r e   S w i t c h e s                                      */
94/*                                                                           */
95/* ************************************************************************* */
96
97/*
98 * Select these feature by moving them from the `if UNDEF' into the `else'
99 * section.
100 */
101#ifdef	UNDEF
102#   define	_BSD_SOURCE	1	/* 4.3+bsd subsystems           */
103#   define	_POSIX_SOURCE	1	/* posix.1                      */
104#   define	_POSIX_C_SOURCE	199309L	/* posix.1 and posix.4          */
105#else
106#   define	_POSIX_C_SOURCE	199506L	/* posix.1 and posix.4 and MORE */
107#   ifndef	_REENTRANT
108#      define	_REENTRANT		/* thread-safe for glibc        */
109#   endif
110#endif
111
112
113/* ************************************************************************* */
114/*                                                                           */
115/*      I n c l u d e d   F i l e s                                          */
116/*                                                                           */
117/* ************************************************************************* */
118
119/*
120 * OS Specific Header Files
121 */
122/*  (None.)  */
123
124/*
125 * Standard C (ANSI) Header Files
126 */
127
128/*
129 * Posix Header Files
130 */
131#include	<unistd.h>
132
133/*
134 * Project Specific Header Files
135 */
136#include	"libcsc_debug.h"
137#include	"libcsc.h"
138
139
140/* ************************************************************************* */
141/*                                                                           */
142/*      M a n i f e s t   C o n s t a n t s                                  */
143/*                                                                           */
144/* ************************************************************************* */
145
146#define	SYMTAB_SIG	(0x53594D54)
147#define	SYMTAB_SIZE	(1009)
148
149#define	MON_ENTER(x)	{if(x->monFunc!=NULL)\
150			(*x->monFunc)(CSC_IN,(void*)x->monData);}
151
152#define	MON_EXIT(x)	{if(x->monFunc!=NULL)\
153			(*x->monFunc)(CSC_OUT,(void*)x->monData);}
154
155
156/* ************************************************************************* */
157/*                                                                           */
158/*      E x t e r n a l   R e f e r e n c e s                                */
159/*                                                                           */
160/* ************************************************************************* */
161
162/*  (None.)  */
163
164
165/* ************************************************************************* */
166/*                                                                           */
167/*      S c a l a r   D a t a   T y p e s                                    */
168/*                                                                           */
169/* ************************************************************************* */
170
171/*  (None.)  */
172
173
174/* ************************************************************************* */
175/*                                                                           */
176/*      N o n - S c a l a r   D a t a   S t r u c t u r e s                  */
177/*                                                                           */
178/* ************************************************************************* */
179
180typedef struct S_symTableType
181   {
182#ifdef	DEBUG
183   long             sig_lo;
184#endif
185   const char*      name;
186   void*            table;
187   int              keyWordSpec;
188   CSCmemListType   memLst;
189   CSCmonFnType     monFunc;
190   const void*      monData;
191   CSCprofileType   profiling;
192   size_t           count;
193#ifdef	DEBUG
194   long             sig_hi;
195#endif
196   } S_symTableType;
197
198
199/* ************************************************************************* */
200/*                                                                           */
201/*      P u b l i c   G l o b a l   V a r i a b l e s                        */
202/*                                                                           */
203/* ************************************************************************* */
204
205/*  (None.)  */
206
207
208/* ************************************************************************* */
209/*                                                                           */
210/*      P r i v a t e   G l o b a l   V a r i a b l e s                      */
211/*                                                                           */
212/* ************************************************************************* */
213
214/*  (None.)  */
215
216
217/* ************************************************************************* */
218/*                                                                           */
219/*      E x e c u t a b l e   C o d e   (Locally Used Functions)             */
220/*                                                                           */
221/* ************************************************************************* */
222
223
224/**************************************************************************
225 * Private Function Prototypes
226 **************************************************************************/
227
228/*  (None.)  */
229
230
231/* ---------------------------------------------------------------------- */
232
233
234/**************************************************************************
235 * Private Function
236 **************************************************************************/
237
238/*  (None.)  */
239
240
241/* ************************************************************************* */
242/*                                                                           */
243/*      E x e c u t a b l e   C o d e   (External Interface Functions)       */
244/*                                                                           */
245/* ************************************************************************* */
246
247
248/**************************************************************************
249 * Public Function CSCsymtabNew
250 **************************************************************************
251
252<SUBROUTINE NAME="CSCsymtabNew">
253
254NAME
255        CSCsymtabNew - create a new libcsc hash table
256
257SYNOPSYS
258        #include "libcsc.h"
259
260        CSCsymTableType   CSCsymtabNew (
261                                       const char*          const name,
262                                             size_t               size,
263                                       const char**               keyWords,
264                                             int                  keyWordSpec,
265                                             CSCmonFnType         monFunc,
266                                       const void*                monData,
267                                             CSCprofileType       profiling
268                                       );
269
270RETURN VALUE
271        CSCsymtabNew(), if successful, returns an opaque data type
272        representing a new libcsc symbol table, or NULL if otherwise not
273        successful.
274
275DESCRIPTION
276        CSCsymtabNew() creates a new libcsc symbol table of `size' entries, and
277        initialized with a set of keywords.
278
279        `name' points to an arbitrary string that is used as the name of the
280        new libcsc symbol table.
281
282        If `size' is zero, then a default size is used.  Since the symbol table
283        is implemented as a hash table, the number of entries can be larger
284        than size.
285
286        If `keyWords' is NULL, then no keywords are loaded.  Otherwise, keyWords
287        is an array of character pointers; a symbol is created and put into the
288        new table for each keyword.  A list of keywords is terminated by a
289        keyword of zero length, not a NULL keyword pointer.
290
291        `keyWordType' is the value used for the keyword symbols' type field.
292
293SEE ALSO
294        CSCsymtabDel(3)
295        CSCsymtabStat(3)
296        CSCsymtabEntryPut(3)
297        CSCsymtabEntryGet(3)
298        CSCsymtabEntryDel(3)
299        CSCsymtabEntryNext(3)
300</SUBROUTINE>
301
302 **************************************************************************/
303
304PUBLIC CSCsymTableType   (CSCsymtabNew) (
305                                        const char*          const name,
306                                              size_t               size,
307                                        const char**               keyWords,
308                                              int                  keyWordSpec,
309                                              CSCmonFnType         monFunc,
310                                        const void*                monData,
311                                              CSCprofileType       profiling
312                                        )
313   {
314   CSCsymTableType   symTab        = NULL;
315   CSCmemListType    memList       = NULL;
316   size_t            hashTableSize = 0;
317
318   ASSERT_RTN (name != NULL, "CSCsymtabNew: no hash name", NULL);
319   ASSERT_RTN (								\
320              ((profiling==CSC_DO_PROFILING)||(profiling==CSC_NO_PROFILING)),\
321              "CSCsymtabNew: illegal profile value",			\
322              NULL							\
323              );
324
325   memList = CSCmemInit (name, NULL, monFunc, monData, CSC_NO_PROFILING);
326   if (memList != NULL)
327      {
328      (void)CSCmemAlloc (memList,(void**)&symTab,1,sizeof(S_symTableType),0);
329      if (symTab != NULL)
330         {
331         symTab->name       = name;
332         symTab->memLst     = memList;
333         symTab->profiling  = profiling;
334         symTab->monFunc    = monFunc;
335         symTab->monData    = monData;
336         symTab->keyWordSpec  = 0;
337         symTab->table        = NULL;
338         symTab->count        = 0;
339#ifdef	DEBUG
340         symTab->sig_lo = SYMTAB_SIG;
341         symTab->sig_hi = SYMTAB_SIG;
342#endif
343
344         hashTableSize = size > 0 ? size : SYMTAB_SIZE;
345
346         symTab->table = CSChashNew (
347                                    name,
348                                    CSC_HASH_ASCIIZ_KEY,
349                                    hashTableSize,
350                                    monFunc,
351                                    monData,
352                                    profiling
353                                    );
354         if (symTab->table != NULL)
355            {
356            symTab->keyWordSpec = keyWordSpec;
357            if (keyWords != NULL)
358               {
359               int               keyWordStat = CSC_OK;
360               CSCsymbolType*    keyWordSym  = NULL;
361               CSChashKeyUnion   hashKey;
362               while ((**keyWords != '\0') && (keyWordStat == CSC_OK))
363                  {
364                  keyWordSym = CSCsymbolIntNew (
365                                               *keyWords,   /* symbol name  */
366                                               keyWordSpec, /* symbol type  */
367                                               0,           /* symbol value */
368                                               memList,     /* memList      */
369                                               0            /* memTag       */
370                                               );
371                  hashKey.asciiz = (char*)*keyWords;
372                  keyWordStat = CSChashEntryPut (
373                                                symTab->table,
374                                                &hashKey,
375                                                &keyWordSym,
376                                                sizeof(CSCsymbolType*)
377                                                );
378                  ++keyWords;
379                  }
380               /* FIXME if keyWordStat != CSC_OK is not handled. */
381               }
382            }
383         else
384            {
385            (void)CSCmemFree (memList, (void**)&symTab, 0);
386            (void)CSCmemDone (memList);
387            symTab = NULL;
388            }
389         }
390      else
391         {
392         (void)CSCmemDone (memList);
393         }
394      }
395
396   return (symTab);
397   }
398
399
400/**************************************************************************
401 * Public Function CSCsymtabDel
402 **************************************************************************
403
404<SUBROUTINE NAME="CSCsymtabDel">
405
406NAME
407        CSCsymtabDel - remove a libcsc symbol table
408
409SYNOPSYS
410        #include "libcsc.h"
411
412        int   CSCsymtabDel (
413                           CSCsymTableType   const symTab
414                           );
415
416RETURN VALUE
417        CSCsymtabDel(), if successful, returns CSC_OK; otherwise,
418        CSC_NOTFOUND, CSC_BADARG, and CSC_CORRUPT can be returned corresponding
419        to NULL pointers, bad function arguments, and internal data errors,
420        respectively.
421
422DESCRIPTION
423        The libcsc symbol table represented by the opaque `symTab' is completely
424        removed.
425
426BUGS
427        Symbols not created by CSCsymbolFloatNew(), CSCsymbolIntNew(), and
428        CSCsymbolPtrNew() may cause problems.  (The name and value.pointer data
429        of the symbol should be dynamically allocated, and the valueFlag field
430        needs to be set the way CSCsymbolFloatNew(), CSCsymbolIntNew(), and
431        CSCsymbolPtrNew() set it.)
432
433SEE ALSO
434        CSCsymtabNew(3)
435        CSCsymtabStat(3)
436        CSCsymtabEntryPut(3)
437        CSCsymtabEntryGet(3)
438        CSCsymtabEntryDel(3)
439        CSCsymtabEntryNext(3)
440</SUBROUTINE>
441
442 **************************************************************************/
443
444PUBLIC int   (CSCsymtabDel) (
445                            CSCsymTableType   const symTab
446                            )
447   {
448   int                delStat = CSC_OK;
449   CSChashEntryType   entry   = NULL;
450   CSCsymbolType*     symPtr  = NULL;
451
452   ASSERT_RTN (symTab != NULL, "CSCsymtabDel: null symTab", CSC_BADARG);
453   ASSERT_RTN (					\
454              symTab->sig_lo == SYMTAB_SIG,	\
455              "CSCsymtabDel: symTab blows",	\
456              CSC_CORRUPT			\
457              );
458   ASSERT_RTN (					\
459              symTab->sig_hi == SYMTAB_SIG,	\
460              "CSCsymtabDel: symTab blows",	\
461              CSC_CORRUPT			\
462              );
463
464   MON_ENTER(symTab);
465
466/*
467 * Things with pointers, like symbols, probably really shouldn't be put into a
468 * hash table because the hash table duplicates the data it stores and can't
469 * know that it is duplicating pointers.  Since this symbol table subsystem uses
470 * the hash table there is the problem of dangling pointers when the hash table
471 * subsystem deletes a hash table (because it can't know about the pointers it
472 * duplicated when entries were put into it).  So, here we have to remove the
473 * dynamically allocated things that would be left dangling when the hash table
474 * is deleted.
475 */
476   entry = NULL;
477   while ((entry=CSCsymtabEntryNext(symTab,entry)) != NULL)
478      {
479      if (CSChashEntryStat(entry,NULL,(void**)&symPtr,NULL) == CSC_OK)
480         {
481         (void)CSCsymbolDel (&symPtr, symTab->memLst, 0);
482         }
483      }
484
485/*
486 * Now, it should be safe to delete the hash.
487 */
488   delStat = CSChashDel ((CSChashTableType)symTab->table);
489
490   if (delStat == CSC_OK)
491      {
492      CSCmemListType   memList = symTab->memLst;
493      CSCmonFnType     monFunc = symTab->monFunc;
494      const void*      monData = symTab->monData;
495      symTab->name       = NULL;
496      symTab->memLst     = NULL;
497      symTab->profiling  = -1;
498      symTab->monFunc    = NULL;
499      symTab->monData    = NULL;
500      symTab->keyWordSpec  = 0;
501      symTab->table        = NULL;
502      symTab->count        = 0;
503#ifdef	DEBUG
504      symTab->sig_lo = -1;
505      symTab->sig_hi = -1;
506#endif
507      (void)CSCmemFree (memList, (void**)&symTab, 0);
508      (void)CSCmemDone (memList);
509      if (monFunc != NULL) (*monFunc) (CSC_OUT, (void*)monData);
510      }
511   else
512      {
513      MON_EXIT(symTab);
514      }
515
516   return (delStat);
517   }
518
519
520/**************************************************************************
521 * Public Function CSCsymtabStat
522 **************************************************************************
523
524<SUBROUTINE NAME="CSCsymtabStat">
525
526NAME
527        CSCsymtabStat - retrieve statistics for a libcsc symbol table
528
529SYNOPSYS
530        #include "libcsc.h"
531
532        int   CSCsymtabStat (
533                            CSCsymTableType   const symTab,
534                            size_t*           const sizePtr
535                            );
536
537RETURN VALUE
538        CSCsymtabStat(), if successful, returns RTS_OK; otherwise,
539        RTS_NOTFOUND, RTS_BADARG, and RTS_ERROR can be returned corresponding
540        to NULL pointers, bad function arguments, and internal data errors,
541        respectively.
542
543DESCRIPTION
544        CSCsymtabStat() queries the libcsc symbol table specified by the
545        opaque `symTab'.
546
547        If `sizePtr' is not NULL, then the count of symbols in `symTab' is
548        written to the size_t that is pointed to by `sizePtr'.
549
550SEE ALSO
551        CSCsymtabNew(3)
552        CSCsymtabDel(3)
553        CSCsymtabEntryPut(3)
554        CSCsymtabEntryGet(3)
555        CSCsymtabEntryDel(3)
556        CSCsymtabEntryNext(3)
557</SUBROUTINE>
558
559 **************************************************************************/
560
561PUBLIC int   (CSCsymtabStat) (
562                             CSCsymTableType   const symTab,
563                             size_t*           const sizePtr
564                             )
565   {
566   int   statStat = CSC_OK;
567
568   ASSERT_RTN (symTab != NULL, "CSCsymtabStat: null symTab", CSC_BADARG);
569   ASSERT_RTN (					\
570              symTab->sig_lo == SYMTAB_SIG,	\
571              "CSCsymtabStat: symTab blows",	\
572              CSC_CORRUPT			\
573              );
574   ASSERT_RTN (					\
575              symTab->sig_hi == SYMTAB_SIG,
576              "CSCsymtabStat: symTab blows",	\
577              CSC_CORRUPT			\
578              );
579
580   MON_ENTER(symTab);
581
582   if (sizePtr != NULL) *sizePtr = symTab->count;
583
584   MON_EXIT(symTab);
585
586   return (statStat);
587   }
588
589
590/**************************************************************************
591 * Public Function CSCsymtabEntryPut
592 **************************************************************************
593
594<SUBROUTINE NAME="CSCsymtabEntryPut">
595
596NAME
597        CSCsymtabEntryPut - add a symbol to a libcsc symbol table
598
599SYNOPSYS
600        #include "libcsc.h"
601
602        int   CSCsymtabEntryPut (
603                                CSCsymTableType   const symTab,
604                                CSCsymbolType*    const symbol
605                                );
606
607RETURN VALUE
608        CSCsymtabEntryPut(), if successful, returns CSC_OK; otherwise,
609        CSC_NOTFOUND, CSC_BADARG, and CSC_CORRUPT can be returned corresponding
610        to NULL pointers, bad function arguments, and internal data errors,
611        respectively.
612
613DESCRIPTION
614        CSCsymtabEntryPut() puts `symbol' into the symbol table specified by
615        `symTab'.
616
617        NOTE    Its best to put only symbols created by CSCsymbolFloatNew(),
618                CSCsymbolIntNew(), and CSCsymbolPtrNew() because the symbol
619                table delete functions expect the symbols to be created the
620                way these function do, with the name and value.pointer data
621                being dynamically allocated, and the valueFlag field being
622                correctly set.
623
624SEE ALSO
625        CSCsymtabNew(3)
626        CSCsymtabDel(3)
627        CSCsymtabStat(3)
628        CSCsymtabEntryGet(3)
629        CSCsymtabEntryDel(3)
630        CSCsymtabEntryNext(3)
631</SUBROUTINE>
632
633 **************************************************************************/
634
635PUBLIC int   (CSCsymtabEntryPut) (
636                                 CSCsymTableType   const symTab,
637                                 CSCsymbolType*    const symbol
638                                 )
639   {
640   int               putStat = CSC_OK;
641   CSCsymbolType*    newSym;
642   CSChashKeyUnion   hashKey;
643
644   ASSERT_RTN (symTab != NULL, "CSCsymtabEntryPut: null symTab", CSC_BADARG);
645   ASSERT_RTN (symbol != NULL, "CSCsymtabEntryPut: null symbol", CSC_BADARG);
646   ASSERT_RTN (						\
647              symTab->sig_lo == SYMTAB_SIG,		\
648              "CSCsymtabEntryPut: symTab blows",	\
649              CSC_CORRUPT				\
650              );
651   ASSERT_RTN (						\
652              symTab->sig_hi == SYMTAB_SIG,		\
653              "CSCsymtabEntryPut: symTab blows",	\
654              CSC_CORRUPT				\
655              );
656
657   newSym = CSCsymbolDup (symbol, symTab->memLst, 0);
658   if (newSym != NULL)
659      {
660
661      MON_ENTER(symTab);
662
663      hashKey.asciiz = newSym->name;
664      putStat = CSChashEntryPut (
665                                symTab->table,
666                                &hashKey,
667                                &newSym,
668                                sizeof(CSCsymbolType*)
669                                );
670      ASSERT ((putStat == CSC_OK) || (putStat == CSC_DUPKEY));
671      if (putStat == CSC_OK) symTab->count += 1;
672
673      MON_EXIT(symTab);
674
675      }
676
677   return (putStat);
678   }
679
680
681/**************************************************************************
682 * Public Function CSCsymtabEntryGet
683 **************************************************************************
684
685<SUBROUTINE NAME="CSCsymtabEntryGet">
686
687NAME
688        CSCsymtabEntryGet - get a symbol in a libcsc symbol table
689
690SYNOPSYS
691        #include "libcsc.h"
692
693        CSCsymbolType*   CSCsymtabEntryGet (
694                                           CSCsymTableType   const symTab,
695                                           char*             const symName,
696                                           CSCmemListType    const memLst
697                                           );
698
699RETURN VALUE
700        CSCsymtabEntryGet(), if successful, returns a pointer to a
701        CSCsymbolType, or NULL if otherwise unsuccessful.
702
703DESCRIPTION
704        CSCsymtabEntryGet() returns a pointer to a duplicate symbol from
705        `symTab' whose name field matches `symName'.
706
707        If `memLst' is not NULL the duplicated symbol is dynamically allocated
708        with CSCmemDup(), and should be removed with CSCmemFree() (with
709        "tagData" of zero) to avoid leaking memory.
710
711        If `memLst' is NULL the duplicated symbol is dynamically allocated with
712        malloc() and should be removed with free() to avoid leaking memory.
713
714SEE ALSO
715        CSCsymtabNew(3)
716        CSCsymtabDel(3)
717        CSCsymtabStat(3)
718        CSCsymtabEntryPut(3)
719        CSCsymtabEntryDel(3)
720        CSCsymtabEntryNext(3)
721</SUBROUTINE>
722
723 **************************************************************************/
724
725PUBLIC CSCsymbolType*   (CSCsymtabEntryGet) (
726                                            CSCsymTableType   const symTab,
727                                            char*             const symName,
728                                            CSCmemListType    const memLst
729                                            )
730   {
731   CSCsymbolType*    symPtr = NULL;
732   CSChashKeyUnion   hashKey;
733   int               getStat;
734   size_t            entrySize;
735
736   ASSERT_RTN (symTab != NULL,  "CSCsymtabEntryGet: null symTab",  NULL);
737   ASSERT_RTN (symName != NULL, "CSCsymtabEntryGet: null symName", NULL);
738   ASSERT_RTN (						\
739              symTab->sig_lo == SYMTAB_SIG,		\
740              "CSCsymtabEntryGet: symTab blows",	\
741              NULL					\
742              );
743   ASSERT_RTN (						\
744              symTab->sig_hi == SYMTAB_SIG,		\
745              "CSCsymtabEntryGet: symTab blows",	\
746              NULL					\
747              );
748
749   MON_ENTER(symTab);
750
751   hashKey.asciiz = (char*)symName;
752   getStat = CSChashEntryGet (
753                             symTab->table,
754                             &hashKey,
755                             (void**)&symPtr,
756                             &entrySize,
757                             memLst
758                             );
759   ASSERT ((getStat == CSC_OK) || (getStat == CSC_NOTFOUND));
760   ASSERT (entrySize == sizeof(CSCsymbolType*));
761
762   MON_EXIT(symTab);
763
764   return (symPtr);
765   }
766
767
768/**************************************************************************
769 * Public Function CSCsymtabEntryDel
770 **************************************************************************
771
772<SUBROUTINE NAME="CSCsymtabEntryDel">
773
774NAME
775        CSCsymtabEntryDel - remove a symbol from a libcsc symbol table
776
777SYNOPSYS
778        #include "libcsc.h"
779
780        int   CSCsymtabEntryDel (
781                                CSCsymTableType   const symTab,
782                                char*             const symName
783                                );
784
785RETURN VALUE
786        CSCsymtabEntryDel(), if successful, returns CSC_OK; otherwise,
787        CSC_NOTFOUND, CSC_BADARG, and CSC_CORRUPT can be returned corresponding
788        to NULL pointers, bad function arguments, and internal data errors,
789        respectively.
790
791DESCRIPTION
792        CSCsymtabEntryDel() removes the symbol entry specified by `symName'
793        from `symTab'.  The symbol in `symTab' whose name field contains
794        `symName' is removed.
795
796BUGS
797        Symbols not created by CSCsymbolFloatNew(), CSCsymbolIntNew(), and
798        CSCsymbolPtrNew() may cause problems.  (The name and value.pointer data
799        of the symbol should be dynamically allocated, and the valueFlag field
800        needs to be set the way CSCsymbolFloatNew(), CSCsymbolIntNew(), and
801        CSCsymbolPtrNew() set it.)
802
803SEE ALSO
804        CSCsymtabNew(3)
805        CSCsymtabDel(3)
806        CSCsymtabStat(3)
807        CSCsymtabEntryPut(3)
808        CSCsymtabEntryGet(3)
809        CSCsymtabEntryNext(3)
810</SUBROUTINE>
811
812 **************************************************************************/
813
814PUBLIC int   (CSCsymtabEntryDel) (
815                                 CSCsymTableType   const symTab,
816                                 char*             const symName
817                                 )
818   {
819   int               delStat = CSC_OK;
820   CSChashKeyUnion   hashKey;
821
822   ASSERT_RTN (symTab != NULL,  "CSCsymtabEntryDel: null symTab",  CSC_BADARG);
823   ASSERT_RTN (symName != NULL, "CSCsymtabEntryDel: null symName", CSC_BADARG);
824   ASSERT_RTN (						\
825              symTab->sig_lo == SYMTAB_SIG,		\
826              "CSCsymtabEntryDel: symTab blows",	\
827              CSC_CORRUPT				\
828              );
829   ASSERT_RTN (						\
830              symTab->sig_hi == SYMTAB_SIG,		\
831              "CSCsymtabEntryDel: symTab blows",	\
832              CSC_CORRUPT				\
833              );
834
835   MON_ENTER(symTab);
836
837   hashKey.asciiz = (char*)symName;
838   delStat = CSChashEntryDel (symTab->table, &hashKey);
839   ASSERT (delStat == CSC_OK);
840   if (delStat == CSC_OK)
841      {
842      ASSERT(symTab->count>=1);
843      symTab->count -= 1;
844      }
845
846   MON_EXIT(symTab);
847
848   return (delStat);
849   }
850
851
852/**************************************************************************
853 * Public Function CSCsymtabEntryNext
854 **************************************************************************
855
856<SUBROUTINE NAME="CSCsymtabEntryNext">
857
858NAME
859        CSCsymtabEntryNext - find next entry in a libcsc symbol table
860
861SYNOPSYS
862        #include "libcsc.h"
863
864        void*   CSCsymtabEntryNext (
865                                   CSCsymTableType   const symTab,
866                                   void*             const lhPtr
867                                   );
868
869RETURN VALUE
870        CSCsymtabEntryNext(), if successful, returns an opaque symbol table
871        entry.  If not successful, CSCsymtabEntryNext() returns NULL.
872
873DESCRIPTION
874        CSCsymtabEntryNext() uses the libcsc symbol table specified by the
875        opaque `symTab' and returns a pointer to the next consecutive entry
876        following the entry pointed to by `lhPtr'.  This next consecutive entry
877        is the entry physically following the entry pointed to by `lhPtr'.
878
879        If `lhPtr' is NULL, then the first item in the table is returned.
880
881        If `symTab' is a table with no entries, or there are no more entries
882        following the entry pointed to by `lhPtr', then NULL is returned.
883
884BUGS
885        There is no legitimate way for client code to know what to do with the
886        void pointer returned from this function.  The secret is the returned
887        value is a CSChashEntryType with its dataPtr field being a pointer to
888        the symbol, but that might (very much not likely) change.
889
890SEE ALSO
891        CSCsymtabNew(3)
892        CSCsymtabDel(3)
893        CSCsymtabStat(3)
894        CSCsymtabEntryPut(3)
895        CSCsymtabEntryGet(3)
896        CSCsymtabEntryDel(3)
897</SUBROUTINE>
898
899 **************************************************************************/
900
901PUBLIC void*   (CSCsymtabEntryNext) (
902                                    CSCsymTableType   const symTab,
903                                    void*             const lhPtr
904                                    )
905   {
906   CSChashEntryType   nextHashEntry = NULL;
907
908   ASSERT_RTN (symTab!=NULL, "CSCsymtabEntryNext: null symTab", NULL);
909   ASSERT_RTN (						\
910              symTab->sig_lo == SYMTAB_SIG,		\
911              "CSCsymtabEntryNext: symTab blows",	\
912              NULL					\
913              );
914   ASSERT_RTN (						\
915              symTab->sig_hi == SYMTAB_SIG,		\
916              "CSCsymtabEntryNext: symTab blows",	\
917              NULL					\
918              );
919
920   MON_ENTER(symTab);
921
922   nextHashEntry = (CSChashEntryType)lhPtr;
923   nextHashEntry = CSChashEntryNext (symTab->table, nextHashEntry);
924
925   MON_EXIT(symTab);
926
927   return (nextHashEntry);
928   }
929
930
931/* End of the file. */
932