Back to index

tetex-bin  3.0
dvips.h
Go to the documentation of this file.
00001 /*
00002  *   This is dvips, a freely redistributable PostScript driver
00003  *   for dvi files.  It is (C) Copyright 1986-2004 by Tomas Rokicki.
00004  *   You may modify and use this program to your heart's content,
00005  *   so long as you send modifications to Tomas Rokicki.  It can
00006  *   be included in any distribution, commercial or otherwise, so
00007  *   long as the banner string defined below is not modified (except
00008  *   for the version number) and this banner is printed on program
00009  *   invocation, or can be printed on program invocation with the -? option.
00010  */
00011 
00012 /*   This file is the header for dvips's global data structures. */
00013 
00014 #define BANNER \
00015 "This is dvips(k) 5.95a Copyright 2005 Radical Eye Software"
00016 #define BANNER2 "(www.radicaleye.com)"
00017 #ifdef KPATHSEA
00018 #include "config.h"
00019 #include "debug.h"
00020 #endif
00021 /*   Please don't turn debugging off! */
00022 #ifndef DEBUG
00023 #define DEBUG
00024 #endif
00025 
00026 #ifndef KPATHSEA
00027 #include <stdio.h>
00028 #if defined(SYSV) || defined(VMS) || defined(__THINK__) || defined(MSDOS) || defined(OS2) || defined(ATARIST) || defined(WIN32)
00029 #include <string.h>
00030 #else
00031 #include <strings.h>
00032 #endif
00033 #endif
00034 #if defined(lint) && defined(sun)
00035 extern char *sprintf() ;
00036 #endif
00037 #include "paths.h"
00038 #include "debug.h"
00039 #ifdef VMS
00040 #include "[.vms]vms.h"
00041 #endif /* VMS */
00042 #include <stdlib.h>
00043 /*
00044  *   Is your malloc big?
00045  */
00046 #if defined(MSDOS) && !defined(__EMX__) && !defined(DJGPP)
00047 #define SMALLMALLOC
00048 #endif
00049 #if defined(OS2) && defined(_MSC_VER)
00050 #define SMALLMALLOC
00051 #endif
00052 /*
00053  *   Constants, used to increase or decrease the capacity of this program.
00054  *
00055  *   Strings are now more dynamically allocated, so STRINGSIZE is not the
00056  *   strict limit it once was.  However, it still sets the maximum size
00057  *   of a string that can be handled in specials, so it should not be
00058  *   set too small.
00059  */
00060 #define STRINGSIZE (200000)  /* maximum total chars in strings in program */
00061 #define RASTERCHUNK (8192)  /* size of chunk of raster */
00062 #define MINCHUNK (240)      /* minimum size char to get own raster */
00063 #define STACKSIZE (350)     /* maximum stack size for dvi files */
00064 #define MAXFRAME (10)       /* maximum depth of virtual font recursion */
00065 #define MAXFONTHD (100)     /* number of unique names of included fonts */
00066 #define STDOUTSIZE (75)     /* width of a standard output line */
00067 /*
00068  *   Other constants, which define printer-dependent stuff.
00069  */
00070 #define SWMEM (180000)      /* available virtual memory in PostScript printer */
00071 #define DPI (actualdpi)     /* dots per inch */
00072 #define VDPI (vactualdpi)   /* dots per inch */
00073 #define RES_TOLERANCE(dpi) ((int)(1+dpi/500))
00074                             /* error in file name resolution versus desired */
00075 #define FONTCOST (298)      /* overhead cost of each sw font */
00076 #define PSFONTCOST (1100)   /* overhead cost for PostScript fonts */
00077 #define PSCHARCOST (20)     /* overhead cost for PostScript font chars */
00078 #define DNFONTCOST (35000)  /* overhead cost for downloaded PS font */
00079 #define CHARCOST (15)       /* overhead cost for each character */
00080 #define OVERCOST (30000)    /* cost of overhead */
00081 #define DICTITEMCOST (20)   /* cost per key, value in dictionary */
00082 #define NAMECOST (40)       /* overhead cost of each new name */
00083 /*
00084  *   Type declarations.  integer must be a 32-bit signed; shalfword must
00085  *   be a sixteen-bit signed; halfword must be a sixteen-bit unsigned;
00086  *   quarterword must be an eight-bit unsigned.
00087  */
00088 #if (defined(MSDOS) && !defined(DJGPP)) || (defined(OS2) && defined(_MSC_VER)) || defined(ATARIST)
00089 typedef long integer;
00090 #else
00091 typedef int integer;
00092 #endif
00093 #ifndef KPATHSEA
00094 typedef char boolean;
00095 #endif
00096 typedef double real;
00097 typedef short shalfword ;
00098 typedef unsigned short halfword ;
00099 typedef unsigned char quarterword ;
00100 #ifdef WIN32
00101 #define Boolean boolean
00102 #else
00103 #ifndef __THINK__
00104 typedef short Boolean ;
00105 #endif
00106 #endif
00107 /*
00108  *   If the machine has a default integer size of 16 bits, and 32-bit
00109  *   integers must be manipulated with %ld, set the macro SHORTINT.
00110  */
00111 #ifdef XENIX
00112 #define SHORTINT
00113 #else
00114 #undef SHORTINT
00115 #endif
00116 #if defined(MSDOS) && !defined(__EMX__) && !defined(DJGPP) || defined(ATARIST)
00117 #define SHORTINT
00118 #endif
00119 #if defined(OS2) && defined(_MSC_VER)
00120 #define SHORTINT
00121 #endif
00122 
00123 /*
00124  *   This is the structure definition for resident fonts.  We use
00125  *   a small and simple hash table to handle these.  We don't need
00126  *   a big hash table.
00127  */
00128 #define RESHASHPRIME (73)
00129 struct resfont {
00130    struct resfont *next ;
00131    char *Keyname, *PSname, *TeXname, *Fontfile, *Vectfile;
00132    char *specialinstructions ;
00133    char *downloadheader ; /* possibly multiple files */
00134    quarterword sent ;
00135 } ;
00136 
00137 /*
00138  *   A chardesc describes an individual character.  Before the fonts are
00139  *   downloaded, the flags indicate that the character has already been used
00140  *   with the following meanings:
00141  */
00142 typedef struct tcd {
00143    integer TFMwidth ;
00144    quarterword *packptr ;
00145    shalfword pixelwidth ;
00146    quarterword flags, flags2 ;
00147 } chardesctype ;
00148 #define EXISTS (1)
00149 #define PREVPAGE (2)
00150 #define THISPAGE (4)
00151 #define TOOBIG (8) /* not used at the moment */
00152 #define REPACKED (16)
00153 #define BIGCHAR (32)
00154 #define STATUSFLAGS (EXISTS|REPACKED|BIGCHAR)
00155 /*
00156  *   The new field flags2 above is now an immutable field (once a font is
00157  *   loaded); for now it only indicates whether a character EXISTS or not.
00158  *   This fixes a problem with -G.
00159  */
00160 /*
00161  *   A fontdesc describes a font.  The name, area, and scalename are located in
00162  *   the string pool. The nextsize pointer is used to link fonts that are used
00163  *   in included psfiles and differ only in scaledsize.  Such fonts also have
00164  *   a non-NULL scalename that gives the scaledsize as found in the included
00165  *   file.  The psflag indicates that the font has been used in an included
00166  *   psfile.  It can be 0, PREVPAGE, THISPAGE, or EXISTS.
00167  */
00168 typedef struct tfd {
00169    integer checksum, scaledsize, designsize, thinspace ;
00170    halfword dpi, loadeddpi ;
00171    halfword alreadyscaled ;
00172    halfword psname ;
00173    halfword loaded ;
00174    quarterword psflag;
00175    quarterword codewidth ;
00176    integer maxchars ;
00177    char *name, *area ;
00178    struct resfont *resfont ;
00179    struct tft *localfonts ;
00180    struct tfd *next ;
00181    struct tfd *nextsize;
00182    char *scalename;
00183    chardesctype *chardesc ;
00184 } fontdesctype ;
00185 
00186 /*  A fontmap associates a fontdesc with a font number.
00187  */
00188 typedef struct tft {
00189    integer fontnum ;
00190    fontdesctype *desc ;
00191    struct tft *next ;
00192 } fontmaptype ;
00193 
00194 /*   Virtual fonts require a `macro' capability that is implemented by
00195  *   using a stack of `frames'.
00196  */
00197 typedef struct {
00198    quarterword *curp, *curl ;
00199    fontdesctype *curf ;
00200    fontmaptype *ff ;
00201 } frametype ;
00202 
00203 /*
00204  *   The next type holds the font usage information in a 256-bit table;
00205  *   there's a 1 for each character that was used in a section.
00206  */
00207 typedef struct {
00208    fontdesctype *fd ;
00209    halfword psfused ;
00210    halfword bitmap[16] ;
00211 } charusetype ;
00212 
00213 /*   Next we want to record the relevant data for a section.  A section is
00214  *   a largest portion of the document whose font usage does not overflow
00215  *   the capacity of the printer.  (If a single page does overflow the
00216  *   capacity all by itself, it is made into its own section and a warning
00217  *   message is printed; the page is still printed.)
00218  *
00219  *   The sections are in a linked list, built during the prescan phase and
00220  *   processed in proper order (so that pages stack correctly on output) during
00221  *   the second phase.
00222  */
00223 typedef struct t {
00224    integer bos ;
00225    struct t *next ;
00226    halfword numpages ;
00227 } sectiontype ;
00228 
00229 /*
00230  *   Sections are actually represented not by sectiontype but by a more
00231  *   complex data structure of variable size, having the following layout:
00232  *      sectiontype sect ;
00233  *      charusetype charuse[numfonts] ;
00234  *      fontdesctype *sentinel = NULL ;
00235  *   (Here numfonts is the number of bitmap fonts currently defined.)
00236  *    Since we can't declare this or take a sizeof it, we build it and
00237  *   manipulate it ourselves (see the end of the prescan routine).
00238  */
00239 /*
00240  *   This is how we build up headers and other lists.
00241  */
00242 struct header_list {
00243    struct header_list *next ;
00244    char *Hname ;
00245    char name[1] ;
00246 } ;
00247 /*
00248  *   Some machines define putlong in their library.
00249  *   We get around this here.
00250  */
00251 #define putlong was_putlong
00252 /*
00253  *   Information on available paper sizes is stored here.
00254  */
00255 struct papsiz {
00256    struct papsiz *next ;
00257    integer xsize, ysize ;
00258    char *name ;
00259    char *specdat ;
00260 } ;
00261 #ifdef MVSXA /* IBM: MVS/XA */
00262 /* this is where we fix problems with conflicts for truncation
00263    of long names (we might only do this if LONGNAME not set but ...) */
00264 #   define pprescanpages pprscnpgs  /* confict with pprescan */
00265 #   define flushDashedPath flshDshdPth  /* conflict with flushDash */
00266 #   define PageList PgList  /* re-definition conflict with pagelist  */
00267 /* adding ascii2ebcdic conversion table to extern */
00268     extern char ascii2ebcdic[] ;
00269 #endif  /* IBM: MVS/XA */
00270 #ifdef VMCMS /* IBM: VM/CMS */
00271 /* this is where we fix problems with conflicts for truncation
00272    of long names (we might only do this if LONGNAME not set but ...) */
00273 #   define pprescanpages pprscnpgs  /* confict with pprescan */
00274 #   define flushDashedPath flshDshdPth  /* conflict with flushDash */
00275 /* adding ascii2ebcdic conversion table to extern */
00276     extern char ascii2ebcdic[] ;
00277 /* redefining fopen for VMCMS, see DVIPSCMS.C */
00278     extern FILE *cmsfopen() ;
00279 #   ifdef fopen
00280 #      undef fopen
00281 #   endif
00282 #   define fopen cmsfopen
00283 #define downloadpspk dnldpspk
00284 #endif  /* IBM: VM/CMS */
00285 /*
00286  *   Remove namespace conflict with standard library on Macintosh
00287  */
00288 #ifdef __THINK__
00289 #define newstring newpoolstring
00290 #endif
00291 
00292 #ifndef VOID
00293 #define VOID void
00294 #endif
00295 
00296 #define USE_PCLOSE (801)
00297 #define USE_FCLOSE (802)
00298 
00299 /* Things that KPATHSEA knows, and are useful even without it. */
00300 #if !defined(KPATHSEA)
00301 
00302 #if defined(MSDOS) || defined(OS2) || defined(WIN32)
00303 #define FOPEN_ABIN_MODE "ab"
00304 #define FOPEN_RBIN_MODE "rb"
00305 #else
00306 #define FOPEN_ABIN_MODE "a"
00307 #define FOPEN_RBIN_MODE "r"
00308 #endif
00309 
00310 #if (defined MSDOS || defined OS2 || defined WIN32)
00311 #define WRITEBIN "wb"
00312 #else
00313 #ifdef VMCMS
00314 #define WRITEBIN "wb, lrecl=1024, recfm=f"
00315 #else
00316 #define WRITEBIN "w"
00317 #endif
00318 #endif
00319 
00320 #if defined(WIN32)
00321 #define STDC_HEADERS
00322 #include <io.h>
00323 #include <fcntl.h>
00324 #define O_BINARY _O_BINARY
00325 #define popen _popen
00326 #define pclose _pclose
00327 #define register
00328 #define SET_BINARY(fd) _setmode((fd), _O_BINARY)
00329 #else /* !WIN32 */
00330 #define SET_BINARY(fd)
00331 #endif
00332 
00333 #if defined(DEVICESEP)
00334 #define IS_DEVICE_SEP(c) ((c) == DEVICESEP)
00335 #else
00336 #define IS_DEVICE_SEP(c) 0
00337 #endif
00338 #define STREQ(s1, s2) (((s1) != NULL) && ((s2) != NULL) && !strcmp((s1), (s2)))
00339 
00340 #if defined(MSDOS) || defined(OS2) || defined(WIN32)
00341 #define NAME_BEGINS_WITH_DEVICE(name) (*(name) && IS_DEVICE_SEP((name)[1]))
00342 #define IS_DIR_SEP(c) ((c) == '/' || (c) == '\\')
00343 #define FILESTRCASEEQ(s1, s2) (strcasecmp (s1, s2) == 0)
00344 #else
00345 #define NAME_BEGINS_WITH_DEVICE(name) 0
00346 #define IS_DIR_SEP(c) ((c) == DIRSEP)
00347 #define FILESTRCASEEQ STREQ
00348 #endif
00349 
00350 #define TOLOWER(c) tolower(c)
00351 #define ISALNUM(c) isalnum(c)
00352 #define ISXDIGIT(c) (isascii (c) && isxdigit(c))
00353 
00354  /* To Prototype or not to prototype ? */
00355 #ifdef NeedFunctionPrototypes
00356 
00357 #define AA(args) args /* For an arbitrary number; ARGS must be in parens.  */
00358 
00359 #define P1H(p1) (p1)
00360 #define P2H(p1,p2) (p1, p2)
00361 #define P3H(p1,p2,p3) (p1, p2, p3)
00362 #define P4H(p1,p2,p3,p4) (p1, p2, p3, p4)
00363 #define P5H(p1,p2,p3,p4,p5) (p1, p2, p3, p4, p5)
00364 #define P6H(p1,p2,p3,p4,p5,p6) (p1, p2, p3, p4, p5, p6)
00365 
00366 #define P1C(t1,n1)(t1 n1)
00367 #define P2C(t1,n1, t2,n2)(t1 n1, t2 n2)
00368 #define P3C(t1,n1, t2,n2, t3,n3)(t1 n1, t2 n2, t3 n3)
00369 #define P4C(t1,n1, t2,n2, t3,n3, t4,n4)(t1 n1, t2 n2, t3 n3, t4 n4)
00370 #define P5C(t1,n1, t2,n2, t3,n3, t4,n4, t5,n5) \
00371   (t1 n1, t2 n2, t3 n3, t4 n4, t5 n5)
00372 #define P6C(t1,n1, t2,n2, t3,n3, t4,n4, t5,n5, t6,n6) \
00373   (t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6)
00374 
00375 #else /* no function prototypes */
00376 
00377 #define AA(args) ()
00378 
00379 #define P1H(p1) ()
00380 #define P2H(p1, p2) ()
00381 #define P3H(p1, p2, p3) ()
00382 #define P4H(p1, p2, p3, p4) ()
00383 #define P5H(p1, p2, p3, p4, p5) ()
00384 #define P6H(p1, p2, p3, p4, p5, p6) ()
00385 
00386 #define P1C(t1,n1) (n1) t1 n1;
00387 #define P2C(t1,n1, t2,n2) (n1,n2) t1 n1; t2 n2;
00388 #define P3C(t1,n1, t2,n2, t3,n3) (n1,n2,n3) t1 n1; t2 n2; t3 n3;
00389 #define P4C(t1,n1, t2,n2, t3,n3, t4,n4) (n1,n2,n3,n4) \
00390   t1 n1; t2 n2; t3 n3; t4 n4;
00391 #define P5C(t1,n1, t2,n2, t3,n3, t4,n4, t5,n5) (n1,n2,n3,n4,n5) \
00392   t1 n1; t2 n2; t3 n3; t4 n4; t5 n5;
00393 #define P6C(t1,n1, t2,n2, t3,n3, t4,n4, t5,n5, t6,n6) (n1,n2,n3,n4,n5,n6) \
00394   t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; t6 n6;
00395 
00396 #endif /* function prototypes */
00397 
00398 #ifdef NeedFunctionPrototypes
00399 #define P9C(t1,n1, t2,n2, t3,n3, t4,n4, t5,n5, t6,n6, t7,n7, t8,n8, t9,n9) \
00400   (t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6, t7 n7, t8 n8, t9 n9)
00401 #else
00402 #define P9C(t1,n1, t2,n2, t3,n3, t4,n4, t5,n5, t6,n6, t7,n7, t8,n8, t9,n9) \
00403   t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; t6 n6; t7 n7; t8 n8; t9 n9;
00404 #endif
00405 
00406 #endif