xref: /plan9/sys/src/cmd/gs/src/inames.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1998, 1999 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: inames.h,v 1.5 2002/06/16 04:47:10 lpd Exp $ */
18 /* Name table interface */
19 
20 #ifndef inames_INCLUDED
21 #  define inames_INCLUDED
22 
23 /*
24  * This file defines those parts of the name table API that depend neither
25  * on the implementation nor on the existence of a single distinguished
26  * instance.  Procedures in this file begin with names_.
27  */
28 
29 /* ---------------- Interface types ---------------- */
30 
31 #ifndef name_table_DEFINED
32 #  define name_table_DEFINED
33 typedef struct name_table_s name_table;
34 #endif
35 
36 typedef uint name_index_t;
37 
38 /* ---------------- Constant values ---------------- */
39 
40 extern const uint name_max_string;
41 
42 /* ---------------- Procedural interface ---------------- */
43 
44 #ifndef gs_ref_memory_DEFINED
45 #  define gs_ref_memory_DEFINED
46 typedef struct gs_ref_memory_s gs_ref_memory_t;
47 #endif
48 
49 /* Allocate and initialize a name table. */
50 name_table *names_init(ulong size, gs_ref_memory_t *imem);
51 
52 /* Get the allocator for a name table. */
53 gs_memory_t *names_memory(const name_table * nt);
54 
55 /*
56  * Look up and/or enter a name in the name table.
57  * The values of enterflag are:
58  *      -1 -- don't enter (return an error) if missing;
59  *       0 -- enter if missing, don't copy the string, which was allocated
60  *              statically;
61  *       1 -- enter if missing, copy the string;
62  *       2 -- enter if missing, don't copy the string, which was already
63  *              allocated dynamically (using the names_memory allocator).
64  * Possible errors: VMerror, limitcheck (if string is too long or if
65  * we have assigned all possible name indices).
66  */
67 int names_ref(name_table * nt, const byte * ptr, uint size, ref * pnref,
68 	      int enterflag);
69 void names_string_ref(const name_table * nt, const ref * pnref, ref * psref);
70 
71 /*
72  * names_enter_string calls names_ref with a (permanent) C string.
73  */
74 int names_enter_string(name_table * nt, const char *str, ref * pnref);
75 
76 /*
77  * names_from_string essentially implements cvn.
78  * It always enters the name, and copies the executable attribute.
79  */
80 int names_from_string(name_table * nt, const ref * psref, ref * pnref);
81 
82 /* Compare two names for equality. */
83 #define names_eq(pnref1, pnref2)\
84   ((pnref1)->value.pname == (pnref2)->value.pname)
85 
86 /* Invalidate the value cache for a name. */
87 void names_invalidate_value_cache(name_table * nt, const ref * pnref);
88 
89 /* Convert between names and indices. */
90 name_index_t names_index(const name_table * nt, const ref * pnref);		/* ref => index */
91 name *names_index_ptr(const name_table * nt, name_index_t nidx);	/* index => name */
92 void names_index_ref(const name_table * nt, name_index_t nidx, ref * pnref);	/* index => ref */
93 
94 /* Get the index of the next valid name. */
95 /* The argument is 0 or a valid index. */
96 /* Return 0 if there are no more. */
97 name_index_t names_next_valid_index(name_table * nt, name_index_t nidx);
98 
99 /* Mark a name for the garbage collector. */
100 /* Return true if this is a new mark. */
101 bool names_mark_index(name_table * nt, name_index_t nidx);
102 
103 /* Get the object (sub-table) containing a name. */
104 /* The garbage collector needs this so it can relocate pointers to names. */
105 void /*obj_header_t */ *
106     names_ref_sub_table(name_table * nt, const ref * pnref);
107 void /*obj_header_t */ *
108     names_index_sub_table(name_table * nt, name_index_t nidx);
109 void /*obj_header_t */ *
110     names_index_string_sub_table(name_table * nt, name_index_t nidx);
111 
112 #endif /* inames_INCLUDED */
113