home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
text
/
tex
/
pastex
/
archives
/
dvidvi1_0.lha
/
DviDvi
/
dvidvi.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-28
|
33KB
|
1,295 lines
/*
* This program converts dvi files to dvi files;
* the command line options are:
*
* page n is first page selected -f n
* page n is last page selected -l n
* print at most n pages -n n
* include pages (ranges allowed) -i { n1..n2 | n1 }[,...]
* exclude pages (ranges allowed) -x { n1..n2 | n1 }[,...]
* work in quiet mode -q
* reverse pages -r
* select even -m 2:1
* select odd -m 2:0
* print both on same page -m 2:0,1(5.5in,0in)
* do folded brochures -m 4:-3,0(5.5in,0in)
* -m 4:1,-2(5.5in,0in)
* etc.
*
* scale magnification -sm m
* scale document-width -sw m
* scale document-height -sh m
*
* The arguments m are instances of magsteps. For example -sm 2
* multiplies the document-magnification by magstep(2) (1.44) and
* -sw -2 multiplies the document-with by magstep(2) (0.694).
*
* The original program is by Tomas Rokicki (version 0.5) but it was
* modified and improved by Esteban ZIMANYI ezimanyi@rc1.vub.ac.be
* to give version 1.0.
*
* This version has been tested for the IBM PC and compatibles under
* compilers Turbo C 2.0 and Microsoft C 6.0.
*
* The options -sm, -sw and -sh were added by Jochen Wiedmann to support
* PasTeX on the Amiga. This was needed because PasTeX doesn't ignore
* the Width- and Height-Parameters included in the Postamble. PasTeX
* needs them to be rearranged to work fine.
*
*/
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#define BANNER "\nThis is dvidvi 1.0, Copyright (C) 1988-91, Radical Eye Software\n"
#define STRINGSIZE (500) /* maximum number of strings in program */
#ifndef VMS
#include <stdio.h>
#include <string.h>
#include <math.h>
#else /* VMS */
#include "sys$library:stdio.h" /* AKT: added sys$library: */
#include <alloc.h>
#endif /* VMS */
#define MAXPPERP (32)
/* defines READBIN, WRITEBIN, PATHSEP and DIRSEP*/
#ifdef MSDOS
#define READBIN "rb" /* MSDOS must use binary mode */
#define WRITEBIN "wb"
#define PATHSEP ';'
#define DIRSEP '\\'
#else
#ifdef VMS
#define READBIN "rb" /* VMS must use binary mode */
#define WRITEBIN "wb"
#define PATHSEP ','
#define DIRSEP ':'
#else
#define READBIN "r" /* UNIX doesn't care */
#define WRITEBIN "w"
#define PATHSEP ':'
#define DIRSEP '/'
#endif
#endif
#ifdef XENIX
#define SHORTINT
#else
#undef SHORTINT
#endif
#ifdef MSDOS
#define SHORTINT
#endif
/*
* Type declarations. integer must be a 32-bit signed; shalfword must
* be a sixteen-bit signed; halfword must be a sixteen-bit unsigned;
* quarterword must be an eight-bit unsigned.
*/
typedef long integer;
typedef char boolean;
typedef short shalfword ;
typedef unsigned long longword;
typedef unsigned short halfword ;
typedef unsigned char quarterword ;
typedef short Boolean ;
/*
* Some globals to keep everyone happy.
*/
integer numpages ; /* the total number of pages in the dvi file. */
integer TeXfonts[256] ; /* information about each font */
char fontseen[256] ; /* have we defined this font yet? */
int modulo ; /* our mod value */
struct pagespec {
int pageno, reversed ;
long hoffset, voffset ; /* in scaled points */
} pages[MAXPPERP] ; /* the organization of the pages on output */
int pagesperpage ; /* how many pages crammed onto each page? */
FILE *infile ; /* input dvi file (cannot be a stream) */
FILE *outfile ; /* output dvi file */
char *temp ; /* a temporary place to put things */
char *nextstring, *maxstring ;
char *oname ; /* output dvi file name */
char *iname ; /* input dvi file name */
char *strings ; /* pointer of the string pool */
char banner[] = BANNER ; /* the startup message */
integer inlength ; /* the length of the input dvi file */
integer postloc ; /* location of the postamble */
integer mag ; /* magnification factor */
integer pagecount ; /* number of actual pages */
integer landscape = 0; /* if landscape special, here it is! */
int rem0special ; /* should we remove the first first-page special? */
integer prevpp = -1 ; /* previous page pointer on output */
integer outputpages ; /* number of pages output */
integer dviloc ; /* our position in the output file */
integer pagefake ; /* number of pages, rounded up to multiple of modulo */
Boolean firsttransf = 0, lasttransf = 0;
integer firstpage ; /* first page selected (option -p) */
integer lastpage ; /* last page selected (option -l) */
integer maxpages ; /* maximum number of page selected (option -n) */
short quiet ; /* quiet mode (option -q) */
Boolean exctransf[40][2] ; /* if the ranges of pages to exclude (option -x)
have to be transformed */
integer exclude[40][2] ; /* the ranges of pages to exclude (option -x)
It is supposed that there are at most 40 ranges
to exclude in the command line */
short excludeseq ; /* number of ranges to exclude (option -x) */
Boolean inctransf[40][2] ; /* if the ranges of pages to exclude (option -x)
have to be transformed */
integer include[40][2] ; /* the ranges of pages to include (option -i)
It is supposed that there are at most 40 ranges
to include in the command line */
short includeseq ; /* number of ranges to include (option -i) */
integer *pageloc ;
integer *pagenumbers ;
int prettycolumn ; /* the column we are at when running pretty */
/* Added 28.07.1993, Jochen Wiedmann */
double scale_magstep = 0.0;
double scale_width = 0.0;
double scale_height = 0.0;
/* */
/*
* This array holds values that indicate the length of a command, if
* we aren't concerned with that command (which is most of them) or
* zero, if it is a special case. This makes running through the
* dvi file a lot easier (and probably faster) than any form of
* dispatch table, especially since we really don't care what the
* pages are made of.
*/
short comlen[256] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0-15 */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 16-31 */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 32-47 */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 48-63 */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 64-79 */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80-95 */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 96-111 */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 112-127 */
2, 3, 4, 5, 9, 2, 3, 4, 5, 9, 1, 0, 0, 1, 1, 2, /* 128-143 */
3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 2, 3, 4, /* 144-159 */
5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, /* 160-175 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 176-191 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 192-207 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 208-223 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 5, 0, /* 224-239 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };/* 240-255 */
/*
* Input bytes from the dvi file.
* These routines could probably be sped up significantly; but they are
* very machine dependent, so I will leave such tuning to the installer.
* They simply get and return bytes in batches of one, two, three, and four,
* updating the current position as necessary.
*/
void
abortpage()
{
error("! unexpected eof on DVI file") ;
}
shalfword dvibyte()
{
register shalfword i ;
if ((i=getc(infile))==EOF)
abortpage() ;
return(i) ;
}
halfword twobytes()
{
register halfword i ;
i = dvibyte() ;
return(i*256+dvibyte()) ; }
integer threebytes()
{
register integer i ;
i = twobytes() ;
return(i*256+dvibyte()) ; }
longword fourbytes()
{
register longword i;
i = twobytes();
return((i<<16)+twobytes());
}
shalfword
signedbyte()
{
register shalfword i ;
if ((i=getc(infile))==EOF)
abortpage() ;
if (i<128) return(i) ;
else return(i-256) ;
}
shalfword
signedpair()
{
register shalfword i ;
i = signedbyte() ;
return(i*256+dvibyte()) ;
}
integer
signedtrio()
{
register integer i ;
i = signedpair() ;
return(i*256+dvibyte()) ;
}
integer
signedquad()
{
register integer i ;
i = signedpair() ;
return(i*65536+twobytes())