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