|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T i
Length: 2821 (0xb05) Types: TextFile Names: »iname.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89 └─⟦ff23ba0e6⟧ »./ghostscript-1.3.tar.Z« └─⟦a24a58cd3⟧ └─⟦this⟧ »iname.c«
/* Copyright (C) 1989 Aladdin Enterprises. All rights reserved. Distributed by Free Software Foundation, Inc. This file is part of Ghostscript. Ghostscript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the Ghostscript General Public License for full details. Everyone is granted permission to copy, modify and redistribute Ghostscript, but only under the conditions described in the Ghostscript General Public License. A copy of this license is supposed to have been given to you along with Ghostscript so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. */ /* iname.c */ /* Name lookup for GhostScript interpreter */ #include "ghost.h" #include "alloc.h" #include "errors.h" #include "name.h" #include "store.h" /* The name table */ #define nt_size 256 private ref name_table[nt_size]; /* t_name */ /* Initialize the name table */ void name_init() { ref *pname = name_table + nt_size; while ( --pname >= name_table ) pname->value.pname = 0; } /* Look up or enter a name in the table. */ /* Return 0 or an error code. */ /* The return may overlap the characters of the string! */ int name_ref(byte *ptr, ushort size, ref *pref, int copyflag /* if true, copy name chars */) { uint hash = string_hash(ptr, size); register ref *ppname = name_table + (hash & (nt_size - 1)); /* t_name */ register name *pname; byte *cptr; while ( (pname = ppname->value.pname) != 0 ) { if ( pname->string.size == size && !memcmp(ptr, pname->string.value.bytes, size) ) { *pref = *ppname; return 0; } ppname = &pname->next; } /* Name was not in the table. Make a new entry. */ pname = (name *)alloc(sizeof(name), "name_ref"); if ( pname == 0 ) return e_VMerror; if ( copyflag ) { cptr = (byte *)alloc(size, "name_ref(string)"); if ( cptr == 0 ) return e_VMerror; memcpy(cptr, ptr, size); } else cptr = ptr; n_store_tasv(&pname->string, t_string, a_read+a_execute, size, bytes, cptr); make_tv(&pname->next, t_null, pname, 0); pname->pvalue = pv_no_defn; make_tv(pref, t_name, pname, pname); *ppname = *pref; return 0; } /* Get the string for a name. */ void name_string_ref(ref *pnref /* t_name */, ref *psref /* result, t_string */) { *psref = pnref->value.pname->string; } /* Enter a name during initialization. */ /* Fatal error if the entry fails. */ void name_enter(char *str, ref *pref) { if ( name_ref((byte *)str, strlen(str), pref, 0) ) printf("name_enter failed - %s", str), exit(1); }