Debian Codegraph @

texk/ps2pk/util.h

raw
1 /* $XConsortium: util.h,v 1.3 92/03/26 16:42:29 eswu Exp $ */
2 /* Copyright International Business Machines,Corp. 1991
3 * All Rights Reserved
4 *
5 * License to use, copy, modify, and distribute this software
6 * and its documentation for any purpose and without fee is
7 * hereby granted, provided that the above copyright notice
8 * appear in all copies and that both that copyright notice and
9 * this permission notice appear in supporting documentation,
10 * and that the name of IBM not be used in advertising or
11 * publicity pertaining to distribution of the software without
12 * specific, written prior permission.
13 *
14 * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
15 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
16 * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
18 * THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND
19 * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
20 * OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF
21 * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
22 * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN
23 * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
24 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
25 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
26 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
27 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
28 * SOFTWARE.
29 */
30 #ifndef UTIL_H
31 #define UTIL_H
32 #include "types.h"
33
34 #ifndef KPATHSEA
35 #ifndef boolean
36 typedef int boolean;
37 #endif
38 #endif
39
40 #ifndef TRUE
41 #define TRUE (1)
42 #endif
43
44 #ifndef FALSE
45 #define FALSE (0)
46 #endif
47
48 /***================================================================***/
49 /* Portable definitions for 2's complement machines.
50 * NOTE: These really should be based on PostScript types,
51 * for example, sizeof(ps_integer), or sizeof(ps_unsigned)
52 */
53 #define MAX_INT32 (~(uint32_t)(0))
54 /* This code is portable, assuming K&R C and 2's complement arithmetic */
55 #define MAX_INTEGER \
56 ((int32_t)((((uint32_t) 1)<<(sizeof(uint32_t)*8-1))-1))
57 #define MIN_INTEGER ((-MAX_INTEGER)-1)
58
59 #define MAX_ARRAY_CNT (65535)
60 #define MAX_DICT_CNT (65535)
61 #define MAX_STRING_LEN (65535)
62 #define MAX_NAME_LEN (128)
63
64 /* this is the size of memory allocated for reading fonts */
65
66 #define VM_SIZE (50*1024)
67 /***================================================================***/
68
69 #ifndef MIN
70 #define MIN(a,b) (((a)<(b)) ? a : b )
71 #endif
72
73 /***================================================================***/
74 /* Routines for managing virtual memory */
75 /***================================================================***/
76 extern boolean vm_init(void);
77 extern int32_t vm_free;
78 extern int32_t vm_size;
79 extern char *vm_next;
80 extern char *vm_alloc(unsigned int bytes);
81 /***================================================================***/
82 /* Macros for managing virtual memory */
83 /***================================================================***/
84 #define vm_next_byte() (vm_next)
85 #define vm_free_bytes() (vm_free)
86 #define vm_avail(B) (B <= vm_free)
87
88
89
90 /***================================================================***/
91 /* Types of PostScript objects */
92 /***================================================================***/
93 #define OBJ_INTEGER (0)
94 #define OBJ_REAL (1)
95 #define OBJ_BOOLEAN (2)
96 #define OBJ_ARRAY (3)
97 #define OBJ_STRING (4)
98 #define OBJ_NAME (5)
99 #define OBJ_FILE (6)
100 #define OBJ_ENCODING (7)
101
102 /***================================================================***/
103 /* Value of PostScript objects */
104 /***================================================================***/
105 typedef union ps_value {
106 char *valueP; /* value pointer for unspecified type */
107 int value; /* value for unspecified type */
108 int integer; /* when type is OBJ_INTEGER */
109 float real; /* when type is OBJ_REAL */
110 int boolean; /* when type is OBJ_BOOLEAN */
111 struct ps_obj *arrayP; /* when type is OBJ_ARRAY */
112 unsigned char *stringP; /* when type is OBJ_STRING */
113 const char *nameP; /* when type is OBJ_NAME */
114 FILE *fileP; /* when type is OBJ_FILE */
115 } psvalue;
116
117 /***================================================================***/
118 /* Definition of a PostScript object */
119 /***================================================================***/
120 typedef struct ps_obj {
121 char type;
122 char unused;
123 unsigned short len;
124 union ps_value data;
125 } psobj;
126
127 /***================================================================***/
128 /* Definition of a PostScript Dictionary Entry */
129 /***================================================================***/
130 typedef struct ps_dict {
131 psobj key;
132 psobj value;
133 } psdict;
134
135 /***================================================================***/
136 /* Macros for testing type of PostScript objects */
137 /***================================================================***/
138 #define objIsInteger(o) ((o).type == OBJ_INTEGER)
139 #define objIsReal(o) ((o).type == OBJ_REAL)
140 #define objIsBoolean(o) ((o).type == OBJ_BOOLEAN)
141 #define objIsArray(o) ((o).type == OBJ_ARRAY)
142 #define objIsString(o) ((o).type == OBJ_STRING)
143 #define objIsName(o) ((o).type == OBJ_NAME)
144 #define objIsFile(o) ((o).type == OBJ_FILE)
145
146 /***================================================================***/
147 /* Macros for setting type of PostScript objects */
148 /***================================================================***/
149 #define objSetInteger(o) ((o).type = OBJ_INTEGER)
150 #define objSetReal(o) ((o).type = OBJ_REAL)
151 #define objSetBoolean(o) ((o).type = OBJ_BOOLEAN)
152 #define objSetArray(o) ((o).type = OBJ_ARRAY)
153 #define objSetString(o) ((o).type = OBJ_STRING)
154 #define objSetName(o) ((o).type = OBJ_NAME)
155 #define objSetFile(o) ((o).type = OBJ_FILE)
156
157 /***================================================================***/
158 /* Macros for testing type of PostScript objects (pointer access) */
159 /***================================================================***/
160 #define objPIsInteger(o) ((o)->type == OBJ_INTEGER)
161 #define objPIsReal(o) ((o)->type == OBJ_REAL)
162 #define objPIsBoolean(o) ((o)->type == OBJ_BOOLEAN)
163 #define objPIsArray(o) ((o)->type == OBJ_ARRAY)
164 #define objPIsString(o) ((o)->type == OBJ_STRING)
165 #define objPIsName(o) ((o)->type == OBJ_NAME)
166 #define objPIsFile(o) ((o)->type == OBJ_FILE)
167
168 /***================================================================***/
169 /* Macros for setting type of PostScript objects (pointer access) */
170 /***================================================================***/
171 #define objPSetInteger(o) ((o)->type = OBJ_INTEGER)
172 #define objPSetReal(o) ((o)->type = OBJ_REAL)
173 #define objPSetBoolean(o) ((o)->type = OBJ_BOOLEAN)
174 #define objPSetArray(o) ((o)->type = OBJ_ARRAY)
175 #define objPSetString(o) ((o)->type = OBJ_STRING)
176 #define objPSetName(o) ((o)->type = OBJ_NAME)
177 #define objPSetFile(o) ((o)->type = OBJ_FILE)
178
179 extern void objFormatInteger(psobj *,int);
180 extern void objFormatReal(psobj *, float);
181 extern void objFormatBoolean(psobj *, boolean);
182 extern void objFormatEncoding(psobj *, int, psobj *);
183 extern void objFormatArray(psobj *, int, psobj *);
184 extern void objFormatString(psobj *, int, char *);
185 extern void objFormatName(psobj *, int, const char *);
186 extern void objFormatFile(psobj *, FILE *);
187
188 extern void *Xalloc(size_t);
189 extern void Xfree(void *);
190 extern intptr_t MakeAtom(const char *, unsigned int, int);
191 extern void QueryFontLib(char *, const char *, void *, int *);
192
193 /*
194 * -------------------------------------------------------------------------
195 * Globals shared -- (everyone else KEEP YOUR MITTS OFF THEM!)
196 * -------------------------------------------------------------------------
197 */
198
199 /* These variables are set by the caller */
200 extern char *tokenStartP; /* Pointer to token buffer in VM */
201 extern char *tokenMaxP; /* Pointer to end of VM we may use + 1 */
202
203 /* These variables are set by P_TOKEN */
204 extern int tokenLength; /* Characters in token */
205 extern boolean tokenTooLong; /* Token too long for space available */
206 extern int tokenType; /* Type of token identified */
207 extern psvalue tokenValue; /* Token value */
208
209 #endif