Files
harbour-core/harbour/source/compiler/hbident.c
Przemyslaw Czerpak 68cb7f510b 2006-08-17 12:40 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/contrib/rdd_ads/ads1.c
  * harbour/include/hbapi.h
  * harbour/include/hbapigt.h
  * harbour/include/hbapiitm.h
  * harbour/include/hbdefs.h
  * harbour/include/hbrdddbf.h
  * harbour/include/hbstack.h
  * harbour/include/hbsxfunc.h
  * harbour/source/common/expropt1.c
  * harbour/source/common/hbstr.c
  * harbour/source/compiler/harbour.c
  * harbour/source/compiler/hbident.c
  * harbour/source/pp/ppcore.c
  * harbour/source/rdd/hbdbsort.c
  * harbour/source/rdd/dbffpt/dbffpt1.c
  * harbour/source/rdd/hbsix/sxcompr.c
  * harbour/source/rtl/hardcr.c
  * harbour/source/rtl/inkey.c
  * harbour/source/rtl/isprint.c
  * harbour/source/rtl/math.c
  * harbour/source/rtl/mtran.c
  * harbour/source/rtl/natmsg.c
  * harbour/source/rtl/gtcrs/chrmap.c
  * harbour/source/rtl/gtcrs/gtcrs.c
  * harbour/source/rtl/gtsln/gtsln.c
  * harbour/source/rtl/gtsln/gtsln.h
  * harbour/source/rtl/gtsln/kbsln.c
  * harbour/source/rtl/gtsln/keytrans.c
  * harbour/source/rtl/gtsln/mousesln.c
  * harbour/source/vm/estack.c
  * harbour/source/vm/extend.c
  * harbour/source/vm/runner.c
  * harbour/utils/hbver/hbverfix.c
    * general code cleanup, public functions declared in header files,
      local changed to static, added mising void for functions without
      parameters, etc.
      We still have some public functions which are not used by core code
      and not declared in header files, like:
         hb_memvarValueBaseAddress(), hb_memvarGetVarHandle(),
         hb_memvarGetValueByHandle(), hb_clsCreate(), hb_clsAdd(),
         hb_clsAssociate(), hb_hashTableDel(), hb_hashTableSize(),
      I haven't touched them yet though we will have to keep in mind that
      we should make sth with them.
2006-08-17 11:05:09 +00:00

106 lines
2.6 KiB
C

/*
* $Id$
*/
/*
* Harbour Project source code:
* The cache for identifiers
*
* Copyright 1999 Ryszard Glab <rglab@imid.med.pl>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
*/
#include <string.h>
#include "hbhash.h"
#include "hbcomp.h"
#define HB_IDENT_TABLE_SIZE 509UL
/* table of identifiers for reuse */
static HB_HASH_TABLE_PTR s_comp_Identifiers = NULL;
/* create a new identifier or return the existing one
*/
char * hb_compIdentifierNew( char * szName, BOOL bCopy )
{
char * szIdent;
szIdent = ( char * )hb_hashTableFind( s_comp_Identifiers, (void *) szName );
if( !szIdent )
{
if( bCopy )
szIdent = hb_strdup( szName );
else
szIdent = szName;
hb_hashTableAdd( s_comp_Identifiers, (void *)szIdent, (void *)szIdent );
}
return szIdent;
}
/* returns a hash key */
static HB_HASH_FUNC( hb_comp_IdentKey ) /* ULONG func (void *Value, void *Cargo) */
{
ULONG ulSum = 0;
char *szName = ( char * )Value;
while( *szName )
ulSum += *szName++;
HB_SYMBOL_UNUSED( HashPtr );
HB_SYMBOL_UNUSED( Cargo );
return ulSum % HB_IDENT_TABLE_SIZE;
}
/* deletes an identifier */
static HB_HASH_FUNC( hb_comp_IdentDel )
{
hb_xfree( Value );
HB_SYMBOL_UNUSED( HashPtr );
HB_SYMBOL_UNUSED( Cargo );
return 1;
}
/* compares two identifiers */
static HB_HASH_FUNC( hb_comp_IdentComp )
{
HB_SYMBOL_UNUSED( HashPtr );
return strcmp( (char *)Value, (char *)Cargo );
}
/* initialize the hash table for identifiers */
void hb_compIdentifierOpen( )
{
s_comp_Identifiers = hb_hashTableCreate( HB_IDENT_TABLE_SIZE, hb_comp_IdentKey,
hb_comp_IdentDel, hb_comp_IdentComp );
}
/* release identifiers table */
void hb_compIdentifierClose( )
{
if( s_comp_Identifiers )
{
hb_hashTableKill( s_comp_Identifiers );
s_comp_Identifiers = NULL;
}
}