Debian Codegraph @

texk/dvipsk/dvips.h

raw
1 /* $Id: dvips.h 77300 2026-01-08 14:56:02Z karl $
2 * Copyright 1986-2026 Tomas Rokicki.
3 * This is dvips, a freely redistributable PostScript driver
4 * for dvi files. You may freely use, modify and/or distribute this
5 * program or any portion thereof.
6 */
7
8 /* This file is the header for dvips's global data structures. */
9
10 #define CREATIONDATE
11
12 #define MAX_CODE 0x110000
13 #define MAX_VF_CODE 0x1000000
14 #define MAX_2BYTES_CODE 0x10000
15 #define VF_MEM_UNIT 0x10000
16 #define CD_IDX(i) ((i>=MAX_2BYTES_CODE ? MAX_2BYTES_CODE : i))
17
18 #define BANNER \
19 "This is dvips(k) " VERSION " (" TL_VERSION ") Copyright 2026 Radical Eye Software"
20 #define BANNER2 "(www.radicaleye.com)"
21 #ifdef KPATHSEA
22 #include "config.h"
23 #include "debug.h"
24 #endif
25 /* Please don't turn debugging off! */
26 #ifndef DEBUG
27 #define DEBUG
28 #endif
29
30 #ifndef KPATHSEA
31 #include <stdio.h>
32 #if defined(SYSV) || defined(VMS) || defined(__THINK__) || defined(MSDOS) || defined(OS2) || defined(ATARIST) || defined(WIN32)
33 #include <string.h>
34 #else
35 #include <strings.h>
36 #endif
37 #endif
38 #if defined(lint) && defined(sun)
39 extern char *sprintf();
40 #endif
41 #include "paths.h"
42 #include "debug.h"
43 #ifdef VMS
44 #include "[.vms]vms.h"
45 #endif /* VMS */
46 #include <stdlib.h>
47 /*
48 * Is your malloc big?
49 */
50 #if defined(MSDOS) && !defined(__EMX__) && !defined(DJGPP)
51 #define SMALLMALLOC
52 #endif
53 #if defined(OS2) && defined(_MSC_VER)
54 #define SMALLMALLOC
55 #endif
56 /*
57 * Constants, used to increase or decrease the capacity of this program.
58 *
59 * Strings are now more dynamically allocated, so STRINGSIZE is not the
60 * strict limit it once was. However, it still sets the maximum size
61 * of a string that can be handled in specials, so it should not be
62 * set too small.
63 */
64 #define STRINGSIZE (200000) /* maximum total chars in strings in program */
65 #define RASTERCHUNK (8192) /* size of chunk of raster */
66 #define MINCHUNK (240) /* minimum size char to get own raster */
67 #define STACKSIZE (500) /* maximum stack size for dvi files */
68 #define MAXFRAME (50) /* maximum depth of virtual font recursion */
69 #define MAXFONTHD (1024) /* number of unique names of included fonts */
70 #define STDOUTSIZE (75) /* width of a standard output line */
71 #define DOWNLOADEDPSSIZE (1000) /* max number of downloaded fonts to check */
72 /*
73 * Other constants, which define printer-dependent stuff.
74 */
75 #define SWMEM (180000) /* available virtual memory in PostScript printer */
76 #define DPI (actualdpi) /* dots per inch */
77 #define VDPI (vactualdpi) /* dots per inch */
78 #define RES_TOLERANCE(dpi) ((int)(1+dpi/500))
79 /* error in file name resolution versus desired */
80 #define FONTCOST (298) /* overhead cost of each sw font */
81 #define PSFONTCOST (1100) /* overhead cost for PostScript fonts */
82 #define PSCHARCOST (20) /* overhead cost for PostScript font chars */
83 #define DNFONTCOST (35000) /* overhead cost for downloaded PS font */
84 #define CHARCOST (15) /* overhead cost for each character */
85 #define OVERCOST (30000) /* cost of overhead */
86 #define DICTITEMCOST (20) /* cost per key, value in dictionary */
87 #define NAMECOST (40) /* overhead cost of each new name */
88 /*
89 * Type declarations. integer must be a 32-bit signed; shalfword must
90 * be a sixteen-bit signed; halfword must be a sixteen-bit unsigned;
91 * quarterword must be an eight-bit unsigned.
92 */
93 #if (defined(MSDOS) && !defined(DJGPP)) || (defined(OS2) && defined(_MSC_VER)) || defined(ATARIST)
94 typedef long integer;
95 typedef unsigned long uinteger;
96 #else
97 typedef int integer;
98 typedef unsigned int uinteger;
99 #endif
100 #ifndef KPATHSEA
101 typedef char boolean;
102 #endif
103 typedef double real;
104 typedef short shalfword;
105 typedef unsigned short halfword;
106 typedef unsigned char quarterword;
107 #ifdef WIN32
108 #define Boolean boolean
109 #else
110 #ifndef __THINK__
111 typedef short Boolean;
112 #endif
113 #endif
114 /*
115 * If the machine has a default integer size of 16 bits, and 32-bit
116 * integers must be manipulated with %ld, set the macro SHORTINT.
117 */
118 #ifdef XENIX
119 #define SHORTINT
120 #else
121 #undef SHORTINT
122 #endif
123 #if defined(MSDOS) && !defined(__EMX__) && !defined(DJGPP) || defined(ATARIST)
124 #define SHORTINT
125 #endif
126 #if defined(OS2) && defined(_MSC_VER)
127 #define SHORTINT
128 #endif
129
130 /*
131 * This is the structure definition for resident fonts. We use
132 * a small and simple hash table to handle these. We don't need
133 * a big hash table.
134 */
135 #define RESHASHPRIME (73)
136 struct resfont {
137 struct resfont *next;
138 char *Keyname, *PSname, *TeXname, *Fontfile, *Vectfile;
139 char *specialinstructions;
140 char *downloadheader; /* possibly multiple files */
141 quarterword sent;
142 };
143
144 /*
145 * A chardesc describes an individual character. Before the fonts are
146 * downloaded, the flags indicate that the character has already been used
147 * with the following meanings:
148 */
149 typedef struct tcd {
150 integer TFMwidth;
151 quarterword *packptr;
152 shalfword pixelwidth;
153 quarterword flags, flags2;
154 } chardesctype;
155 #define EXISTS (1)
156 #define PREVPAGE (2)
157 #define THISPAGE (4)
158 #define TOOBIG (8) /* not used at the moment */
159 #define REPACKED (16)
160 #define BIGCHAR (32)
161 #define STATUSFLAGS (EXISTS|REPACKED|BIGCHAR)
162 /*
163 * The new field flags2 above is now an immutable field (once a font is
164 * loaded); for now it only indicates whether a character EXISTS or not.
165 * This fixes a problem with -G.
166 */
167 /*
168 * A fontdesc describes a font. The name, area, and scalename are located in
169 * the string pool. The nextsize pointer is used to link fonts that are used
170 * in included psfiles and differ only in scaledsize. Such fonts also have
171 * a non-NULL scalename that gives the scaledsize as found in the included
172 * file. The psflag indicates that the font has been used in an included
173 * psfile. It can be 0, PREVPAGE, THISPAGE, or EXISTS.
174 */
175 typedef struct tfd {
176 integer checksum, scaledsize, designsize, thinspace, dir;
177 halfword dpi, loadeddpi;
178 halfword alreadyscaled;
179 halfword psname;
180 halfword loaded;
181 quarterword psflag;
182 quarterword codewidth;
183 integer maxchars;
184 integer llx, lly, urx, ury ;
185 char *name, *area;
186 struct resfont *resfont;
187 struct tft *localfonts;
188 struct tfd *next;
189 struct tfd *nextsize;
190 char *scalename;
191 chardesctype *chardesc;
192 int iswide, kind;
193 } fontdesctype;
194
195 #define VF_TEX (1)
196 #define VF_OMEGA (2)
197 #define VF_PTEX (3)
198 #define TFM_TEX (0x000)
199 #define OFM_OMEGA (0x100)
200 #define JFM_PTEX (0x200)
201
202 /* A fontmap associates a fontdesc with a font number.
203 */
204 typedef struct tft {
205 integer fontnum;
206 fontdesctype *desc;
207 struct tft *next;
208 } fontmaptype;
209
210 /* Virtual fonts require a `macro' capability that is implemented by
211 * using a stack of `frames'.
212 */
213 typedef struct {
214 quarterword *curp, *curl;
215 fontdesctype *curf;
216 fontmaptype *ff;
217 } frametype;
218
219 /*
220 * The next type holds the font usage information in a 256-bit table;
221 * there's a 1 for each character that was used in a section.
222 */
223 typedef struct {
224 fontdesctype *fd;
225 halfword psfused;
226 halfword bitmap[16];
227 } charusetype;
228
229 /* Next we want to record the relevant data for a section. A section is
230 * a largest portion of the document whose font usage does not overflow
231 * the capacity of the printer. (If a single page does overflow the
232 * capacity all by itself, it is made into its own section and a warning
233 * message is printed; the page is still printed.)
234 *
235 * The sections are in a linked list, built during the prescan phase and
236 * processed in proper order (so that pages stack correctly on output) during
237 * the second phase.
238 */
239 typedef struct t {
240 integer bos;
241 struct t *next;
242 halfword numpages;
243 } sectiontype;
244
245 /*
246 * Sections are actually represented not by sectiontype but by a more
247 * complex data structure of variable size, having the following layout:
248 * sectiontype sect;
249 * charusetype charuse[numfonts];
250 * fontdesctype *sentinel = NULL;
251 * (Here numfonts is the number of bitmap fonts currently defined.)
252 * Since we can't declare this or take a sizeof it, we build it and
253 * manipulate it ourselves (see the end of the prescan routine).
254 */
255 /*
256 * This is how we build up headers and other lists.
257 */
258 struct header_list {
259 struct header_list *next;
260 const char *Hname;
261 char *precode;
262 char *postcode;
263 char *name;
264 };
265 /*
266 * Some machines define putlong in their library.
267 * We get around this here.
268 */
269 #define putlong was_putlong
270 /*
271 * Information on available paper sizes is stored here.
272 */
273 struct papsiz {
274 struct papsiz *next;
275 integer xsize, ysize;
276 const char *name;
277 const char *specdat;
278 };
279 #ifdef MVSXA /* IBM: MVS/XA */
280 /* this is where we fix problems with conflicts for truncation
281 of long names (we might only do this if LONGNAME not set but ...) */
282 # define pprescanpages pprscnpgs /* confict with pprescan */
283 # define flushDashedPath flshDshdPth /* conflict with flushDash */
284 # define PageList PgList /* re-definition conflict with pagelist */
285 /* adding ascii2ebcdic conversion table to extern */
286 extern char ascii2ebcdic[];
287 #endif /* IBM: MVS/XA */
288 #ifdef VMCMS /* IBM: VM/CMS */
289 /* this is where we fix problems with conflicts for truncation
290 of long names (we might only do this if LONGNAME not set but ...) */
291 # define pprescanpages pprscnpgs /* confict with pprescan */
292 # define flushDashedPath flshDshdPth /* conflict with flushDash */
293 /* adding ascii2ebcdic conversion table to extern */
294 extern char ascii2ebcdic[];
295 /* redefining fopen for VMCMS, see DVIPSCMS.C */
296 extern FILE *cmsfopen();
297 # ifdef fopen
298 # undef fopen
299 # endif
300 # define fopen cmsfopen
301 #define downloadpspk dnldpspk
302 #endif /* IBM: VM/CMS */
303 /*
304 * Remove namespace conflict with standard library on Macintosh
305 */
306 #ifdef __THINK__
307 #define newstring newpoolstring
308 #endif
309
310 #ifndef VOID
311 #define VOID void
312 #endif
313
314 #define USE_PCLOSE (801)
315 #define USE_FCLOSE (802)
316
317 /* output Unicode string on console in windows */
318 #if defined(KPATHSEA) && defined(WIN32)
319 #undef perror
320 #define fprintf_str win32_fprintf
321 #define fputs_str win32_fputs
322 #define putc_str win32_putc
323 #define perror win32_perror
324 #else
325 #define fprintf_str fprintf
326 #define fputs_str fputs
327 #define putc_str putc
328 #endif
329
330 /* Things that KPATHSEA knows, and are useful even without it. */
331 #if !defined(KPATHSEA)
332
333 #if defined(MSDOS) || defined(OS2) || defined(WIN32)
334 #define FOPEN_ABIN_MODE "ab"
335 #define FOPEN_RBIN_MODE "rb"
336 #else
337 #define FOPEN_ABIN_MODE "a"
338 #define FOPEN_RBIN_MODE "r"
339 #endif
340
341 #if (defined MSDOS || defined OS2 || defined WIN32)
342 #define WRITEBIN "wb"
343 #else
344 #ifdef VMCMS
345 #define WRITEBIN "wb, lrecl=1024, recfm=f"
346 #else
347 #define WRITEBIN "w"
348 #endif
349 #endif
350
351 #if defined(WIN32)
352 #define STDC_HEADERS
353 #include <io.h>
354 #include <fcntl.h>
355 #define O_BINARY _O_BINARY
356 #define register
357 #define SET_BINARY(fd) (void)_setmode((fd), _O_BINARY)
358 #else /* !WIN32 */
359 #define SET_BINARY(fd) (void)0
360 #endif
361
362 #if defined(DEVICESEP)
363 #define IS_DEVICE_SEP(c) ((c) == DEVICESEP)
364 #else
365 #define IS_DEVICE_SEP(c) 0
366 #endif
367 #define STREQ(s1, s2) (((s1) != NULL) && ((s2) != NULL) && !strcmp((s1), (s2)))
368
369 #if defined(MSDOS) || defined(OS2) || defined(WIN32)
370 #define NAME_BEGINS_WITH_DEVICE(name) (*(name) && IS_DEVICE_SEP((name)[1]))
371 #define IS_DIR_SEP(c) ((c) == '/' || (c) == '\\')
372 #define FILESTRCASEEQ(s1, s2) (strcasecmp (s1, s2) == 0)
373 #else
374 #define NAME_BEGINS_WITH_DEVICE(name) 0
375 #define IS_DIR_SEP(c) ((c) == DIRSEP)
376 #define FILESTRCASEEQ STREQ
377 #endif
378
379 #define TOLOWER(c) tolower(c)
380 #define ISALNUM(c) isalnum(c)
381 #define ISXDIGIT(c) (isascii (c) && isxdigit(c))
382
383 #endif