/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21/*22* hsearch() for systems that have <search.h> but no hsearch()23* why would such a system provide the interface but not the24* implementation? that's what happens when one slimes their25* way through standards compliance26*27* NOTE: please excuse the crude feature test28*/2930#if !_UWIN3132void _STUB_hsearch(){}3334#else3536#if _PACKAGE_ast37#include <ast.h>38#endif3940#define hcreate ______hcreate41#define hdestroy ______hdestroy42#define hsearch ______hsearch4344#include <search.h>4546#undef hcreate47#undef hdestroy48#undef hsearch4950#include "dthdr.h"5152#if defined(__EXPORT__)53#define extern __EXPORT__54#endif5556/* POSIX hsearch library based on libdt57** Written by Kiem-Phong Vo (AT&T Research, 07/19/95)58*/5960/* type of objects in hash table */61typedef struct _hash_s62{ Dtlink_t link;63ENTRY item;64} Hash_t;6566/* object delete function */67#if __STD_C68static void hashfree(Dt_t* dt, Void_t* obj, Dtdisc_t* disc)69#else70static void hashfree(dt, obj, disc)71Dt_t* dt;72Void_t* obj;73Dtdisc_t* disc;74#endif75{76free(((Hash_t*)obj)->item.key);77free(obj);78}7980static Dt_t* Hashtab; /* object dictionary */81static Dtdisc_t Hashdisc = /* discipline */82{ sizeof(Dtlink_t), -1,830,84NIL(Dtmake_f), hashfree,85NIL(Dtcompar_f), /* always use strcmp */86NIL(Dthash_f),87NIL(Dtmemory_f),88NIL(Dtevent_f)89};9091extern92#if __STD_C93int hcreate(size_t nel)94#else95int hcreate(nel)96size_t nel;97#endif98{99if(Hashtab) /* already opened */100return 0;101102if(!(Hashtab = dtopen(&Hashdisc,Dtset)) )103return 0;104105return 1;106}107108extern void hdestroy()109{ if(Hashtab)110dtclose(Hashtab);111Hashtab = NIL(Dt_t*);112}113114extern115#if __STD_C116ENTRY* hsearch(ENTRY item, ACTION action)117#else118ENTRY* hsearch(item, action)119ENTRY item;120ACTION action;121#endif122{123reg Hash_t* o;124125if(!Hashtab)126return NIL(ENTRY*);127128if(!(o = (Hash_t*)dtmatch(Hashtab,item.key)) && action == ENTER &&129(o = (Hash_t*)malloc(sizeof(Hash_t)) ) )130{ o->item = item;131o = (Hash_t*)dtinsert(Hashtab,o);132}133134return o ? &(o->item) : NIL(ENTRY*);135}136137#endif138139140