summaryrefslogtreecommitdiff
path: root/dviware/epson
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /dviware/epson
Initial commit
Diffstat (limited to 'dviware/epson')
-rw-r--r--dviware/epson/eps-0.2/Makefile21
-rw-r--r--dviware/epson/eps-0.2/README.DJG23
-rw-r--r--dviware/epson/eps-0.2/README.LINUX70
-rw-r--r--dviware/epson/eps-0.2/README.TC23
-rw-r--r--dviware/epson/eps-0.2/eps/Bset.c63
-rw-r--r--dviware/epson/eps-0.2/eps/Bset.h28
-rw-r--r--dviware/epson/eps-0.2/eps/Makefile31
-rw-r--r--dviware/epson/eps-0.2/eps/Makefile.bak30
-rw-r--r--dviware/epson/eps-0.2/eps/eps.c680
-rw-r--r--dviware/epson/eps-0.2/eps/epson.c157
-rw-r--r--dviware/epson/eps-0.2/eps/epson.h165
-rw-r--r--dviware/epson/eps-0.2/eps/makefile.djg27
-rw-r--r--dviware/epson/eps-0.2/eps/version.h1
-rw-r--r--dviware/epson/eps-0.2/h/PROTO.h165
-rw-r--r--dviware/epson/eps-0.2/h/bounds.h9
-rw-r--r--dviware/epson/eps-0.2/h/conv.h106
-rw-r--r--dviware/epson/eps-0.2/h/decinf.h21
-rw-r--r--dviware/epson/eps-0.2/h/dviclass.h74
-rw-r--r--dviware/epson/eps-0.2/h/dvicodes.h78
-rw-r--r--dviware/epson/eps-0.2/h/dvistate.h116
-rw-r--r--dviware/epson/eps-0.2/h/error.h13
-rw-r--r--dviware/epson/eps-0.2/h/fio.h57
-rw-r--r--dviware/epson/eps-0.2/h/font.h305
-rw-r--r--dviware/epson/eps-0.2/h/fontconf.h12
-rw-r--r--dviware/epson/eps-0.2/h/getopt.h17
-rw-r--r--dviware/epson/eps-0.2/h/gfclass.h62
-rw-r--r--dviware/epson/eps-0.2/h/gfcodes.h48
-rw-r--r--dviware/epson/eps-0.2/h/gripes.h15
-rw-r--r--dviware/epson/eps-0.2/h/num.h44
-rw-r--r--dviware/epson/eps-0.2/h/pkdetails.h24
-rw-r--r--dviware/epson/eps-0.2/h/postamble.h51
-rw-r--r--dviware/epson/eps-0.2/h/sdecode.h56
-rw-r--r--dviware/epson/eps-0.2/h/search.h40
-rw-r--r--dviware/epson/eps-0.2/h/seek.h17
-rw-r--r--dviware/epson/eps-0.2/h/tfm.h89
-rw-r--r--dviware/epson/eps-0.2/h/types.h109
-rw-r--r--dviware/epson/eps-0.2/lib/Makefile103
-rw-r--r--dviware/epson/eps-0.2/lib/bcopy.c31
-rw-r--r--dviware/epson/eps-0.2/lib/bzero.c18
-rw-r--r--dviware/epson/eps-0.2/lib/conv.c53
-rw-r--r--dviware/epson/eps-0.2/lib/dviclass.c98
-rw-r--r--dviware/epson/eps-0.2/lib/dvistate.c229
-rw-r--r--dviware/epson/eps-0.2/lib/error.c185
-rw-r--r--dviware/epson/eps-0.2/lib/findpost.c86
-rw-r--r--dviware/epson/eps-0.2/lib/fio.c44
-rw-r--r--dviware/epson/eps-0.2/lib/font.c508
-rw-r--r--dviware/epson/eps-0.2/lib/font_subr.c234
-rw-r--r--dviware/epson/eps-0.2/lib/getopt.c501
-rw-r--r--dviware/epson/eps-0.2/lib/gfclass.c82
-rw-r--r--dviware/epson/eps-0.2/lib/gffont.c924
-rw-r--r--dviware/epson/eps-0.2/lib/gripes0.c87
-rw-r--r--dviware/epson/eps-0.2/lib/gripes1.c144
-rw-r--r--dviware/epson/eps-0.2/lib/magfactor.c39
-rw-r--r--dviware/epson/eps-0.2/lib/makefile.djg109
-rw-r--r--dviware/epson/eps-0.2/lib/pkfont.c698
-rw-r--r--dviware/epson/eps-0.2/lib/pxlfont.c293
-rw-r--r--dviware/epson/eps-0.2/lib/rotate.c152
-rw-r--r--dviware/epson/eps-0.2/lib/rstfont.c285
-rw-r--r--dviware/epson/eps-0.2/lib/scaletfm.c117
-rw-r--r--dviware/epson/eps-0.2/lib/scanpost.c104
-rw-r--r--dviware/epson/eps-0.2/lib/sdecode.c588
-rw-r--r--dviware/epson/eps-0.2/lib/search.c173
-rw-r--r--dviware/epson/eps-0.2/lib/seek.c159
-rw-r--r--dviware/epson/eps-0.2/lib/skip.c30
-rw-r--r--dviware/epson/eps-0.2/lib/split.c224
-rw-r--r--dviware/epson/eps-0.2/lib/strsave.c31
-rw-r--r--dviware/epson/eps-0.2/lib/tempfile.c97
-rw-r--r--dviware/epson/eps-0.2/lib/tfm.c109
-rw-r--r--dviware/epson/eps-0.2/lib/tfmfont.c243
-rw-r--r--dviware/epson/epson/240/cmcsc10.pkbin0 -> 4404 bytes
-rw-r--r--dviware/epson/epson/240/cmmi10.pkbin0 -> 4956 bytes
-rw-r--r--dviware/epson/epson/240/cmmi7.pkbin0 -> 3728 bytes
-rw-r--r--dviware/epson/epson/240/cmr10.pkbin0 -> 4264 bytes
-rw-r--r--dviware/epson/epson/240/cmr12.pkbin0 -> 4912 bytes
-rw-r--r--dviware/epson/epson/240/cmr17.pkbin0 -> 6864 bytes
-rw-r--r--dviware/epson/epson/240/cmr6.pkbin0 -> 2996 bytes
-rw-r--r--dviware/epson/epson/240/cmr7.pkbin0 -> 3388 bytes
-rw-r--r--dviware/epson/epson/240/cmr8.pkbin0 -> 3636 bytes
-rw-r--r--dviware/epson/epson/240/cmsy10.pkbin0 -> 5036 bytes
-rw-r--r--dviware/epson/epson/240/cmsy7.pkbin0 -> 3904 bytes
-rw-r--r--dviware/epson/epson/240/cmti10.pkbin0 -> 4936 bytes
-rw-r--r--dviware/epson/epson/346/cmbx10.pkbin0 -> 5936 bytes
82 files changed, 9625 insertions, 0 deletions
diff --git a/dviware/epson/eps-0.2/Makefile b/dviware/epson/eps-0.2/Makefile
new file mode 100644
index 0000000000..decca0695f
--- /dev/null
+++ b/dviware/epson/eps-0.2/Makefile
@@ -0,0 +1,21 @@
+%.o: %.c
+ cc -x c++ -c -O $<
+
+BINDIR = /usr/local/bin
+
+all: LIB EPS
+
+EPS:
+ ( cd eps; $(MAKE) )
+
+LIB:
+ ( cd lib; $(MAKE) )
+
+install:
+ ( cd eps; $(MAKE) install BINDIR=${BINDIR} )
+
+clean:
+ for dir in lib eps; do \
+ ( cd $$dir; $(MAKE) clean ) \
+ done
+
diff --git a/dviware/epson/eps-0.2/README.DJG b/dviware/epson/eps-0.2/README.DJG
new file mode 100644
index 0000000000..a0e0c9ee2a
--- /dev/null
+++ b/dviware/epson/eps-0.2/README.DJG
@@ -0,0 +1,23 @@
+This will work on MSDOS with djgpp. I haven't finished all the
+Makefiles yet.
+
+This is basically the procedure:
+
+1. cd lib. make -f makefile.djg.
+
+2. cd eps. make -f makefile.djg
+
+To print this with MSDOS you need to use
+
+copy /b <file> prn:
+
+You can change the location of 'fontdesc' by editing the Makefile.djg
+in lib.
+
+Here is an example fontdesc for MSDOS:
+
+font pk epson 3 d:\\tex\\fonts\\epson\\%m\\%f.pk
+
+NOTICE the '\\'. This string winds up going through sprintf somewhere
+in the code, that's why.
+
diff --git a/dviware/epson/eps-0.2/README.LINUX b/dviware/epson/eps-0.2/README.LINUX
new file mode 100644
index 0000000000..1230fc7578
--- /dev/null
+++ b/dviware/epson/eps-0.2/README.LINUX
@@ -0,0 +1,70 @@
+1. What is this?
+
+ This is a dvi driver for epson 9-pin dot matrix. It was built from
+the mctex package, which is found in the standard TeX distribution.
+
+ I converted all the source to c++. This was done mostly to
+catch some portability problems when I built this for MSDOS.
+
+ Next, I added the epson driver which is in the eps directory.
+This driver is designed to use 240 x 216 dpi fonts. I have included
+the standard U_WASH.mf set of Metafont modes, which includes the
+setting for building epson fonts.
+
+ I also modified the mctex code to allow for separate vertical
+and horizontal dpi, since my epson is 240 x 216.
+
+ Just to wet your appetite I am including the necessary fonts
+to print 'sample.tex'. If you want other fonts you'll need to use
+Metafont to make them. You may have defs for this in your 'modes.mf',
+under 'EpsonMXFX'. The only set of fonts I have for epson is far too
+extensive for any possible use, and I haven't had time to weed through
+them to eliminate seldom-used stuff. If anyone has a handy way to
+build just a minimal set of TeX and LaTeX fonts please let me know.
+
+Note: You must really be desperate to print TeX on your epson. This
+is never going to look like a laser printer. And I hope you have lots
+of time on your hands to wait for the printout, cause you'll need it.
+I must really be desperate to write this. But if you really must try
+this, you'll probably get as good a result out of your epson as is
+possible.
+
+2. You'll need to install a fontdesc file to describe the location of
+your fonts. Here's mine:
+
+font pk epson 3 /usr/local/lib/tex/fonts/epson/%m/%f.pk
+
+I put this file in '/usr/local/lib/tex/fonts/fontdesc'. You may want
+to make /usr/local/lib/tex a symlink to wherever TeX lives (/usr/TeX,
+maybe?) This says that the font cmr10 at 240x216 dpi can be found at
+'/usr/local/lib/tex/fonts/epson/240/cmr10.pk'. This is the
+convention used by TeX software on MSDOS. Actually, I think its a
+good one. But feel free to change it.
+
+3. Supported printers? I don't know. It works on my Panasonic
+kx-1080i. Other epson 9-pin compatibles might work. My printer
+accepts the code 'esc-f0#' where # is a number of spaces to skip. I
+called this the HasFastSpace switch (-f). Some epson-types don't seem
+to accept this. It's not really needed anyway, so it's off by
+default.
+
+Oh yes, typing eps will give you the usage.
+
+Oh, one more thing. On my 0.99.7 system I can't get /dev/lp1 to work
+unless I say 'lpcntl /dev/lp1 7' to turn on the interrupt code.
+Otherwise I get all kinds of errors when I send a reset code to the
+printer.
+
+4. Questions:
+
+"Why should I use this instead of dvips + ghostscript?"
+
+Because it uses a special set of bitmaps fonts made just for the 9-pin
+epson (240 x 216 dpi). The results are much better quality. Or
+should I say, much less bad quality?
+
+5. Please send complaints, bug reports, patches, complements, money,
+etc. to
+ neal@ctd.comsat.com
+
+6. Someone please teach me to write recursive make files.
diff --git a/dviware/epson/eps-0.2/README.TC b/dviware/epson/eps-0.2/README.TC
new file mode 100644
index 0000000000..daea5169fb
--- /dev/null
+++ b/dviware/epson/eps-0.2/README.TC
@@ -0,0 +1,23 @@
+This worked at one time on borland c++. It just needs Makefiles in
+lib and in eps directories. You will need a response file for tlib in
+the lib directory. I did this once before, but lost it when I ported
+this stuff to Linux.
+
+IMPORTANT: MSDOS doesn't provide enough memory for a full bitmap.
+You MUST define TWOPASS. This will force two passes over a half-page
+bitmap.
+
+To print this with MSDOS you need to do
+
+copy /b <file> prn:
+
+You can change the location of 'fontdesc' by editing the Makefile.djg
+in lib.
+
+Here is an example fontdesc for MSDOS:
+
+font pk epson 3 d:\\tex\\fonts\\epson\\%m\\%f.pk
+
+NOTICE the '\\'. This string winds up going through sprintf somewhere
+in the code, that's why.
+
diff --git a/dviware/epson/eps-0.2/eps/Bset.c b/dviware/epson/eps-0.2/eps/Bset.c
new file mode 100644
index 0000000000..c51dabab09
--- /dev/null
+++ b/dviware/epson/eps-0.2/eps/Bset.c
@@ -0,0 +1,63 @@
+static const char rcsid[] = "$Header: c:/mctex/imagen/rcs/bset.c 1.1 91/08/05 23:41:24 ROOT_DOS Exp Locker: ROOT_DOS $";
+
+/* Copyright (c) 1993 Neal Becker
+ * All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+*/
+
+/*
+$Log: bset.c $
+ * Revision 1.1 91/08/05 23:41:24 ROOT_DOS
+ * Initial revision
+ *
+*/
+
+static const int BitMask[ 8 ] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+
+inline int min( int a, int b ) {
+ return ( a > b ) ? b : a;
+}
+
+inline unsigned char TopPart( char S, int Pos ) {
+ return ((unsigned char)S) >> Pos;
+}
+
+inline unsigned char BottomPart( char S, int Pos ) {
+ return S << ( 8 - Pos );
+}
+
+static void MemOr( char* D, char* S, int count ) {
+ for(; count != 0; count--, D++, S++ )
+ *D |= *S;
+}
+
+void Bset( char* S, int Slen, char* D, int Dlen, int Pos ) {
+ char* Dest = D + ( Pos / 8 );
+ int BitPos = Pos % 8;
+ char* Dend = D + Dlen - 1;
+ int BytesToMove = min( Slen, Dlen - ( Pos / 8 ) );
+ if( BitPos == 0 ) {
+ MemOr( Dest, S, BytesToMove );
+ }
+ else {
+ for( ; BytesToMove != 0; BytesToMove--, Dest++, S++ ) {
+ *Dest |= TopPart( *S, BitPos );
+ if( Dest + 1 > Dend ) break;
+ *( Dest + 1 ) |= BottomPart( *S, BitPos );
+ }
+ }
+}
+
+void SetBits( int Slen, char* D, int Dlen, int Pos ) {
+ char* Dest = D + ( Pos / 8 );
+ int BitPos = 7 - (Pos % 8);
+ int BitsToMove = min( Slen, Dlen - Pos );
+ for( ; BitsToMove > 0 ; BitsToMove-- ) {
+ *Dest |= BitMask[ BitPos-- ];
+ if( BitPos < 0 ) {
+ Dest++;
+ BitPos = 7;
+ }
+ }
+}
diff --git a/dviware/epson/eps-0.2/eps/Bset.h b/dviware/epson/eps-0.2/eps/Bset.h
new file mode 100644
index 0000000000..1ffd214ab8
--- /dev/null
+++ b/dviware/epson/eps-0.2/eps/Bset.h
@@ -0,0 +1,28 @@
+#ifndef Bset_h
+#define Bset_h
+
+/* $Header: c:/mctex/imagen/rcs/bset.h 1.1 91/08/05 23:41:08 ROOT_DOS Exp Locker: ROOT_DOS $ */
+
+/* Copyright (c) 1993 Neal Becker
+ * All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+*/
+
+/*
+$Log: bset.h $
+ * Revision 1.1 91/08/05 23:41:08 ROOT_DOS
+ * Initial revision
+ *
+*/
+
+void Bset( char* S, int Slen, char* D, int Dlen, int Pos );
+
+void SetBits( int Slen, char* D, int Dlen, int Pos );
+
+#endif
+
+
+
+
+
diff --git a/dviware/epson/eps-0.2/eps/Makefile b/dviware/epson/eps-0.2/eps/Makefile
new file mode 100644
index 0000000000..a8fbcb6462
--- /dev/null
+++ b/dviware/epson/eps-0.2/eps/Makefile
@@ -0,0 +1,31 @@
+CC = gcc
+
+CFLAGS= -I../h -O
+
+%.o: %.c
+ ${CC} -c ${CFLAGS} -x c++ $<
+
+SRCS= eps.c epson.c Bset.c
+
+OBJS= eps.o epson.o Bset.o
+
+LIBS= ../lib/lib.a
+
+all: eps
+
+eps : ${OBJS}
+ ${CC} ${CFLAGS} ${OBJS} ${LIBS} -o $@
+
+install:
+ install -s eps ${BINDIR}
+
+clean:
+ rm eps *.o
+
+MAKEDEPEND = makedepend
+
+depend:
+ ${MAKEDEPEND} -I/usr/g++-include ${CFLAGS} ${SRCS}
+
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
diff --git a/dviware/epson/eps-0.2/eps/Makefile.bak b/dviware/epson/eps-0.2/eps/Makefile.bak
new file mode 100644
index 0000000000..2157763331
--- /dev/null
+++ b/dviware/epson/eps-0.2/eps/Makefile.bak
@@ -0,0 +1,30 @@
+CC = gcc
+
+CFLAGS= -I../h -O
+
+%.o: %.c
+ ${CC} -c ${CFLAGS} -x c++ $<
+
+SRCS= eps.c epson.c Bset.c
+
+OBJS= eps.o epson.o Bset.o
+
+LIBS= ../lib/lib.a
+
+all: eps
+
+eps : ${OBJS}
+ ${CC} ${CFLAGS} ${OBJS} ${LIBS} -o $@
+
+install:
+ install -s eps ${BINDIR}
+
+clean:
+ rm eps *.o
+
+MAKEDEPEND = makedepend
+
+depend:
+ ${MAKEDEPEND} -I/usr/g++-include ${CFLAGS} ${SRCS}
+
+
diff --git a/dviware/epson/eps-0.2/eps/eps.c b/dviware/epson/eps-0.2/eps/eps.c
new file mode 100644
index 0000000000..6b24b563f3
--- /dev/null
+++ b/dviware/epson/eps-0.2/eps/eps.c
@@ -0,0 +1,680 @@
+/* Copyright (c) 1993 Neal Becker
+ * All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+*/
+
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static const char rcsid[] = "$Header: c:/mctex/imagen/rcs/eps.c 1.1 91/08/05 23:40:48 ROOT_DOS Exp Locker: ROOT_DOS $";
+#endif
+
+/*
+ * DVI to Imagen driver
+ *
+ * Reads DVI version 2 files and converts to imPRESS commands for spooling to
+ * the Imagen (via ipr).
+ *
+ * TODO:
+ * think about fonts with characters outside [0..127]
+ */
+
+/*
+$Log: eps.c $
+ * Revision 1.1 91/08/05 23:40:48 ROOT_DOS
+ * Initial revision
+ *
+*/
+
+#include "PROTO.h"
+#include <stdio.h>
+#include "types.h"
+#include "conv.h"
+#include "dviclass.h"
+#include "dvicodes.h"
+#include "error.h"
+#include "fio.h"
+#include "font.h"
+#include "gripes.h"
+#include "dvistate.h"
+#include "version.h"
+
+#include "epson.h"
+#include "Bset.h"
+
+#include <stdlib.h> /* for atoi, exit */
+
+char *ProgName;
+extern char *optarg;
+extern int optind;
+
+/* Globals */
+char serrbuf[BUFSIZ]; /* buffer for stderr */
+
+/*
+ * We store Imagen font family numbers in the f_int field the font
+ * routines allocate for us.
+ */
+
+int LFlag; /* -l => landscape mode */
+int ReversePages; /* -p => [no] page reversal */
+int SFlag; /* -s => silent (no page numbers) */
+int Debug; /* -D => debug flag */
+
+char *PrintEngine; /* e.g., canon, ricoh */
+
+char *DVIFileName; /* name of input DVI file */
+
+epson* Printer;
+
+BitMap* theBitMap;
+
+#ifdef TWOPASS
+static int Pass = 0;
+#endif
+
+static void LoadGlyph(struct glyph* g);
+static void SetGlyph( int c, struct font* f, struct glyph* g);
+
+/*
+ * Assign a unique Imagen family to each font in the DVI file.
+ */
+struct font *
+DefineFont(char* name, i32 dvimag, i32 dvidsz)
+{
+ register struct font *f;
+ char *path;
+
+ f = GetFont(name, dvimag, dvidsz, PrintEngine, &path);
+ if (f == NULL) {
+ GripeCannotGetFont(name, dvimag, dvidsz, PrintEngine, path);
+ return (NULL);
+ }
+ if (Debug) {
+ (void) fprintf(stderr, "[%s -> %s]\n", Font_TeXName(f), path);
+ (void) fflush(stderr);
+ }
+ return (f);
+}
+
+/*
+ * Start a new page (interpreter found a DVI_BOP).
+ */
+void
+BeginPage(i32* count)
+{
+
+ if (!SFlag) {
+ static int beenhere;
+
+ if (beenhere)
+ (void) putc(' ', stderr);
+ else
+ beenhere = 1;
+ (void) fprintf(stderr, "[%ld", (long)count[0]);
+ (void) fflush(stderr);
+ }
+ theBitMap->Clear();
+ Printer->Reset();
+}
+
+/*
+ * End the page (interpreter found a DVI_EOP).
+ */
+void
+EndPage( )
+{
+
+ if (!SFlag) {
+ (void) putc(']', stderr);
+ (void) fflush(stderr);
+ }
+#ifdef TWOPASS
+ Printer->PrintBitMap( *theBitMap );
+ if( Pass % 2 == 1 ) /* finished 2nd pass */
+ Printer->EoP();
+ else /* finished first pass */
+ Printer->SyncVpos();
+#else
+ Printer->PrintBitMap( *theBitMap );
+ Printer->EoP();
+#endif /* TWOPASS */
+}
+
+/*
+ * Perform a \special.
+ * This version ignores all, with a warning.
+ */
+void
+DoSpecial(i32 len)
+{
+
+ error(0, 0, "warning: ignoring \\special");
+ (void) fseek(ds.ds_fp, (long)len, 1);
+}
+
+/*
+ * Set a rule at dvi_hh, dvi_vv.
+ */
+void
+SetRule(i32 h, i32 w)
+{
+ if( LFlag == 0 ) {
+ for( int i = 0; i < h; i++ ) {
+ int Row = dvi_vv - i;
+#ifdef TWOPASS
+ if( Pass % 2 == 1 )
+ Row -= BitMapRows;
+#endif
+ int Pos = dvi_hh - LeftMarginPixels;
+ if( Pos >= 0 ) {
+ if( Row >= 0 && Row < BitMapRows )
+ theBitMap->SetBits( w, Row, Pos );
+ }
+ }
+ }
+ else {
+ for( int i = 0; i < w; i++ ) {
+ int Row = dvi_hh + i;
+#ifdef TWOPASS
+ if( Pass % 2 == 1 )
+ Row -= BitMapRows;
+#endif
+ if( Row >= 0 && Row < BitMapRows ) {
+ int Pos = HPixels - dvi_vv - LeftMarginPixels;
+ if( Pos >= 0 )
+ theBitMap->SetBits( h, Row, Pos );
+ }
+ }
+ }
+}
+
+/*
+ * Main
+ page loop. This reads one page of the DVI file.
+ * Returns 1 for EOP and 0 for end of last page (POST).
+ */
+int
+PageLoop()
+{
+ static struct font NoFont; /* font with zero pspace, etc */
+ register int c;
+ register i32 p;
+ register struct font *f = &NoFont;
+ register FILE *fp = ds.ds_fp;
+ int doingpage = 0, advance;
+#ifdef TWOPASS
+ int Pass = 0;
+ long PageStartPos;
+#endif
+
+ if (ReversePages)
+ if (ds.ds_prevpage == -1)
+ return (0); /* Mark 10:31 (kilroy was here) */
+ else
+ (void) fseek(fp, ds.ds_prevpage, 0);
+#ifdef TWOPASS
+ PageStartPos = ftell( fp );
+#endif
+
+ /*
+ * This would be a `for (;;)', but that makes the function
+ * crawl off the right of the screen.
+ *
+ * We handle ordinary characters early, as they are the
+ * most common opcodes in DVI files, and doing so makes the
+ * loop run faster.
+ */
+loop:
+ c = fgetbyte(fp);
+ if (DVI_IsChar(c)) {
+ register struct glyph *g;
+
+ p = c;
+ advance = 1;
+do_char:
+ g = GLYPH(f, p);
+ if (!GVALID(g)) {
+ GripeBadGlyph(p, f);
+ goto loop;
+ }
+ if ((g->g_flags & GF_SEEN) == 0)
+ LoadGlyph(g);
+ SetGlyph( (int)p, f, g);
+ if (advance) {
+ dvi_h += g->g_tfmwidth;
+ dvi_hh += g->g_pixwidth;
+ p = fromSPh(dvi_h);
+ FIXDRIFT(dvi_hh, p);
+ }
+ goto loop;
+ }
+
+ if (c == EOF) /* unexpected end of DVI file */
+ GripeUnexpectedDVIEOF();
+
+ /*
+ * Gather up a parameter, if known.
+ */
+ switch (DVI_OpLen(c)) {
+
+ case DPL_NONE:
+ break;
+
+ case DPL_SGN1:
+ p = fgetbyte(fp);
+ p = Sign8(p);
+ break;
+
+ case DPL_SGN2:
+ fGetWord(fp, p);
+ p = Sign16(p);
+ break;
+
+ case DPL_SGN3:
+ fGet3Byte(fp, p);
+ p = Sign24(p);
+ break;
+
+ case DPL_SGN4:
+ fGetLong(fp, p);
+ break;
+
+ case DPL_UNS1:
+ p = fgetbyte(fp);
+ p = UnSign8(p);
+ break;
+
+ case DPL_UNS2:
+ fGetWord(fp, p);
+ p = UnSign16(p);
+ break;
+
+ case DPL_UNS3:
+ fGet3Byte(fp, p);
+ p = UnSign24(p);
+ break;
+
+ default:
+ panic("DVI_OpLen(%d) = %d", c, DVI_OpLen(c));
+ /* NOTREACHED */
+ }
+
+ /*
+ * Now switch on the type.
+ */
+ switch (DVI_DT(c)) {
+
+ case DT_SET:
+ advance = 1;
+ goto do_char;
+
+ case DT_PUT:
+ advance = 0;
+ goto do_char;
+
+ case DT_SETRULE:
+ DVIRule(SetRule, 1);
+ goto loop;
+
+ case DT_PUTRULE:
+ DVIRule(SetRule, 0);
+ goto loop;
+
+ case DT_NOP:
+ goto loop;
+
+ case DT_BOP:
+ if (doingpage)
+ GripeUnexpectedOp("BOP (already in page)");
+ DVIBeginPage(BeginPage);
+ doingpage = 1;
+ goto loop;
+
+ case DT_EOP:
+ if (!doingpage)
+ GripeUnexpectedOp("EOP (no BOP)");
+ EndPage();
+#ifdef TWOPASS
+ Pass++;
+ if( Pass % 2 == 1 ) {
+ fseek( fp, PageStartPos, 0 );
+ doingpage = 0;
+ goto loop;
+ }
+ else
+#endif
+ return (1);
+
+ case DT_PUSH:
+ *ds.ds_sp++ = ds.ds_cur;
+ goto loop;
+
+ case DT_POP:
+ ds.ds_cur = *--ds.ds_sp;
+ goto loop;
+
+ case DT_W0:
+ p = dvi_w;
+ goto right;
+
+ case DT_W:
+ dvi_w = p;
+ goto right;
+
+ case DT_X0:
+ p = dvi_x;
+ goto right;
+
+ case DT_X:
+ dvi_x = p;
+ goto right;
+
+ case DT_RIGHT:
+right:
+ dvi_h += p;
+ if (F_SMALLH(f, p)) {
+ dvi_hh += fromSPh(p);
+ p = fromSPh(dvi_h);
+ FIXDRIFT(dvi_hh, p);
+ } else
+ dvi_hh = fromSPh(dvi_h);
+ goto loop;
+
+ case DT_Y0:
+ p = dvi_y;
+ goto down;
+
+ case DT_Y:
+ dvi_y = p;
+ goto down;
+
+ case DT_Z0:
+ p = dvi_z;
+ goto down;
+
+ case DT_Z:
+ dvi_z = p;
+ goto down;
+
+ case DT_DOWN:
+down:
+ dvi_v += p;
+ if (F_SMALLV(f, p)) {
+ dvi_vv += fromSPv(p);
+ p = fromSPv(dvi_v);
+ FIXDRIFT(dvi_vv, p);
+ } else
+ dvi_vv = fromSPv(dvi_v);
+ goto loop;
+
+ case DT_FNTNUM:
+ f = DVIFindFont((i32)(c - DVI_FNTNUM0));
+ goto loop;
+
+ case DT_FNT:
+ f = DVIFindFont(p);
+ goto loop;
+
+ case DT_XXX:
+ DoSpecial(p);
+ goto loop;
+
+ case DT_FNTDEF:
+ SkipFontDef(fp);
+ goto loop;
+
+ case DT_PRE:
+ GripeUnexpectedOp("PRE");
+ /* NOTREACHED */
+
+ case DT_POST:
+ if (doingpage) {
+ GripeUnexpectedOp("POST (no EOP)");
+ /* NOTREACHED */
+ }
+ return (0);
+
+ case DT_POSTPOST:
+ GripeUnexpectedOp("POSTPOST");
+ /* NOTREACHED */
+
+ case DT_UNDEF:
+ GripeUndefinedOp(c);
+ /* NOTREACHED */
+
+ default:
+ panic("DVI_DT(%d) = %d", c, DVI_DT(c));
+ /* NOTREACHED */
+ }
+ /* NOTREACHED */
+}
+
+#if defined( __MSDOS__ )
+# if !defined( __GNUC__ )
+# include <io.h>
+# include <alloc.h>
+# endif /* __GNUC__ */
+# include <fcntl.h>
+extern int _fmode;
+#endif
+
+void ShowUse( const char* ProgName ) {
+ fprintf( stderr, "Usage: %s [delmpHVsDXYfv]\n", ProgName );
+ fprintf( stderr, "\
+ \t-d maxdrift\n\
+ \t-e engine\n\
+ \t-l landscape\n\
+ \t-m mag\n\
+ \t-p toggle page reversal\n\
+ \t-H horiz. res. (dpi)\n\
+ \t-V vert. res. (dpi)\n\
+ \t-s silent\n\
+ \t-D debug\n\
+ \t-X x offset in 0.001 in\n\
+ \t-Y y offset in 0.001 in\n\
+ \t-f fast horiz space\n\
+ \t-v show version number\n\
+ ");
+ exit( 2 );
+}
+
+main(int argc, char **argv)
+{
+ register int c;
+ int xoff = 0, yoff = 0; /* margins from -X and -Y */
+ int hdpi = DefaultDPIh; /* resolution from -r */
+ int vdpi = DefaultDPIv; /* resolution from -r */
+ FILE *fp = stdin;
+ int FastSpace = 0;
+
+ setbuf(stderr, serrbuf);
+#ifdef __MSDOS__
+ _fmode = O_BINARY;
+ setmode( fileno( stdout ), O_BINARY );
+ setmode( fileno( stdin ), O_BINARY );
+#endif
+
+ ProgName = *argv;
+ ds.ds_usermag = 1000;
+ ds.ds_maxdrift = DefaultMaxDrift;
+ ReversePages = 0; /* default is to reverse pages */
+ PrintEngine = "epson";
+ DVIFileName = "`stdin'";
+
+ while ((c = getopt(argc, argv, "d:e:lm:pH:V:sDX:Y:fv")) != EOF) {
+ switch (c) {
+
+ case 'd': /* max drift value */
+ ds.ds_maxdrift = atoi(optarg);
+ break;
+
+ case 'e': /* engine */
+ PrintEngine = optarg;
+ break;
+
+ case 'l': /* landscape mode */
+ LFlag++;
+ break;
+
+ case 'm': /* magnification */
+ ds.ds_usermag = atoi(optarg);
+ break;
+
+ case 'p': /* toggle page reversal */
+ ReversePages = !ReversePages;
+ break;
+
+ case 'H': /* resolution */
+ hdpi = atoi(optarg);
+ break;
+
+ case 'V': /* resolution */
+ vdpi = atoi(optarg);
+ break;
+
+ case 's': /* silent */
+ SFlag++;
+ break;
+
+ case 'D':
+ Debug++;
+ break;
+
+ case 'X': /* x offset, in 1/1000 inch increments */
+ xoff = atoi(optarg);
+ break;
+
+ case 'Y': /* y offset */
+ yoff = atoi(optarg);
+ break;
+ case 'f': /* fast spaces */
+ FastSpace = 1;
+ break;
+ case 'v':
+ fprintf( stderr, "eps version %s\n", EpsVersion );
+ case '?':
+ ShowUse( ProgName );
+ }
+ }
+
+ if (optind < argc)
+ if ((fp = fopen(DVIFileName = argv[optind], "r")) == NULL)
+ error(1, errno, "can't open %s", DVIFileName);
+
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+ if( Debug )
+ fprintf( stderr, "Start: brk(0)=%p,coreleft=%lx\n",
+ sbrk(0), coreleft() );
+#endif
+ DVISetState(fp, DefineFont, hdpi, vdpi, xoff, yoff);
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+ if( Debug )
+ fprintf( stderr, "After DVISetState: brk(0)=%p,coreleft=%lx\n",
+ sbrk(0), coreleft() );
+#endif
+ theBitMap = new BitMap;
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+ if( Debug )
+ fprintf( stderr, "After BitMap: brk(0)=%p,coreleft=%lx\n",
+ sbrk(0), coreleft() );
+#endif
+
+ Printer = new epson( stdout, FastSpace );
+
+ /* All set! */
+ while (PageLoop())
+ /* void */;
+ if (!SFlag) {
+ (void) fprintf(stderr, "\n");
+ (void) fflush(stderr);
+ }
+ (void) fflush(stdout);
+ if (ferror(stdout))
+ error(1, -1, "error writing imPRESS output");
+
+ exit(0);
+ /* NOTREACHED */
+}
+
+static void ShowBits( char x )
+{
+ for( int i = 7; i >= 0; --i ) {
+ if( x & BitMask[ i ] )
+ putc( '*', stdout );
+ else
+ putc( ' ', stdout );
+ }
+}
+
+
+/*
+ * Download the character c of font f (glyph=g).
+ * The value of c is guaranteed to be in [0..127].
+ */
+static void
+LoadGlyph(struct glyph* g)
+{
+ g->g_pixwidth = fromSPh(g->g_tfmwidth);
+ g->g_flags |= GF_SEEN;
+}
+
+static void
+SetGlyph(int c, struct font* f, struct glyph* g)
+{
+ register char *p;
+ register int i, j, w;
+
+ if (!HASRASTER(g)) /* never load dull glyphs */
+ return; /* (imagen cannot handle them) */
+
+ if (!LFlag) {
+ p = RASTER(g, f, ROT_NORM);
+ } else {
+ p = RASTER(g, f, ROT_RIGHT);
+ }
+
+
+ /* Define the character */
+
+ /*
+ * Now put out the bitmap.
+ */
+/* fprintf( stderr, "adv:%ld width:%ld xor:%ld height:%ld yor:%ld\n",
+ (long)(g->g_pixwidth), (long)(g->g_width), (long)(g->g_xorigin), (long)(g->g_height), (long)(g->g_yorigin) );
+*/
+ w = (g->g_width + 7) >> 3;
+ for (i = 0; i < g->g_height; i++ ) {
+ int Row = ( LFlag ) ?
+ ( dvi_hh - g->g_yorigin + i ) :
+ ( dvi_vv - g->g_yorigin + i ) ;
+#ifdef TWOPASS
+ if( Pass % 2 == 1 )
+ Row -= BitMapRows;
+#endif
+ if( Row >= 0 && Row < BitMapRows ) {
+ int Pos = ( LFlag ) ?
+ HPixels - dvi_vv - g->g_xorigin :
+ dvi_hh - g->g_xorigin;
+ Pos -= LeftMarginPixels;
+ if( Pos >= 0 )
+ theBitMap->Set( p, w, Row, Pos );
+ }
+ p += w;
+ }
+/*
+ for (i = 0; i < g->g_height; i++ ) {
+ for (j = 0; j < w; j++ ) {
+ ShowBits( BitMap[ dvi_vv - g->g_yorigin + i ][(dvi_hh - g->g_xorigin)/8 + j] );
+ }
+ putc( '\n', stdout );
+ }
+ putc( '\n', stdout );
+*/
+}
diff --git a/dviware/epson/eps-0.2/eps/epson.c b/dviware/epson/eps-0.2/eps/epson.c
new file mode 100644
index 0000000000..8963e0baeb
--- /dev/null
+++ b/dviware/epson/eps-0.2/eps/epson.c
@@ -0,0 +1,157 @@
+static const char rcsid[] = "$Header: c:/mctex/imagen/rcs/epson.c 1.1 91/08/05 23:40:37 ROOT_DOS Exp Locker: ROOT_DOS $";
+
+/* Copyright (c) 1993 Neal Becker
+ * All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+*/
+
+/*
+$Log: epson.c $
+ * Revision 1.1 91/08/05 23:40:37 ROOT_DOS
+ * Initial revision
+ *
+*/
+
+#include "epson.h"
+
+
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+# include <mem.h>
+#endif /* __MSDOS__ */
+
+#include <stdlib.h>
+#include "PROTO.h"
+
+BitMapRow::BitMapRow() {
+ if( ( Bits = new char[ HBytes ] ) == 0 )
+ GripeOutOfMemory( HBytes, "BitMap" );
+ Printed = Length = 0;
+ Start = MaxShort;
+}
+
+void BitMapRow::Clear() {
+ memset( Bits, 0, HBytes );
+ Printed = Length = 0;
+ Start = MaxShort;
+}
+
+BitMap::BitMap() {
+ for( int i = 0; i < ( BitMapRows + ExtraRows ); i++ ) {
+ if( ( Rows[ i ] = new BitMapRow ) == NULL )
+ GripeOutOfMemory( sizeof( BitMapRow ), "BitMap" );
+ }
+}
+
+void BitMap::Clear() {
+ for( int i = 0; i < ( BitMapRows + ExtraRows ); i++ )
+ Rows[ i ]->Clear();
+}
+
+#if defined __MSDOS__ && !defined( __GNUC__ )
+
+#include <alloc.h>
+void ReportMem() {
+ fprintf( stderr,"%lX Bytes Left\n", (unsigned long)farcoreleft() );
+}
+
+#else /* __MSDOS__ */
+
+void ReportMem() {}
+
+#endif /* __MSDOS__ */
+
+void epson::PrintBitMap( BitMap& theBitMap ) {
+ for( DviPos = 0; DviPos < BitMapRows; DviPos ++ ) {
+ if( theBitMap.NeedToPrint( DviPos ) )
+ PrintRow( theBitMap, DviPos );
+ }
+ if( ferror( fp ) )
+ panic( "error writing output" );
+}
+
+void epson::PrintRow( BitMap& theBitMap, int Row ) {
+ SetVpos( Row );
+ Output8Rows( theBitMap, Row );
+};
+
+void epson::Output8Rows( BitMap& theBitMap, int Row ) {
+ int FirstBytePos = theBitMap.FindFirst( Row );
+ int RealSpaces = FirstBytePos / 3;
+ int TotalSpaces = RealSpaces + LeftMarginSpaces;
+ int HByte = 0; /* current byte pos */
+ if( TotalSpaces > 0 ) {
+ if( HasFastSpace ) {
+ fputs( "\x1b" "f0", fp );
+ fputc( TotalSpaces, fp );
+ }
+ else {
+ for( int i = 0; i < TotalSpaces; i++ )
+ fputc( ' ', fp );
+ }
+ HByte += RealSpaces * 3;
+ }
+ int LastBytePos = theBitMap.FindLength( Row );
+ int NumBits = 8 * ( LastBytePos - HByte + 1 );
+ char n1 = NumBits & 0xff;
+ char n2 = (unsigned)(NumBits) >> 8;
+ fputs( "\x1b" "*" "\x3", fp );
+ fputc( n1, fp );
+ fputc( n2, fp );
+ char Bytes[ 8 ];
+ for( ; HByte <= LastBytePos; HByte++ ) {
+ Encode8Bytes( theBitMap, Row, HByte, Bytes );
+ for( int HBit = 7; HBit >= 0; HBit-- )
+ fputc( Bytes[ HBit ], fp );
+ }
+ Eol();
+ for( int V = 0; V < 8; V++ ) {
+ int TheRow = Row + ( V * 3 );
+ if( TheRow >= BitMapRows ) break;
+ theBitMap.Mark( TheRow );
+ }
+}
+
+
+void epson::Encode8Bytes( BitMap& theBitMap, int Row, int HByte, char Bytes[ 8 ] ) {
+ memset( Bytes, 0, 8 );
+ for( int VBit = 0; VBit < 8; VBit++ ) {
+ int TheRow = Row + ( VBit * 3 );
+ if( TheRow >= BitMapRows ) break;
+ char TheChar = theBitMap.Rows[ TheRow ]->Bits[ HByte ];
+ char TheMask = BitMask[ 7 - VBit ];
+ for( int HBit = 0; HBit <= 7; HBit++ )
+ if( TheChar & BitMask[ HBit ] )
+ Bytes[ HBit ] |= TheMask;
+ }
+}
+
+int BitMap::FindLength( int Row ) {
+ for( int i = 0, l = 0; i < 8; i++ ) {
+ int TheRow = Row + ( i * 3 );
+ if( TheRow >= BitMapRows ) break;
+ l = max( l, Rows[ TheRow ]->Length );
+ }
+ return l;
+}
+
+int BitMap::FindFirst( int Row ) {
+ for( int i = 0, l = 0xff; i < 8; i++ ) {
+ int TheRow = Row + ( i * 3 );
+ if( TheRow >= BitMapRows ) break;
+ l = min( l, Rows[ TheRow ]->Start );
+ }
+ return l;
+}
+
+void epson::SetVpos( int n ) {
+ while( n - PrintPos > 255 )
+ Vaddv( 255 );
+ Vaddv( n - PrintPos );
+}
+
+void epson::Vaddv( int n ) {
+ fputs( "\x1b" "J", fp );
+ fputc( n, fp );
+ PrintPos += n;
+}
diff --git a/dviware/epson/eps-0.2/eps/epson.h b/dviware/epson/eps-0.2/eps/epson.h
new file mode 100644
index 0000000000..ef557cb6ad
--- /dev/null
+++ b/dviware/epson/eps-0.2/eps/epson.h
@@ -0,0 +1,165 @@
+#ifndef Epson_h
+#define Epson_h
+
+/* $Header: /usr/local/src/mctex/imagen/epson.h,v 1.1 1993/03/31 03:16:47 neal Exp neal $ */
+
+/* Copyright (c) 1993 Neal Becker
+ * All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+*/
+
+/*
+$Log: epson.h,v $
+ * Revision 1.1 1993/03/31 03:16:47 neal
+ * Initial revision
+ *
+ * Revision 1.1 91/08/05 23:40:19 ROOT_DOS
+ * Initial revision
+ *
+*/
+
+#include <stdio.h>
+#include "Bset.h"
+
+#define MaxImFamily 128 /* hardware limitation on font family index */
+#define DefaultDPIh 240 /* 300 for Imagen 8/300, 240 for Imprint-10 */
+#define DefaultDPIv 216 /* 300 for Imagen 8/300, 240 for Imprint-10 */
+#define DefaultMaxDrift 3 /* default value for MaxDrift */
+
+/* 1 inch left margin */
+const int HPixels = 240 * 7.5;
+const int VPixels = 216 * 11;
+const int HBytes = ( HPixels + 7 ) / 8;
+#ifdef TWOPASS
+const int BitMapRows = VPixels / 2;
+#else
+const int BitMapRows = VPixels;
+#endif /* TWOPASS */
+const int ExtraRows = 0;
+const int LeftMarginSpaces = 10; /* 10 extra spaces = 1 inch margin */
+const int LeftMarginPixels = 240;
+
+const short MaxShort = 0x7fff;
+
+inline int max( int a, int b ) {
+ return ( a > b ) ? a : b;
+}
+
+inline int min( int a, int b ) {
+ return ( a < b ) ? a : b;
+}
+
+struct BitMapRow {
+ short Length; /* last byte pos used */
+ short Start; /* first byte pos used */
+ unsigned char Printed;
+ char* Bits;
+ BitMapRow();
+ void Clear();
+ void Set( char* S, int Slen, int Pos ) {
+ Bset( S, Slen, Bits, HBytes, Pos );
+ Length = max( Length, min( HBytes - 1, Pos / 8 + Slen + 1 ) );
+ Start = min( Start, Pos / 8 );
+ };
+
+ void SetBits( int Slen, int Pos ) {
+ ::SetBits( Slen, Bits, HPixels, Pos );
+ Length = max( Length, min( HBytes - 1, Pos / 8 + Slen / 8 + 1 ) );
+ Start = min( Start, Pos / 8 );
+ };
+
+ int NeedToPrint() {
+ return !Printed && Start != MaxShort;
+ };
+
+ void Mark() {
+ Printed = 1;
+ };
+};
+
+struct BitMap {
+ BitMapRow* Rows[ BitMapRows + ExtraRows ];
+ BitMap();
+ void Clear();
+ int NeedToPrint( int Row ) {
+ return Rows[ Row ]->NeedToPrint();
+ };
+ int FindLength( int Row );
+ int FindFirst( int Row );
+ void Mark( int Row ) {
+ Rows[ Row ]->Mark();
+ };
+ void Set( char* S, int Slen, int Row, int Pos ) {
+ Rows[ Row ]->Set( S, Slen, Pos );
+ };
+ void SetBits( int Slen, int Row, int Pos ) {
+ Rows[ Row ]->SetBits( Slen, Pos );
+ };
+};
+
+static const int BitMask[ 8 ] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+void ReportMem();
+
+class epson {
+
+private:
+ FILE* fp;
+ int PrintPos;
+ int DviPos;
+ int HasFastSpace;
+
+ void PrintRow( BitMap& theBitMap, int Row );
+
+ void Output8Rows( BitMap& theBitMap, int Row );
+
+ void Encode8Bytes( BitMap& theBitMap, int Row, int HByte, char Bytes[ 8 ] );
+
+ void SetVpos( int Row );
+
+ void Vaddv( int n );
+
+/* Reset Printer, Select Pica (10 cpi) */
+ void Init() {
+ fputs( "\x1b" "@" "\x1b" "P", fp );
+ }
+
+public:
+
+ epson( FILE* f, int fastspace = 0 ) : fp( f ), DviPos( 0 ), PrintPos( 0 ),
+ HasFastSpace( fastspace )
+ { Init(); Reset(); }
+
+ void Reset() {
+ SetVaddv( 0 );
+ PrintPos = 0;
+ }
+
+ void Eol() {
+ fputc( '\r', fp );
+ }
+
+ void EoP() {
+ fputc( '\f', fp );
+ }
+
+ void SetVaddv( int n ) {
+ fputs( "\x1b" "3", fp );
+ fputc( n, fp );
+ }
+
+ void ResVaddv() {
+ fputs( "\x1b" "2", fp );
+ }
+
+ void PrintBitMap( BitMap& theBitMap );
+
+ void SyncVpos() {
+ SetVpos( DviPos );
+ }
+
+};
+
+#endif
+
+
diff --git a/dviware/epson/eps-0.2/eps/makefile.djg b/dviware/epson/eps-0.2/eps/makefile.djg
new file mode 100644
index 0000000000..4a246eb335
--- /dev/null
+++ b/dviware/epson/eps-0.2/eps/makefile.djg
@@ -0,0 +1,27 @@
+CC = gcc
+
+CFLAGS= -I../h -O
+
+%.o: %.c
+ ${CC} -c -x c++ ${CFLAGS} $<
+
+SRCS= eps.c epson.c bset.c
+
+OBJS= eps.o epson.o bset.o
+
+LIBS= ../lib/lib.a
+
+all: eps
+
+eps : ${OBJS}
+ ${CC} ${CFLAGS} ${OBJS} ${LIBS} -o $@
+
+install:
+ install -s eps ${BINDIR}
+
+clean:
+ rm eps *.o
+
+depend:
+ ${MAKEDEPEND} -I/usr/g++-include ${CFLAGS} ${SRCS}
+
diff --git a/dviware/epson/eps-0.2/eps/version.h b/dviware/epson/eps-0.2/eps/version.h
new file mode 100644
index 0000000000..ad056c69a8
--- /dev/null
+++ b/dviware/epson/eps-0.2/eps/version.h
@@ -0,0 +1 @@
+const char* EpsVersion = "0.2";
diff --git a/dviware/epson/eps-0.2/h/PROTO.h b/dviware/epson/eps-0.2/h/PROTO.h
new file mode 100644
index 0000000000..84908eba1e
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/PROTO.h
@@ -0,0 +1,165 @@
+#ifndef PROTO_h
+#define PROTO_h
+#include "types.h"
+#include <stdio.h> /* for FILE */
+#include <stdarg.h> /* for va_list */
+#include "bounds.h"
+#include "conv.h"
+#include "decinf.h"
+#include "dviclass.h"
+#include "dvicodes.h"
+#include "dvistate.h"
+#include "fio.h"
+#include "font.h"
+#include "fontconf.h"
+#include "gfclass.h"
+#include "gfcodes.h"
+#include "gripes.h"
+#include "num.h"
+#include "pkdetails.h"
+#include "postamble.h"
+#include "sdecode.h"
+#include "search.h"
+#include "tfm.h"
+
+/* FROM conv.c */
+extern void CSetConversion(struct conversion *c, int hdpi, int vdpi,int usermag, i32 num, i32 denom, i32 dvimag);
+/* FROM dviclass.c */
+/* FROM dvistate.c */
+extern void DVISetState(FILE *fp, struct font *(*fontfn)(char* name, i32 dvimag, i32 dvidsz), int hdpi, int vdpi, int xoffset, int yoffset);
+static void pre(void);
+static void post(struct PostAmbleInfo *p);
+static void fntdef(struct PostAmbleFont *p);
+extern struct font *DVIFindFont(i32 n);
+extern void DVIRule(void (*fn)(i32 h, i32 w), int advance);
+extern void DVIBeginPage(void (*fn)(i32* count));
+/* FROM error.c */
+extern void SetErrorTrap(void (*fn)(int,char*));
+static char *readback(void);
+static void verror(int quit, char *a0, char *fmt, va_list l, int e);
+extern void error(int quit, int e, char *fmt, ... );
+extern void panic(char *fmt, ... );
+/* FROM findpost.c */
+extern int FindPostAmble(register FILE *f);
+/* FROM fio.c */
+extern i32 GetByte(register FILE *fp);
+extern i32 GetWord(register FILE *fp);
+extern i32 Get3Byte(register FILE *fp);
+extern i32 GetLong(register FILE *fp);
+/* FROM font.c */
+extern void fontinit(char *file);
+static struct fontops *findops(register char *name);
+static void readconf(char *name);
+static void setfenv(struct fontconf *pfc, char *env, char *suf);
+static void setfont(struct fontconf *pfc, char *path);
+static void badcf(char *why);
+static void basify(char *s, char *buf, int size);
+static void pave(char *result, char *proto, char *name, int mag);
+extern struct font *GetFont(char *nm, i32 dvimag, i32 dvidsz, char *dev, char **fname);
+extern struct font *GetRasterlessFont(char *nm, i32 dvimag, i32 dvidsz, char *dev, char **fname);
+static struct font *getafont(char *nm, i32 dvimag, i32 dvidsz, char *dev, char **fname, int wantrast);
+/* FROM font_subr.c */
+extern int FontHasGlyphs(register struct font *f, register int low, register int high);
+static struct glyph *AllocGlyph(int n);
+extern void FreeGlyph(struct font *f, register struct glyph *g);
+extern void FreeFont(register struct font *f);
+extern struct glyph *GetGlyph(register struct font *f, int c);
+extern char *GetRaster(register struct glyph *g, register struct font *f, int r);
+extern void FreeRaster(struct glyph *g);
+extern char *Font_TeXName(register struct font *f);
+/* FROM getopt.c */
+extern int getopt(register int argc, register char **argv, char *optstring);
+/* FROM gfclass.c */
+/* FROM gffont.c */
+static int findGFpostamble(int fd, long *postp, long *postpostp);
+static int gf_read(register struct font *f, int fd);
+static char *drawchar(register char *p, int abbrev, struct bounds globalb, char *gfname);
+extern char *copyit(void);
+static int gf_getgly(register struct font *f, int l, int h);
+static int gf_rasterise(struct font *f, int l, int h);
+static void gf_freefont(struct font *f);
+/* FROM gripes0.c */
+extern void GripeOutOfMemory(int n, char *why);
+extern void GripeCannotGetFont(char *name, i32 mag, i32 dsz, char *dev, char *fullname);
+extern void GripeDifferentChecksums(char *font, i32 tfmsum, i32 fontsum);
+extern void GripeMissingFontsPreventOutput(int n);
+/* FROM gripes1.c */
+static char *dfn(void);
+extern void GripeNoSuchFont(i32 n);
+extern void GripeFontAlreadyDefined(i32 n);
+extern void GripeUnexpectedDVIEOF(void);
+extern void GripeUnexpectedOp(char *s);
+extern void GripeMissingOp(char *s);
+extern void GripeCannotFindPostamble(void);
+extern void GripeMismatchedValue(char *s);
+extern void GripeUndefinedOp(int n);
+extern void GripeBadGlyph(i32 c, struct font *f);
+/* FROM magfactor.c */
+extern double DMagFactor(int mag);
+/* FROM pkfont.c */
+static int pk_unpack(register struct pk_details *pk);
+static void skip_specials(struct font *f);
+static int pk_read(register struct font *f, int fd);
+static int scan_characters(struct font *f, char **reason);
+static int pk_getgly(register struct font *f, int l, int h);
+static int pk_rasterise(struct font *f, int l, int h);
+static void pk_freefont(struct font *f);
+/* FROM pxlfont.c */
+static int pxl_read(struct font *f, int fd);
+static int pxl_getgly(register struct font *f, int l, register int h);
+static char *makeraster(register int h, register int w, register char *rp);
+static int pxl_rasterise(register struct font *f, int l, register int h);
+static void pxl_freefont(struct font *f);
+/* FROM rotate.c */
+extern void SetRotation(register struct glyph *g, int r);
+static void RotateClockwise(struct glyph *glyph);
+/* FROM rstfont.c */
+static int rst_read(struct font *f, int fd);
+static int rst_getgly(register struct font *f, int l, register int h);
+static int rst_rasterise(register struct font *f, int l, register int h);
+static void rst_freefont(struct font *f);
+/* FROM scaletfm.c */
+extern i32 ScaleOneWidth(register i32 t, register i32 z);
+extern void ScaleGlyphs(register struct font *f, int l, int h);
+/* FROM scanpost.c */
+extern void ScanPostAmble(register FILE *f, void (*headerfunc)(struct PostAmbleInfo *p), void (*fontfunc)(struct PostAmbleFont *p));
+/* FROM sdecode.c */
+static int canon(register struct decode_info *di);
+static char *word(register struct decode_info *di, int quietly);
+extern void SDsetclass(register char *spaces, register char *semis);
+static struct sdecode *lookup(register char *str, register struct sdecode *p, register int max);
+extern void SDecode(FILE *fp, register i32 len, struct sdecode *table, int tsize);
+static void args(register struct sdecode *tp, register struct decode_info *di);
+static void badarg(int c, struct decode_info *di);
+static int scan(struct decode_info* di, char** fmtp, ...);
+static int scan_i(char *p, int c, i32 *result);
+static int scan_d(char *p, double *result);
+/* FROM search.c */
+extern struct search *SCreate(register unsigned int dsize);
+extern char *SSearch(register struct search *s, register i32 key, int *disp);
+extern void SEnumerate(register struct search *s, register void (*f)(char*, i32));
+/* FROM seek.c */
+extern FILE *CopyFile(FILE *f);
+extern FILE *SeekFile(FILE *f);
+/* FROM skip.c */
+extern void SkipFontDef(register FILE *fp);
+/* FROM split.c */
+extern int split(register char *s, register char **w, int nw);
+/* FROM strsave.c */
+extern char *strsave(register char *s);
+/* FROM tempfile.c */
+extern int MakeRWTempFile(register char *name);
+/* FROM tfm.c */
+extern int readtfmfile(register FILE *f, register struct tfmdata *t, int stopafterwidth);
+static int trd_header(register FILE *f, register struct tfmheader *th);
+static int trd_ci(register FILE *f, register int nc, register struct char_info_word *ci);
+static int trd_fix(register FILE *f, register int nf, register i32 *p);
+/* FROM tfmfont.c */
+static int box_read(struct font *f, int fd);
+static int blank_read(struct font *f, int fd);
+static int tfm_read(struct font *f, int fd);
+static int do_read(register struct font *f, int fd, int blank);
+static int tfm_getgly(register struct font *f, int l, register int h);
+static int tfm_rasterise(struct font *f, int l, int h);
+static void tfm_freefont(struct font *f);
+#endif
diff --git a/dviware/epson/eps-0.2/h/bounds.h b/dviware/epson/eps-0.2/h/bounds.h
new file mode 100644
index 0000000000..891f46a52e
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/bounds.h
@@ -0,0 +1,9 @@
+#ifndef bounds_h
+#define bounds_h
+
+struct bounds {
+ i32 min_m, max_m; /* min and max `m' (colunm) values */
+ i32 min_n, max_n; /* min and max `n' (row) values */
+};
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/conv.h b/dviware/epson/eps-0.2/h/conv.h
new file mode 100644
index 0000000000..ba1afced37
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/conv.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+/*
+ * Conversions. Conversion factors convert between values in scaled
+ * points and values in device-dependent units. The results of all
+ * conversions are rounded to the nearest integral value, of type (i32).
+ */
+
+/*
+ * This is now done using `double' values, but may be changed to
+ * fixed-point or some other `fast' method, as long as the results
+ * are consistent and reasonably accurate. The structure `conversion'
+ * holds the conversion-method-dependent quantities; the macros
+ * fromSP and toSP apply the conversion to a value. (Note that
+ * fromSP and toSP need not be macros, but should be fast.)
+ *
+ * SetConversion sets the (single, global) conversion factor.
+ * If a driver needs special conversions, there is another routine,
+ * CSetConversion that sets a specific conversion, and cfromSP and
+ * ctoSP to apply these.
+ *
+ * IS USING DOTS PER INCH SUFFICIENT? (Pixels per point might be better.)
+ *
+ * Note that it is necessary to set the global conversion factor before
+ * using any fonts.
+ */
+#ifndef Conv_h
+#define Conv_h
+
+typedef struct conversion {
+ double c_fromsph; /* multiplier to convert from scaled points */
+ double c_tosph; /* multiplier to convert to scaled points:
+ could divide by c_fromsp, but this should
+ be faster and more accurate */
+ double c_fromspv; /* multiplier to convert from scaled points */
+ double c_tospv; /* multiplier to convert to scaled points:
+ could divide by c_fromsp, but this should
+ be faster and more accurate */
+ double c_mag; /* the magnification this conversion
+ represents; mainly for GetFont() */
+ double c_hdpi; /* dpi (should be pixels per point?) */
+ double c_vdpi;
+} Conv;
+
+extern Conv Conversion; /* the global conversion factor */
+
+/*
+ * In order to do this, we need to round properly. The compilers I
+ * have tend to generate very poor code for this. The following is
+ * intended to help them out. Smarter compilers can do better, but
+ * if they are smart enough, they will realise that the variables
+ * here are not used anywhere else, and discard them. (For a compiler
+ * to do this given separate compliation, `static' is a must.)
+ */
+#ifdef lint /* or a smart compiler */
+
+#define ROUND(f) ((i32) ((f) < 0.0 ? (f) - 0.5 : (f) + 0.5))
+#define CEIL(f) ((double) (i32) (f) < (f) ? (i32) (f) + 1 : (i32) (f))
+
+#else /* lint */
+
+static double _half = 0.5;
+static double _d;
+#define ROUND(f) ((i32) (_d = (f), _d < 0.0 ? _d - _half : _d + _half))
+
+#ifdef NEGATIVE_FLOAT_ROUNDS_TO_NEGATIVE_INFINITY
+#define CEIL(f) (-(i32) -(f))
+#else /* we will assume that floating to integer truncates */
+static i32 _i;
+#define CEIL(f) (_i = _d = (f), _i < _d ? _i + 1 : _i)
+#endif /* round towards negative infinity */
+
+#endif /* lint */
+
+#define SetConversion(hdpi, vdpi, usermag, num, denom, dvimag) \
+ CSetConversion(&Conversion, hdpi, vdpi, usermag, num, denom, dvimag)
+
+#define cfromSPh(c, v) ROUND((c)->c_fromsph * (v))
+#define ctoSPh(c, v) ROUND((c)->c_tosph * (v))
+
+#define fromSPh(v) cfromSPh(&Conversion, v)
+#define toSPh(v) ctoSPh(&Conversion, v)
+
+#define cfromSPv(c, v) ROUND((c)->c_fromspv * (v))
+#define ctoSPv(c, v) ROUND((c)->c_tospv * (v))
+
+#define fromSPv(v) cfromSPv(&Conversion, v)
+#define toSPv(v) ctoSPv(&Conversion, v)
+
+/*
+ * Conversions for rules are a bit different: we must round up, rather
+ * than off. ConvRule applies the global conversion value for a rule
+ * value (height or width); CConvRule applies a specific conversion.
+ */
+#define CConvRuleh(c, v) CEIL((c)->c_fromsph * (v))
+#define ConvRuleh(v) CConvRuleh(&Conversion, v)
+
+#define CConvRulev(c, v) CEIL((c)->c_fromspv * (v))
+#define ConvRulev(v) CConvRulev(&Conversion, v)
+
+#endif \ No newline at end of file
diff --git a/dviware/epson/eps-0.2/h/decinf.h b/dviware/epson/eps-0.2/h/decinf.h
new file mode 100644
index 0000000000..d13f81d67a
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/decinf.h
@@ -0,0 +1,21 @@
+#ifndef decodeinfo_h
+#define decodeinfo_h
+
+struct decode_info {
+ /* data used to read from input file */
+ int di_nch; /* number of characters remaining in buffer */
+ char *di_cp; /* next character to be read from buffer */
+ long di_nfilech; /* number of characters remaining in file */
+ FILE *di_file; /* the file itself */
+
+ /* information used and/or returned by the canon routine */
+ int di_lexstate; /* lexical state */
+ int di_call; /* set when we reach terminating `semicolon' */
+
+ /* information used more globally */
+ char *di_word; /* last word from word() */
+ char *di_kw; /* the keyword */
+ int di_bkw; /* true iff keyword is in static buffer */
+};
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/dviclass.h b/dviware/epson/eps-0.2/h/dviclass.h
new file mode 100644
index 0000000000..bf3d67c9ce
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/dviclass.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef dviclass_h
+#define dviclass_h
+/*
+ * Macros to convert DVI opcodes to (hopefully) simpler values.
+ */
+
+/*
+ * Large range types---code may be any value (including EOF).
+ */
+#define DVI_IsChar(code) ((ui32)(code) < 128)
+#define DVI_IsFont(code) ((code) >= 171 && (code) < 235)
+
+/*
+ * Symbolic names for generic types (for things with parameters).
+ * These are obtained via the macro DVI_DT(int c), where 0 <= c <= 255.
+ */
+#define DT_CHAR 0
+#define DT_SET 1
+#define DT_SETRULE 2
+#define DT_PUT 3
+#define DT_PUTRULE 4
+#define DT_NOP 5
+#define DT_BOP 6
+#define DT_EOP 7
+#define DT_PUSH 8
+#define DT_POP 9
+#define DT_RIGHT 10
+#define DT_W0 11
+#define DT_W 12
+#define DT_X0 13
+#define DT_X 14
+#define DT_DOWN 15
+#define DT_Y0 16
+#define DT_Y 17
+#define DT_Z0 18
+#define DT_Z 19
+#define DT_FNTNUM 20
+#define DT_FNT 21
+#define DT_XXX 22
+#define DT_FNTDEF 23
+#define DT_PRE 24
+#define DT_POST 25
+#define DT_POSTPOST 26
+#define DT_UNDEF 27
+
+/*
+ * Symbolic names for parameter lengths, obtained via the macro
+ * DVL_OpLen(int c).
+ *
+ * N.B.: older drivers may assume that 0 => none, 1-4 => 1-4 bytes
+ * and 5-7 => unsigned version of 1-4---so DO NOT change these values!
+ */
+#define DPL_NONE 0
+#define DPL_SGN1 1
+#define DPL_SGN2 2
+#define DPL_SGN3 3
+#define DPL_SGN4 4
+#define DPL_UNS1 5
+#define DPL_UNS2 6
+#define DPL_UNS3 7
+/* there are no unsigned four byte parameters */
+
+#define DVI_OpLen(code) (dvi_oplen[code])
+#define DVI_DT(code) (dvi_dt[code])
+extern char dvi_oplen[];
+extern char dvi_dt[];
+#endif
diff --git a/dviware/epson/eps-0.2/h/dvicodes.h b/dviware/epson/eps-0.2/h/dvicodes.h
new file mode 100644
index 0000000000..8d283b32ca
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/dvicodes.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef dvicodes_h
+#define dvicodes_h
+
+/* DVI opcodes */
+
+#define DVI_VERSION 2 /* version number that should appear in
+ pre- and post-ambles */
+
+#define DVI_SET1 128 /* set character, 1 byte param */
+#define DVI_SET2 129 /* set character, 2 byte param */
+#define DVI_SET3 130 /* set character, 3 byte param */
+#define DVI_SET4 131 /* set character, 4 byte param */
+#define DVI_SETRULE 132 /* set a rule */
+#define DVI_PUT1 133 /* put char, don't move right */
+#define DVI_PUT2 134 /* put char, 2 byte */
+#define DVI_PUT3 135 /* etc */
+#define DVI_PUT4 136
+#define DVI_PUTRULE 137 /* put rule, don't move right */
+#define DVI_NOP 138 /* no-op */
+#define DVI_BOP 139 /* begin page */
+#define DVI_EOP 140 /* end page */
+#define DVI_PUSH 141 /* push h,v,w,x,y,z */
+#define DVI_POP 142 /* pop h,v,w,x,y,z */
+#define DVI_RIGHT1 143 /* move right, 1 byte signed param */
+#define DVI_RIGHT2 144 /* move right, 2 byte signed param */
+#define DVI_RIGHT3 145 /* etc */
+#define DVI_RIGHT4 146
+#define DVI_W0 147 /* h += w */
+#define DVI_W1 148 /* w = 1 byte signed param, h += w */
+#define DVI_W2 149 /* w = 2 byte etc, h += w */
+#define DVI_W3 150
+#define DVI_W4 151
+#define DVI_X0 152 /* like DVI_W0 but for x */
+#define DVI_X1 153 /* etc */
+#define DVI_X2 154
+#define DVI_X3 155
+#define DVI_X4 156
+#define DVI_DOWN1 157 /* v += 1 byte signed param */
+#define DVI_DOWN2 158 /* v += 2 byte signed param */
+#define DVI_DOWN3 159 /* etc */
+#define DVI_DOWN4 160
+#define DVI_Y0 161 /* y = 1 byte signed param, v += y */
+#define DVI_Y1 162 /* etc */
+#define DVI_Y2 163
+#define DVI_Y3 164
+#define DVI_Y4 165
+#define DVI_Z0 166 /* z = 1 byte signed param, v += z */
+#define DVI_Z1 167 /* etc */
+#define DVI_Z2 168
+#define DVI_Z3 169
+#define DVI_Z4 170
+#define DVI_FNTNUM0 171
+
+#define DVI_FNT1 235 /* select font, 1 byte param */
+#define DVI_FNT2 236 /* etc */
+#define DVI_FNT3 237
+#define DVI_FNT4 238
+#define DVI_XXX1 239 /* for \special: if length < 256 */
+#define DVI_XXX2 240 /* etc */
+#define DVI_XXX3 241
+#define DVI_XXX4 242
+#define DVI_FNTDEF1 243 /* Define font, 1 byte param (0 to 63) */
+#define DVI_FNTDEF2 244 /* etc */
+#define DVI_FNTDEF3 245
+#define DVI_FNTDEF4 246
+#define DVI_PRE 247 /* preamble */
+#define DVI_POST 248 /* postamble */
+#define DVI_POSTPOST 249 /* end of postamble */
+#define DVI_FILLER 223 /* filler bytes at end of dvi file */
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/dvistate.h b/dviware/epson/eps-0.2/h/dvistate.h
new file mode 100644
index 0000000000..7cba2f6547
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/dvistate.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+#ifndef dvistate_h
+#define dvistate_h
+
+/* DVI file information (as used by dvi-to-device programs) */
+
+/*
+ * Units of distance are stored in scaled points, but we can convert to
+ * units of 10^-7 meters by multiplying by the numbers in the preamble.
+ * The values hh and vv are kept in device coordinates.
+ */
+
+/* the structure of the stack used to hold the values (h,v,hh,vv,w,x,y,z) */
+typedef struct dvi_stack {
+ i32 h; /* the saved h */
+ i32 v; /* the saved v */
+ i32 hh; /* the saved hh */
+ i32 vv; /* the saved vv */
+ i32 w; /* etc */
+ i32 x;
+ i32 y;
+ i32 z;
+} DviStack;
+
+/*
+ * DVI state machine interpreter encapsulation (global state).
+ */
+struct dvi_state {
+ /*
+ * Variables that must be set by user before calling SetDVIState().
+ */
+ int ds_usermag; /* user-supplied (additional) magnification */
+ int ds_maxdrift; /* maximum drift, typically 3 */
+
+ /* the rest are set by DVISetState() */
+
+ /*
+ * Values based on the (postamble of the) DVI file,
+ * or used by the interpreter.
+ */
+ i32 ds_num; /* numerator from DVI file */
+ i32 ds_denom; /* denominator from DVI file */
+ i32 ds_dvimag; /* magnification from DVI file */
+ i32 ds_maxheight; /* height of tallest page */
+ i32 ds_maxwidth; /* width of widest page */
+ i32 ds_prevpage; /* previous page of DVI file */
+ int ds_npages; /* number of DVI pages */
+ DviStack *ds_stack; /* base of stack of DVI values */
+ DviStack *ds_sp; /* current place in stack */
+ DviStack ds_cur; /* current values */
+ DviStack ds_fresh; /* fresh values for new pages: not all
+ zero unless there are no margins.
+ This works because all DVI motion
+ is relative. */
+ /*
+ * Although this is not strictly within the realm of DVI
+ * state, we need a place to store the fonts we allocate
+ * while reading through the postamble. Each entry in
+ * the ds_fonts search table is a pointer to a font,
+ * so that *(struct font **)SSearch(...) is the pointer.
+ */
+ struct search *ds_fonts;/* font table */
+
+ /*
+ * A few routines want a private copy of the DVI file pointer.
+ */
+ FILE *ds_fp; /* input DVI file */
+};
+
+extern struct dvi_state ds;
+
+/* shorthand */
+#define dvi_h ds.ds_cur.h
+#define dvi_v ds.ds_cur.v
+#define dvi_hh ds.ds_cur.hh
+#define dvi_vv ds.ds_cur.vv
+#define dvi_w ds.ds_cur.w
+#define dvi_x ds.ds_cur.x
+#define dvi_y ds.ds_cur.y
+#define dvi_z ds.ds_cur.z
+
+/*
+ * Set up the state for the interpreter loop.
+ */
+void DVISetState();
+
+/*
+ * Service routines (called from main loop).
+ */
+struct font *DVIFindFont();
+void DVIRule(), DVIBeginPage();
+
+/*
+ * Drift fixing. Note that the first argument must be an lvalue.
+ * It is the desired position in pixels, and is maintained within
+ * ds.ds_maxdrift pixels of the second argument, which is the
+ * `absolute' DVI position rounded to the nearest pixel.
+ */
+#define FIXDRIFT(xx, x) \
+ if ((x) >= (xx)) \
+ if ((x) - (xx) <= ds.ds_maxdrift) \
+ /* position is in bounds */; \
+ else \
+ (xx) = (x) - ds.ds_maxdrift; \
+ else \
+ if ((xx) - (x) <= ds.ds_maxdrift) \
+ /* position is in bounds */; \
+ else \
+ (xx) = (x) + ds.ds_maxdrift
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/error.h b/dviware/epson/eps-0.2/h/error.h
new file mode 100644
index 0000000000..4204dbbc32
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/error.h
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+#ifndef error_h
+#define error_h
+
+/*
+ * Errors.
+ */
+#endif
diff --git a/dviware/epson/eps-0.2/h/fio.h b/dviware/epson/eps-0.2/h/fio.h
new file mode 100644
index 0000000000..e4b3aafa4e
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/fio.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef fio_h
+#define fio_h
+
+/*
+ * File I/O: numbers.
+ *
+ * We deal in fixed format numbers and (FILE *)s here.
+ * For pointer I/O, see pio.h.
+ *
+ * N.B.: These do the `wrong thing' at EOF. It is imperative
+ * that the caller add appropriate `if (feof(fp))' statements.
+ */
+
+/*
+ * Get one unsigned byte. Note that this is a proper expression.
+ * The reset have more limited contexts, and are therefore OddLy
+ * CapItaliseD.
+ */
+#define fgetbyte(fp) (unsigned)getc(fp)
+
+/*
+ * Get a two-byte unsigned integer, a three-byte unsigned integer,
+ * or a four-byte signed integer.
+ */
+#define fGetWord(fp, r) ((r) = (unsigned)getc(fp) << 8, (r) |= (unsigned)getc(fp))
+#define fGet3Byte(fp,r) ((r) = (unsigned long)getc(fp) << 16, (r) |= (unsigned long)getc(fp) << 8, \
+ (r) |= (unsigned long)getc(fp))
+#define fGetLong(fp, r) ((r) = (unsigned long)getc(fp) << 24, (r) |= (unsigned long)getc(fp) << 16, \
+ (r) |= (unsigned long)getc(fp) << 8, (r) |= (unsigned long)getc(fp))
+
+/*
+ * Fast I/O write (and regular write) macros.
+ */
+#define putbyte(fp, r) ((void) putc((r), fp))
+
+#define PutWord(fp, r) ((void) putc((r) >> 8, fp), \
+ (void) putc((r), fp))
+#define Put3Byte(fp, r) ((void) putc((r) >> 16, fp), \
+ (void) putc((r) >> 8, fp), \
+ (void) putc((r), fp))
+#define PutLong(fp, r) ((void) putc((r) >> 24, fp), \
+ (void) putc((r) >> 16, fp), \
+ (void) putc((r) >> 8, fp), \
+ (void) putc((r), fp))
+
+/*
+ * Function types
+ */
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/font.h b/dviware/epson/eps-0.2/h/font.h
new file mode 100644
index 0000000000..e8beca4db0
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/font.h
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef font_h
+#define font_h
+
+/*
+ * Font file information, readers, etc.
+ */
+
+#ifndef _MCTEX_TYPES_
+#include "types.h"
+#endif
+
+/*
+ * First, font independent information: per glyph info, and per font
+ * info.
+ */
+struct glyph {
+ short g_flags; /* see below */
+ /*
+ * The following cannot be used with GetRasterlessFont
+ */
+ short g_rotation; /* see below */
+ char *g_raster; /* raster, if known */
+ /*
+ * These, however, do come with rasterless fonts,
+ * even though they relate only to the raster.
+ */
+ i32 g_height; /* height of bounding box */
+ i32 g_width; /* width of bounding box */
+ i32 g_yorigin; /* y origin (>= 0 -> within box) */
+ i32 g_xorigin; /* x origin (>= 0 -> within box) */
+ /*
+ * These of course come with every font.
+ */
+ i32 g_rawtfmwidth; /* raw TFM width (in FIXes) */
+ i32 g_tfmwidth; /* TFM width in scaled points */
+ /*
+ * The X and Y escapements come from PK and GF fonts.
+ * They are in scaled pixels (65536 scaled pixels = 1 pixel).
+ * If they are not defined by the font, these are set to
+ * NO_ESCAPEMENT.
+ */
+ i32 g_xescapement; /* x escapement (`chardx') */
+ i32 g_yescapement; /* y escapement (`chardy') */
+#define NO_ESCAPEMENT ((i32)0x89abcdef)
+ /*
+ * This is provided purely for DVI to device conversion programs.
+ */
+ int g_pixwidth; /* width in pixels */
+ /*
+ * Mainly for internal use, index is the glyph index within the
+ * font. That is, f->f_gly[i]->g_index == i.
+ */
+ int g_index; /* character index */
+ /*
+ * g_details and g_integer are purely for the font reading
+ * subroutines to use however they will. g_next makes lists
+ * of glyphs while the glyphs are free.
+ */
+ union { /* various options */
+ char *g_details; /* details: arbitrary */
+ i32 g_integer; /* 32 bit integer */
+ struct glyph *g_next; /* linked list */
+ } g_un;
+};
+
+/*
+ * Glyph flags.
+ */
+#define GF_VALID 0x0001 /* glyph is `real' */
+#define GF_SEEN 0x0002 /* glyph has been encountered/loaded */
+
+#define GF_USR0 0x0100 /* reserved to user code */
+#define GF_USR1 0x0200 /* reserved to user code */
+#define GF_USR2 0x0400 /* reserved to user code */
+#define GF_USR3 0x0800 /* reserved to user code */
+
+/*
+ * Rotations are in quarter-pi steps, counterclockwise of course.
+ * This order must be maintained; see rotate.c.
+ */
+#define ROT_NORM 0 /* no rotation: `normal' position */
+#define ROT_LEFT 1 /* 1/4 turn counterclockwise */
+#define ROT_DOWN 2 /* 1/2 turn, i.e., upside-down */
+#define ROT_RIGHT 3 /* 3/4 turn ccw, or 1/4 turn cw */
+
+struct font {
+ int f_flags; /* see below */
+ struct fontops *f_ops; /* operations */
+ /*
+ * f_un is provided for DVI drivers, which typically need
+ * some way to translate DVI font numbers into local values.
+ * Most seem to need integers.
+ */
+ union {
+ int f_int; /* value if int */
+ i32 f_i32; /* value if i32 */
+ char *f_ptr; /* value if pointer */
+ } f_un;
+#ifdef notdef
+ /* for LRU cacheing; not yet implemented */
+ i32 f_lastuse;
+#endif
+ /*
+ * f_details is provided for font reading subroutines.
+ * It is intended to be cast to a pointer to a structure
+ * that is allocated by those routines, and used to keep
+ * track of whatever information those routines need to
+ * determine glyph boxes and (if asked for) rasters.
+ */
+ char *f_details; /* type dependent stuff */
+ /*
+ * f_path is the full pathname to the font file, filled in
+ * by GetFont and GetRasterlessFont. Note that since we
+ * hold on to the path until the font is freed, it should be
+ * possible to cache glyph accesses on memory-poor machines.
+ */
+ char *f_path; /* font file pathname */
+ /*
+ * f_dvimag and f_dvidsz are the magnification and design size
+ * values from the DVI file. f_font and f_scaled correspond to
+ * TeX's idea of the proper name for the font (e.g., `cmr10',
+ * `cmbx10 scaled 1440'). (Note that f_scaled is just the
+ * ratio of f_dvimag and f_dvidsz; you could save a bit of memory
+ * by eliminating it and altering the routine Font_TeXName()).
+ * f_design_size is the font's design size, or 0 for fake (TFM)
+ * fonts. f_checksum should be set by the font reading routines
+ * to the font checksum. If the value is nonzero, it will be
+ * compared to the checksum in the DVI file.
+ */
+ i32 f_dvimag; /* magnification from DVI file */
+ i32 f_dvidsz; /* design size from DVI file */
+ char *f_font; /* TeX's name for the font */
+ int f_scaled; /* the ratio of dvimag to dvidsz, x1000 */
+ i32 f_design_size; /* font design size */
+ i32 f_checksum; /* font checksum, or 0 */
+ /*
+ * The three values f_pspace, f_nspace, and f_vspace correspond
+ * to the amount of positive, negative, and vertical space that
+ * limits `kerning' (if horizontal) or `in-line motion' (vertical).
+ * f_pspace is equal to 1/6 of f_dvimag, and f_nspace and f_vspace
+ * are -4 and 5 times this value respectively. DVItype puts it
+ * this way (slightly edited):
+ *
+ * Rounding to the nearest pixel is best done in [this]
+ * manner ... so as to be inoffensive to the eye: When [a]
+ * horizontal motion is small, like a kern, [the device
+ * position] changes by rounding the kern; but when the
+ * motion is large, [the device position] changes by rounding
+ * the [DVI position] so that accumulated rounding errors
+ * disappear. We allow a larger space in the negative
+ * direction than in the positive one, because TeX makes
+ * comparatively large backspaces when it positions accents.
+ *
+ * Vertical motion is done similarly, but with the threshold
+ * between ``small'' and ``large'' increased by a factor of
+ * five. The idea is to make fractions like ``$1\over2$''
+ * round consistently, but to absorb accumulated rounding
+ * errors in the baseline-skip moves.
+ *
+ * There is, however, an exception:
+ *
+ * A sequence of consecutive rules, or consecutive characters
+ * in a fixed-width font whose width is not an integer number
+ * of pixels, can cause [the device position] to drift far
+ * away from a correctly rounded value.
+ *
+ * The drift correction is applied after every horizontal or
+ * vertical motion, including any resulting from printing a
+ * character.
+ */
+ i32 f_pspace; /* limit on positive kerns */
+ i32 f_nspace; /* limit on negative kerns */
+ i32 f_vspace; /* limit on vertical `kerns' */
+
+ /*
+ * If set, f_hppp and f_vppp tell how many pixels there are
+ * per scaled point in the font. For instance, a 300 dpi font
+ * has 300pixels/1inch * 1inch/72.27pt * 65536pt/1sp ~=
+ * 272046 pixels/sp.
+ *
+ * If they are zero, the font does not tell us.
+ */
+ i32 f_hppp; /* horizontal pixels per point */
+ i32 f_vppp; /* vertical pixels per point */
+ /*
+ * f_lowch and f_highch bound the region in which f_gly
+ * indicies are valid. Specificially, f_gly[i] may be
+ * read or written if and only if i is in the half-open
+ * interval [f_lowch..f_highch). f_gly is an array of
+ * pointers to glyph structures. The structures themselves
+ * are not allocated until requested.
+ *
+ * f_glybase is the actual return from malloc(), since it
+ * is theoretically possible for f_gly-f_lowch to become
+ * NULL.
+ */
+ int f_lowch; /* first character */
+ int f_highch; /* last character, plus 1 */
+ struct glyph **f_gly; /* glyphs */
+ struct glyph **f_glybase;
+};
+
+/*
+ * Macros for rounding DVI and device motions per DVItype rules.
+ */
+#define F_SMALLH(f, m) ((m) < (f)->f_pspace && (m) > (f)->f_nspace)
+#define F_SMALLV(f, m) ((m) < (f)->f_vspace && -(m) < (f)->f_vspace)
+
+/*
+ * Font flags.
+ */
+#define FF_RASTERS 0x0001 /* font has rasters */
+#define FF_USR0 0x0100 /* reserved to user code */
+#define FF_USR1 0x0200 /* reserved to user code */
+#define FF_USR2 0x0400 /* reserved to user code */
+#define FF_USR3 0x0800 /* reserved to user code */
+
+/*
+ * Operations on fonts.
+ *
+ * The `fo_dpitomag' field is used as a multiplier for a desired
+ * resolution in dots per inch. The result of the multiplication
+ * is converted to a font name by multipying by 1000.0 and rounding.
+ * The idea is that PXL files will have a multiplier of 5.0, and
+ * others will have a multiplier of 1.0. This suffices for the
+ * present, at any rate; in the future, this field may be replaced
+ * with something more general.
+ *
+ * N.B.: more operations may be added as they are discovered to be
+ * useful.
+ */
+struct fontops {
+ char *fo_name; /* name, e.g., "gf" */
+ int fo_fakefont; /* 1="box", 2="blank"; else 0 */
+ double fo_dpitomag; /* multiplier */
+ int (*fo_read)(struct font* f, int fd); /* open and read the font itself */
+ int (*fo_getgly)(struct font* f, int l, int h); /* obtain specified glyphs (range) */
+#ifdef notdef
+ void (*fo_freegly)(); /* release specified glyphs */
+#endif
+ int (*fo_rasterise)(struct font* f, int l, int h); /* rasterise specified glyphs */
+ void (*fo_freefont)(struct font* f); /* discard font (free details) */
+ struct fontops *fo_next; /* purely for font.c */
+};
+
+/*
+ * Return a pointer to the glyph information for character `c' in
+ * font `f'.
+ */
+#define GLYPH(f, c) \
+ ((c) < (f)->f_lowch || (c) >= (f)->f_highch ? (struct glyph *)0 : \
+ ((f)->f_gly[c] ? (f)->f_gly[c] : GetGlyph(f, (int)(c))))
+
+/*
+ * True iff glyph `g' is valid. Useful for checking return values
+ * from GLYPH().
+ */
+#define GVALID(g) ((g) && ((g)->g_flags & GF_VALID))
+
+/*
+ * True iff glyph g has a raster.
+ */
+#define HASRASTER(g) ((g)->g_height && (g)->g_width)
+
+/*
+ * Return a pointer to the raster information for glyph `g' in font
+ * `f' at rotation `r'.
+ */
+#define RASTER(g, f, r) ((g)->g_rotation == (r) && (g)->g_raster ? \
+ (g)->g_raster : GetRaster(g, f, r))
+
+/*
+ * Function types.
+ */
+struct font *GetFont(), *GetRasterlessFont();
+struct glyph *GetGlyph();
+char *GetRaster();
+void FreeFont();
+void FreeGlyph();
+void FreeRaster();
+char *Font_TeXName();
+double DMagFactor(); /* from magfactor.c */
+void fontinit();
+
+/*
+ * Normally from stdio.h
+ */
+#ifndef NULL
+#define NULL 0
+#endif
+
+/*
+ * The following environment variable overrides the default font
+ * configuration file. That default is used when fontinit() is not
+ * called, or is passed a null pointer.
+ */
+#define CONFENV "TEXFONTDESC"
+#endif
diff --git a/dviware/epson/eps-0.2/h/fontconf.h b/dviware/epson/eps-0.2/h/fontconf.h
new file mode 100644
index 0000000000..c8022c35e6
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/fontconf.h
@@ -0,0 +1,12 @@
+#ifndef fontconf_h
+#define fontconf_h
+
+struct fontconf {
+ struct fontconf *fc_next;
+ struct fontops *fc_ops;
+ char *fc_path; /* path, with metacharacters */
+ char *fc_spec; /* specifier */
+ int fc_slop; /* slop value */
+};
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/getopt.h b/dviware/epson/eps-0.2/h/getopt.h
new file mode 100644
index 0000000000..4817e9dfa7
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/getopt.h
@@ -0,0 +1,17 @@
+#ifndef GETOPT_H
+#define GETOPT_H
+
+extern int optind;
+extern char *optarg;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int getopt( int argc, char** argv, char* optstring );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/gfclass.h b/dviware/epson/eps-0.2/h/gfclass.h
new file mode 100644
index 0000000000..d9cf177816
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/gfclass.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+#ifndef gfclass_h
+#define gfclass_h
+
+/*
+ * GF classification codes
+ */
+
+/*
+ * Predicate for simple paint commands. This is presumably the most
+ * common GF operation; it may be profitable to check for this before
+ * switching out on the command type.
+ */
+#define GF_IsPaint(c) ((c) < 64)
+
+/*
+ * Symbolic names for command `types', as returned by the macro
+ * GT_TYPE(int c).
+ */
+#define GT_PAINT0 0 /* paint without parameter */
+#define GT_PAINT 1 /* paint with parameter */
+#define GT_BOC 2 /* long BOC */
+#define GT_BOC1 3 /* short BOC */
+#define GT_EOC 4 /* EOC */
+#define GT_SKIP0 5 /* parameterless SKIP */
+#define GT_SKIP 6 /* parmeterised SKIP */
+#define GT_NEW_ROW 7 /* NEW_ROW_n */
+#define GT_XXX 8 /* XXXn */
+#define GT_YYY 9 /* YYY */
+#define GT_NOP 10 /* no op */
+#define GT_CHAR_LOC 11 /* CHAR_LOC */
+#define GT_CHAR_LOC0 12 /* abbreviated CHAR_LOC */
+#define GT_PRE 13
+#define GT_POST 14
+#define GT_POSTPOST 15
+#define GT_UNDEF 16
+
+/*
+ * Symbolic names for parameter lengths, obtained via the macro
+ * GT_OpLen(int c).
+ */
+#define GPL_NONE 0 /* no parameter, or too complex */
+#define GPL_UNS1 1 /* one one-byte parameter in 0..255 */
+#define GPL_UNS2 2 /* one two-byte parameter in 0..65535 */
+#define GPL_UNS3 3 /* one three-byte parameter in 0..16777215 */
+#define GPL_SGN4 4 /* one four-byte signed parameter */
+/*
+ * there are no unsigned four byte parameters, and no shorter signed
+ * parameters
+ */
+
+#define GF_OpLen(code) (gf_oplen[code])
+#define GF_TYPE(code) (gf_gt[code])
+extern char gf_oplen[];
+extern char gf_gt[];
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/gfcodes.h b/dviware/epson/eps-0.2/h/gfcodes.h
new file mode 100644
index 0000000000..07850da642
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/gfcodes.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+#ifndef gfcodes_h
+#define gfcodes_h
+
+/*
+ * GF (generic font) opcodes.
+ */
+
+#define GF_PAINT_0 0 /* paint with `d' = 0 */
+ /* ... through PAINT_63, d = 63 */
+#define GF_PAINT1 64 /* paint, with a one-byte parameter */
+#define GF_PAINT2 65 /* paint, with a two-byte parameter */
+#define GF_PAINT3 66 /* paint, with a three-byte parameter */
+#define GF_BOC 67 /* beginning of character */
+#define GF_BOC1 68 /* compressed form of BOC */
+#define GF_EOC 69 /* end of character */
+#define GF_SKIP0 70 /* finish this row, begin next with white */
+#define GF_SKIP1 71 /* finish row, one byte parameter */
+#define GF_SKIP2 72
+#define GF_SKIP3 73
+#define GF_NEW_ROW_0 74 /* begin a new row, ready to blacken */
+#define GF_NEW_ROW_1 75 /* begin a new row, but one col. from left */
+ /* through GF_NEW_ROW_164 */
+#define GF_XXX1 239 /* special (interpreter dependent) command */
+#define GF_XXX2 240 /* like XXX1, but two byte length parameter */
+#define GF_XXX3 241
+#define GF_XXX4 242
+#define GF_YYY 243 /* takes four byte parameter, otherwise nop */
+ /* (generated by METAFONT for numspecial) */
+#define GF_NOP 244 /* no op */
+#define GF_CHAR_LOC 245 /* character locator */
+#define GF_CHAR_LOC0 246 /* abbreviated form of CHAR_LOC */
+#define GF_PRE 247 /* introduces preamble */
+#define GF_POST 248 /* introduces postamble */
+#define GF_POSTPOST 249 /* marks end of postamble */
+
+ /* codes 250 through 255 are undefined */
+
+#define GF_ID 131 /* identifies this revision of GF */
+
+#define GF_FILLER 223 /* filler bytes at end of GF file */
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/gripes.h b/dviware/epson/eps-0.2/h/gripes.h
new file mode 100644
index 0000000000..57f13544b8
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/gripes.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef gripes_h
+#define gripes_h
+
+/*
+ * Declarations for the various gripes.
+ */
+
+#endif \ No newline at end of file
diff --git a/dviware/epson/eps-0.2/h/num.h b/dviware/epson/eps-0.2/h/num.h
new file mode 100644
index 0000000000..0af7239411
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/num.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef num_h
+#define num_h
+
+/*
+ * Pointer I/O: numbers.
+ *
+ * We deal in fixed format numbers and pointers here.
+ * For file I/O, see fio.h.
+ */
+
+/*
+ * Get one unsigned byte. Note that this is a proper expression.
+ * The rest have more limited contexts, and are therefore OddLy
+ * CapItaliseD.
+ */
+#define pgetbyte(p) UnSign8(*(p)++)
+
+/*
+ * Get a two-byte unsigned integer, a three-byte unsigned integer,
+ * or a four-byte signed integer.
+ */
+#define pGetWord(p, r) ((r) = UnSign8(*(p)++) << 8, \
+ (r) |= UnSign8(*(p)++))
+#define pGet3Byte(p,r) ((r) = UnSign8(*(p)++) << 16, \
+ (r) |= UnSign8(*(p)++) << 8, \
+ (r) |= UnSign8(*(p)++))
+#define pGetLong(p, r) ((r) = UnSign8(*(p)++) << 24, \
+ (r) |= UnSign8(*(p)++) << 16, \
+ (r) |= UnSign8(*(p)++) << 8, \
+ (r) |= UnSign8(*(p)++))
+
+/*
+ * ADD pputbyte, pPutWord, pPut3Byte, pPutLong HERE IF THEY PROVE
+ * USEFUL. (But then must consider changing PutWord &c in fio.h.)
+ */
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/pkdetails.h b/dviware/epson/eps-0.2/h/pkdetails.h
new file mode 100644
index 0000000000..8562f4b5d4
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/pkdetails.h
@@ -0,0 +1,24 @@
+#ifndef pkdetails_h
+#define pkdetails_h
+
+struct cp {
+ char *cp_packet; /* the beginning of the packet */
+ int cp_type; /* decoded pre type, see below */
+};
+
+struct pk_details {
+ char *pk_ptr; /* next byte to fetch */
+ int pk_c; /* most recent byte fetched, if nybbling */
+ int pk_1nyb; /* true => nybble 1 is next (bits 0..3) */
+ char *pk_base; /* base of allocated memory */
+ int pk_dyn_f; /* the dyn_f value */
+ int pk_repeat; /* the repeat count */
+ int pk_minc; /* minimum character value */
+ int pk_maxc; /* maximum character value */
+#define MAXSTD 256 /* maximum `standard' character value */
+ int pk_gleft; /* number of valid glyphs left uninterpreted */
+ struct cp pk_cpack[MAXSTD]; /* for characters in [0..MAXSTD) */
+ struct cp *pk_morec; /* for characters in [MAXSTD..maxc] */
+};
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/postamble.h b/dviware/epson/eps-0.2/h/postamble.h
new file mode 100644
index 0000000000..8830dc2c8e
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/postamble.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef postamble_h
+#define postamble_h
+
+/* Definitions for ScanPostAmble */
+
+/*
+ * ScanPostAmble reads the postamble of a DVI file from the (stdio)
+ * file specified in its first argument. It is handed two pointers to
+ * functions. The first (ScanPostAmble's second argument) is called
+ * after the header information has been read, and given a pointer to a
+ * PostAmbleInfo structure. It is the job of this function to extract the
+ * required information from this structure (which is deallocated when
+ * ScanPostAmble returns).
+ *
+ * The second function is called once for each font definition occurring in
+ * the postamble, and is given a pointer to a PostAmbleFont structure. This
+ * function should do whatever the device needs to read the actual font.
+ *
+ * If the DVI file appears malformed, ScanPostAmble will print an error
+ * message and exit. (Drastic, perhaps, but effective.)
+ */
+
+struct PostAmbleInfo {
+ i32 pai_PrevPagePointer; /* previous page pointer */
+ i32 pai_Numerator; /* numerator from dvi file */
+ i32 pai_Denominator; /* denominator from dvi file*/
+ i32 pai_DVIMag; /* \magnification */
+ i32 pai_TallestPageHeight; /* height of tallest page */
+ i32 pai_WidestPageWidth; /* width of widest page */
+ int pai_DVIStackSize; /* DVI stack size required */
+ int pai_NumberOfPages; /* total number of pages in DVI file */
+};
+
+struct PostAmbleFont {
+ char *paf_name; /* name of font (null terminated) */
+ int paf_n1; /* length of first part of name */
+ int paf_n2; /* length of second part of name */
+ i32 paf_DVIFontIndex; /* font index number */
+ i32 paf_DVIChecksum; /* checksum from DVI file */
+ i32 paf_DVIMag; /* "at size" */
+ i32 paf_DVIDesignSize; /* design size of font */
+};
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/sdecode.h b/dviware/epson/eps-0.2/h/sdecode.h
new file mode 100644
index 0000000000..31b30de342
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/sdecode.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef sdecode_h
+#define sdecode_h
+
+/*
+ * Specials consist of keyword/value groupings, with the simple syntax
+ * suggested by the BNF
+ *
+ * list ::= kv | list ',' kv
+ * kv ::= word opt_eq words
+ * opt_eq ::= '=' | <empty>
+ * words ::= word | words ' ' word
+ *
+ * `Words' include any character that is not a space, comma, or quote,
+ * and can include these by using quoting. Inside and outside quotes,
+ * `\"' produces `"'; `\\' produces `\'; and `\,' produces `,'.
+ *
+ * No single word can exceed WDMAX characters (after quotes are interpreted).
+ * WDMAX is defined in sdecode.c, and is typically large (>= 1024).
+ *
+ * Each special is typed according to its arguments, which are collected
+ * and decoded, and passed to the special function as ordinary parameters.
+ * All possible argument-types must be known to the special decoder.
+ * The function also receives its own name (from the table) as its
+ * first argument.
+ */
+
+/* value argument types */
+enum sd_args {
+ sda_none, /* no arguments, just a flag */
+ sda_s, /* one string argument (`foo abc') */
+ sda_d, /* one decimal (i32) argument (`foo 2') */
+ sda_f, /* one floating (double) argument (`foo 3.14') */
+ sda_dd, /* two decimal arguments (`foo 3 4') */
+ sda_ff, /* two floating arguments (`foo .3 .4') */
+ sda_ddddff, /* four decimal args, then 2 floating args */
+ sda_nd, /* array n of decimal arguments */
+ sda_nx, /* array n of hex arguments (`x 1a00 d02f ...') */
+ sda_rest /* fn(len1, ptr, len2); uses up rest of input */
+};
+
+struct sdecode {
+ char *sd_name; /* keyword to match */
+ enum sd_args sd_args; /* arguments to collect */
+ void (*sd_fn)(...); /* actual arguments depend on sd_args */
+};
+
+#define SDsize(tab) ((int)(sizeof(tab) / sizeof(*tab)))
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/search.h b/dviware/epson/eps-0.2/h/search.h
new file mode 100644
index 0000000000..9cf5e312be
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/search.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef search_h
+#define search_h
+
+/* search structures and routines for 32-bit key, arbitrary data */
+
+struct search {
+ unsigned s_dsize; /* data object size (includes key size) */
+ unsigned s_space; /* space left (in terms of objects) */
+ unsigned s_n; /* number of objects in the table */
+ char *s_data; /* data area */
+};
+
+/* returns a pointer to the search table (for future search/installs) */
+struct search *SCreate(); /* create a search table */
+
+/* returns a pointer to the data object found or created */
+char *SSearch(); /* search for a data object */
+
+/* clears a search table (wipes out all entries) */
+#define SClear(s) ((s)->s_space += (s)->s_n, (s)->s_n = 0)
+
+/* the third argument to SSearch controls operation as follows: */
+#define S_LOOKUP 0x00 /* pseudo flag */
+#define S_CREATE 0x01 /* create object if not found */
+#define S_EXCL 0x02 /* complain if already exists */
+
+/* in addition, it is modified before return to hold status: */
+#define S_COLL 0x04 /* collision (occurs iff S_EXCL set) */
+#define S_FOUND 0x08 /* found (occurs iff existed already) */
+#define S_NEW 0x10 /* created (occurs iff S_CREATE && !S_EXCL) */
+#define S_ERROR 0x20 /* problem creating (out of memory) */
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/seek.h b/dviware/epson/eps-0.2/h/seek.h
new file mode 100644
index 0000000000..07617d6bea
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/seek.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef seek_h
+#define seek_h
+
+/*
+ * Declarations for seek.c: SeekFile(FILE *fp) returns a
+ * version of `fp' on which `fseek' functions properly;
+ * CopyFile(FILE *fp) returns a temporary copy of fp.
+ */
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/tfm.h b/dviware/epson/eps-0.2/h/tfm.h
new file mode 100644
index 0000000000..72e196f799
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/tfm.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef tfm_h
+#define tfm_h
+
+/*
+ * TFM file information.
+ */
+
+/*
+ * TFM files start with a series of unsigned 16 bit integers. We
+ * read this into the structure `tfm_header'. These are type i32
+ * so that they may be used as integer quantities without concern
+ * as to sign extension.
+ */
+struct tfmheader {
+ i32 th_lf; /* length of the file (16 bit words) */
+ i32 th_lh; /* length of the header data (words) */
+ i32 th_bc; /* beginning character */
+ i32 th_ec; /* ending character (inclusive) */
+ i32 th_nw; /* number of words in width table */
+ i32 th_nh; /* number of words in height table */
+ i32 th_nd; /* number of words in depth table */
+ i32 th_ni; /* words in italic correction table */
+ i32 th_nl; /* words in ligature/kern table */
+ i32 th_nk; /* words in kern table */
+ i32 th_ne; /* words in extensible character table */
+ i32 th_np; /* number of font parameter words */
+};
+
+/*
+ * The remainder of the TFM file comprises the following information,
+ * all of which are 32 bit quantities:
+ *
+ * header: array [0..lh-1] of stuff
+ * char_info: array [bc..ec] of char_info_word
+ * width: array [0..nw-1] of fix_word
+ * height: array [0..nh-1] of fix_word
+ * depth: array [0..nd-1] of fix_word
+ * italic: array [0..ni-1] of fix_word
+ * lig_kern: array [0..nl-1] of lig_kern_command
+ * kern: array [0..ne-1] of extensible_recipie
+ * param: array [0..np-1] of fix_word
+ */
+
+/*
+ * A char_info_word is built of four unsigned eight-bit quantities. The first
+ * is an index into the width table (this saves 24 bits for every
+ * character that has the same width as another character). The
+ * second is a composite height and depth index. The third is a
+ * composite italic index and tag, and the fourth is a remainder.
+ *
+ * XXX needs explaining
+ */
+struct char_info_word {
+ char ci_width; /* width index */
+ char ci_h_d; /* height and depth index */
+ char ci_i_t; /* italic index and tag */
+ char ci_remainder; /* ??? */
+};
+
+/*
+ * These macros split up h_and_d and i_and_t values.
+ */
+#define T_CI_H(ci) (((ci)->ci_h_d >> 4) & 0xf)
+#define T_CI_D(ci) ((ci)->ci_h_d & 0xf)
+#define T_CI_I(ci) (((ci)->ci_i_t >> 2) & 0x3f)
+#define T_CI_T(ci) ((ci)->ci_i_t & 3)
+
+/*
+ * This structure contains everything one might need to know about
+ * a TFM file at run-time.
+ *
+ * XXX incomplete, or wrong, as yet
+ */
+struct tfmdata {
+ struct tfmheader t_hdr; /* full header */
+ struct char_info_word *t_ci; /* char info */
+ i32 *t_width; /* widths table */
+ i32 *t_height; /* heights */
+ i32 *t_depth; /* depths */
+};
+
+#endif
diff --git a/dviware/epson/eps-0.2/h/types.h b/dviware/epson/eps-0.2/h/types.h
new file mode 100644
index 0000000000..1d38f45db9
--- /dev/null
+++ b/dviware/epson/eps-0.2/h/types.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+/*
+ * MC-TeX types and macros (system dependent).
+ * Check to make sure they are correct for your system.
+ */
+
+#ifndef _MCTEX_TYPES_
+#define _MCTEX_TYPES_
+
+/*
+ * Define void as int if your compiler does not support void,
+ * or if there are bugs in its support (e.g., 4.1BSD).
+ */
+/* #define void int */
+
+/*
+ * Define the following if and only if vfprintf is in your C library.
+ * If not, lib/error.c will make assumptions about the implementation
+ * of stdio. If neither works, you may have to come up with something
+ * yourself.
+ */
+#define HAVE_VPRINTF
+
+/*
+ * Define BSD_FILE_SYSTEM if you have the BSD file system `stat'
+ * structure (with the st_blksize field). Otherwise, MakeSeekable()
+ * will be slower than necessary.
+ */
+/* #define BSD_FILE_SYSTEM */
+
+/*
+ * Define this as the name of a routine that handles overlapping block
+ * copies, if there is such a routine. Usually it will be called memmove()
+ * but on 4.3BSD it is called bcopy(). Note that the 4.2BSD bcopy() does
+ * not handle overlap, and must not be used here. If there is no routine,
+ * or if its overlap handling is uncertain, leave BLOCK_COPY undefined.
+ *
+ * (The bcopy provided in lib/bcopy.c does handle overlap.)
+ */
+#include <strings.h> /* for bcopy */
+#define BLOCK_COPY(from, to, len) bcopy(from, to, len)
+
+/*
+ * If you have memcpy/memmove, but not bcopy, use the definition below.
+ * If you have neither, try the bcopy provided in lib/bcopy.c.
+ */
+/* #define bcopy(from, to, len) memcpy(to, from, len) */
+
+/*
+ * If you have memcmp, but not bcmp, use the definition below.
+ * If you have neither, try the bcmp provided in lib/bcmp.c.
+ */
+/* #define bcmp(s1, s2, len) memcmp(s1, s2, len) */
+
+/* #define bzero(addr, count) memset(addr, 0, count) */
+
+/*
+ * Define the following types and macros as required by your system.
+ */
+
+typedef short i16; /* a 16 bit integer (signed) */
+
+typedef long i32; /* a 32 bit integer (signed) */
+typedef unsigned long ui32; /* a 32 bit integer (unsigned) */
+
+/* macros to sign extend quantities that are less than 32 bits long */
+
+/* these compilers mishandle (int)(char)(constant), but a subterfuge works */
+#if defined(sun) || defined(hp300)
+#define Sign8(n) ((i32)(char)(int)(n))
+#endif
+
+/* these have signed characters and (int)(char)(constant) works */
+#if defined(vax) || defined(mips)
+#define Sign8(n) ((i32)(char)(n))
+#endif
+
+/* this works everywhere, but may be slow */
+#ifndef Sign8
+#define Sign8(n) ((n) & 0x80 ? ((n) | ~0xff) : (n))
+#endif
+
+/* this should work everywhere */
+#ifndef Sign16
+#define Sign16(n) ((i32)(i16)(n))
+#endif
+
+/* this works where int is 32 bits, and >> sign extents and is fast */
+#if defined(vax) || defined(mips)
+#define Sign24(n) (((n) << 8) >> 8)
+#endif
+
+/* this works everywhere, but may be slow */
+#ifndef Sign24
+#define Sign24(n) ((n) & 0x800000L ? ((n) | ~0xffffffL) : (n))
+#endif
+
+/* macros to truncate quantites that may be signed */
+#define UnSign8(n) ((i32)(n) & 0xffL)
+#define UnSign16(n) ((i32)(n) & 0xffffL)
+#define UnSign24(n) ((i32)(n) & 0xffffffL)
+
+#endif /* _MCTEX_TYPES_ */
diff --git a/dviware/epson/eps-0.2/lib/Makefile b/dviware/epson/eps-0.2/lib/Makefile
new file mode 100644
index 0000000000..f2206462d7
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/Makefile
@@ -0,0 +1,103 @@
+#
+# Copyright (c) 1987, 1989 University of Maryland
+# Department of Computer Science. All rights reserved.
+# Permission to copy for any purpose is hereby granted
+# so long as this copyright notice remains intact.
+#
+# Makefile for ctex/lib (C-TeX library routines)
+#
+# $Header: /usr/src/local/tex/local/mctex/lib/RCS/Makefile,v 3.2 89/10/17 09:27:30 chris Exp $
+#
+CFLAGS= -x c++ -I../h -O
+
+%.o: %.c
+ gcc -c -x c++ -I../h -O $<
+
+DESTDIR=
+
+CC=gcc
+# SysV sites should set RANLIB=:
+RANLIB= ranlib
+#RANLIB=:
+
+# This will be overridden by ../Makefile, but just in case...
+FONTDESC=/usr/local/lib/tex/fonts/fontdesc
+
+# 4.1BSD Vax:
+#ASSRC= vaxbcopy.s vaxbzero.s
+#ASOBJ= vaxbcopy.o vaxbzero.o
+#MISCC= getopt.c
+#MISCO= getopt.o
+
+# 4.2BSD Vax:
+#ASSRC=
+#ASOBJ=
+#MISCC= getopt.c
+#MISCO= getopt.o
+
+# 4.2BSD Sun:
+#ASSRC=
+#ASOBJ=
+#MISCC=
+#MISCO=
+
+# 4.2BSD Pyramid:
+#ASSRC=
+#ASOBJ=
+#MISCC= getopt.c
+#MISCO= getopt.o
+
+# 4.3BSD Vax, and many others
+ASSRC=
+ASOBJ=
+MISCC=
+MISCO=
+
+# machines without any of bcopy,bzero,getopt
+#ASSRC=
+#ASOBJ=
+#MISCC= bcopy.c bzero.c getopt.c
+#MISCO= bcopy.o bzero.o getopt.o
+
+MISCO= getopt.o
+# all machines
+# regular library routines
+CSRC= conv.c dviclass.c dvistate.c error.c findpost.c fio.c font.c \
+ font_subr.c gfclass.c gripes0.c gripes1.c magfactor.c rotate.c \
+ scaletfm.c scanpost.c sdecode.c search.c seek.c skip.c split.c \
+ strsave.c tempfile.c tfm.c ${MISCC}
+COBJ= conv.o dviclass.o dvistate.o error.o findpost.o fio.o font.o \
+ font_subr.o gfclass.o gripes0.o gripes1.o magfactor.o rotate.o \
+ scaletfm.o scanpost.o sdecode.o search.o seek.o skip.o split.o \
+ strsave.o tempfile.o tfm.o ${MISCO}
+# font routines
+FSRC= gffont.c pkfont.c pxlfont.c tfmfont.c
+FOBJ= gffont.o pkfont.o pxlfont.o tfmfont.o
+
+OBJS= ${COBJ} ${ASOBJ} ${FOBJ}
+
+all: lib.a
+
+lib.a: ${OBJS}
+ ar cr lib.a ${OBJS}
+ ${RANLIB} lib.a
+
+
+# no installation is necessary; this entry is just for standardisation
+install:
+
+clean:
+ rm -f *.o lib.a
+
+cleandir: clean
+ rm -f .depend
+
+depend: ${CSRC} ${FSRC}
+ mkdep ${CFLAGS} ${CSRC} ${FSRC}
+
+# XXX should be able to check these
+lint:
+
+# font.o needs to know where to find the font description file
+font.o:
+ ${CC} ${CFLAGS} -DFONTDESC=\"${FONTDESC}\" -c font.c
diff --git a/dviware/epson/eps-0.2/lib/bcopy.c b/dviware/epson/eps-0.2/lib/bcopy.c
new file mode 100644
index 0000000000..3fa6ebbd18
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/bcopy.c
@@ -0,0 +1,31 @@
+#include "PROTO.h"
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/bcopy.c,v 3.1 89/08/22 21:42:07 chris Exp $";
+#endif
+
+/*
+ * Sample bcopy() routine.
+ * This should be rewritten to be as fast as possible for your
+ * machine.
+ */
+
+#ifndef __MSDOS__
+bcopy(from, to, count)
+ register char *from, *to;
+ register int count;
+{
+
+ if (from == to)
+ return;
+ if (from > to) {
+ while (--count >= 0)
+ *to++ = *from++;
+ } else {
+ from += count;
+ to += count;
+ while (--count >= 0)
+ *--to = *--from;
+ }
+}
+
+#endif /* __MSDOS__ */
diff --git a/dviware/epson/eps-0.2/lib/bzero.c b/dviware/epson/eps-0.2/lib/bzero.c
new file mode 100644
index 0000000000..269b5a210c
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/bzero.c
@@ -0,0 +1,18 @@
+#include "PROTO.h"
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/bzero.c,v 3.1 89/08/22 21:42:12 chris Exp $";
+#endif
+
+/*
+ * Sample bzero() routine.
+ * This should be rewritten to be as fast as possible for your
+ * machine.
+ */
+bzero(addr, count)
+ register char *addr;
+ register int count;
+{
+
+ while (--count >= 0)
+ *addr++ = 0;
+}
diff --git a/dviware/epson/eps-0.2/lib/conv.c b/dviware/epson/eps-0.2/lib/conv.c
new file mode 100644
index 0000000000..fbfc1f0430
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/conv.c
@@ -0,0 +1,53 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/conv.c,v 3.1 89/08/22 21:48:01 chris Exp $";
+#endif
+
+/*
+ * Conversions.
+ */
+
+#include "types.h"
+#include "conv.h"
+
+double DMagFactor();
+
+Conv Conversion; /* the global conversion */
+
+/*
+ * Set a conversion (possibly the global conversion).
+ */
+extern void CSetConversion(register struct conversion *c, int hdpi, int vdpi, int usermag, i32 num, i32 denom, i32 dvimag)
+{
+ double dhdpi = hdpi;
+ double dvdpi = vdpi;
+
+ c->c_mag = DMagFactor((int) dvimag) * DMagFactor(usermag);
+ c->c_hdpi = dhdpi;
+ c->c_vdpi = dvdpi;
+
+ /*
+ * The conversion facture is figured as follows: there are exactly
+ * num/denom DVI units per decimicron, and 254000 decimicrons per
+ * inch, and dpi pixels per inch. Then we have to adjust this by
+ * the stated magnification.
+ */
+ c->c_fromsph = (num / 254000.0) * (dhdpi / denom) * c->c_mag;
+ c->c_fromspv = (num / 254000.0) * (dvdpi / denom) * c->c_mag;
+
+ /*
+ * c->c_tosp is 1/c->c_fromsp, but we will invert the expression
+ * above in the hopes of some extra accuracy.
+ *
+ * IS THIS ANY GOOD? I NEED A NUMERICAL ANALYST!
+ */
+ c->c_tosph = (254000.0 / num) * (denom / dhdpi) * (1.0 / c->c_mag);
+ c->c_tospv = (254000.0 / num) * (denom / dvdpi) * (1.0 / c->c_mag);
+}
diff --git a/dviware/epson/eps-0.2/lib/dviclass.c b/dviware/epson/eps-0.2/lib/dviclass.c
new file mode 100644
index 0000000000..740e62bbf1
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/dviclass.c
@@ -0,0 +1,98 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/dviclass.c,v 3.1 89/08/22 21:48:35 chris Exp $";
+#endif
+
+/*
+ * dviclass - DVI code classification tables.
+ */
+
+#include "dviclass.h"
+
+/* shorthand---in lowercase for contrast (read on!) */
+#define four(x) x, x, x, x
+#define six(x) four(x), x, x
+#define sixteen(x) four(x), four(x), four(x), four(x)
+#define sixty_four(x) sixteen(x), sixteen(x), sixteen(x), sixteen(x)
+#define one_twenty_eight(x) sixty_four(x), sixty_four(x)
+
+/*
+ * This table contains the byte length of the single operand, or DPL_NONE
+ * if no operand, or if it cannot be decoded this way.
+ *
+ * The sequences UNS1, UNS2, UNS3, SGN4 (`SEQ_U') and SGN1, SGN2, SGN3,
+ * SGN4 (`SEQ_S') are rather common, and so we define macros for these.
+ */
+#define SEQ_U DPL_UNS1, DPL_UNS2, DPL_UNS3, DPL_SGN4
+#define SEQ_S DPL_SGN1, DPL_SGN2, DPL_SGN3, DPL_SGN4
+
+char dvi_oplen[256] = {
+ one_twenty_eight(DPL_NONE),
+ /* characters 0 through 127 */
+ SEQ_U, /* DVI_SET1 through DVI_SET4 */
+ DPL_NONE, /* DVI_SETRULE */
+ SEQ_U, /* DVI_PUT1 through DVI_PUT4 */
+ DPL_NONE, /* DVI_PUTRULE */
+ DPL_NONE, /* DVI_NOP */
+ DPL_NONE, /* DVI_BOP */
+ DPL_NONE, /* DVI_EOP */
+ DPL_NONE, /* DVI_PUSH */
+ DPL_NONE, /* DVI_POP */
+ SEQ_S, /* DVI_RIGHT1 through DVI_RIGHT4 */
+ DPL_NONE, /* DVI_W0 */
+ SEQ_S, /* DVI_W1 through DVI_W4 */
+ DPL_NONE, /* DVI_X0 */
+ SEQ_S, /* DVI_X1 through DVI_X4 */
+ SEQ_S, /* DVI_DOWN1 through DVI_DOWN4 */
+ DPL_NONE, /* DVI_Y0 */
+ SEQ_S, /* DVI_Y1 through DVI_Y4 */
+ DPL_NONE, /* DVI_Z0 */
+ SEQ_S, /* DVI_Z1 through DVI_Z4 */
+ sixty_four(DPL_NONE), /* DVI_FNTNUM0 through DVI_FNTNUM63 */
+ SEQ_U, /* DVI_FNT1 through DVI_FNT4 */
+ SEQ_U, /* DVI_XXX1 through DVI_XXX4 */
+ SEQ_U, /* DVI_FNTDEF1 through DVI_FNTDEF4 */
+ DPL_NONE, /* DVI_PRE */
+ DPL_NONE, /* DVI_POST */
+ DPL_NONE, /* DVI_POSTPOST */
+ six(DPL_NONE) /* 250 through 255 */
+};
+
+char dvi_dt[256] = {
+ one_twenty_eight(DT_CHAR),
+ /* characters 0 through 127 */
+ four(DT_SET), /* DVI_SET1 through DVI_SET4 */
+ DT_SETRULE, /* DVI_SETRULE */
+ four(DT_PUT), /* DVI_PUT1 through DVI_PUT4 */
+ DT_PUTRULE, /* DVI_PUTRULE */
+ DT_NOP, /* DVI_NOP */
+ DT_BOP, /* DVI_BOP */
+ DT_EOP, /* DVI_EOP */
+ DT_PUSH, /* DVI_PUSH */
+ DT_POP, /* DVI_POP */
+ four(DT_RIGHT), /* DVI_RIGHT1 through DVI_RIGHT4 */
+ DT_W0, /* DVI_W0 */
+ four(DT_W), /* DVI_W1 through DVI_W4 */
+ DT_X0, /* DVI_X0 */
+ four(DT_X), /* DVI_X1 through DVI_X4 */
+ four(DT_DOWN), /* DVI_DOWN1 through DVI_DOWN4 */
+ DT_Y0, /* DVI_Y0 */
+ four(DT_Y), /* DVI_Y1 through DVI_Y4 */
+ DT_Z0, /* DVI_Z0 */
+ four(DT_Z), /* DVI_Z1 through DVI_Z4 */
+ sixty_four(DT_FNTNUM), /* DVI_FNTNUM0 through DVI_FNTNUM63 */
+ four(DT_FNT), /* DVI_FNT1 through DVI_FNT4 */
+ four(DT_XXX), /* DVI_XXX1 through DVI_XXX4 */
+ four(DT_FNTDEF), /* DVI_FNTDEF1 through DVI_FNTDEF4 */
+ DT_PRE, /* DVI_PRE */
+ DT_POST, /* DVI_POST */
+ DT_POSTPOST, /* DVI_POSTPOST */
+ six(DT_UNDEF) /* 250 through 255 */
+};
diff --git a/dviware/epson/eps-0.2/lib/dvistate.c b/dviware/epson/eps-0.2/lib/dvistate.c
new file mode 100644
index 0000000000..5bba771a0b
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/dvistate.c
@@ -0,0 +1,229 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/dvistate.c,v 1.1 89/08/22 21:49:03 chris Exp $";
+#endif
+
+/*
+ * dvistate - basic DVI machine interpreter
+ */
+
+#include <stdio.h>
+#include "types.h"
+#include "conv.h"
+#include "dvicodes.h"
+#include "error.h"
+#include "fio.h"
+#include "font.h"
+#include "gripes.h"
+#include "postamble.h"
+#include "search.h"
+#include "seek.h"
+#include "dvistate.h"
+
+struct dvi_state ds;
+
+/* yech, statics! */
+static struct font *(*s_deffnt)(char*, i32, i32);
+static int s_hdpi;
+static int s_vdpi;
+static int s_errs;
+
+#include <stdlib.h> /* for malloc() */
+
+/*
+ * Read through the postamble and the preamble and set up the
+ * global DVI state. Each font is passed to (*fontfn)().
+ * Upon return, the input file (fp) is positioned at the beginning
+ * of the first page.
+ *
+ * dpi is the resolution of the printer in pixels (dots) per inch,
+ * and xoffset and yoffset are the values from the -X and -Y flags
+ * (default zero). We add 1000 to each offset (since the offsets
+ * are in 1/1000ths of an inch), and then multiply by dpi and divide
+ * by 1000, to get the actual offset.
+ *
+ * If a device introduces a constant offset, e.g., of .25 inch
+ * horizontally and .31 inch vertically, the caller can compensate
+ * by passing (xflag - 2500) and (yflag - 3100).
+ */
+extern void DVISetState(FILE *fp, struct font *(*fontfn)(char* name, i32 dvimag, i32 dvidsz), int hdpi, int vdpi, int xoffset, int yoffset)
+{
+
+ /* make sure fseek() will work */
+ if ((ds.ds_fp = SeekFile(fp)) == NULL)
+ error(1, -1, "unable to copy input to temp file (disk full?)");
+
+ /* h and v must be deferred until we have a conversion */
+ ds.ds_fresh.hh = ((1000 + (i32)xoffset) * hdpi) / 1000;
+ ds.ds_fresh.vv = ((1000 + (i32)yoffset) * vdpi) / 1000;
+
+ ds.ds_fonts = SCreate(sizeof(struct font *));
+ if (ds.ds_fonts == NULL)
+ error(1, 0, "cannot create font table (out of memory?)");
+ s_errs = 0;
+ s_hdpi = hdpi;
+ s_vdpi = vdpi;
+ s_deffnt = fontfn;
+ ScanPostAmble(ds.ds_fp, post, fntdef);
+ if (s_errs)
+ GripeMissingFontsPreventOutput(s_errs);
+ pre();
+}
+
+/*
+ * Read the preamble and apply sanity checks.
+ * The presence of a preamble is virtually certain,
+ * since we have already found and read a postamble.
+ */
+static void
+pre()
+{
+ register int n;
+ register FILE *fp = ds.ds_fp;
+
+ rewind(fp);
+ if (GetByte(fp) != Sign8(DVI_PRE))
+ GripeMissingOp("PRE");
+ if (GetByte(fp) != Sign8(DVI_VERSION))
+ GripeMismatchedValue("version number");
+ if (GetLong(fp) != ds.ds_num)
+ GripeMismatchedValue("numerator");
+ if (GetLong(fp) != ds.ds_denom)
+ GripeMismatchedValue("denominator");
+ if (GetLong(fp) != ds.ds_dvimag)
+ GripeMismatchedValue("\\magnification");
+ n = UnSign8(GetByte(fp));
+ while (--n >= 0)
+ (void) GetByte(fp);
+}
+
+/*
+ * Store the relevant information from the DVI postamble.
+ */
+static void post(register struct PostAmbleInfo *p)
+{
+ register int n;
+
+ ds.ds_prevpage = p->pai_PrevPagePointer;
+ ds.ds_num = p->pai_Numerator;
+ ds.ds_denom = p->pai_Denominator;
+ ds.ds_dvimag = p->pai_DVIMag;
+ ds.ds_maxheight = p->pai_TallestPageHeight;
+ ds.ds_maxwidth = p->pai_WidestPageWidth;
+ ds.ds_npages = p->pai_NumberOfPages;
+
+ /* set the global conversion factor */
+ SetConversion(s_hdpi, s_vdpi,
+ ds.ds_usermag, ds.ds_num, ds.ds_denom, ds.ds_dvimag);
+
+ ds.ds_fresh.h = toSPh(ds.ds_fresh.hh);
+ ds.ds_fresh.v = toSPv(ds.ds_fresh.vv);
+#ifdef unneeded /* counting on init-to-zero ... */
+ ds.ds_fresh.w = 0;
+ ds.ds_fresh.x = 0;
+ ds.ds_fresh.y = 0;
+ ds.ds_fresh.z = 0;
+#endif
+ /* make the stack */
+ n = p->pai_DVIStackSize * sizeof(DviStack);
+ if ((ds.ds_stack = (struct dvi_stack *)malloc((unsigned)n)) == NULL)
+ GripeOutOfMemory(n, "DVI stack");
+ ds.ds_sp = ds.ds_stack;
+}
+
+/*
+ * Handle a font definition from the postamble.
+ */
+static void fntdef(register struct PostAmbleFont *p)
+{
+ register struct font *f, **fp;
+ int def = S_CREATE | S_EXCL;
+
+ fp = (struct font **)SSearch(ds.ds_fonts, p->paf_DVIFontIndex, &def);
+ if (fp == NULL) {
+ if (def & S_COLL)
+ GripeFontAlreadyDefined(p->paf_DVIFontIndex);
+ else
+ error(1, 0, "cannot stash font %ld (out of memory?)",
+ (long)p->paf_DVIFontIndex);
+ /* NOTREACHED */
+ }
+
+ /* apply driver function to get font */
+ f = (*s_deffnt)(p->paf_name, p->paf_DVIMag, p->paf_DVIDesignSize);
+ if (f == NULL) {
+ s_errs++;
+ return;
+ }
+ *fp = f;
+
+ /* match checksums, unless one is (or both are) zero */
+ if (p->paf_DVIChecksum && f->f_checksum &&
+ p->paf_DVIChecksum != f->f_checksum)
+ GripeDifferentChecksums(f->f_path, p->paf_DVIChecksum,
+ f->f_checksum);
+}
+
+/*
+ * Given a font index, return the corresponding pointer.
+ */
+extern struct font *DVIFindFont(i32 n)
+{
+ int x = S_LOOKUP;
+ char *p;
+
+ if ((p = SSearch(ds.ds_fonts, n, &x)) == NULL) {
+ GripeNoSuchFont(n);
+ /* NOTREACHED */
+ }
+ return (*(struct font **)p);
+}
+
+/*
+ * Handle a rule: read width and height, then call the given function.
+ * If `advance', move dvi position afterwards.
+ */
+extern void DVIRule(void (*fn)(i32 h, i32 w), int advance)
+{
+ register i32 h, w, ww;
+ register FILE *fp = ds.ds_fp;
+
+ fGetLong(fp, h);
+ fGetLong(fp, ww);
+ h = ConvRulev(h);
+ w = ConvRuleh(ww);
+ (*fn)(h, w);
+ if (advance) {
+ dvi_hh += w;
+ dvi_h += ww;
+ w = fromSPh(dvi_h);
+ FIXDRIFT(dvi_hh, w);
+ }
+}
+
+/*
+ * Handle a BOP: read the ten \count values and the previous page pointer,
+ * reset DVI position, and call the given function.
+ */
+extern void DVIBeginPage(void (*fn)(i32* count))
+{
+ register int i;
+ i32 count[10];
+
+ for (i = 0; i < 10; i++)
+ count[i] = GetLong(ds.ds_fp);
+ ds.ds_prevpage = GetLong(ds.ds_fp);
+
+ /* reset DVI page position and stack pointer, then call driver */
+ ds.ds_cur = ds.ds_fresh;
+ ds.ds_sp = ds.ds_stack;
+
+ (*fn)(count);
+}
diff --git a/dviware/epson/eps-0.2/lib/error.c b/dviware/epson/eps-0.2/lib/error.c
new file mode 100644
index 0000000000..bde9dfd674
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/error.c
@@ -0,0 +1,185 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/error.c,v 2.8 89/08/22 21:49:12 chris Exp $";
+#endif
+
+/*
+ * Print an error message with an optional system error number, and
+ * optionally quit.
+ *
+ * THIS CODE IS SYSTEM DEPENDENT UNLESS varargs WORKS WITH vprintf
+ * OR _doprnt. It should work properly under System V using vprintf.
+ * (If you have vprintf, define HAVE_VPRINTF in ../h/types.h.)
+ */
+
+#include "types.h" /* for HAVE_VPRINTF */
+#include "error.h"
+#include <stdio.h>
+#include <stdarg.h>
+
+#if defined(lint) && !defined(LINT_ANYWAY)
+
+/* ARGSUSED */
+void SetErrorTrap(fn) void (*fn)(); {;}
+
+/* VARARGS3 ARGSUSED */
+void error(quit, e, fmt) int quit, e; char *fmt; {;}
+
+/* VARARGS1 ARGSUSED */
+void panic(fmt) char *fmt; { exit(1); /* NOTREACHED */ }
+
+#else lint
+
+extern char *ProgName; /* program name from argv[0] */
+extern int errno; /* Unix system-call error */
+extern char *sys_errlist[]; /* table of error number => string */
+extern int sys_nerr; /* size of table */
+
+static FILE *trap_file; /* error diversion file, if any */
+static void (*trap_fn)(int, char*); /* trap function */
+static char *trap_buf; /* buffer for trapped error strings */
+static int trap_size; /* size of trap_buf */
+
+/* extern char *malloc(), *realloc(); */
+#include <stdlib.h>
+
+/*
+ * Enable error trapping: register the function fn as the trapper.
+ * If fn is NULL, stop trapping.
+ */
+void
+SetErrorTrap(void (*fn)(int, char*))
+{
+ int tempfd;
+ char fname[BUFSIZ];
+
+ /* shut down any existing error trap */
+ if (trap_file) {
+ (void) fclose(trap_file);
+ trap_file = NULL;
+ }
+ if ((trap_fn = fn) == NULL)
+ return;
+ /* begin trapping */
+ if ((tempfd = MakeRWTempFile(fname)) < 0)
+ error(1, -1, "cannot create temporary file %s", fname);
+ if (trap_size == 0) {
+ trap_buf = (char*)malloc((unsigned)(trap_size = 1000));
+ if (trap_buf == 0)
+ error(1, -1,
+ "cannot get space for error buffer");
+ }
+ if ((trap_file = fdopen(tempfd, "r+")) == NULL)
+ error(1, -1, "cannot get stdio file for error trap");
+}
+
+/*
+ * Read a trapped error into trap_buf.
+ * Return a pointer to the (NUL-terminated) text.
+ * If something goes wrong, return something else printable.
+ */
+static char *
+readback()
+{
+ int nbytes = ftell(trap_file) + 1;
+
+ if (nbytes > trap_size) {
+ if (trap_buf == NULL)
+ trap_buf = (char*)malloc((unsigned)nbytes);
+ else
+ trap_buf = (char*)realloc(trap_buf, (unsigned)nbytes);
+ if (trap_buf == NULL) {
+ trap_size = 0;
+ return ("Ouch! Lost error text: out of memory?");
+ }
+ }
+ rewind(trap_file); /* now can read */
+ nbytes = fread(trap_buf, 1, nbytes, trap_file);
+ if (nbytes < 0)
+ return ("Ouch! Trouble reading error text!");
+ trap_buf[nbytes] = 0;
+ return (trap_buf);
+}
+
+/*
+ * Print an error message to the error output (either stderr, or
+ * if trapping errors, to the error trap file). We precede this
+ * with the program's name and an optional string (a0), then use
+ * the format and variable argument list, then append an optional
+ * Unix error string. Finally, if errors are being trapped, we
+ * pass the error text and the quit flag to the trap function.
+ *
+ * In the interest of `look and feel', if errors are being trapped,
+ * the program name is omitted.
+ */
+static void
+verror(int quit, char* a0, char* fmt, va_list l, int e)
+{
+ register FILE *fp = trap_file;
+
+ /* print to the trap file, if any, else stderr */
+ if ((fp = trap_file) != NULL)
+ rewind(fp); /* now can write */
+ else {
+ fp = stderr;
+ (void) fflush(fp);
+ }
+ if (trap_file == NULL)
+ (void) fprintf(fp, "%s: ", ProgName);
+ if (a0)
+ (void) fprintf(fp, "%s", a0);
+#ifdef HAVE_VPRINTF
+ (void) vfprintf(fp, fmt, l);
+#else
+ (void) _doprnt(fmt, l, fp);
+#endif
+ if (e > 0) {
+ if (e < sys_nerr)
+ (void) fprintf(fp, ": %s", sys_errlist[e]);
+ else
+ (void) fprintf(fp, ": Unknown error code %d", e);
+ }
+ (void) putc('\n', fp);
+ (void) fflush(fp);
+ if (trap_file != NULL)
+ (*trap_fn)(quit, readback());
+ if (quit)
+ exit(quit);
+}
+
+/*
+ * Print an error message and optionally quit.
+ */
+void
+error(int quit, int e, char* fmt, ...)
+{
+ va_list l;
+
+ va_start(l, fmt);
+ verror(quit, (char *)NULL, fmt, l, e);
+ va_end(l);
+}
+
+/*
+ * Panic (print to stderr and abort).
+ */
+void
+panic(char* fmt, ...)
+{
+ va_list l;
+
+ SetErrorTrap((void (*)(int,char*))NULL); /* shut down any trap */
+ va_start(l, fmt);
+ verror(0, "panic: ", fmt, l, 0);
+ va_end(l);
+ abort();
+}
+
+#endif /* lint */
diff --git a/dviware/epson/eps-0.2/lib/findpost.c b/dviware/epson/eps-0.2/lib/findpost.c
new file mode 100644
index 0000000000..f42d0a617d
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/findpost.c
@@ -0,0 +1,86 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/findpost.c,v 2.3 89/08/22 21:50:11 chris Exp $";
+#endif
+
+/*
+ * FindPostAmble - Find the postamble of a DVI file.
+ *
+ * N.B.: This routine assumes that ftell() returns byte offsets,
+ * not magic cookies.
+ */
+
+#include <stdio.h>
+#include "types.h"
+#include "dvicodes.h"
+#include "fio.h"
+#include "num.h"
+
+/*
+ * The end of the file consists of a four-byte postamble pointer,
+ * followed by the DVI_VERSION byte, followed by at least four
+ * bytes of DVI_FILLER, and at least enough bytes to make the file
+ * size a multiple of four. Normally, this would be between 4 and 7
+ * inclusive, but some versions of TeX append huge amounts of padding.
+ */
+#define POSTSIZE 512 /* how many bytes to read at a time */
+
+/* long ftell(); */ /* should be declared in stdio.h */
+
+extern int FindPostAmble(register FILE *f)
+{
+ register long offset;
+ register char *p;
+ register int i;
+ register i32 n;
+ char postbuf[POSTSIZE];
+
+ /*
+ * Working backwards from end-of-file, read POSTSIZE bytes.
+ * Keep looking until we find something or run out of filler.
+ */
+ fseek(f, 0L, 2);
+ offset = ftell(f);
+ do {
+ if ((offset -= POSTSIZE) < 0L)
+ offset = 0L; /* no negative fseeks please */
+ fseek(f, offset, 0);
+ if ((i = fread(postbuf, sizeof(char), POSTSIZE, f)) <= 0)
+ break;
+ for (p = postbuf + i; --i >= 0;)
+ if (UnSign8(*--p) != DVI_FILLER)
+ goto found_something;
+ } while (offset);
+ return (-1); /* ran out of filler: not a DVI file */
+
+ /*
+ * We found something other than a filler byte at *p (which is
+ * the same as postbuf[i]). It had better be a version byte.
+ * If so, we want to start at the byte four bytes before that,
+ * and get one long; that will tell us where the postamble
+ * begins.
+ */
+found_something:
+ if (UnSign8(*p) != DVI_VERSION)
+ return (-1); /* not a DVI file */
+ if ((i -= 4) >= 0) {
+ /* it is in the buffer, so just fish it out */
+ p -= 4;
+ pGetLong(p, n);
+ } else {
+ if ((offset += i) < 0L)
+ return (-1); /* tsk */
+ fseek(f, offset, 0);
+ fGetLong(f, n);
+ }
+ offset = n;
+ fseek(f, offset, 0);
+ return (0); /* success */
+}
diff --git a/dviware/epson/eps-0.2/lib/fio.c b/dviware/epson/eps-0.2/lib/fio.c
new file mode 100644
index 0000000000..4fd01f77c4
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/fio.c
@@ -0,0 +1,44 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/fio.c,v 2.4 89/08/22 21:50:31 chris Exp $";
+#endif
+
+/*
+ * File I/O subroutines for getting bytes, words, 3bytes, and longwords.
+ * N.B.: these believe they are working on a DVI file.
+ */
+
+#include <stdio.h>
+#include "types.h"
+#include "error.h"
+#include "fio.h"
+
+static char eofmsg[] = "unexpected EOF, help";
+
+/* for symmetry: */
+#define fGetByte(fp, r) ((r) = getc(fp))
+#define Sign32(i) (i)
+
+#define make(name, func, signextend) \
+i32 \
+name(register FILE *fp) \
+{ \
+ register i32 n; \
+ \
+ func(fp, n); \
+ if (feof(fp)) \
+ error(1, 0, eofmsg); \
+ return (signextend(n)); \
+}
+
+make(GetByte, fGetByte, Sign8)
+make(GetWord, fGetWord, Sign16)
+make(Get3Byte, fGet3Byte, Sign24)
+make(GetLong, fGetLong, Sign32)
diff --git a/dviware/epson/eps-0.2/lib/font.c b/dviware/epson/eps-0.2/lib/font.c
new file mode 100644
index 0000000000..bd0f821dfa
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/font.c
@@ -0,0 +1,508 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/font.c,v 2.12 89/11/06 15:00:47 chris Exp $";
+#endif
+
+/*
+ * Routines for working with fonts. In particular, the configuration
+ * dependent code is here.
+ *
+ * Specific fonts (GF, PXL, etc.) have functions in separate files.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <ctype.h>
+#include "types.h"
+#include "conv.h"
+#include "error.h"
+#include "font.h"
+
+/*
+ * Define the default configuration file.
+ * Also define the maximum path name length.
+ */
+#ifdef __MSDOS__
+#define FONTDESC "d:\\tex\\fontdesc"
+#endif
+#ifndef FONTDESC
+#define FONTDESC "/usr/local/lib/tex/fontdesc"
+#endif
+
+#define PATHLEN 1024
+
+/*
+ * A font configuration. The font list is ordered.
+ *
+ * A specifier is typically a particular print engine, since
+ * different engines need slightly different fonts.
+ */
+
+/*
+ * EQ is a fast way to check for string equivalence.
+ */
+#define EQ(a, b) (*(a) == *(b) && strcmp(a, b) == 0)
+
+/*
+ * Private variables and functions.
+ */
+static int didinit; /* true => initialised already */
+static char *cfname; /* config file name, for errors */
+static int cfline; /* config file line, likewise */
+static struct fontops *fontops;/* font operations code: list head */
+static struct fontconf *fonts; /* font list */
+static struct fontconf **nextfc;/* used during initialisation */
+static char spec_any[] = "*"; /* the `anything' specifier */
+
+
+/*
+ * Imports.
+ */
+extern int errno;
+#include <stdlib.h> /* getenv, malloc */
+#include <string.h> /* strncpy */
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+# include <io.h>
+#else
+# include <osfcn.h> /* open */
+#endif
+
+/*
+ * You may get warnings from lint about sprintf(), which is of type
+ * `char *' in early 4BSD releases. Ignore the warning.
+ */
+
+/*
+ * Here, alas, we know about all the kinds of fonts.
+ * This also means that every DVI interpreter pulls in
+ * the full set of font manipulation routines.
+ *
+ * PERHAPS THIS SHOULD BE CONFIGURABLE.
+ */
+#define ADDFONT(x) { \
+ extern struct fontops x; \
+ x.fo_next = fontops; \
+ fontops = &x; \
+}
+
+extern void fontinit(char *file)
+{
+
+ if (didinit) {
+ /*
+ * Could free the old configuration and fire up
+ * a new one, but for now . . .
+ */
+ error(1, 0, "attempt to reinit fonts");
+ /* NOTREACHED */
+ }
+ didinit++;
+ ADDFONT(invisops);
+ ADDFONT(tfmops);
+ ADDFONT(blankops);
+ ADDFONT(boxops);
+ ADDFONT(pxlops);
+ ADDFONT(gfops);
+ ADDFONT(pkops);
+ nextfc = &fonts;
+ if (file == NULL)
+ if ((file = getenv(CONFENV)) == NULL)
+ file = FONTDESC;
+ readconf(file);
+}
+
+/*
+ * Find a font's operations, given its name.
+ */
+static struct fontops *findops(register char *name)
+{
+ register struct fontops *fo;
+
+ for (fo = fontops; fo != NULL; fo = fo->fo_next)
+ if (EQ(fo->fo_name, name))
+ return (fo);
+ return (NULL);
+}
+
+/*
+ * Read the named configuration file. The file is split into
+ * lines, and lines are split into words; if the first word is
+ * "font", this is a fontconf, and we read the remainder of the
+ * words and make a fontconf entry.
+ */
+static void readconf(char *name)
+{
+ register FILE *f; /* config file */
+ register int c; /* char and word counter */
+ int isenv; /* true => doing `fontenv', not `font' */
+ char *env; /* value from getenv() */
+ struct fontconf proto; /* prototype fontconf */
+ char *v[20]; /* word vector */
+ char line[BUFSIZ]; /* input line */
+
+ if ((f = fopen(name, "r")) == NULL)
+ error(1, -1, "cannot read font configuration file \"%s\"",
+ name);
+ cfname = name;
+ cfline = 0;
+ while (fgets(line, sizeof (line), f) != NULL) {
+ cfline++;
+ if ((c = strlen(line)) > 0) {
+ if (line[--c] != '\n')
+ badcf("line too long");
+ line[c] = 0;
+ }
+ if ((c = split(line, v, sizeof v / sizeof *v)) < 0)
+ badcf("too many words");
+ /* skip things that are not fonts */
+ if (c == 0)
+ continue;
+ if (EQ(v[0], "font"))
+ isenv = 0;
+ else if (EQ(v[0], "fontenv"))
+ isenv = 1;
+ else
+ continue;
+ switch (c) {
+ case 1:
+ badcf("missing font typename");
+ /* NOTREACHED */
+ case 2:
+ badcf("missing font spec (engine)");
+ /* NOTREACHED */
+ case 3:
+ badcf("missing slop value");
+ /* NOTREACHED */
+ case 4:
+ badcf(isenv ? "need environment variable" :
+ "need pathname");
+ /* NOTREACHED */
+ case 5:
+ if (isenv)
+ badcf("need suffix");
+ break;
+ case 6:
+ if (isenv)
+ break;
+ default:
+ error(0, 0,
+ "%s, line %d: warning: %d extra word(s) ignored",
+ cfname, cfline, c - 5);
+ break;
+ }
+ if ((proto.fc_ops = findops(v[1])) == NULL) {
+ error(0, 0,
+ "\"%s\", line %d: unknown font type \"%s\" ignored",
+ cfname, cfline, v[1]);
+ continue;
+ }
+
+ /*
+ * For fontenv, if the environment variable is not actually
+ * set in the environment, just skip over this line.
+ */
+ if (isenv && (env = getenv(v[4])) == NULL)
+ continue;
+ proto.fc_next = NULL;
+ proto.fc_spec = EQ(v[2], spec_any) ? NULL : strsave(v[2]);
+ proto.fc_slop = atoi(v[3]);
+ if (proto.fc_slop < 0) /* quietly enforce proper slops */
+ proto.fc_slop = 0;
+ if (isenv)
+ setfenv(&proto, env, v[5]);
+ else
+ setfont(&proto, strsave(v[4]));
+ }
+}
+
+/*
+ * Handle fontenv lines by appending as many configuration entries
+ * as there are components in the given environment variable.
+ */
+static void setfenv(struct fontconf *pfc, char *env, char *suf)
+{
+ register char *s, *t;
+ register int len, suflen = strlen(suf);
+ register char *mem, *slash;
+ char *munch = strsave(env); /* a copy we can write on */
+ struct fontops *fo;
+
+ /*
+ * Loop over the path. Turn `foo' into `foo/<suf1><suf2>';
+ * turn an empty string into just <suf1><suf2>. Put these
+ * names in fresh memory and set them up as places to search.
+ */
+ for (s = env; (t = s) != NULL; s = t) {
+ for (;;) {
+ if (*t == ':') {
+ *t++ = 0;
+ len = t - s; /* includes trailing NUL */
+ break;
+ }
+ if (*t++ == 0) {
+ len = t - s; /* includes trailing NUL */
+ t = NULL;
+ break;
+ }
+ }
+ if (len != 0) {
+#ifdef __MSDOS__
+ slash = "\\";
+#else
+ slash = "/";
+#endif
+ len++;
+ } else
+ slash = "";
+ if ((mem = (char*)malloc(len + suflen)) == NULL)
+ error(1, -1, "out of memory while saving $%s", env);
+ (void) sprintf(mem, "%s%s%s", s, slash, suf);
+ setfont(pfc, mem);
+ }
+ free(munch);
+}
+
+/*
+ * Turn a prototype fontconf into a real one.
+ */
+static void setfont(struct fontconf *pfc, char *path)
+{
+ register struct fontconf *fc;
+
+ if ((fc = (struct fontconf *)malloc(sizeof(*fc))) == NULL)
+ error(1, -1, "out of memory for font configuration (sorry)");
+ *fc = *pfc;
+ fc->fc_path = path;
+ *nextfc = fc;
+ nextfc = &fc->fc_next;
+}
+
+/*
+ * Complain about a problem in the configuration file.
+ */
+static void badcf(char *why)
+{
+
+ error(1, 0, "\"%s\", line %d: %s", cfname, cfline, why);
+ /* NOTREACHED */
+}
+
+/*
+ * Copy string s into buffer buf, dropping off any numerical suffix.
+ * E.g., cmr7 and cmr10 become cmr. (This is the `%b' operator.)
+ */
+static void basify(char *s, char *buf, int size)
+{
+ register char *p, *endp;
+ register int n;
+
+ for (p = s; *p; p++)
+ if (!isdigit(*p))
+ endp = p;
+ if ((n = endp + 1 - s) >= size)
+ error(1, 0, "font name `%s' too long for %%b (sorry)", s);
+ (void) strncpy(buf, s, n);
+ buf[n] = 0;
+}
+
+/*
+ * Turn a prototype path, name, and magnification into a full
+ * path (expand %f, %m, %b).
+ */
+static void pave(char *result, char *proto, char *name, int mag)
+{
+ register int c;
+ register char *s, *d, *p;
+ char num[30], fontbase[256];
+
+ d = result;
+ p = proto;
+ s = NULL;
+ num[0] = 0; /* will need changing for other bases */
+ fontbase[0] = 0;
+
+ while (p != NULL) {
+ /*
+ * If sourcing from s, take its next character, and
+ * insert it directly. Otherwise take the next path
+ * character and interpret it.
+ */
+ if (s != NULL) {
+ if ((c = *s++) == 0) {
+ s = NULL;
+ continue;
+ }
+ goto put;
+ }
+ if ((c = *p++) == 0)
+ p = NULL;
+ if (c != '%')
+ goto put;
+
+ switch (c = *p++) {
+
+ case 'b':
+ if (fontbase[0] == 0)
+ basify(name, fontbase, sizeof(fontbase));
+ s = fontbase;
+ continue;
+
+ case 'f':
+ case 'n':
+ case 's':
+ s = name;
+ continue;
+
+ case 'd':
+ case 'm':
+ if (num[0] == 0)
+ (void) sprintf(num, "%d", mag);
+ s = num;
+ continue;
+
+ case 0:
+ c = '%';
+ p--;
+ /* FALLTHROUGH */
+ }
+put:
+ if (d - result >= PATHLEN)
+ error(1, 0, "font path `%s' too long (sorry)", proto);
+ *d++ = c;
+ }
+}
+
+/*
+ * Given a font name and size, return the first font that fits, along
+ * with its name (via fname). If we cannot find such a font, we set
+ * *fname to point to a `canonical' example font name, unless there are
+ * are no fonts for the device, in which case we set *fname to NULL.
+ */
+extern struct font *GetFont(char *nm, i32 dvimag, i32 dvidsz, char *dev, char **fname)
+{
+
+ return (getafont(nm, dvimag, dvidsz, dev, fname, 1));
+}
+
+/*
+ * Same as GetFont, but caller promises never to ask for rasters.
+ */
+extern struct font *GetRasterlessFont(char *nm, i32 dvimag, i32 dvidsz, char *dev, char **fname)
+{
+
+ return (getafont(nm, dvimag, dvidsz, dev, fname, 0));
+}
+
+/*
+ * NEED TO THINK ABOUT gf NAMING CONVENTIONS HERE: ARE THEY LIKE pxl?
+ * WHAT ABOUT OTHERS?
+ */
+static struct font *getafont(char *nm, i32 dvimag, i32 dvidsz, char *dev, char **fname, int wantrast)
+{
+ register int slop, fmag;
+ register struct font *f;
+ register struct fontconf *fc;
+ register struct fontops *fo;
+ register char *path;
+ int fd, scaled;
+ double mag;
+ static char firstpath[PATHLEN], laterpath[PATHLEN];
+
+ if (!didinit)
+ fontinit((char *)NULL);
+
+ /*
+ * The equation below means, approximately, `the font is
+ * magnified by the ratio of the actual size dvimag to the
+ * design size dvidsz, and then further scaled by the
+ * global magnification.' We multiply this by the printer's
+ * resolution in dots per inch, then use the per-font
+ * conversion factor to convert a dots-per-inch value to
+ * a font name `%m' magnification (extension).
+ */
+ mag = (double) dvimag / (double) dvidsz;
+ scaled = mag * 1000.0 + 0.5;
+ mag *= Conversion.c_mag * Conversion.c_hdpi;
+
+ path = firstpath; /* no canonical font name yet */
+ for (fc = fonts; fc != NULL; fc = fc->fc_next) {
+ if (dev != NULL && fc->fc_spec != NULL &&
+ !EQ(dev, fc->fc_spec))
+ continue;
+ /*
+ * Fake fonts are ignored unless there is already
+ * `canonical' real font. The first non-fake font
+ * is the `canonical' one.
+ */
+ fo = fc->fc_ops;
+ if (path == firstpath && fo->fo_fakefont)
+ continue;
+ fmag = mag * fo->fo_dpitomag + 0.5;
+ for (slop = 0; slop <= fc->fc_slop; slop++) {
+ pave(path, fc->fc_path, nm, fmag + slop);
+ if ((fd = open(path, 0)) >= 0)
+ goto found;
+ path = laterpath; /* tried at least one now */
+ if (slop) {
+ pave(path, fc->fc_path, nm, fmag - slop);
+ if ((fd = open(path, 0)) >= 0)
+ goto found;
+ }
+ }
+ }
+
+ /* not found */
+ if (path == firstpath) {
+ *fname = NULL;
+ errno = ENXIO;
+ } else {
+ *fname = firstpath;
+ errno = ENOENT;
+ }
+ return (NULL);
+
+found:
+ *fname = path;
+
+ /* allocate space for the per-font info, and read it in */
+ f = (struct font *)malloc(sizeof *f);
+ if (f == NULL) {
+ errno = ENOMEM;
+ return (NULL);
+ }
+ f->f_flags = wantrast ? FF_RASTERS : 0;
+ f->f_ops = fc->fc_ops;
+ f->f_path = strsave(path);
+ f->f_font = strsave(nm);
+ f->f_dvimag = dvimag;
+ f->f_dvidsz = dvidsz;
+ f->f_scaled = scaled;
+ f->f_pspace = f->f_dvimag / 6; /* a three-unit "thin space" */
+ f->f_nspace = -4 * f->f_pspace;
+ f->f_vspace = 5 * f->f_pspace;
+ errno = 0;
+ if ((*f->f_ops->fo_read)(f, fd)) {
+ int e = errno; /* paranoid */
+
+ free(f->f_path);
+ free(f->f_font);
+ free((char *)f);
+ errno = e;
+ return (NULL);
+ }
+ if (f->f_ops->fo_fakefont) {
+ error(0, 0, "Warning: no font for %s", Font_TeXName(f));
+ if (firstpath[0])
+ error(0, 0, "(wanted, e.g., \"%s\")", firstpath);
+ error(0, 0, "I will substitute %s for the missing glyphs",
+ f->f_ops->fo_fakefont == 1 ? "boxes" : "white space");
+ }
+ return (f);
+}
diff --git a/dviware/epson/eps-0.2/lib/font_subr.c b/dviware/epson/eps-0.2/lib/font_subr.c
new file mode 100644
index 0000000000..1e188a427c
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/font_subr.c
@@ -0,0 +1,234 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/font_subr.c,v 2.8 89/10/30 04:08:52 chris Exp $";
+#endif
+
+/*
+ * Subroutines common to all fonts.
+ */
+
+#include "types.h"
+#include "error.h"
+#include "font.h"
+
+static struct glyph *freeglyphs;
+
+/* char *malloc(); */
+#include <stdlib.h> /* for malloc */
+
+extern errno;
+
+/*
+ * Set up the font structures to note that a font has glyphs in
+ * the half-open interval [low, high).
+ *
+ * SHOULD I ALLOW ADDITIONS TO THE RANGE VIA SUBSEQUENT CALLS TO
+ * FontHasGlyphs?
+ */
+extern int FontHasGlyphs(register struct font *f, register int low, register int high)
+{
+ register struct glyph **gp;
+
+ /* record bounds */
+ f->f_lowch = low;
+ f->f_highch = high;
+
+ /*
+ * Allocate space for all the glyph pointers, and set
+ * them all to NULL.
+ */
+ if (low >= high) /* no glyphs */
+ gp = NULL;
+ else {
+ gp = (struct glyph **) malloc((unsigned) (high - low) *
+ sizeof (*gp));
+ if (gp == NULL)
+ return (-1);
+ }
+ f->f_glybase = gp;
+ f->f_gly = gp - low;
+ while (++low <= high)
+ *gp++ = NULL;
+ return (0);
+}
+
+/*
+ * AllocGlyph allocates a new glyph. ReleaseGlyph puts one onto the free
+ * list. We maintain a local list of free glyphs.
+ */
+#define ReleaseGlyph(g) \
+ ((g)->g_un.g_next = freeglyphs, freeglyphs = (g))
+
+static struct glyph *AllocGlyph(int n)
+{
+ register struct glyph *g;
+ register int i;
+
+ if ((g = freeglyphs) == NULL) {
+ g = (struct glyph *) malloc((unsigned) (128 * sizeof (*g)));
+ if (g == NULL)
+ error(1, errno, "out of glyph memory");
+ g += (i = 128);
+ while (--i >= 0) {
+ g--;
+ ReleaseGlyph(g);
+ }
+ }
+ freeglyphs = g->g_un.g_next;
+ g->g_flags = 0;
+ g->g_raster = NULL;
+ g->g_index = n;
+ g->g_xescapement = NO_ESCAPEMENT;/* default, if not set by font */
+ g->g_yescapement = NO_ESCAPEMENT;
+ return (g);
+}
+
+/*
+ * Free one glyph.
+ */
+extern void FreeGlyph(struct font *f, register struct glyph *g)
+{
+ int n = g->g_index;
+
+#ifdef notdef
+ (*f->f_ops->fo_freegly)(f, n, n);
+#endif
+ if (g->g_raster != NULL)
+ free(g->g_raster);
+ ReleaseGlyph(g);
+ f->f_gly[n] = NULL;
+}
+
+/*
+ * Free a font.
+ */
+extern void FreeFont(register struct font *f)
+{
+ register struct glyph *g;
+ register int i;
+
+#ifdef notdef
+ (*f->f_ops->fo_freegly)(f, f->f_lowch, f->f_highch);
+#endif
+ for (i = f->f_lowch; i < f->f_highch; i++) {
+ if ((g = f->f_gly[i]) == NULL)
+ continue;
+ if (g->g_raster != NULL)
+ free(g->g_raster);
+ ReleaseGlyph(g);
+ }
+ if (f->f_glybase != NULL)
+ free((char *)f->f_glybase);
+ (*f->f_ops->fo_freefont)(f);
+ free(f->f_path);
+ free(f->f_font);
+ free((char *)f);
+}
+
+/*
+ * Get glyph `c' in font `f'. We pull in a few adjacent glyphs here
+ * under the (perhaps naive) assumption that things will go faster
+ * that way.
+ *
+ * TODO:
+ * try different adjacency values
+ * make adjacency a font attribute? (or an op)
+ */
+#define ADJ 4 /* must be a power of 2 */
+#define GET_ADJ(c, l, h) ((h) = ADJ + ((l) = (c) & ~(ADJ - 1)))
+
+extern struct glyph *GetGlyph(register struct font *f, int c)
+{
+ register int i, h, l;
+
+ GET_ADJ(c, l, h);
+ if (l < f->f_lowch)
+ l = f->f_lowch;
+ if (h > f->f_highch)
+ h = f->f_highch;
+ if (l >= h)
+ return (NULL);
+ for (i = l; i < h; i++)
+ if (f->f_gly[i] == NULL)
+ f->f_gly[i] = AllocGlyph(i);
+
+ if ((*f->f_ops->fo_getgly)(f, l, h)) {
+ /*
+ * I do not know what to do about this just yet, so:
+ */
+ panic("getgly fails and I am confused ... help!");
+ }
+
+ /*
+ * Apply the appropriate scale factor to the TFM widths.
+ * This makes them come out in scaled points, instead of FIXes.
+ */
+ ScaleGlyphs(f, l, h); /* ??? */
+
+ return (f->f_gly[c]);
+}
+
+/*
+ * Get the raster for glyph g in font f at rotation r.
+ */
+extern char *GetRaster(register struct glyph *g, register struct font *f, int r)
+{
+ int l, h;
+
+ /* abort if caller did not ask for rasters in advance */
+ if ((f->f_flags & FF_RASTERS) == 0)
+ panic("GetRaster(%s)", f->f_path);
+
+ /*
+ * If there is no raster, get one. Blank characters,
+ * however, never have rasters.
+ */
+ if (g->g_raster == NULL) {
+ if (!HASRASTER(g))
+ return (NULL);
+ /*
+ * THE FOLLOWING DEPENDS ON THE ADJACENCY MATCHING THAT IN
+ * GetGlyph() ABOVE.
+ */
+ GET_ADJ(g->g_index, l, h);
+ if (l < f->f_lowch)
+ l = f->f_lowch;
+ if (h > f->f_highch)
+ h = f->f_highch;
+ if ((*f->f_ops->fo_rasterise)(f, l, h))
+ error(1, 0, "rasterise fails (out of memory?)");
+ }
+ if (g->g_rotation != r)
+ SetRotation(g, r);
+ return (g->g_raster);
+}
+
+extern void FreeRaster(struct glyph *g)
+{
+
+ if (g->g_raster) {
+ free((g)->g_raster);
+ g->g_raster = NULL;
+ }
+}
+
+/*
+ * Return a TeX-style font name, including scale factor.
+ * SHOULD I BOTHER WITH \magstep STYLE NAMES?
+ */
+extern char *Font_TeXName(register struct font *f)
+{
+ static char result[200];
+
+ if (f->f_scaled == 1000)
+ return (f->f_font);
+ (void) sprintf(result, "%s scaled %d", f->f_font, f->f_scaled);
+ return (result);
+}
diff --git a/dviware/epson/eps-0.2/lib/getopt.c b/dviware/epson/eps-0.2/lib/getopt.c
new file mode 100644
index 0000000000..f1862750c4
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/getopt.c
@@ -0,0 +1,501 @@
+/* Getopt for GNU.
+ Copyright (C) 1987 Free Software Foundation, Inc.
+
+ NO WARRANTY
+
+ BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
+NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
+WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
+RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
+WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
+AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
+DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
+CORRECTION.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
+STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
+WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
+LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
+OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
+DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
+A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
+PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
+
+ GENERAL PUBLIC LICENSE TO COPY
+
+ 1. You may copy and distribute verbatim copies of this source file
+as you receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy a valid copyright notice "Copyright
+ (C) 1987 Free Software Foundation, Inc."; and include following the
+copyright notice a verbatim copy of the above disclaimer of warranty
+and of this License. You may charge a distribution fee for the
+physical act of transferring a copy.
+
+ 2. You may modify your copy or copies of this source file or
+any portion of it, and copy and distribute such modifications under
+the terms of Paragraph 1 above, provided that you also do the following:
+
+ a) cause the modified files to carry prominent notices stating
+ that you changed the files and the date of any change; and
+
+ b) cause the whole of any work that you distribute or publish,
+ that in whole or in part contains or is a derivative of this
+ program or any part thereof, to be licensed at no charge to all
+ third parties on terms identical to those contained in this
+ License Agreement (except that you may choose to grant more
+ extensive warranty protection to third parties, at your option).
+
+ c) You may charge a distribution fee for the physical act of
+ transferring a copy, and you may at your option offer warranty
+ protection in exchange for a fee.
+
+ 3. You may copy and distribute this program or any portion of it in
+compiled, executable or object code form under the terms of Paragraphs
+1 and 2 above provided that you do the following:
+
+ a) cause each such copy to be accompanied by the
+ corresponding machine-readable source code, which must
+ be distributed under the terms of Paragraphs 1 and 2 above; or,
+
+ b) cause each such copy to be accompanied by a
+ written offer, with no time limit, to give any third party
+ free (except for a nominal shipping charge) a machine readable
+ copy of the corresponding source code, to be distributed
+ under the terms of Paragraphs 1 and 2 above; or,
+
+ c) in the case of a recipient of this program in compiled, executable
+ or object code form (without the corresponding source code) you
+ shall cause copies you distribute to be accompanied by a copy
+ of the written offer of source code which you received along
+ with the copy you received.
+
+ 4. You may not copy, sublicense, distribute or transfer this program
+except as expressly provided under this License Agreement. Any attempt
+otherwise to copy, sublicense, distribute or transfer this program is void and
+your rights to use the program under this License agreement shall be
+automatically terminated. However, parties who have received computer
+software programs from you with this License Agreement will not have
+their licenses terminated so long as such parties remain in full compliance.
+
+ 5. If you wish to incorporate parts of this program into other free
+programs whose distribution conditions are different, write to the Free
+Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
+worked out a simple rule that can be stated here, but we will often permit
+this. We will be guided by the two goals of preserving the free status of
+all derivatives of our free software and of promoting the sharing and reuse of
+software.
+
+
+In other words, you are welcome to use, share and improve this program.
+You are forbidden to forbid anyone else to use, share and improve
+what you give them. Help stamp out software-hoarding! */
+
+/* This version of `getopt' appears to the caller like standard Unix `getopt'
+ but it behaves differently for the user, since it allows the user
+ to intersperse the options with the other arguments.
+
+ As `getopt' works, it permutes the elements of `argv' so that,
+ when it is done, all the options precede everything else. Thus
+ all application programs are extended to handle flexible argument order.
+
+ Setting the environment variable _POSIX_OPTION_ORDER disables permutation.
+ Then the behavior is completely standard.
+
+ GNU application programs can use a third alternative mode in which
+ they can distinguish the relative order of options and other arguments. */
+
+#if ( defined(MSDOS) || defined(__MSDOS__) ) && !defined( __GNUC__ )
+#define bcopy(a,b,c) memcpy((b),(a),(c))
+#define index strchr
+#include <stdlib.h> /* for getenv */
+#ifdef __TURBOC__
+# include <mem.h>
+# define alloca malloc
+#else
+# include <memory.h>
+#endif
+#include <string.h>
+#endif
+
+#ifdef linux
+# include <alloca.h>
+# include <strings.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef sparc
+#include <alloca.h>
+#endif
+
+/* For communication from `getopt' to the caller.
+ When `getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when `ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+char *optarg = 0;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to `getopt'.
+
+ On entry to `getopt', zero means this is the first call; initialize.
+
+ When `getopt' returns EOF, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, `optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+int optind = 0;
+
+/* The next char to be scanned in the option-element
+ in which the last option character we returned was found.
+ This allows us to pick up the scan where we left off.
+
+ If this is zero, or a null string, it means resume the scan
+ by advancing to the next ARGV-element. */
+
+static char *nextchar;
+
+/* Callers store zero here to inhibit the error message
+ for unrecognized options. */
+
+int opterr = 1;
+
+/* Describe how to deal with options that follow non-option ARGV-elements.
+
+ UNSPECIFIED means the caller did not specify anything;
+ the default is then REQUIRE_ORDER if the environment variable
+ _OPTIONS_FIRST is defined, PERMUTE otherwise.
+
+ REQUIRE_ORDER means don't recognize them as options.
+ Stop option processing when the first non-option is seen.
+ This is what Unix does.
+
+ PERMUTE is the default. We permute the contents of `argv' as we scan,
+ so that eventually all the options are at the end. This allows options
+ to be given in any order, even with programs that were not written to
+ expect this.
+
+ RETURN_IN_ORDER is an option available to programs that were written
+ to expect options and other ARGV-elements in any order and that care about
+ the ordering of the two. We describe each non-option ARGV-element
+ as if it were the argument of an option with character code zero.
+ Using `-' as the first character of the list of option characters
+ requests this mode of operation.
+
+ The special argument `--' forces an end of option-scanning regardless
+ of the value of `ordering'. In the case of RETURN_IN_ORDER, only
+ `--' can cause `getopt' to return EOF with `optind' != ARGC. */
+
+static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering;
+
+/* Handle permutation of arguments. */
+
+/* Describe the part of ARGV that contains non-options that have
+ been skipped. `first_nonopt' is the index in ARGV of the first of them;
+ `last_nonopt' is the index after the last of them. */
+
+static int first_nonopt;
+static int last_nonopt;
+
+/* Exchange two adjacent subsequences of ARGV.
+ One subsequence is elements [first_nonopt,last_nonopt)
+ which contains all the non-options that have been skipped so far.
+ The other is elements [last_nonopt,optind), which contains all
+ the options processed since those non-options were skipped.
+
+ `first_nonopt' and `last_nonopt' are relocated so that they describe
+ the new indices of the non-options in ARGV after they are moved. */
+
+static void
+exchange (char** argv)
+{
+ int nonopts_size
+ = (last_nonopt - first_nonopt) * sizeof (char *);
+ char **temp = (char **) alloca (nonopts_size);
+
+ /* Interchange the two blocks of data in argv. */
+
+ bcopy (&argv[first_nonopt], temp, nonopts_size);
+ bcopy (&argv[last_nonopt], &argv[first_nonopt],
+ (optind - last_nonopt) * sizeof (char *));
+ bcopy (temp, &argv[first_nonopt + optind - last_nonopt],
+ nonopts_size);
+
+ /* Update records for the slots the non-options now occupy. */
+
+ first_nonopt += (optind - last_nonopt);
+ last_nonopt = optind;
+}
+
+/* Scan elements of ARGV (whose length is ARGC) for option characters
+ given in OPTSTRING.
+
+ If an element of ARGV starts with '-', and is not exactly "-" or "--",
+ then it is an option element. The characters of this element
+ (aside from the initial '-') are option characters. If `getopt'
+ is called repeatedly, it returns successively each of theoption characters
+ from each of the option elements.
+
+ If `getopt' finds another option character, it returns that character,
+ updating `optind' and `nextchar' so that the next call to `getopt' can
+ resume the scan with the following option character or ARGV-element.
+
+ If there are no more option characters, `getopt' returns `EOF'.
+ Then `optind' is the index in ARGV of the first ARGV-element
+ that is not an option. (The ARGV-elements have been permuted
+ so that those that are not options now come last.)
+
+ OPTSTRING is a string containing the legitimate option characters.
+ A colon in OPTSTRING means that the previous character is an option
+ that wants an argument. The argument is taken from the rest of the
+ current ARGV-element, or from the following ARGV-element,
+ and returned in `optarg'.
+
+ If an option character is seen that is not listed in OPTSTRING,
+ return '?' after printing an error message. If you set `opterr' to
+ zero, the error message is suppressed but we still return '?'.
+
+ If a char in OPTSTRING is followed by a colon, that means it wants an arg,
+ so the following text in the same ARGV-element, or the text of the following
+ ARGV-element, is returned in `optarg. Two colons mean an option that
+ wants an optional arg; if there is text in the current ARGV-element,
+ it is returned in `optarg'.
+
+ If OPTSTRING starts with `-', it requests a different method of handling the
+ non-option ARGV-elements. See the comments about RETURN_IN_ORDER, above. */
+
+int
+getopt (int argc, char** argv, char* optstring)
+{
+ /* Initialize the internal data when the first call is made.
+ Start processing options with ARGV-element 1 (since ARGV-element 0
+ is the program name); the sequence of previously skipped
+ non-option ARGV-elements is empty. */
+
+ if (optind == 0)
+ {
+ first_nonopt = last_nonopt = optind = 1;
+
+ nextchar = 0;
+
+ /* Determine how to handle the ordering of options and nonoptions. */
+
+ if (optstring[0] == '-')
+ ordering = RETURN_IN_ORDER;
+ else if (getenv ("_POSIX_OPTION_ORDER") != 0)
+ ordering = REQUIRE_ORDER;
+ else
+ ordering = PERMUTE;
+ }
+
+ if (nextchar == 0 || *nextchar == 0)
+ {
+ if (ordering == PERMUTE)
+ {
+ /* If we have just processed some options following some non-options,
+ exchange them so that the options come first. */
+
+ if (first_nonopt != last_nonopt && last_nonopt != optind)
+ exchange (argv);
+ else if (last_nonopt != optind)
+ first_nonopt = optind;
+
+ /* Now skip any additional non-options
+ and extend the range of non-options previously skipped. */
+
+ while (optind < argc
+ && (argv[optind][0] != '-'
+ || argv[optind][1] == 0))
+ optind++;
+ last_nonopt = optind;
+ }
+
+ /* Special ARGV-element `--' means premature end of options.
+ Skip it like a null option,
+ then exchange with previous non-options as if it were an option,
+ then skip everything else like a non-option. */
+
+ if (optind != argc && !strcmp (argv[optind], "--"))
+ {
+ optind++;
+
+ if (first_nonopt != last_nonopt && last_nonopt != optind)
+ exchange (argv);
+ else if (first_nonopt == last_nonopt)
+ first_nonopt = optind;
+ last_nonopt = argc;
+
+ optind = argc;
+ }
+
+ /* If we have done all the ARGV-elements, stop the scan
+ and back over any non-options that we skipped and permuted. */
+
+ if (optind == argc)
+ {
+ /* Set the next-arg-index to point at the non-options
+ that we previously skipped, so the caller will digest them. */
+ if (first_nonopt != last_nonopt)
+ optind = first_nonopt;
+ return EOF;
+ }
+
+ /* If we have come to a non-option and did not permute it,
+ either stop the scan or describe it to the caller and pass it by. */
+
+ if (argv[optind][0] != '-' || argv[optind][1] == 0)
+ {
+ if (ordering == REQUIRE_ORDER)
+ return EOF;
+ optarg = argv[optind++];
+ return 0;
+ }
+
+ /* We have found another option-ARGV-element.
+ Start decoding its characters. */
+
+ nextchar = argv[optind] + 1;
+ }
+
+ /* Look at and handle the next option-character. */
+
+ {
+ char c = *nextchar++;
+ char *temp = (char *) index (optstring, c);
+
+ /* Increment `optind' when we start to process its last character. */
+ if (*nextchar == 0)
+ optind++;
+
+ if (temp == 0 || c == ':')
+ {
+ if (opterr != 0)
+ {
+ if (c < 040 || c >= 0177)
+ fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
+ argv[0], c);
+ else
+ fprintf (stderr, "%s: unrecognized option `-%c'\n",
+ argv[0], c);
+ }
+ return '?';
+ }
+ if (temp[1] == ':')
+ {
+ if (temp[2] == ':')
+ {
+ /* This is an option that accepts an argument optionally. */
+ if (*nextchar != 0)
+ {
+ optarg = nextchar;
+ optind++;
+ }
+ else
+ optarg = 0;
+ nextchar = 0;
+ }
+ else
+ {
+ /* This is an option that requires an argument. */
+ if (*nextchar != 0)
+ {
+ optarg = nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ we must advance to the next element now. */
+ optind++;
+ }
+ else if (optind == argc)
+ {
+ if (opterr != 0)
+ fprintf (stderr, "%s: no argument for `-%c' option\n",
+ argv[0], c);
+ optarg = 0;
+ }
+ else
+ /* We already incremented `optind' once;
+ increment it again when taking next ARGV-elt as argument. */
+ optarg = argv[optind++];
+ nextchar = 0;
+ }
+ }
+ return c;
+ }
+}
+
+#ifdef TEST
+
+/* Compile with -DTEST to make an executable for use in testing
+ the above definition of `getopt'. */
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ char c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind;
+ if ((c = getopt (argc, argv, "abc:d:0123456789")) == EOF)
+ break;
+
+ switch (c)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\n");
+ break;
+
+ case 'b':
+ printf ("option b\n");
+ break;
+
+ case 'c':
+ printf ("option c with value `%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\n");
+ }
+
+ return 0;
+}
+
+#endif /* TEST */
diff --git a/dviware/epson/eps-0.2/lib/gfclass.c b/dviware/epson/eps-0.2/lib/gfclass.c
new file mode 100644
index 0000000000..5732e676a9
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/gfclass.c
@@ -0,0 +1,82 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/gfclass.c,v 2.3 89/08/22 21:52:30 chris Exp $";
+#endif
+
+/*
+ * gfclass - GF code classification tables.
+ */
+
+#include "gfclass.h"
+
+/* shorthand---in lowercase for contrast (read on!) */
+#define three(x) x, x, x
+#define four(x) x, x, x, x
+#define five(x) four(x), x
+#define six(x) four(x), x, x
+#define eight(x) four(x), four(x)
+#define sixteen(x) eight(x), eight(x)
+#define thirty_two(x) sixteen(x), sixteen(x)
+#define sixty_four(x) thirty_two(x), thirty_two(x)
+#define one_twenty_eight(x) sixty_four(x), sixty_four(x)
+#define one_sixty_five(x) one_twenty_eight(x), thirty_two(x), five(x)
+
+/*
+ * Length of the single (or first) operand, if any.
+ */
+char gf_oplen[256] = {
+ sixty_four(GPL_NONE), /* GF_PAINT_0 through GF_PAINT_63 */
+ GPL_UNS1, /* GF_PAINT1 */
+ GPL_UNS2, /* GF_PAINT2 */
+ GPL_UNS3, /* GF_PAINT3 */
+ GPL_NONE, /* GF_BOC */
+ GPL_NONE, /* GF_BOC1 */
+ GPL_NONE, /* GF_EOC */
+ GPL_NONE, /* GF_SKIP0 */
+ GPL_UNS1, /* GF_SKIP1 */
+ GPL_UNS2, /* GF_SKIP2 */
+ GPL_UNS3, /* GF_SKIP3 */
+ one_sixty_five(GPL_NONE),/* GF_NEW_ROW_0 through GF_NEW_ROW_164 */
+ GPL_UNS1, /* GF_XXX1 */
+ GPL_UNS2, /* GF_XXX2 */
+ GPL_UNS3, /* GF_XXX3 */
+ GPL_SGN4, /* GF_XXX4 */
+ GPL_SGN4, /* GF_YYY */
+ GPL_NONE, /* GF_NOP */
+ GPL_NONE, /* GF_CHAR_LOC */
+ GPL_NONE, /* GF_CHAR_LOC0 */
+ GPL_NONE, /* GF_PRE */
+ GPL_NONE, /* GF_POST */
+ GPL_NONE, /* GF_POSTPOST */
+ six(GPL_NONE) /* 250 through 255 */
+};
+
+/*
+ * Types of the various opcodes.
+ */
+char gf_gt[256] = {
+ sixty_four(GT_PAINT0), /* GF_PAINT_0 through GF_PAINT_63 */
+ three(GT_PAINT), /* GF_PAINT1 through GF_PAINT3 */
+ GT_BOC, /* GF_BOC */
+ GT_BOC1, /* GF_BOC1 */
+ GT_EOC, /* GF_EOC */
+ GT_SKIP0, /* GF_SKIP0 */
+ three(GT_SKIP), /* GF_SKIP1 through GF_SKIP3 */
+ one_sixty_five(GT_NEW_ROW),/* GF_NEW_ROW_0 throgh GF_NEW_ROW_164 */
+ four(GT_XXX), /* GF_XXX1 through GF_XXX4 */
+ GT_YYY, /* GF_YYY */
+ GT_NOP, /* GF_NOP */
+ GT_CHAR_LOC, /* GF_CHAR_LOC */
+ GT_CHAR_LOC0, /* GF_CHAR_LOC0 */
+ GT_PRE, /* GF_PRE */
+ GT_POST, /* GF_POST */
+ GT_POSTPOST, /* GF_POSTPOST */
+ six(GT_UNDEF) /* 250 through 255 */
+};
diff --git a/dviware/epson/eps-0.2/lib/gffont.c b/dviware/epson/eps-0.2/lib/gffont.c
new file mode 100644
index 0000000000..8f614f5cfa
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/gffont.c
@@ -0,0 +1,924 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/gffont.c,v 2.9 89/09/02 17:16:17 chris Exp $";
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "types.h"
+#include "error.h"
+#include "font.h"
+#include "gfcodes.h"
+#include "gfclass.h"
+#include "num.h"
+#include <stdlib.h> /* for malloc */
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+# include <io.h>
+#else
+# include <osfcn.h> /* for read, open, close, lseek */
+#endif
+
+/*
+ * GF font operations.
+ *
+ * GF files may be compact, but this code surely is not!
+ *
+ * TODO:
+ * think about fonts with characters outside [0..255]
+ * find some way to free gf body when done
+ */
+
+struct fontops gfops =
+ { "gf", 0, 1.0, gf_read, gf_getgly, gf_rasterise, gf_freefont };
+
+/*
+ * Local info.
+ */
+
+/*
+ * A bounding box. The names follow those in the GF documentation.
+ */
+
+/*
+ * char_loc is one `character locator' from a GF file, save for the
+ * `character residue', which we need not.
+ */
+struct char_loc {
+ i32 cl_dx; /* x escapement (scaled pixels) */
+ i32 cl_dy; /* y escapement (scaled pixels) */
+ i32 cl_w; /* TFM width */
+ i32 cl_p; /* pointer to BOC (or specials) */
+};
+
+/*
+ * GF details include:
+ * -> the main body of the GF file (all bytes save pre- and post-amble);
+ * -> global box boundaries;
+ * and character locators, addressed by `character residue'. Empty
+ * slots are indicated by a -1 `pointer'.
+ */
+struct gf_details {
+ char *gd_body; /* GF body */
+ char *gd_base; /* == gd_body - preamble_size */
+ struct bounds gd_gb; /* global boundaries */
+ struct char_loc gd_cl[256]; /* character locators */
+};
+
+/*
+ * Get the gf_details from font f.
+ */
+#define ftogd(f) ((struct gf_details *)(f)->f_details)
+
+extern int errno;
+/* char *malloc(), *copyit(); */
+
+/*
+ * This code mimicks findpost.c.
+ */
+#define POSTSIZE 512
+
+/*
+ * Find the GF postamble. Store the offsets of the POST and POSTPOST
+ * opcodes through postp and postpostp.
+ */
+static int findGFpostamble(int fd, long *postp, long *postpostp)
+{
+ register long offset;
+ register char *p;
+ register int i;
+ register i32 n;
+ char postbuf[POSTSIZE];
+
+ offset = lseek(fd, 0L, 2);
+ do {
+
+ if ((offset -= POSTSIZE) < 0L)
+ offset = 0L;
+ (void) lseek(fd, offset, 0);
+ i = read(fd, postbuf, POSTSIZE);
+ if (i <= 0)
+ break;
+ for (p = postbuf + i; --i >= 0;)
+ if (UnSign8(*--p) != GF_FILLER)
+ goto found_something;
+ } while (offset);
+ return (-1); /* ran out of filler */
+
+found_something:
+ if (UnSign8(*p) != GF_ID)
+ return (-1); /* not a GF file */
+ offset += i; /* this is the offset of *p */
+ *postpostp = offset - 5;/* POSTPOST should be here */
+ /* we need 4 bytes for the pointer */
+ if (i >= 4)
+ p -= 4;
+ else {
+ offset -= 4;
+ if (offset < 0L)
+ return (-1); /* tsk */
+ (void) lseek(fd, offset, 0);
+ if (read(fd, p = postbuf, 4) != 4)
+ return (-1);
+ }
+ /*
+ * p now points to the postamble pointer. Get it and
+ * seek to the postamble, also saving the offset.
+ */
+ pGetLong(p, n);
+ *postp = offset = n;
+ (void) lseek(fd, offset, 0);
+ return (0); /* made it */
+}
+
+/*
+ * Read a GF file.
+ */
+static int gf_read(register struct font *f, int fd)
+{
+ register struct gf_details *gd;
+ register char *p;
+ register struct char_loc *cl;
+ register int i;
+ int presize, postsize, bodysize, firstc, lastc;
+ char *postamble;
+ long postaddr, postpostaddr;
+ i32 lasteoc;
+ char *problem = NULL;
+ struct stat st;
+ char b[4];
+ int saverr;
+
+ gd = NULL; /* prepare for failure */
+ postamble = NULL;
+
+ /*
+ * The file had best be at least 50 bytes long. A
+ * `completely empty' GF file might consist of a PRE, a GF_ID,
+ * no comment (one zero byte), then: POST, pointer to last
+ * EOC, design size, checksum, hppp, vppp, min_m, max_m,
+ * min_n, max_n, POSTPOST, pointer to POST, GF_ID, and four
+ * FILLERs.
+ */
+ (void) fstat(fd, &st);
+ if (st.st_size < 50) { /* too small to be a GF file */
+ problem = "file is too short";
+ goto fail;
+ }
+
+ /*
+ * Read the very beginning and pick up the preamble size.
+ */
+ if (read(fd, b, 4) != 4)
+ goto fail;
+ if (UnSign8(b[0]) != GF_PRE) {
+ problem = "file does not begin with PRE";
+ goto fail;
+ }
+ i = UnSign8(b[1]);
+ if (i != GF_ID)
+ error(0, 0, "Warning: strange GF id (%d) in \"%s\"", i,
+ f->f_path);
+ presize = 3 + UnSign8(b[2]);
+
+ /*
+ * Find the postamble, allocate space, and read it in.
+ */
+ if (findGFpostamble(fd, &postaddr, &postpostaddr)) {
+ problem = "cannot find postamble";
+ goto fail;
+ }
+ postsize = postpostaddr - postaddr + 1;
+ if ((p = (char*)malloc(postsize)) == NULL)
+ goto fail;
+ if (read(fd, p, postsize) != postsize)
+ goto fail;
+ postamble = p;
+
+ /*
+ * Make sure we found it.
+ */
+ if (pgetbyte(p) != GF_POST) {
+ problem = "no GF_POST at postamble";
+ goto fail;
+ }
+ if (UnSign8(postamble[postsize - 1]) != GF_POSTPOST) {
+ problem = "no GF_POSTPOST after postamble";
+ goto fail;
+ }
+
+ /*
+ * Looks okay. Allocate detail space and poke through the postamble.
+ */
+ if ((gd = (struct gf_details *) malloc(sizeof (*gd))) == NULL)
+ goto fail;
+ gd->gd_body = NULL;
+
+ pGetLong(p, lasteoc); /* actually one past last EOC */
+ pGetLong(p, f->f_design_size);
+ pGetLong(p, f->f_checksum);
+ pGetLong(p, f->f_hppp);
+ pGetLong(p, f->f_vppp);
+
+ pGetLong(p, gd->gd_gb.min_m);
+ pGetLong(p, gd->gd_gb.max_m);
+ pGetLong(p, gd->gd_gb.min_n);
+ pGetLong(p, gd->gd_gb.max_n);
+
+ /*
+ * Zap all the character locators, then read those that are
+ * defined in the postamble. Remember the first and last
+ * characters so that we know which glyphs are defined. Lastc
+ * is actually the last-plus-one'th character.
+ */
+ for (cl = gd->gd_cl, i = 256; --i >= 0; cl++)
+ cl->cl_p = -1;
+ firstc = 256;
+ lastc = 0;
+ for (;;) {
+ i32 dx, dy;
+
+ switch (pgetbyte(p)) {
+
+ case GF_CHAR_LOC:
+ i = pgetbyte(p);
+ pGetLong(p, dx);
+ pGetLong(p, dy);
+ goto merge;
+
+ case GF_CHAR_LOC0:
+ i = pgetbyte(p);
+ dx = ((i32) pgetbyte(p)) << 16;
+ dy = 0;
+merge:
+ if (i < firstc)
+ firstc = i;
+ if (i >= lastc)
+ lastc = i + 1;
+ cl = &gd->gd_cl[i];
+ cl->cl_dx = dx;
+ cl->cl_dy = dy;
+ pGetLong(p, cl->cl_w);
+ pGetLong(p, cl->cl_p);
+ break;
+
+ case GF_POSTPOST:
+ goto done;
+
+ default:
+ error(0, 0, "I do not understand %d here",
+ UnSign8(p[-1]));
+ problem = "unexpected opcode in postamble";
+ goto fail;
+ }
+ }
+done:
+ free(postamble);
+ postamble = NULL; /* all done with it */
+
+ /*
+ * Alas, we need the instructions whether or not we need
+ * the rasters, since the raster bounding box information
+ * can only be properly determined by converting the rasters.
+ * Compute the size of the main body of the GF file, then
+ * read it in.
+ */
+ bodysize = lasteoc - presize;
+ if ((gd->gd_body = (char*)malloc(bodysize + 1)) == NULL)
+ goto fail;
+ (void) lseek(fd, (long) presize, 0);
+ if (read(fd, gd->gd_body, bodysize) != bodysize)
+ goto fail;
+ /*
+ * The next byte might be a special, so we just
+ * arbitrarily stuff in a POST.
+ */
+ gd->gd_body[bodysize] = GF_POST;
+ gd->gd_base = gd->gd_body - presize;
+
+ f->f_details = (char *)gd;
+ if (FontHasGlyphs(f, firstc, lastc))
+ goto fail2;
+ (void) close(fd);
+ return (0);
+
+fail:
+ if (problem == NULL)
+ error(0, errno, "trouble reading \"%s\"", f->f_path);
+ else {
+ error(0, 0, "%s", problem);
+ error(0, 0, "(are you sure \"%s\" is a GF file?)", f->f_path);
+ }
+ errno = 0;
+fail2:
+ saverr = errno;
+ if (postamble != NULL)
+ free(postamble);
+ if (gd != NULL) {
+ if (gd->gd_body != NULL)
+ free(gd->gd_body);
+ free((char *) gd);
+ }
+ (void) close(fd);
+ errno = saverr;
+ return (-1);
+}
+
+/*
+ * Some global variables, used while building rasters. (These are
+ * referenced also in copyit(), so must be global. Fortunately, no
+ * one yet requires the font routines to be re-entrant.)
+ */
+static char *buildraster; /* raster being built */
+static int buildsize; /* size of buildraster (bytes) */
+
+static struct bounds tempb; /* bounds used during buildraster */
+static struct bounds ob; /* observed bounds */
+
+/*
+ * Bit tables: `left' and `right' bits. lbits[b] has all the bits
+ * that are to the left of bit b set; rbits[b] has all the bits
+ * that are to the right of bit b set, as well as bit b itself.
+ */
+static char lbits[] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe };
+static char rbits[] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
+
+/*
+ * The magic address `nullraster' is known in getgly() as a valid
+ * but empty raster, and changed there to NULL. A NULL return from
+ * drawchar indicates failure; we need something to distinguish the
+ * empty raster.
+ */
+static char nullraster[1];
+
+/*
+ * `Inline functions':
+ * -> convert a bit number to a byte number (round down);
+ * -> convert a number of bits to a number of bytes (round up);
+ * and convert a bit to a bit index.
+ */
+#define btoby(b) ((b) >> 3)
+#define btonb(b) (((b) + 7) >> 3)
+#define btobi(b) ((b) & 7)
+
+/*
+ * Helper function for getgly: build the raster, and compute its
+ * minimal bounding box. Called with `p' pointing past the backpointer
+ * field of the BOC command (i.e., at min_m or del_m). `abbrev' is true
+ * iff this was a BOC1. `globalb' are the global bounds from the GF file,
+ * whose name is pointed to by gfname.
+ */
+static char *drawchar(register char *p, int abbrev, struct bounds globalb, char *gfname)
+{
+ register i32 m; /* m register (column) */
+ register char *colp; /* pointer to byte corresponding to m */
+ register int c; /* temporary */
+ register i32 i; /* temporary */
+ register int black; /* true when paint_switch==black */
+ register i32 n; /* n register (row) */
+ int stride; /* multiplier to convert linear to 2d array */
+ int wrotethisrow; /* true iff we wrote in the current row */
+ char *virtrast; /* virtual origin version of buildraster */
+ int mustcopy; /* true if we must copy the built raster */
+ struct bounds gb; /* bounds from the GF file */
+
+ /* get the bounds */
+ if (abbrev) {
+ c = pgetbyte(p);/* del_m */
+ gb.min_m = (gb.max_m = pgetbyte(p)) - c;
+ c = pgetbyte(p);/* del_n */
+ gb.min_n = (gb.max_n = pgetbyte(p)) - c;
+ } else {
+ pGetLong(p, gb.min_m);
+ pGetLong(p, gb.max_m);
+ pGetLong(p, gb.min_n);
+ pGetLong(p, gb.max_n);
+ }
+
+ /*
+ * Trim the GF bounds according to the global bounds. We
+ * use the trimmed values to allocate the build space.
+ */
+ tempb = gb;
+#define GB_ADJ(field, cmp) \
+ if (tempb.field cmp globalb.field) \
+ tempb.field = globalb.field
+ GB_ADJ(min_m, <);
+ GB_ADJ(max_m, >);
+ GB_ADJ(min_n, <);
+ GB_ADJ(max_n, >);
+#undef GB_ADJ
+
+ /*
+ * First check for completely empty characters---that is,
+ * those where min > max. The space in cmtex10, for instance,
+ * could be a completely empty character, but for some reason
+ * METAFONT declares cmtex10 space as [0..0][0..0].
+ * Nonetheless, we will not assume that [0..-1][0..0] or
+ * the like are impossible.
+ */
+ if (tempb.min_m > tempb.max_m || tempb.min_n > tempb.max_n)
+ return (nullraster);
+
+ /*
+ * Compute the distance between rows (the number of bytes per
+ * column), then make sure there is room in the build space
+ * for [min_n..max_n] of these, possibly by allocating a new raster.
+ */
+ stride = btonb(tempb.max_m - tempb.min_m + 1);
+ c = stride * (tempb.max_n - tempb.min_n + 1);
+ if (c > buildsize) {
+ if (buildraster != NULL)
+ free(buildraster);
+ if ((buildraster = (char*)malloc(c)) == NULL) {
+ buildsize = 0;
+ return (NULL);
+ }
+ buildsize = c;
+ }
+
+ /*
+ * If we are using an old raster that is too big, remember to
+ * scrunch it down later.
+ */
+ mustcopy = buildsize > c;
+
+ /* clear the raster to white */
+ bzero(buildraster, c);
+
+ /*
+ * Make a virtual origin raster pointer. The virtual origin is
+ * where raster[0][0] is, whether or not there is a raster[0][0].
+ * Normally, this would be
+ * &buildraster[-gb.min_n * stride - btoby(gb.min_m)],
+ * but it is complicated by two things. Firstly, we would like
+ * n==max_n to be the bottommost point in the raster (low
+ * addresses), and n==min_n to be the topmost (high addresses).
+ * In other words, we need to reflect the n (Y) values about
+ * the X axis: negate them. Secondly, the raster we create
+ * must be `flush left'. That is, somewhere along its rows,
+ * bit 0x80 must be set at the left edge of one of its columns.
+ * We need to subtract away the minimum bit index before
+ * calculating bit values. This cannot really be done in
+ * advance, since we cannot address bits directly.
+ */
+ virtrast = &buildraster[gb.max_n * stride];
+
+ /*
+ * Set up the bounds-trimming variables. We could do this by
+ * simply setting the observed min point to a very large number,
+ * and the observed max point to a very small number, but this
+ * way we need not come up with extreme numbers (which might not
+ * be portable).
+ *
+ * If at least one pixel is blackened, the observed bounds will
+ * become the correct bounds in the code below, and we will have
+ * min<=max; but if no pixels are blackened, we arrange to have
+ * min>max, so we have to check for that again later.
+ *
+ * This would be `min = max + 1' and `max = min - 1', but for
+ * efficiency, the observed m bounds are kept offset by gb.min_m
+ * until we finish drawing the character.
+ */
+ ob.min_m = tempb.max_m + 1 - gb.min_m;
+ ob.max_m = tempb.min_m - 1 - gb.min_m;
+ ob.min_n = tempb.max_n + 1;
+ ob.max_n = tempb.min_n - 1;
+ wrotethisrow = 0;
+
+#define FIX_N_BOUNDS() { \
+ if (wrotethisrow) { \
+ c = -n; /* recall that n is reflected about X axis */ \
+ if (c < ob.min_n) \
+ ob.min_n = c; \
+ if (c > ob.max_n) \
+ ob.max_n = c; \
+ wrotethisrow = 0; \
+ } \
+}
+
+ /*
+ * Initialise state variables: m = min_m, n = max_n,
+ * paint_switch = white.
+ */
+ m = 0; /* gb.min_m - gb.min_m */
+ n = -gb.max_n; /* reflected */
+ colp = &virtrast[n * stride];
+if (colp != buildraster)
+panic("gffont drawchar colp != buildraster");
+ black = 0;
+
+ /*
+ * Now interpret the character.
+ * `for (;;)' pushes everything off the right edge, alas.
+ */
+more:
+ c = pgetbyte(p);
+ if (GF_IsPaint(c)) /* faster? */
+ goto paint;
+ switch (GF_OpLen(c)) {
+
+ case GPL_NONE:
+ break;
+
+ case GPL_UNS1:
+ i = pgetbyte(p);
+ break;
+
+ case GPL_UNS2:
+ pGetWord(p, i);
+ break;
+
+ case GPL_UNS3:
+ pGet3Byte(p, i);
+ break;
+
+ case GPL_SGN4:
+ pGetLong(p, i);
+ break;
+
+ default:
+ panic("gffont drawchar GF_OpLen(%d) = %d", c, GF_OpLen(c));
+ /* NOTREACHED */
+ }
+
+ switch (GF_TYPE(c)) {
+
+ case GT_PAINT0:
+paint:
+ i = c - GF_PAINT_0;
+ /* FALLTHROUGH */
+
+ case GT_PAINT:
+ /*
+ * Paint `i' bits in the current row at columns [m..m+i).
+ */
+ if (i && black) {
+ /* remember to adjust n bounds later */
+ wrotethisrow = 1;
+ /* adjust minimum m bound */
+ if (m < ob.min_m)
+ ob.min_m = m;
+
+ /*
+ * Finish the partial byte at colp. There are 8-k
+ * bits to set to finish it, where k is the bit
+ * index value from m. If we need to set fewer
+ * than 8-k bits, set them now and skip the rest
+ * of this.
+ */
+ c = 8 - btobi(m);
+ if (i < c) { /* cannot finish it off */
+ *colp |= UnSign8(lbits[i]) >> btobi(m);
+ m += i;
+ } else { /* finish it off */
+ *colp++ |= rbits[btobi(m)];
+ i -= c;
+ m += c;
+
+ /*
+ * Update m to reflect having written the
+ * remaining i bits, then write them.
+ * First write all the full bytes, then
+ * start a partial byte with whatever
+ * is left over, if anything.
+ */
+ m += i;
+ i >>= 3;
+ while (--i >= 0)
+ *colp++ = 0xff;
+ *colp |= lbits[btobi(m)];
+ }
+
+ /* adjust maximum m bound */
+ if (m > ob.max_m)
+ ob.max_m = m;
+ } else {
+ /*
+ * Add the bit index so that we round up whenever
+ * this fills the partial byte at colp.
+ */
+ colp += (i + btobi(m)) >> 3;
+ m += i;
+ }
+ black = !black;
+ break;
+
+ case GT_EOC: /* all done */
+ FIX_N_BOUNDS();
+ goto done;
+
+ case GT_SKIP0: /* skip no rows */
+ i = 0;
+ /* FALLTHROUGH */
+
+ case GT_SKIP: /* skip some rows, draw white */
+ m = 0;
+ black = 0;
+ goto skip_or_new_row;
+
+ case GT_NEW_ROW: /* next row near left col, draw black */
+ m = c - GF_NEW_ROW_0;
+ black = 1;
+ i = 0; /* n offset is 1: skip no rows */
+skip_or_new_row:
+ FIX_N_BOUNDS();
+ n += i + 1; /* += because reflected */
+ colp = &virtrast[n * stride + btoby(m)];
+ break;
+
+ case GT_XXX: /* special */
+ p += i;
+ break;
+
+ case GT_YYY: /* numspecial */
+ break;
+
+ case GT_NOP: /* dull */
+ break;
+
+ case GT_BOC: /* should not appear */
+ case GT_BOC1:
+ case GT_CHAR_LOC:
+ case GT_CHAR_LOC0:
+ case GT_PRE:
+ case GT_POST:
+ case GT_POSTPOST:
+ case GT_UNDEF:
+ error(0, 0, "unexpected GF opcode %d", c);
+ error(1, 0, "bad GF file \"%s\"", gfname);
+ /* NOTREACHED */
+
+ default:
+ panic("gffont drawchar GF_TYPE(%d) = %d", c, GF_TYPE(c));
+ /* NOTREACHED */
+ }
+ goto more;
+
+done:
+ /*
+ * The observed bounds `m' values are both off by gb.min_m, so
+ * fix them now.
+ */
+ ob.min_m += gb.min_m;
+ ob.max_m += gb.min_m;
+
+ /* as noted above, we have to make sure there were some points */
+ if (ob.min_m > ob.max_m)
+ return (nullraster);
+if (ob.min_n > ob.max_n)
+panic("gffont min>max: n but not m");
+
+ /*
+ * If we used too much memory for the raster, copy it now.
+ */
+ if (mustcopy || tempb.min_n != ob.min_n || tempb.max_n != ob.max_n ||
+ btonb(ob.max_m - ob.min_m + 1) != stride)
+ return (copyit());
+
+ /*
+ * If the left column bounds match, just move the raster in place.
+ */
+ if (tempb.min_m == ob.min_m) {
+ p = buildraster;
+ buildraster = NULL;
+ buildsize = 0;
+ return (p);
+ }
+
+ /*
+ * The raster must be copied, but only because it is not
+ * `left justified'.
+ *
+ * CONSIDER DEFERRING THIS PHASE UNTIL THE RASTER IS USED
+ */
+ return (copyit());
+}
+
+/*
+ * Copy the built raster to newly allocated space.
+ * We may need to shift all the bits left as well.
+ */
+extern char *copyit(void)
+{
+ register char *o, *p;
+ register int i, oldoff, newoff;
+ char *n;
+
+ /*
+ * Compute the observed minimum stride.
+ */
+ newoff = btonb(ob.max_m - ob.min_m + 1);
+ n = (char*)malloc((unsigned)(newoff * (ob.max_n - ob.min_n + 1)));
+ if ((p = n) == NULL)
+ return (NULL);
+
+ /*
+ * Compute the old stride.
+ */
+ oldoff = btonb(tempb.max_m - tempb.min_m + 1);
+if (oldoff < newoff)
+panic("gffont copyit oldoff < newoff");
+
+ /*
+ * Point at the old raster, then add the offset to the first
+ * written row, and then the offset to the first written column.
+ */
+ o = buildraster;
+ o += (ob.max_n - tempb.max_n) * oldoff;
+ i = ob.min_m - tempb.min_m;
+ o += btoby(i);
+
+ /*
+ * Now copy each row, doing shifting if required.
+ */
+ if ((i = btobi(i)) != 0) { /* must shift, alas */
+ register int r = 8 - i, j, k;
+
+ oldoff -= newoff;
+ for (k = ob.max_n; k >= ob.min_n; k--) {
+ for (j = newoff; --j > 0;) {
+ *p = *o++ << i;
+ *p++ |= UnSign8(*o) >> r;
+ }
+ /* last byte is special: no rightward bits */
+ *p++ = *o++ << i;
+ o += oldoff;
+ }
+ } else if (oldoff > newoff) { /* compressing columns */
+ for (i = ob.max_n; i >= ob.min_n; i--) {
+ bcopy(o, p, newoff);
+ o += oldoff;
+ p += newoff;
+ }
+ } else /* just squeezing out extra rows */
+ bcopy(o, p, newoff * (ob.max_n - ob.min_n + 1));
+
+ /* finally, return the copy */
+ return (n);
+}
+
+/*
+ * Obtain the specified range of glyphs.
+ */
+static int gf_getgly(register struct font *f, int l, int h)
+{
+ register struct glyph *g;
+ register struct char_loc *cl;
+ register char *p;
+ register i32 c;
+ register int i;
+ register i32 thisboc;
+ int abbrev;
+ struct gf_details *gd = ftogd(f);
+
+ /*
+ * For each glyph, make sure there exists an instance of that
+ * character residue. Go find the actual glyph (which may be
+ * arbitrarily far down a chain of pointers) and get its info.
+ */
+ for (cl = &gd->gd_cl[i = l]; i < h; i++, cl++) {
+ g = f->f_gly[i];
+ thisboc = cl->cl_p;
+
+ /*
+ * Screw around locating the character for real.
+ */
+ while (thisboc != -1) {
+ p = gd->gd_base + thisboc;
+skip:
+ c = pgetbyte(p);
+ switch (GF_TYPE(c)) {
+
+ case GT_XXX:
+ switch (GF_OpLen(c)) {
+
+ case GPL_UNS1:
+ c = pgetbyte(p);
+ break;
+
+ case GPL_UNS2:
+ pGetWord(p, c);
+ break;
+
+ case GPL_UNS3:
+ pGet3Byte(p, c);
+ break;
+
+ case GPL_SGN4:
+ pGetLong(p, c);
+ break;
+
+ default:
+ panic("gf_getgly GF_OpLen(%d) = %d",
+ c, GF_OpLen(c));
+ /* NOTREACHED */
+ }
+ p += c;
+ goto skip;
+
+ case GT_YYY:
+ p += 4;
+ goto skip;
+
+ case GT_BOC:
+ abbrev = 0;
+ pGetLong(p, c);
+ break;
+
+ case GT_BOC1:
+ abbrev = 1;
+ c = pgetbyte(p);
+ break;
+
+ default:
+ error(0, 0, "GF code %d; I expected BOC", c);
+ error(1, 0, "bad GF file \"%s\"", f->f_path);
+ /* NOTREACHED */
+ }
+ /*
+ * Found a BOC. If it is the right character,
+ * go handle it.
+ */
+ if (c == i)
+ goto handleit;
+ if ((c & 255) != i) {
+ error(0, 0, "%d != %d mod 256", c, i);
+ error(1, 0, "Bad GF file \"%s\"", f->f_path);
+ }
+ /*
+ * Follow the backpointer.
+ */
+ if (abbrev)
+ thisboc = -1;
+ else
+ pGetLong(p, thisboc);
+ }
+
+ /*
+ * If we get here, the glyph is not valid after all.
+ */
+ continue;
+
+ /*
+ * The glyph is okay. Set it up.
+ */
+handleit:
+ g->g_flags = GF_VALID;
+ g->g_xescapement = cl->cl_dx;
+ g->g_yescapement = cl->cl_dy;
+ g->g_rawtfmwidth = cl->cl_w;
+ if (!abbrev)
+ p += 4; /* skip backpointer */
+ if ((p = drawchar(p, abbrev, gd->gd_gb, f->f_path)) == NULL)
+ return (-1); /* ??? */
+ if (p == nullraster) {
+ /* min > max, hence max-min+1 <= 0; we want 0 */
+ g->g_height = 0;
+ g->g_width = 0;
+ g->g_yorigin = 0;
+ g->g_xorigin = 0;
+ g->g_raster = NULL;
+ } else {
+ /* set height &c based on observed bounds */
+ g->g_height = ob.max_n - ob.min_n + 1;
+ g->g_width = ob.max_m - ob.min_m + 1;
+ g->g_yorigin = ob.max_n;
+ g->g_xorigin = -ob.min_m;
+ g->g_raster = p;
+ }
+ g->g_rotation = ROT_NORM;
+ }
+ return (0);
+}
+
+/*
+ * Obtain rasters for the specified glyphs. We did this above, while
+ * adjusting the bounding boxes, so this routine should never get called.
+ */
+static int gf_rasterise(struct font *f, int l, int h)
+{
+
+ panic("gf_rasterise(%s, %d, %d)", f->f_path, l, h);
+ return( -1 );
+}
+
+/*
+ * Discard the font details.
+ */
+static void gf_freefont(struct font *f)
+{
+ struct gf_details *gd;
+
+ if ((gd = ftogd(f)) != NULL) {
+ free(gd->gd_body);
+ free((char *) gd);
+ }
+}
diff --git a/dviware/epson/eps-0.2/lib/gripes0.c b/dviware/epson/eps-0.2/lib/gripes0.c
new file mode 100644
index 0000000000..c85d5a50e9
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/gripes0.c
@@ -0,0 +1,87 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/gripes0.c,v 2.5 89/09/01 13:52:38 chris Exp $";
+#endif
+
+/*
+ * Common errors (`gripes').
+ */
+
+#include <stdio.h>
+#include "types.h"
+#include "error.h"
+#include "gripes.h"
+
+extern errno;
+
+/*
+ * Cannot allocate memory.
+ */
+extern void GripeOutOfMemory(int n, char *why)
+{
+
+ error(1, -1, "ran out of memory allocating %d bytes for %s", n, why);
+ /* NOTREACHED */
+}
+
+/*
+ * Cannot get a font.
+ * RETURNS TO CALLER
+ */
+extern void GripeCannotGetFont(char *name, i32 mag, i32 dsz, char *dev, char *fullname)
+{
+ int e = errno;
+ char scale[40];
+
+ if (mag == dsz) /* no scaling */
+ scale[0] = 0;
+ else
+ (void) sprintf(scale, " scaled %d",
+ (int) ((double) mag / (double) dsz * 1000.0 + .5));
+
+ error(0, e, "no font for %s%s", name, scale);
+ if (fullname)
+ error(0, 0, "(wanted, e.g., \"%s\")", fullname);
+ else {
+ if (dev)
+ error(1, 0, "(there are no fonts for the %s engine!)",
+ dev);
+ else
+ error(1, 0, "(I cannot find any fonts!)");
+ /* NOTREACHED */
+ }
+}
+
+/*
+ * Font checksums do not match.
+ * RETURNS TO CALLER
+ */
+extern void GripeDifferentChecksums(char *font, i32 tfmsum, i32 fontsum)
+{
+
+ error(0, 0, "\
+WARNING: TeX and I have different checksums for font\n\
+\t\"%s\"\n\
+\tPlease notify your TeX maintainer\n\
+\t(TFM checksum = 0%lo, my checksum = 0%lo)",
+ font, (long)tfmsum, (long)fontsum);
+}
+
+/*
+ * A font, or several fonts, are missing, so no output.
+ */
+extern void GripeMissingFontsPreventOutput(int n)
+{
+ static char s[2] = {'s', 0};
+
+ error(1, 0, "%d missing font%s prevent%s output (sorry)", n,
+ n > 1 ? s : &s[1], n == 1 ? s : &s[1]);
+ /* NOTREACHED */
+}
diff --git a/dviware/epson/eps-0.2/lib/gripes1.c b/dviware/epson/eps-0.2/lib/gripes1.c
new file mode 100644
index 0000000000..d1a05c95e7
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/gripes1.c
@@ -0,0 +1,144 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/gripes1.c,v 1.1 89/08/22 21:54:19 chris Exp $";
+#endif
+
+/*
+ * Gripes having to do with DVI files.
+ */
+
+#include <stdio.h>
+#include "types.h"
+#include "error.h"
+#include "font.h"
+#include "gripes.h"
+
+extern char *DVIFileName;
+
+static char *dfn(void)
+{
+
+ return (DVIFileName ? DVIFileName : "the input");
+}
+
+/*
+ * Save string space by declaring these here.
+ */
+#if __STDC__ >= 1
+static const char dfl[] = "DVI file";
+static const char areyousure[] = "(are you sure %s is a %s?)";
+#else
+static char dfl[] = "DVI file";
+static char areyousure[] = "(are you sure %s is a %s?)";
+#endif
+
+/*
+ * DVI file requests a font it never defined.
+ */
+extern void GripeNoSuchFont(i32 n)
+{
+
+ error(0, 0, "%s wants font %ld, which it never defined", dfl, (long)n);
+ error(1, 0, areyousure, dfn(), dfl);
+ /* NOTREACHED */
+}
+
+/*
+ * DVI file redefines a font.
+ */
+extern void GripeFontAlreadyDefined(i32 n)
+{
+
+ error(0, 0, "%s redefines font %ld", dfl, n);
+ error(1, 0, areyousure, dfn(), dfl);
+ /* NOTREACHED */
+}
+
+/*
+ * Unexpected end of DVI file.
+ */
+extern void GripeUnexpectedDVIEOF(void)
+{
+
+ GripeUnexpectedOp("end of file");
+ /* NOTREACHED */
+}
+
+/*
+ * Unexpected DVI opcode.
+ */
+extern void GripeUnexpectedOp(char *s)
+{
+
+ error(0, 0, "unexpected %s in %s", s, dfl);
+ error(1, 0, areyousure, dfn(), dfl);
+ /* NOTREACHED */
+}
+
+/*
+ * Missing DVI opcode.
+ */
+extern void GripeMissingOp(char *s)
+{
+
+ error(0, 0, "missing %s in %s", s, dfl);
+ error(1, 0, areyousure, dfn(), dfl);
+ /* NOTREACHED */
+}
+
+/*
+ * Cannot find DVI postamble.
+ */
+extern void GripeCannotFindPostamble(void)
+{
+
+ error(0, 0, "cannot find postamble");
+ error(1, 0, areyousure, dfn(), dfl);
+ /* NOTREACHED */
+}
+
+/*
+ * Inconsistent DVI value.
+ */
+extern void GripeMismatchedValue(char *s)
+{
+
+ error(0, 0, "mismatched %s in %s", s, dfl);
+ error(1, 0, areyousure, dfn(), dfl);
+ /* NOTREACHED */
+}
+
+/*
+ * Undefined DVI opcode.
+ */
+extern void GripeUndefinedOp(int n)
+{
+
+ error(0, 0, "undefined DVI opcode %d", n);
+ error(1, 0, areyousure, dfn(), dfl);
+ /* NOTREACHED */
+}
+
+/*
+ * DVI file requests glyph that is not in some font, or
+ * when no font is set for this page.
+ *
+ * RETURNS TO CALLER
+ */
+extern void GripeBadGlyph(i32 c, struct font *f)
+{
+
+ if (f->f_path == NULL) {
+ error(0, 0, "bad %s: char without setfont", dfl);
+ error(1, 0, "(try checking %s with dvitype)", dfn());
+ /* NOTREACHED */
+ }
+ error(0, 0, "there is no character %ld in %s!", (long)c, f->f_path);
+}
diff --git a/dviware/epson/eps-0.2/lib/magfactor.c b/dviware/epson/eps-0.2/lib/magfactor.c
new file mode 100644
index 0000000000..40fce6f95e
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/magfactor.c
@@ -0,0 +1,39 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+/*
+ * Convert a magnification factor to floating point. This is used in
+ * conjunction with the FONT_SLOP stuff to try to get the file names
+ * right, and may also be used by DVI reading programs to get slightly
+ * more accurate values for (mag/1000.0).
+ */
+extern double DMagFactor(int mag)
+{
+
+ switch (mag) {
+
+ case 1095: /* stephalf */
+ return (1.095445);
+
+ case 1315: /* stepihalf */
+ return (1.314534);
+
+ case 2074: /* stepiv */
+ return (2.0736);
+
+ case 2488: /* stepv */
+ return (2.48832);
+
+ case 2986: /* stepiv */
+ return (2.985984);
+
+ default: /* remaining mags have been ok */
+ return ((double) mag / 1000.);
+ }
+ /* NOTREACHED */
+}
diff --git a/dviware/epson/eps-0.2/lib/makefile.djg b/dviware/epson/eps-0.2/lib/makefile.djg
new file mode 100644
index 0000000000..94fa56139e
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/makefile.djg
@@ -0,0 +1,109 @@
+#
+# Copyright (c) 1987, 1989 University of Maryland
+# Department of Computer Science. All rights reserved.
+# Permission to copy for any purpose is hereby granted
+# so long as this copyright notice remains intact.
+#
+# Makefile for ctex/lib (C-TeX library routines)
+#
+# $Header: /usr/src/local/tex/local/mctex/lib/RCS/Makefile,v 3.2 89/10/17 09:27:30 chris Exp $
+#
+CFLAGS= -x c++ -I../h -O
+
+%.o: %.c
+ gcc -c -x c++ -I../h -O $<
+
+DESTDIR=
+SHELL= d:/bin/sh
+
+CC=gcc
+# SysV sites should set RANLIB=:
+RANLIB= ranlib
+#RANLIB=:
+
+# This will be overridden by ../Makefile, but just in case...
+FONTDESC=d:\\tex\\fonts\\fontdesc
+
+# 4.1BSD Vax:
+#ASSRC= vaxbcopy.s vaxbzero.s
+#ASOBJ= vaxbcopy.o vaxbzero.o
+#MISCC= getopt.c
+#MISCO= getopt.o
+
+# 4.2BSD Vax:
+#ASSRC=
+#ASOBJ=
+#MISCC= getopt.c
+#MISCO= getopt.o
+
+# 4.2BSD Sun:
+#ASSRC=
+#ASOBJ=
+#MISCC=
+#MISCO=
+
+# 4.2BSD Pyramid:
+#ASSRC=
+#ASOBJ=
+#MISCC= getopt.c
+#MISCO= getopt.o
+
+# 4.3BSD Vax, and many others
+ASSRC=
+ASOBJ=
+MISCC=
+MISCO=
+
+# machines without any of bcopy,bzero,getopt
+#ASSRC=
+#ASOBJ=
+#MISCC= bcopy.c bzero.c getopt.c
+#MISCO= bcopy.o bzero.o getopt.o
+
+MISCO= getopt.o
+# all machines
+# regular library routines
+CSRC= conv.c dviclass.c dvistate.c error.c findpost.c fio.c font.c \
+ font_subr.c gfclass.c gripes0.c gripes1.c magfactor.c rotate.c \
+ scaletfm.c scanpost.c sdecode.c search.c seek.c skip.c split.c \
+ strsave.c tempfile.c tfm.c ${MISCC}
+COBJ1= conv.o dviclass.o dvistate.o error.o findpost.o fio.o font.o
+COBJ2= font_subr.o gfclass.o gripes0.o gripes1.o magfactor.o rotate.o
+COBJ3= scaletfm.o scanpost.o sdecode.o search.o seek.o skip.o split.o
+COBJ4= strsave.o tempfile.o tfm.o ${MISCO}
+# font routines
+FSRC= gffont.c pkfont.c pxlfont.c tfmfont.c
+FOBJ= gffont.o pkfont.o pxlfont.o tfmfont.o
+
+COBJ= ${COBJ1} ${COBJ2} ${COBJ3} ${COBJ4}
+OBJS= ${COBJ} ${ASOBJ} ${FOBJ}
+
+all: lib.a
+
+lib.a: ${OBJS}
+ ar rv lib.a ${COBJ1}
+ ar rv lib.a ${COBJ2}
+ ar rv lib.a ${COBJ3}
+ ar rv lib.a ${COBJ4}
+ ar rv lib.a ${FOBJ}
+ ${RANLIB} lib.a
+
+
+# no installation is necessary; this entry is just for standardisation
+install:
+
+clean:
+ rm -f *.o lib.a
+
+cleandir: clean
+ rm -f .depend
+
+depend: ${CSRC} ${FSRC}
+ mkdep ${CFLAGS} ${CSRC} ${FSRC}
+
+# XXX should be able to check these
+lint:
+
+# font.o needs to know where to find the font description file
+font.o:
+ ${CC} ${CFLAGS} -c font.c
diff --git a/dviware/epson/eps-0.2/lib/pkfont.c b/dviware/epson/eps-0.2/lib/pkfont.c
new file mode 100644
index 0000000000..a4abea4fd1
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/pkfont.c
@@ -0,0 +1,698 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/pkfont.c,v 2.10 89/08/22 21:54:49 chris Exp $";
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "types.h"
+#include "error.h"
+#include "font.h"
+#include "num.h"
+#include <stdlib.h> /* for malloc */
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+# include <io.h>
+#else
+# include <osfcn.h> /* for read, close */
+#endif
+
+/*
+ * PK font operations.
+ *
+ * The spelling `nybble' is a concession to the authors of the PK format.
+ */
+
+struct fontops pkops =
+ { "pk", 0, 1.0, pk_read, pk_getgly, pk_rasterise, pk_freefont };
+
+/*
+ * Local info.
+ */
+
+/*
+ * Commands.
+ */
+#define PK_XXX1 240 /* 1 byte special */
+#define PK_XXX2 241 /* 2 byte special */
+#define PK_XXX3 242 /* 3 byte special */
+#define PK_XXX4 243 /* 4 byte special */
+#define PK_YYY 244 /* METAFONT numspecial */
+#define PK_POST 245 /* marks postamble */
+#define PK_NO_OP 246 /* do nothing */
+#define PK_PRE 247 /* marks preamble */
+ /* 248..255 undefined */
+#define PK_IsUndef(c) ((c) > PK_PRE)
+
+#define PK_ID 89 /* marks this brand of PK file */
+
+/*
+ * Information about a character packet.
+ */
+
+#define CP_SHORT 0 /* short preamble */
+#define CP_EXT_SHORT 1 /* extended short preamble */
+#define CP_LONG 2 /* long preamble */
+
+/*
+ * The PK details include:
+ * -> a pointer to the next byte to fetch;
+ * -> the most recent byte fetched (when we are using nextnyb());
+ * -> a flag indicating that we have used nybble 0 (bits 4..7) and
+ * should use nybble 1 next;
+ * -> the base address of the memory allocated for the PK file;
+ * -> the value of dyn_f (during character translation);
+ * -> the repeat count (during rasterisation);
+ * -> the lowest glyph number that is legal;
+ * -> the highest glyph number that is legal;
+ * -> glyph instructions for the standard glyphs;
+ * -> glyph instructions for more (nonstandard) glyphs;
+ * and the number of glyphs left unrasterised.
+ */
+
+/*
+ * Fetch the next byte from the PK file.
+ */
+#define nextbyte(pk) pgetbyte((pk)->pk_ptr)
+
+/*
+ * PK packed number encoding. Nybbles in [1..dyn_f] represent themselves.
+ * Values in (dyn_f..13] are two-nybble values, and represent values
+ * dyn_f+1 through (13-dyn_f+1)*16+15. Zero marks a long number; 14 and
+ * 15 specify repeat counts instead (which are another packed number).
+ * Note that we cannot represent the number zero as a packed number.
+ */
+#define PK_LONGNUM 0 /* a `long number' */
+#define PK_REPEAT 14 /* set repeat count */
+#define PK_REPEAT1 15 /* set repeat to 1 */
+
+/*
+ * Get the next nybble. This is an expression rendition of
+ * if (--pk->pk_1nyb < 0) {
+ * pk->pk_1nyb = 1;
+ * pk->pk_c = nextbyte(pk);
+ * return (pk->pk_c >> 4);
+ * } else
+ * return (pk->pk_c & 0xf);
+ */
+#define nextnyb(pk) \
+ (--(pk)->pk_1nyb < 0 ? \
+ ((pk)->pk_1nyb = 1, ((pk)->pk_c = nextbyte(pk)) >> 4) : \
+ (pk)->pk_c & 0xf)
+
+/*
+ * Get the pk_details from font f.
+ */
+#define ftopk(f) ((struct pk_details *)(f)->f_details)
+
+static int scan_characters();
+
+extern int errno;
+/* char *malloc(); */
+
+/*
+ * PK subroutines.
+ */
+
+/*
+ * Unpack a packed number.
+ */
+static int pk_unpack(register struct pk_details *pk)
+{
+ register int i, j;
+
+top:
+ if ((i = nextnyb(pk)) == PK_LONGNUM) {
+#if PK_LONGNUM != 0 /* this may be silly, but . . . */
+ i = 0;
+#endif
+ /*
+ * Expand a long number. There are one fewer leading
+ * zeros than there are nonzero digits to obtain, so
+ * count up the leading zeros, add one, and get that
+ * many digits. (The `digits' are hexadecimal values.)
+ */
+ do {
+ i++;
+ } while ((j = nextnyb(pk)) == 0);
+ while (--i >= 0) {
+ j <<= 4;
+ j += nextnyb(pk);
+ }
+ return (j - 15 + (13 - pk->pk_dyn_f) * 16 + pk->pk_dyn_f);
+ }
+ if (i <= pk->pk_dyn_f)
+ return (i);
+ if (i < PK_REPEAT)
+ return ((i - pk->pk_dyn_f - 1) * 16 + nextnyb(pk) +
+ pk->pk_dyn_f + 1);
+
+ /*
+ * There is a repeat count, either one or a packed number.
+ * Get it first, then start over. (tail recursion)
+ */
+ if (i == PK_REPEAT)
+ pk->pk_repeat = pk_unpack(pk);
+ else
+ pk->pk_repeat = 1;
+ goto top;
+}
+
+/*
+ * Skip over special commands (PK_XXX?, PK_YYY).
+ */
+static void skip_specials(struct font *f)
+{
+ struct pk_details *pk = ftopk(f);
+ register char *p = pk->pk_ptr;
+ register i32 i;
+
+ for (;;) {
+ switch (UnSign8(*p++)) {
+
+ case PK_XXX1:
+ i = UnSign8(*p++);
+ p += i;
+ break;
+
+ case PK_XXX2:
+ pGetWord(p, i);
+ p += i;
+ break;
+
+ case PK_XXX3:
+ pGet3Byte(p, i);
+ p += i;
+ break;
+
+ case PK_XXX4:
+ pGetLong(p, i);
+ p += i;
+ break;
+
+ case PK_YYY:
+ p += 4;
+ break;
+
+ case PK_NO_OP:
+ break;
+
+ case PK_PRE:
+ error(1, 0, "unexpected PK_PRE in \"%s\"", f->f_path);
+ break;
+
+ default:
+ p--;
+ if (PK_IsUndef(UnSign8(*p)))
+ error(1, 0, "invalid opcode %d in \"%s\"",
+ f->f_path);
+ pk->pk_ptr = p;
+ return;
+ }
+ }
+}
+
+/*
+ * Read a PK file.
+ */
+static int pk_read(register struct font *f, int fd)
+{
+ register struct pk_details *pk;
+ register char *p;
+ int i, minc;
+ struct stat st;
+ char *reason;
+
+ pk = NULL; /* prepare for failure */
+ reason = NULL;
+ (void) fstat(fd, &st);
+ if (st.st_size < 4) { /* ??? */
+ reason = "file is too small";
+ goto fail;
+ }
+ if ((pk = (struct pk_details *)malloc(sizeof (*pk))) == NULL)
+ goto fail;
+ pk->pk_morec = NULL;
+ if ((pk->pk_base = (char*)malloc(st.st_size)) == NULL)
+ goto fail;
+ if (read(fd, pk->pk_base, st.st_size) != st.st_size)
+ goto fail;
+ pk->pk_ptr = pk->pk_base;
+ if (nextbyte(pk) != PK_PRE) {
+ reason = "file does not begin with PK_PRE";
+ goto fail;
+ }
+ if (nextbyte(pk) != PK_ID) {
+ reason = "bad PK_ID";
+ goto fail;
+ }
+ i = nextbyte(pk);
+ p = pk->pk_ptr + i; /* skip comment */
+ pGetLong(p, f->f_design_size);
+ pGetLong(p, f->f_checksum);
+ pGetLong(p, f->f_hppp);
+ pGetLong(p, f->f_vppp);
+ pk->pk_ptr = p;
+
+ f->f_details = (char *)pk;
+
+ /* scan the characters, fail if necessary */
+ if (scan_characters(f, &reason))
+ goto fail;
+
+ /* ignore the postamble */
+
+ /* COMPRESS pk->pk_base DATA? */
+
+ if (FontHasGlyphs(f, pk->pk_minc, pk->pk_maxc + 1))
+ goto fail;
+ (void) close(fd);
+ return (0);
+
+fail:
+ if (reason) {
+ error(0, 0, "%s", reason);
+ error(0, 0, "(are you sure %s is a PK file?)", f->f_path);
+ errno = 0;
+ }
+ if (pk != NULL) {
+ if (pk->pk_base != NULL)
+ free(pk->pk_base);
+ if (pk->pk_morec != NULL)
+ free((char *)pk->pk_morec);
+ free((char *)pk);
+ }
+ (void) close(fd);
+ return (-1);
+}
+
+/*
+ * Scan through the characters in the PK file, and set the offsets
+ * and preamble types for each of the character packets.
+ */
+static int scan_characters(struct font *f, char **reason)
+{
+ register struct pk_details *pk = ftopk(f);
+ register i32 c, pl;
+ register char *p;
+ register struct cp *cp;
+ int type;
+
+#ifdef lint
+ /* reason will be used someday ... I think */
+ reason = reason;
+#endif
+
+ /* set up the minimisers and the glyph count */
+ pk->pk_minc = 1;
+ pk->pk_maxc = 0;
+ pk->pk_gleft = 0;
+
+ /* mark all character packets as untouched */
+ for (cp = pk->pk_cpack, c = MAXSTD; --c >= 0; cp++)
+ cp->cp_packet = NULL;
+
+ /*
+ * Loop through the packets until we reach a POST, skipping
+ * the glyph instructions themselves after each definition,
+ * and specials (if any) before each.
+ */
+ for (;; pk->pk_ptr = p + pl) {
+ skip_specials(f);
+ p = pk->pk_ptr;
+ if ((c = pgetbyte(p)) == PK_POST)
+ break; /* whoops, done after all */
+
+ /*
+ * Look at the low three bits to decide preamble size.
+ * A value of 7 is a `long preamble'; 4, 5, and 6 are
+ * `extended short preambles'; and 0, 1, 2, and 3 are
+ * `short preambles'.
+ *
+ * We ignore most of the preamble, reading only the
+ * `packet length' and the character code at this time.
+ */
+ switch (c & 7) {
+
+ case 7: /* long */
+ type = CP_LONG;
+ pGetLong(p, pl);
+ pGetLong(p, c);
+ break;
+
+ case 6:
+ case 5:
+ case 4: /* extended short */
+ type = CP_EXT_SHORT;
+ pGetWord(p, pl);
+ pl += (c & 3) << 16;
+ c = pgetbyte(p);
+ break;
+
+ default: /* short */
+ type = CP_SHORT;
+ pl = ((c & 3) << 8) + pgetbyte(p);
+ c = pgetbyte(p);
+ break;
+ }
+
+ if (c >= MAXSTD) {
+ /*
+ * BEGIN XXX - should alloc pk_morec, but is hard
+ * and not now useful
+ */
+ error(0, 0, "ignoring character %d in \"%s\"",
+ f->f_path);
+ error(0, 0, "because some darn programmer was lazy!");
+ continue;
+ /* END XXX */
+ } else
+ cp = &pk->pk_cpack[c];
+
+ cp->cp_packet = pk->pk_ptr;
+ cp->cp_type = type;
+
+ /* adjust range */
+ if (c < pk->pk_minc)
+ pk->pk_minc = c;
+ if (c > pk->pk_maxc)
+ pk->pk_maxc = c;
+
+ pk->pk_gleft++; /* and count the glyph */
+ }
+ return (0); /* no problems */
+}
+
+/*
+ * Obtain the specified range of glyphs.
+ */
+static int pk_getgly(register struct font *f, int l, int h)
+{
+ register struct pk_details *pk = ftopk(f);
+ register char *p;
+ register struct glyph *g;
+ register int i;
+ register struct cp *cp;
+
+ if (pk == NULL)
+ panic("pk_getgly(%s)", f->f_path);
+ for (i = l; i < h; i++) {
+ if (i < MAXSTD)
+ cp = &pk->pk_cpack[i];
+ else {
+ if (i > pk->pk_maxc)
+ panic("pk_getgly(%s, %d)", f->f_path, i);
+ cp = &pk->pk_morec[i - MAXSTD];
+ }
+ p = cp->cp_packet;
+ if (p == NULL) /* glyph is not valid */
+ continue;
+ g = f->f_gly[i];
+ p++; /* skip flag */
+ switch (cp->cp_type) {
+
+ case CP_LONG:
+ p += 8; /* skip packet len, character code */
+ pGetLong(p, g->g_rawtfmwidth);
+ pGetLong(p, g->g_xescapement);
+ pGetLong(p, g->g_yescapement);
+ pGetLong(p, g->g_width);
+ pGetLong(p, g->g_height);
+ pGetLong(p, g->g_xorigin);
+ pGetLong(p, g->g_yorigin);
+ break;
+
+ case CP_EXT_SHORT: {
+ i32 dm;
+
+ p += 3; /* skip packet len, character code */
+ pGet3Byte(p, g->g_rawtfmwidth);
+ pGetWord(p, dm);
+ g->g_xescapement = dm << 16;
+ g->g_yescapement = 0;
+ pGetWord(p, g->g_width);
+ pGetWord(p, g->g_height);
+ pGetWord(p, g->g_xorigin);
+ g->g_xorigin = Sign16(g->g_xorigin);
+ pGetWord(p, g->g_yorigin);
+ g->g_yorigin = Sign16(g->g_yorigin);
+ break;
+ }
+
+ case CP_SHORT:
+ p += 2; /* skip packet len, character code */
+ pGet3Byte(p, g->g_rawtfmwidth);
+ g->g_xescapement = pgetbyte(p) << 16;
+ g->g_yescapement = 0;
+ g->g_width = pgetbyte(p);
+ g->g_height = pgetbyte(p);
+ g->g_xorigin = pgetbyte(p);
+ g->g_xorigin = Sign8(g->g_xorigin);
+ g->g_yorigin = pgetbyte(p);
+ g->g_yorigin = Sign8(g->g_yorigin);
+ break;
+ }
+ g->g_flags = GF_VALID;
+ g->g_un.g_details = p;
+ }
+ return (0);
+}
+
+/*
+ * Bit masks for pk_rasterise().
+ */
+static char bmask[8] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe};
+static char rbits[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
+
+/*
+ * Obtain rasters for the specified glyphs.
+ */
+static int pk_rasterise(struct font *f, int l, int h)
+{
+ struct pk_details *pk0;
+ struct glyph *g0;
+ char *p0, *rp0;
+ int flag, ii;
+
+ if ((pk0 = ftopk(f)) == NULL)
+ panic("pk_rasterise(%s)", f->f_path);
+ for (ii = l; ii < h; ii++) {
+ {
+ register struct glyph *g;
+ register char *p;
+ register int i;
+
+ g = f->f_gly[i = ii];
+ if ((g->g_flags & GF_VALID) == 0)
+ continue; /* no glyph */
+ if (!HASRASTER(g)) /* empty raster */
+ goto done;
+
+ /*
+ * Allocate a raster.
+ */
+ rp0 = (char*)malloc(((g->g_width + 7) >> 3) * g->g_height);
+ if ((g->g_raster = rp0) == NULL)
+ return (-1);/* ??? */
+ g->g_rotation = ROT_NORM;
+
+ /*
+ * Pick up the flag byte, then start at the real
+ * packet, which we saved in g_details.
+ */
+ if (i < MAXSTD)
+ p = pk0->pk_cpack[i].cp_packet;
+ else
+ p = pk0->pk_morec[i - MAXSTD].cp_packet;
+ flag = UnSign8(*p);
+ p0 = g->g_un.g_details;
+ g0 = g;
+ }
+ if ((pk0->pk_dyn_f = flag >> 4) == 14) {
+ register char *p = p0, *rp = rp0;
+ register int j, ls, rs, i, w;
+
+ /*
+ * Expand a bit-packed representation.
+ * If we get lucky, it is byte packed and
+ * we can just copy it over.
+ */
+ i = g0->g_height;
+ j = g0->g_width;
+ if ((j & 7) == 0) {
+ bcopy(p, rp, i * (j >> 3));
+ goto done;
+ }
+
+ /*
+ * No such luck.
+ */
+ w = j;
+ ls = 0;
+ while (--i >= 0) {
+ rs = 8 - ls;
+ /* know j always != 8 */
+ for (j = w; j > 8; j -= 8) {
+ *rp = *p++ << ls;
+ *rp++ |= UnSign8(*p) >> rs;
+ }
+
+ /*
+ * We need j more bits; there are rs
+ * bits available at *p. Ask for j,
+ * which gets min(j, rs).
+ */
+ *rp++ = (*p << ls) & bmask[j];
+ /* account for j bits */
+ ls += j; ls &= 7;
+ /* then adjust j based on rs */
+ j -= rs;
+ /* still need j more bits */
+ if (j < 0) /* got them all */
+ continue;
+ p++;
+ if (j == 0) /* there were just enough */
+ continue;
+ /* take j more bits */
+ rp[-1] |= UnSign8(*p & bmask[j]) >> rs;
+ }
+ } else {
+ register struct pk_details *pk = pk0;
+ register int on = flag & 8 ? 0xff : 0;
+ register char *rowp; /* pointer into this row */
+ register int j; /* trimmed run count */
+ register int k; /* misc */
+ register int b; /* bit index in current col */
+ register int i; /* run count */
+ register int colsleft; /* columns left this row */
+ register int rowsleft; /* rows left */
+ static char *row; /* a one-row buffer */
+ static int rowsize; /* and its size in bytes */
+ int wb; /* row width in bytes */
+
+ wb = (g0->g_width + 7) >> 3;
+ if (rowsize < wb) { /* get more row space */
+ if (row)
+ free(row);
+ /* keep a slop byte */
+ row = (char*)malloc((unsigned) (wb + 1));
+ if (row == NULL)
+ return (-1); /* ??? */
+ rowsize = wb;
+ }
+ bzero(row, wb);
+ rowsleft = g0->g_height;
+ colsleft = g0->g_width;
+ pk->pk_repeat = 0;
+ pk->pk_ptr = p0;
+ pk->pk_1nyb = 0; /* start on nybble 0 */
+ rowp = row;
+ b = 0;
+ while (rowsleft > 0) { /* do all rows */
+ /* EXPAND IN LINE? */
+ i = pk_unpack(pk);
+ /*
+ * Work until the run count is exhausted
+ * (or at least pretty tired).
+ *
+ * (Okay, so the joke is stolen!)
+ */
+ while ((j = i) > 0) {
+ /*
+ * If the count is more than the
+ * rest of this row, trim it down.
+ */
+ if (j > colsleft)
+ j = colsleft;
+ i -= j; /* call them done */
+ /*
+ * We need k=8-b bits to finish
+ * up the current byte. If we
+ * can finish it, do so; the proper
+ * bits to set are in rbits[k].
+ */
+ if (j >= (k = 8 - b)) {
+ j -= k;
+ colsleft -= k;
+ *rowp++ |= on & rbits[k];
+ b = 0;
+ }
+ /*
+ * Set any full bytes.
+ */
+ while (j >= 8) {
+ *rowp++ = on;
+ j -= 8;
+ colsleft -= 8;
+ }
+ /*
+ * Finally, begin a new byte, or
+ * add to the current byte, with
+ * j more bits. We know j <= 8-b.
+ * (If j==0, we may be writing on
+ * our slop byte, which is why we
+ * keep one around....)
+ */
+if (j > 8-b) panic("pk_rasterise j>8-b");
+ *rowp |= (on & bmask[j]) >> b;
+ colsleft -= j;
+ b += j; b &= 7;
+ if (colsleft == 0) {
+ pk->pk_repeat++;
+ rowsleft -= pk->pk_repeat;
+ while (--pk->pk_repeat >= 0) {
+ bcopy(row, rp0, wb);
+ rp0 += wb;
+ }
+if (rowsleft == 0 && i) panic("pk_rasterise leftover bits");
+ pk->pk_repeat = 0;
+ rowp = row;
+ colsleft = g0->g_width;
+ bzero(row, wb);
+ b = 0;
+ }
+ }
+ on = 0xff - on;
+ }
+ }
+
+done:
+ /*
+ * Successfully converted another glyph.
+ */
+ pk0->pk_gleft--;
+ }
+
+if (pk0->pk_gleft < 0)
+panic("%s: gleft==%d", f->f_path, pk0->pk_gleft);
+ if (pk0->pk_gleft == 0) {
+ free(pk0->pk_base);
+ if (pk0->pk_morec != NULL)
+ free((char *) pk0->pk_morec);
+ free((char *) pk0);
+ f->f_details = NULL;
+ }
+ return (0);
+}
+
+/*
+ * Discard the font details.
+ */
+static void pk_freefont(struct font *f)
+{
+ register struct pk_details *pk = ftopk(f);
+
+ if (pk != NULL) {
+ free(pk->pk_base);
+ if (pk->pk_morec != NULL)
+ free((char *) pk->pk_morec);
+ free((char *) pk);
+ }
+}
diff --git a/dviware/epson/eps-0.2/lib/pxlfont.c b/dviware/epson/eps-0.2/lib/pxlfont.c
new file mode 100644
index 0000000000..a58c95537a
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/pxlfont.c
@@ -0,0 +1,293 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/pxlfont.c,v 2.5 89/08/22 21:55:34 chris Exp $";
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include "types.h"
+#include "error.h"
+#include "font.h"
+#include "fio.h"
+#include <stdlib.h> /* for malloc */
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+# include <io.h>
+#else
+# include <osfcn.h> /* for lseek, read, close */
+#endif
+
+/*
+ * PXL font operations.
+ */
+
+struct fontops pxlops =
+ { "pxl", 0, 5.0, pxl_read, pxl_getgly, pxl_rasterise, pxl_freefont };
+
+/*
+ * Local info.
+ */
+#define PXLID 1001 /* ID denoting PXL files */
+#define TAILSIZE (517 * 4) /* size of pxl tail info */
+
+/*
+ * pc describes one PXL character information block.
+ */
+struct pc {
+ i16 pc_width; /* character width (pixels) */
+ i16 pc_height; /* character height (pixels) */
+ i16 pc_xoffset; /* X offset of reference point */
+ i16 pc_yoffset; /* Y offset of reference point */
+ i32 pc_rastoff; /* raster offset */
+ i32 pc_TFMwidth; /* TFM width (FIXes) */
+};
+
+/*
+ * pxl_details are the PXL-specific font details.
+ *
+ * We keep track of the number of characters converted to internal
+ * glyph form, and when all have been done, we discard the now-
+ * useless details.
+ */
+struct pxl_details {
+ int pd_nconv; /* number of characters converted */
+ char *pd_ras; /* raster space, until converted */
+ struct pc pd_pc[128]; /* `font directory' */
+};
+
+/*
+ * Get the pxl_details from font f.
+ */
+#define ftopd(f) ((struct pxl_details *) (f)->f_details)
+
+extern errno;
+/* char *malloc(); */
+
+/*
+ * Read a PXL file.
+ */
+static int pxl_read(struct font *f, int fd)
+{
+ register struct pxl_details *pd;
+ register FILE *fp;
+ register struct pc *pc;
+ register int i;
+ int saverr;
+ i32 pxlid;
+ struct stat st;
+
+ fp = NULL;
+ if ((pd = (struct pxl_details *)malloc(sizeof (*pd))) == 0)
+ goto fail;
+ pd->pd_ras = 0;
+
+ /*
+ * There should be 4n bytes, with an absolute minimum of TAILSIZE+4
+ * (+4 for the initial PXLID).
+ */
+ (void) fstat(fd, &st);
+ if ((st.st_size & 3) != 0 || st.st_size < (TAILSIZE + 4)) {
+ errno = EINVAL;
+ goto fail;
+ }
+
+ /*
+ * Set up the raster pointer (if we need rasters).
+ */
+ if (f->f_flags & FF_RASTERS) {
+ i = st.st_size - (TAILSIZE + 4);
+ if (i != 0) {
+ if ((pd->pd_ras = (char*)malloc((unsigned) i)) == 0)
+ goto fail;
+ (void) lseek(fd, 4L, 0);
+ if (read(fd, pd->pd_ras, i) != i)
+ goto fail;
+ }
+ }
+
+ /*
+ * Read the glyph information.
+ */
+ errno = 0; /* try to make errno meaningful */
+ if ((fp = fdopen(fd, "r")) == NULL) {
+ if (errno == 0)
+ errno = EMFILE;
+ goto fail;
+ }
+ (void) fseek(fp, (long) -TAILSIZE, 2);
+ for (i = 128, pc = pd->pd_pc; --i >= 0; pc++) {
+ fGetWord(fp, pc->pc_width);
+ fGetWord(fp, pc->pc_height);
+ fGetWord(fp, pc->pc_xoffset);
+ fGetWord(fp, pc->pc_yoffset);
+ fGetLong(fp, pc->pc_rastoff);
+ fGetLong(fp, pc->pc_TFMwidth);
+ }
+ f->f_checksum = GetLong(fp);
+ (void) GetLong(fp); /* mag */
+ f->f_design_size = GetLong(fp); /* designsize */
+ f->f_hppp = 0; /* ??? maybe 200? */
+ f->f_vppp = 0;
+ (void) GetLong(fp); /* dirpointer */
+ pxlid = GetLong(fp);
+ if (pxlid != PXLID)
+ error(0, 0, "Warning: strange PXL id (%d) in \"%s\"",
+ pxlid, f->f_path);
+
+ f->f_details = (char *)pd;
+ if (FontHasGlyphs(f, 0, 128))
+ goto fail;
+ (void) fclose(fp);
+ pd->pd_nconv = 0;
+ return (0);
+
+fail:
+ saverr = errno;
+ if (pd) {
+ if (pd->pd_ras)
+ free(pd->pd_ras);
+ free((char *)pd);
+ }
+ if (fp)
+ (void) fclose(fp);
+ else
+ (void) close(fd);
+ errno = saverr;
+ return (-1);
+}
+
+/*
+ * Obtain the specified range of glyphs.
+ */
+static int pxl_getgly(register struct font *f, int l, register int h)
+{
+ register struct glyph *g;
+ register struct pc *pc;
+ register int i;
+ struct pxl_details *pd;
+
+ if ((pd = ftopd(f)) == NULL)
+ error(1, 0, "pxl_getgly details==0: cannot happen");
+ /*
+ * By definition, all 128 glyphs are valid. Just copy the
+ * PXL information.
+ */
+ for (pc = &pd->pd_pc[i = l]; i < h; i++, pc++) {
+ g = f->f_gly[i];
+ g->g_flags = GF_VALID;
+ g->g_height = pc->pc_height;
+ g->g_width = pc->pc_width;
+ g->g_yorigin = pc->pc_yoffset;
+ g->g_xorigin = pc->pc_xoffset;
+ g->g_rawtfmwidth = pc->pc_TFMwidth;
+ }
+ return (0);
+}
+
+/*
+ * Helper function for rasterise: return a pointer to a converted
+ * (malloc()ed and minimised) raster.
+ */
+static char *makeraster(register int h, register int w, register char *rp)
+{
+ register char *cp;
+ register int i, o;
+ char *rv;
+
+ /*
+ * The height and width values are in bits. Convert width to
+ * bytes, rounding up. The raw raster (at rp) is almost what
+ * we want, but not quite: it has `extra' bytes at the end of
+ * each row, to pad out to a multiple of four bytes.
+ */
+ w = (w + 7) >> 3;
+ o = (4 - w) & 3; /* offset (number of `extra' bytes) */
+ if ((cp = (char*)malloc((unsigned) (h * w))) == NULL)
+ return (NULL);
+ if (o == 0) {
+ /*
+ * The raster fits exactly; just copy it to the allocated
+ * memory space. (We must copy anyway, so that glyphs
+ * can be freed, e.g., after rotation.)
+ */
+ bcopy(rp, cp, h * w);
+ return (cp);
+ }
+ rv = cp;
+ while (--h >= 0) {
+ /*
+ * Copy each row, then skip over the extra stuff.
+ */
+ for (i = w; --i >= 0;)
+ *cp++ = *rp++;
+ rp += o;
+ }
+ return (rv);
+}
+
+/*
+ * Obtain rasters for the specified glyphs.
+ */
+static int pxl_rasterise(register struct font *f, int l, register int h)
+{
+ register struct glyph *g;
+ register struct pc *pc;
+ register int i;
+ register struct pxl_details *pd;
+
+ if ((pd = ftopd(f)) == NULL)
+ error(1, 0, "pxl_rasterise details==0: cannot happen");
+ if (pd->pd_ras == NULL)
+ error(1, 0, "pxl_rasterise pd_ras==NULL: cannot happen");
+ for (pc = &pd->pd_pc[i = l]; i < h; i++, pc++) {
+ g = f->f_gly[i];
+ if (pc->pc_rastoff == 0) {
+ /*
+ * g should not claim a raster, since it has none.
+ */
+ if (HASRASTER(g))
+ error(1, 0, "bad PXL glyph %d in \"%s\"",
+ g->g_index, f->f_path);
+ } else {
+ g->g_raster = makeraster(pc->pc_height, pc->pc_width,
+ pd->pd_ras + ((pc->pc_rastoff - 1) << 2));
+ if (g->g_raster == NULL)
+ return (-1); /* ??? */
+ g->g_rotation = ROT_NORM;
+ }
+ }
+
+ /*
+ * If we have converted all the characters, dump the
+ * pre-conversion rasters. In fact, dump everything.
+ */
+ pd->pd_nconv += h - l;
+ if (pd->pd_nconv == 128) {
+ free(pd->pd_ras);
+ free((char *)pd);
+ f->f_details = NULL;
+ }
+ return (0);
+}
+
+/*
+ * Discard the font details.
+ */
+static void pxl_freefont(struct font *f)
+{
+ struct pxl_details *pd;
+
+ if ((pd = ftopd(f)) != NULL) {
+ if (pd->pd_ras != NULL)
+ free(pd->pd_ras);
+ free((char *)pd);
+ }
+}
diff --git a/dviware/epson/eps-0.2/lib/rotate.c b/dviware/epson/eps-0.2/lib/rotate.c
new file mode 100644
index 0000000000..171e7db7db
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/rotate.c
@@ -0,0 +1,152 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/rotate.c,v 2.4 89/08/22 21:56:05 chris Exp $";
+#endif
+
+/*
+ * Routines to generate rotated bitmaps given unrotated inputs.
+ *
+ * The rotated bitmap is indistinguishable from the unrotated one (aside
+ * from being rotated of course!).
+ */
+
+#include "types.h"
+#include "error.h"
+#include "font.h"
+
+static void RotateClockwise();
+
+extern int errno;
+/* char *malloc(); */
+#include <stdlib.h> /* for malloc */
+
+/*
+ * Rounding, but by powers of two only.
+ */
+#define ROUND2(n,r) (((n) + ((r) - 1)) & ~((r) - 1))
+
+/*
+ * Set the rotation of glyph g to r.
+ */
+extern void SetRotation(register struct glyph *g, int r)
+{
+
+ if (r < ROT_NORM || r > ROT_RIGHT)
+ error(1, 0, "bad rotation value %d", r);
+
+ /*
+ * The null glyph is trivial to rotate by any amount.
+ *
+ * Note that this assumes that any raster has been obtained
+ * BEFORE calling SetRotation()!
+ */
+ if (g->g_raster == NULL) {
+ g->g_rotation = r;
+ return;
+ }
+
+ /*
+ * This is hardly efficient, but it *is* expedient....
+ */
+ while (g->g_rotation != r) {
+ RotateClockwise(g);
+ g->g_rotation = (g->g_rotation - 1) & 3;
+ }
+}
+
+/*
+ * Rotation by 1/4 turn clockwise (from ROT_NORM to ROT_RIGHT, e.g.).
+ */
+static void RotateClockwise(struct glyph *glyph)
+{
+ register char *nrast; /* new raster */
+ register char *orast; /* old raster */
+ register int oheight; /* old raster height, new raster width */
+ register int owidth; /* old raster width, new raster height */
+ unsigned int size; /* size of new raster (in bytes) */
+ int nplus; /* offset between rows in nrast */
+
+ /*
+ * First, get a new raster.
+ */
+ {
+ register struct glyph *g = glyph;
+ register int t;
+
+ oheight = g->g_height;
+ owidth = g->g_width;
+
+ /*
+ * Offset is (new width) rounded to bytes.
+ */
+ nplus = ROUND2(oheight, 8) >> 3;
+
+ /*
+ * Size of new raster is (new height) * (new rounded width,
+ * in bytes).
+ */
+ size = nplus * owidth;
+ if ((nrast = (char*)malloc(size)) == NULL)
+ error(1, errno, "out of memory");
+ bzero(nrast, size);
+
+ /*
+ * New y origin is old x origin; new x origin is old height
+ * minus old y origin - 1.
+ */
+ t = g->g_yorigin;
+ g->g_yorigin = g->g_xorigin;
+ g->g_xorigin = oheight - t - 1;
+
+ /* While we are at it, exchange height & width... */
+ g->g_height = owidth;
+ g->g_width = oheight;
+
+ /* and grab a pointer to the old raster. */
+ orast = g->g_raster;
+ }
+
+ /*
+ * Now copy bits from the old raster to the new one. The mapping
+ * function is
+ *
+ * for i in [0..height)
+ * for j in [0..width)
+ * new[j, height-i-1] = old[i, j]
+ *
+ * Thus i maps to height-i-1 and (since we have to do our own 2
+ * dimensional array indexing) j to nplus*j. We call the mapped
+ * variables mapi and mapj, and, since we scan sequentially through
+ * the old raster, can discard the original i and j.
+ */
+ {
+ register int mapj, c, k, mapi;
+
+ mapi = oheight;
+ owidth *= nplus;
+ while (--mapi >= 0) {
+ k = 7;
+ for (mapj = 0; mapj < owidth; mapj += nplus) {
+ if (++k == 8) /* get another byte */
+ c = *orast++, k = 0;
+ if (c & 0x80) /* old[i,j] was set */
+ nrast[mapj + (mapi >> 3)] |=
+ 1 << (7 - (mapi & 7));
+ c <<= 1;
+ }
+ }
+ }
+
+ /*
+ * Finally, free the storage associated with the original raster.
+ */
+ free(glyph->g_raster);
+ glyph->g_raster = nrast;
+}
diff --git a/dviware/epson/eps-0.2/lib/rstfont.c b/dviware/epson/eps-0.2/lib/rstfont.c
new file mode 100644
index 0000000000..8eae3e91b3
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/rstfont.c
@@ -0,0 +1,285 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ *
+ * The code in this file was partially derived from another version by
+ * Tim Morgan at UCI.
+ *
+ * TODO:
+ * test
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header$";
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include "types.h"
+#include "error.h"
+#include "font.h"
+#include "fio.h"
+
+/*
+ * RST (Imagen's font format) font operations.
+ */
+
+#ifdef UCI
+#define D 1.0 /* I think */
+#else
+#define D 150.0
+#endif
+
+struct fontops rstops =
+ { "rst", 0, D, rst_read, rst_getgly, rst_rasterise, rst_freefont };
+
+#undef D
+
+/*
+ * Local info.
+ */
+#define FILEMARK_SIZE 8 /* header `file mark' bytes to skip */
+
+/*
+ * rc describes one RST character information block.
+ */
+struct rc {
+ i16 rc_height; /* character height (pixels) */
+ i16 rc_width; /* character width (pixels) */
+ i16 rc_yoffset; /* Y offset of reference point */
+ i16 rc_xoffset; /* X offset of reference point */
+ i32 rc_rastoff; /* raster offset */
+ i32 rc_TFMwidth; /* TFM width */
+};
+
+/*
+ * rst_details are the RST-specific font details.
+ *
+ * We keep track of the number of characters converted to internal
+ * glyph form, and when all have been done, we discard the now-
+ * useless details.
+ */
+struct rst_details {
+ int rd_nconv; /* number of characters unconverted */
+ struct rc *rd_rc; /* `font directory' */
+ char *rd_ras; /* raster space, until converted */
+ long rd_rastbase; /* adjust rc_rastoff by rastbase */
+};
+
+/*
+ * Get the rst_details from font f.
+ */
+#define ftord(f) ((struct rst_details *)(f)->f_details)
+
+extern errno;
+char *malloc();
+long ftell();
+
+/*
+ * Read an RST file.
+ */
+static int rst_read(struct font *f, int fd)
+{
+ register struct rst_details *rd;
+ register FILE *fp;
+ register struct rc *rc;
+ register int i;
+ int saverr;
+ long presize, diroff;
+ i32 firstgly, lastgly;
+
+ fp = NULL;
+ if ((rd = (struct rst_details *)malloc(sizeof *rd)) == 0)
+ goto fail;
+ rd->rd_ras = 0;
+ rd->rd_rc = 0;
+
+ /*
+ * Read the header.
+ */
+ errno = 0; /* try to make errno meaningful */
+ if ((fp = fdopen(fd, "r")) == NULL) {
+ if (errno == 0)
+ errno = EMFILE;
+ goto fail;
+ }
+ (void) fseek(fp, (long)FILEMARK_SIZE, 0);
+ fGetWord(fp, presize); /* bytes in preamble (from FILEMARK_SIZE+2) */
+ presize += 2 + FILEMARK_SIZE;
+ i = getc(fp); /* version */
+ if (i != 0) {
+ error(0, 0, "Warning: strange RST version (%d) in \"%s\"", i,
+ f->f_path);
+ errno = EINVAL;
+ goto fail;
+ }
+ fGet3Byte(fp, diroff); /* offset to glyph directory */
+ fGetWord(fp, firstgly); /* first glyph */
+ fGetWord(fp, lastgly); /* last glyph (inclusive) */
+ lastgly++; /* make it exclusive */
+
+ (void) GetLong(fp); /* mag */
+ fGetLong(fp, f->f_design_size);
+ /* interline, interword, rotation, charadv, lineadv */
+ (void) fseek(fp, (long)(4 + 4 + 2 + 1 + 1), 1);
+ fGetLong(fp, f->f_checksum);
+ f->f_hppp = 0; /* ??? */
+ f->f_vppp = 0;
+
+ /*
+ * Read the glyph directory.
+ */
+ i = lastgly - firstgly;
+ rd->rd_rc = (struct rc *)malloc((unsigned) (i * sizeof(*rc)));
+ if (rd->rd_rc == 0)
+ goto fail;
+ (void) fseek(fp, presize, 0);
+ for (rc = rd->rd_rc; --i >= 0; rc++) {
+ fGetWord(fp, rc->rc_height);
+ fGetWord(fp, rc->rc_width);
+ fGetWord(fp, rc->rc_yoffset);
+ fGetWord(fp, rc->rc_xoffset);
+ fGetLong(fp, rc->rc_TFMwidth);
+ fGet3Byte(fp, rc->rc_rastoff);
+ }
+
+ /*
+ * Set up the raster pointer (if we need rasters).
+ */
+ if (f->f_flags & FF_RASTERS) {
+ struct stat st;
+
+ rd->rd_rastbase = ftell(fp);
+ /* back to unbuffered I/O */
+ (void) fstat(fd, &st);
+ i = st.st_size - presize - 15 * (lastgly - firstgly);
+ if (i < 0)
+ error(1, 0, "calculated raster size < 0 for \"%s\"",
+ f->f_path);
+ if (i != 0) {
+ if ((rd->rd_ras = malloc((unsigned) i)) == 0)
+ goto fail;
+ (void) lseek(fd, rd->rd_rastbase, 0);
+ if (read(fd, rd->rd_ras, i) != i)
+ goto fail;
+ }
+ }
+
+ f->f_details = (char *) rd;
+ if (FontHasGlyphs(f, firstgly, lastgly))
+ goto fail;
+
+ (void) fclose(fp);
+ rd->rd_unconv = lastgly - firstgly;
+ return (0);
+
+fail:
+ saverr = errno;
+ if (rd) {
+ if (rd->rd_rc)
+ free((char *)rd->rd_rc);
+ if (rd->rd_ras)
+ free(rd->rd_ras);
+ free((char *) rd);
+ }
+ if (fp)
+ (void) fclose(fp);
+ else
+ (void) close(fd);
+ errno = saverr;
+ return (-1);
+}
+
+/*
+ * Obtain the specified range of glyphs.
+ */
+static int rst_getgly(register struct font *f, int l, register int h)
+{
+ register struct glyph *g;
+ register struct rc *rc;
+ register int i;
+ struct rst_details *rd;
+
+ if ((rd = ftord(f)) == NULL)
+ panic("rst_getgly");
+
+ /*
+ * By definition, all glyphs are valid. Just copy the
+ * RST information.
+ */
+ for (rc = &rd->rd_rc[(i = l) - f->f_lowch]; i < h; i++, rc++) {
+ g = f->f_gly[i];
+ g->g_flags = GF_VALID;
+ g->g_height = rc->rc_height;
+ g->g_width = rc->rc_width;
+ g->g_yorigin = rc->rc_yoffset;
+ g->g_xorigin = rc->rc_xoffset;
+ g->g_rawtfmwidth = rc->rc_TFMwidth;
+ }
+ return (0);
+}
+
+/*
+ * Obtain rasters for the specified glyphs.
+ */
+static int rst_rasterise(register struct font *f, int l, register int h)
+{
+ register struct glyph *g;
+ register struct rc *rc;
+ register struct rst_details *rd;
+ register int i;
+ unsigned sz;
+
+ if ((rd = ftord(f)) == NULL)
+ panic("rst_rasterise details==0");
+ if (rd->rd_ras == NULL)
+ panic("rst_rasterise rd_ras==NULL");
+ for (rc = &rd->rd_rc[(i = l) - f->f_lowch]; i < h; i++, rc++) {
+ g = f->f_gly[i];
+ if (!HASRASTER(g))
+ continue;
+ if (rc->rc_rastoff == 0) {
+ error(1, 0, "bad RST glyph %d in \"%s\"",
+ g->g_index, f->f_path);
+ } else {
+ sz = ((g->g_width + 7) >> 3) * g->g_height;
+ if ((g->g_raster = malloc(sz)) == NULL)
+ return (-1); /* ??? */
+ g->g_rotation = ROT_NORM;
+ bcopy(rd->rd_ras + rc->rc_rastoff - rd->rd_rastbase,
+ g->g_raster, sz);
+ }
+ }
+
+ /*
+ * If we have converted all the characters, dump the
+ * pre-conversion rasters. In fact, dump everything.
+ */
+ rd->rd_unconv -= h - l;
+ if (rd->rd_unconv == 0) {
+ free((char *)rd->rd_rc);
+ free(rd->rd_ras);
+ free((char *)rd);
+ f->f_details = NULL;
+ }
+ return (0);
+}
+
+/*
+ * Discard the font details.
+ */
+static void rst_freefont(struct font *f)
+{
+ struct rst_details *rd;
+
+ if ((rd = ftord(f)) != NULL) {
+ free((char *)rd->rd_rc);
+ free(rd->rd_ras);
+ free((char *)rd);
+ }
+}
diff --git a/dviware/epson/eps-0.2/lib/scaletfm.c b/dviware/epson/eps-0.2/lib/scaletfm.c
new file mode 100644
index 0000000000..65efd174d9
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/scaletfm.c
@@ -0,0 +1,117 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/scaletfm.c,v 3.2 89/11/23 16:34:43 chris Exp $";
+#endif
+
+#include "types.h"
+#include "error.h"
+#include "font.h"
+
+/*
+ * From DVITYPE.WEB:
+ *
+ * ``The most important part of in_TFM is the width computation, which
+ * involvles multiplying the relative widths in the TFM file by the scaling
+ * factor in the DVI file. This fixed-point multiplication must be done with
+ * precisely the same accuracy by all DVI-reading programs, in order to
+ * validate the assumptions made by DVI-writing programs like \TeX 82.
+ *
+ * Let us therefore summarize what needs to be done. Each width in a TFM
+ * file appears as a four-byte quantity called a fix_word. A fix_word whose
+ * respective bytes are (a,b,c,d) represents the number
+ *
+ * {{ b * 2^{-4} + c * 2^{-12} + d * 2^{-20}, if a = 0;
+ * x = {{
+ * {{ -16 + b * 2^{-4} + c * 2^{-12} + d * 2^{-20}, if a = 255.
+ *
+ * (No other choices of a are allowed, since the magnitude of a TFM dimension
+ * must be less than 16.) We want to multiply this quantity by the integer
+ * z, which is known to be less than 2^{27}. Let \alpha = 16z. If z <
+ * 2^{23}, the individual multiplications b * z, c * z, d * z cannot
+ * overflow; otherwise we will divide z by 2, 4, 8, or 16, to obtain a
+ * multiplier less than 2^{23}, and we can compensate for this later. If z
+ * has thereby been replaced by z' = z/2^e, let \beta = 2^{4-e}; we shall
+ * compute
+ *
+ * \lfloor (b + c * 2^{-8} + d * 2^{-16})z' / \beta \rfloor
+ *
+ * if a = 0, or the same quantity minus \alpha if a = 255. This calculation
+ * must be done exactly, for the reasons stated above; the following program
+ * does the job in a system-independent way, assuming that arithmetic is
+ * exact on numbers less than 2^{31} in magnitude.''
+ */
+#define ZLIM ((i32)1 << 23) /* z must be < zlim */
+
+/*
+ * Scale the single TFM width t by z.
+ */
+extern i32 ScaleOneWidth(register i32 t, register i32 z)
+{
+ register i32 alpha, log2beta;
+ register int a0;
+
+ /* First compute \alpha, \beta, and z': */
+ alpha = 16 * z;
+ log2beta = 4;
+ while (z >= ZLIM) {
+ z >>= 1;
+ log2beta--;
+ }
+
+ /* The four values 'a', 'b', 'c', and 'd' are fields within t: */
+#define a (UnSign8(t >> 24))
+#define b (UnSign8(t >> 16))
+#define c (UnSign8(t >> 8))
+#define d (UnSign8(t))
+ if (t) {
+ a0 = a;
+ t = (((((d * z) >> 8) + c * z) >> 8) + b * z) >> log2beta;
+ if (a0) {
+ if (a0 != 255)
+ error(0, 0, "bad TFM width! [ScaleOneWidth]");
+ t -= alpha;
+ }
+ }
+ return (t);
+}
+
+/*
+ * Scale a set of glyphs [l..h) in font f according to f->f_dvimag
+ * (that is, set g_tfmwidth from g_rawtfmwidth).
+ */
+extern void ScaleGlyphs(register struct font *f, int l, int h)
+{
+ register int i, a0;
+ register i32 t, z, alpha, log2beta;
+
+ z = f->f_dvimag;
+ alpha = 16 * z;
+ log2beta = 4;
+ while (z >= ZLIM) {
+ z >>= 1;
+ log2beta--;
+ }
+
+ for (i = l; i < h; i++) {
+ if ((t = f->f_gly[i]->g_rawtfmwidth) != 0) {
+ a0 = a;
+ t = (((((d * z) >> 8) + c * z) >> 8) + b * z) >>
+ log2beta;
+ if (a0) {
+ if (a0 != 255)
+ error(0, 0,
+ "\"%s\", glyph %d: bad TFM width",
+ f->f_path, i);
+ t -= alpha;
+ }
+ }
+ f->f_gly[i]->g_tfmwidth = t;
+ }
+}
diff --git a/dviware/epson/eps-0.2/lib/scanpost.c b/dviware/epson/eps-0.2/lib/scanpost.c
new file mode 100644
index 0000000000..d50439709f
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/scanpost.c
@@ -0,0 +1,104 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/scanpost.c,v 3.1 89/08/22 21:57:42 chris Exp $";
+#endif
+
+/*
+ * ScanPostAmble - read a DVI postamble.
+ */
+
+#include <stdio.h>
+#include "types.h"
+#include "dvicodes.h"
+#include "fio.h"
+#include "gripes.h"
+#include "postamble.h"
+
+extern void ScanPostAmble(register FILE *f, void (*headerfunc)(struct PostAmbleInfo *p), register void (*fontfunc)(struct PostAmbleFont *p))
+{
+ register int n;
+ register char *s;
+ char name[512];
+
+ if (FindPostAmble(f))
+ GripeCannotFindPostamble();
+ if (GetByte(f) != Sign8(DVI_POST))
+ GripeMissingOp("POST");
+
+ /* Read the postamble info stuff. */
+ {
+ struct PostAmbleInfo pai;
+ register struct PostAmbleInfo *p = &pai;
+
+ p->pai_PrevPagePointer = GetLong(f);
+ p->pai_Numerator = GetLong(f);
+ p->pai_Denominator = GetLong(f);
+ p->pai_DVIMag = GetLong(f);
+ p->pai_TallestPageHeight = GetLong(f);
+ p->pai_WidestPageWidth = GetLong(f);
+ p->pai_DVIStackSize = GetWord(f);
+ p->pai_NumberOfPages = GetWord(f);
+
+ (*headerfunc)(p);
+ }
+
+ /* Now read all the font definitions. */
+ {
+ struct PostAmbleFont paf;
+ register struct PostAmbleFont *p = &paf;
+ int c;
+
+ for (;;) {
+ if ((c = getc(f)) == EOF)
+ GripeUnexpectedDVIEOF();
+ switch (c) {
+
+ case DVI_NOP:
+ break;
+
+ case DVI_FNTDEF1:
+ p->paf_DVIFontIndex = UnSign8(getc(f));
+ break;
+
+ case DVI_FNTDEF2:
+ p->paf_DVIFontIndex = UnSign16(GetWord(f));
+ break;
+
+ case DVI_FNTDEF3:
+ p->paf_DVIFontIndex = UnSign24(Get3Byte(f));
+ break;
+
+ case DVI_FNTDEF4:
+ p->paf_DVIFontIndex = GetLong(f);
+ break;
+
+ case DVI_POSTPOST:
+ return;
+
+ default:
+ GripeMissingOp("POSTPOST");
+ /*NOTREACHED*/
+ }
+ p->paf_DVIChecksum = GetLong(f);
+ p->paf_DVIMag = GetLong(f);
+ p->paf_DVIDesignSize = GetLong(f);
+ p->paf_n1 = UnSign8(getc(f));
+ p->paf_n2 = UnSign8(getc(f));
+ p->paf_name = name; /* never trust people not to
+ clobber it */
+ n = p->paf_n1 + p->paf_n2;
+ s = name;
+ while (--n >= 0)
+ *s++ = GetByte(f);
+ *s = 0;
+ (*fontfunc)(p);
+ }
+ }
+}
diff --git a/dviware/epson/eps-0.2/lib/sdecode.c b/dviware/epson/eps-0.2/lib/sdecode.c
new file mode 100644
index 0000000000..146a5981af
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/sdecode.c
@@ -0,0 +1,588 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/sdecode.c,v 3.4 89/11/06 15:01:07 chris Exp $";
+#endif
+
+#include <stdio.h>
+#include <stdarg.h>
+#include "types.h"
+#include "sdecode.h"
+#include <string.h> /* for strcmp */
+#include <stdlib.h> /* for free */
+
+static char cclass[256]; /* XXX assumes 8-bit char */
+#define CCL_SPACE 0x01 /* white space */
+#define CCL_SEMI 0x02 /* `semicolon' (statement separator) */
+#define isstopc(c) (cclass[c] != 0) /* both space and semi char */
+static int sdset; /* flag says whether cclass[] set up */
+
+extern char *DVIFileName;
+
+#ifndef BLOCK_COPY
+/*
+ * Copy the text at `src' `downward' in memory for `len' bytes.
+ * This is like strcpy or memcpy, but handles one direction of
+ * overlap (when dst < src).
+ */
+static void
+movedown(src, dst, len)
+ register char *src, *dst;
+ register int len;
+{
+
+ while (--len >= 0)
+ *dst++ = *src++;
+}
+#endif
+
+/*
+ * We have a number of states to do word interpretation. Outside words,
+ * we skip blanks and `semicolons'. The first non-blank, non-`semi' enters
+ * WORD state; in WORD state, double quote characters switch to
+ * QUOTE state, after which another double quote switches back to
+ * WORD state, and blanks and `semi' end WORD state, switching to DONE.
+ * While in WORD or QUOTE states, `c produces c for all characters c;
+ * to do this, we use two more states.
+ */
+#define S_DULL 0 /* not in a word */
+#define S_WORD 1 /* in a word */
+#define S_QUOTE 2 /* inside "" in a word */
+#define S_BKQT1 3 /* not in "", but just read one ` */
+#define S_BKQT2 4 /* in "", but just read one ` */
+#define S_DONE 5 /* found end of word */
+
+/*
+ * Structure used to communicate between the various functions.
+ */
+
+/*
+ * `Edit' the text in the buffer in-place.
+ * Return the count of characters resulting from the edit (e.g.,
+ * from `foo`"bar' the count would be 7).
+ * Set di_call if we reach state S_DONE by encountering a `semicolon'.
+ * The edited text begins wherever di_cp points.
+ * We begin the edit in the state given by di_lexstate.
+ */
+static int canon(register struct decode_info *di)
+{
+ register int state, c, n;
+ register char *cp, *outp, *s;
+
+ state = di->di_lexstate;
+ n = di->di_nch;
+ cp = outp = di->di_cp;
+ while (--n >= 0) {
+ c = *cp++;
+ switch (state) {
+
+ case S_DULL:
+ if (isstopc(c))
+ continue;
+ state = S_WORD;
+ /* FALLTHROUGH */
+
+ case S_WORD:
+ if (c == '"') {
+ state = S_QUOTE;
+ continue;
+ }
+ if (c == '`') {
+ state = S_BKQT1;
+ continue;
+ }
+ /* look for `semicolon' (call) characters */
+ if (cclass[c] & CCL_SEMI)
+ di->di_call = 1;
+ if (isstopc(c)) {
+ state = S_DONE;
+ goto done;
+ }
+ break;
+
+ case S_QUOTE:
+ if (c == '`') {
+ state = S_BKQT2;
+ continue;
+ }
+ if (c == '"') {
+ state = S_WORD;
+ continue;
+ }
+ break;
+
+ case S_BKQT1:
+ state = S_WORD;
+ break;
+
+ case S_BKQT2:
+ state = S_QUOTE;
+ break;
+
+ default:
+ panic("sdecode canon");
+ /* NOTREACHED */
+ }
+ *outp++ = c;
+ }
+ n = 0;
+done:
+ c = outp - di->di_cp; /* wrote this many chars */
+ di->di_lexstate = state;/* save new state */
+ di->di_nch = n; /* and new counts and pointers */
+ di->di_cp = cp;
+ return (c);
+}
+
+#define WDMAX BUFSIZ /* when testing, make this small */
+
+/*
+ * Read a word from the input file.
+ * Returns NULL (and sets di_call) at end of \special.
+ *
+ * We gather up to WDMAX + k characters at a time into an input
+ * buffer, and lex them using `canon' above. The result is at most
+ * as long as the original text. Since a single legal word might
+ * be up to WDMAX bytes long, k must be at least 1 (for the trailing
+ * NUL). If the input word is longer, we flush the trailing part,
+ * using the k `extra' bytes (and again k must be at least 1).
+ *
+ * If there is a current keyword and it is in the current buffer
+ * (di_bkw != 0), and we have to move existing buffer text around
+ * or write over it with new file text, we save the keyword and
+ * clear di_bkw.
+ */
+static char *word(register struct decode_info *di, int quietly)
+{
+ register int n;
+ register char *p;
+ register int len, trunc = 0;
+ static char inbuf[WDMAX + 20]; /* k=20 */
+
+ len = 0; /* no word bytes yet */
+ p = di->di_cp; /* where canon() writes (nil if first time) */
+ di->di_lexstate = S_DULL;
+ /*
+ * Loop invariants:
+ * len is in [0..WDMAX)
+ * di_lexstate != S_DONE
+ */
+ do {
+ /* if the buffer is empty, refill it */
+ if (di->di_nch == 0) {
+ /* compute remaining buffer space */
+ n = sizeof inbuf - len;
+ /* read n bytes or rest of string, whichever smaller */
+ if (di->di_nfilech < n && (n = di->di_nfilech) == 0) {
+ /* `eof': fake up a call-terminator */
+ di->di_call = 1;
+ if (di->di_lexstate == S_DULL)
+ return (di->di_word = NULL);
+ break; /* take partial word */
+ }
+ /* save keyword if this will clobber it */
+ if (di->di_bkw) {
+ di->di_kw = strsave(di->di_kw);
+ di->di_bkw = 0;
+ }
+ /* if there is some canon text, move it to front */
+ if (len && p > inbuf) {
+#ifdef BLOCK_COPY
+ bcopy(p, inbuf, len);
+#else
+ movedown(p, inbuf, len);
+#endif
+ }
+ /* canon text is (or will be) at front now */
+ p = inbuf;
+ di->di_cp = p + len;
+ if (fread(di->di_cp, 1, n, di->di_file) != n) {
+ if (ferror(di->di_file))
+ error(1, -1, "error reading %s",
+ DVIFileName);
+ GripeUnexpectedDVIEOF();
+ }
+ di->di_nfilech -= n;
+ di->di_nch = n;
+ }
+ n = canon(di);
+ if ((len += n) > WDMAX) {
+ len = WDMAX;
+ trunc = 1;
+ }
+ } while (di->di_lexstate != S_DONE);
+ p[len] = 0;
+
+ /*
+ * If the word was too long (and hence truncated), complain
+ * (unless we are quietly skipping over the remains of a
+ * broken \special).
+ */
+ if (trunc && !quietly) {
+ /* word was too long; complain */
+ error(0, 0,
+#if WDMAX > 20
+ "over-long word in \\special: `%.20s...'",
+#else
+ "over-long word in \\special: `%s...'",
+#endif
+ p);
+ error(0, 0, "(truncated to %d characters)", WDMAX);
+ }
+ return (di->di_word = p);
+}
+
+/*
+ * Initialise the character class table.
+ */
+extern void SDsetclass(register char *spaces, register char *semis)
+{
+ register int c;
+
+ if (spaces == NULL)
+ spaces = "\b\t\n\f\r ";
+ if (semis == NULL)
+ semis = ";\n";
+
+ for (c = 0; c < sizeof cclass / sizeof *cclass; c++)
+ cclass[c] = 0;
+ while ((c = *spaces++) != 0)
+ cclass[c] |= CCL_SPACE;
+ while ((c = *semis++) != 0)
+ cclass[c] |= CCL_SEMI;
+ sdset = 1;
+}
+
+/*
+ * Perform a binary search for the given string in the given table.
+ */
+static struct sdecode *lookup(register char *str, register struct sdecode *p, register int max)
+{
+ register struct sdecode *m;
+ register int dir;
+
+ while (max > 0) {
+ /*
+ * Look at the median; pick the right hand one if
+ * there are two such entries (when `max' is even).
+ * Set dir positive if str is `greater than' m->sd_name,
+ * negative if it is `less'. If not equal, move
+ * left or right accordingly. When max is even and
+ * we move right, we have to use (max-1)/2 since we
+ * broke the tie towards the right.
+ */
+ m = p + (max >> 1);
+ if ((dir = *str - *m->sd_name) == 0)
+ dir = strcmp(str, m->sd_name);
+ if (dir == 0) /* found */
+ return (m);
+ if (dir > 0) { /* str > mid: move right */
+ p = m + 1;
+ max = (max - 1) >> 1;
+ } else /* str < mid: move left */
+ max >>= 1;
+ }
+ return (NULL);
+}
+
+/*
+ * Decode a series of \special keywords.
+ *
+ * The table points to a sorted list of keywords to match.
+ * On a match, the appropriate function is called with appropriate
+ * arguments.
+ *
+ * Characters in `semi' (if not NULL) act like `statement separators'.
+ * For instance, decoding with semi=>";\n" means that
+ *
+ * \special{foo 1; bar 2 4^^Jbaz 3}
+ *
+ * tries to call foo(1), bar(2,4), and baz(3) (in that order).
+ */
+extern void SDecode(FILE *fp, register i32 len, struct sdecode *table, int tsize)
+{
+ register char *cp;
+ register struct sdecode *tp;
+ register int h;
+ struct decode_info di;
+
+ /* set defaults, if necessary */
+ if (!sdset)
+ SDsetclass((char *)NULL, (char *)NULL);
+
+ di.di_nch = 0;
+ di.di_cp = NULL;
+ di.di_nfilech = len;
+ di.di_file = fp;
+ di.di_bkw = 0;
+ for (;;) {
+ di.di_call = 0;
+ if ((cp = word(&di, 0)) == NULL)
+ return; /* (all done) */
+ tp = lookup(cp, table, tsize);
+ if (tp == NULL) {
+ error(0, 0,
+ "Warning: unrecognised \\special keyword `%s' ignored", cp);
+ /* di_call is not set, so fall through */
+ } else {
+ di.di_kw = cp;
+ di.di_bkw = 1;
+ args(tp, &di);
+ if (!di.di_call)
+ error(0, 0,
+ "Warning: extra arguments to \\special `%s' ignored", di.di_kw);
+ if (!di.di_bkw)
+ free(di.di_kw);
+ di.di_bkw = 0;
+ }
+ /* eat extra arguments, or arguments to an unknown function */
+ while (!di.di_call)
+ (void) word(&di, 1);
+ }
+}
+
+/*
+ * Gather up the arguments to the given function, then (if all goes well)
+ * call that function with those arguments. On return, if di_call is not
+ * set, there were extra arguments left over.
+ */
+static void args(register struct sdecode *tp, register struct decode_info *di)
+{
+ char *fmt;
+ int n, room, f1;
+ i32 *ip, i[4];
+ double d[2];
+
+ switch (tp->sd_args) {
+
+ case sda_none:
+ (*tp->sd_fn)(tp->sd_name);
+ return;
+
+ case sda_s:
+ fmt = "s";
+ if (scan(di, &fmt))
+ break;
+ (*tp->sd_fn)(tp->sd_name, di->di_word);
+ return;
+
+ case sda_d:
+ fmt = "d";
+ if (scan(di, &fmt, &i[0]))
+ break;
+ (*tp->sd_fn)(tp->sd_name, i[0]);
+ return;
+
+ case sda_f:
+ fmt = "f";
+ if (scan(di, &fmt, &d[0]))
+ break;
+ (*tp->sd_fn)(tp->sd_name, d[0]);
+ return;
+
+ case sda_dd:
+ fmt = "dd";
+ if (scan(di, &fmt, &i[0], &i[1]))
+ break;
+ (*tp->sd_fn)(tp->sd_name, i[0], i[1]);
+ return;
+
+ case sda_ff:
+ fmt = "ff";
+ if (scan(di, &fmt, &d[0], &d[1]))
+ break;
+ (*tp->sd_fn)(tp->sd_name, d[0], d[1]);
+ return;
+
+ case sda_ddddff:
+ fmt = "ddddff";
+ if (scan(di, &fmt, &i[0], &i[1], &i[2], &i[3], &d[0], &d[1]))
+ break;
+ (*tp->sd_fn)(tp->sd_name, i[0], i[1], i[2], i[3], d[0], d[1]);
+ return;
+
+ case sda_nd:
+ f1 = 'd';
+ goto array;
+
+ case sda_nx:
+ f1 = 'x';
+ goto array;
+
+ case sda_rest:
+ (*tp->sd_fn)(tp->sd_name,
+ (i32)di->di_nch, di->di_cp, (i32)di->di_nfilech);
+ di->di_call = 1;
+ di->di_nch = 0;
+ di->di_nfilech = 0;
+ return;
+
+ default:
+ panic("sdecode args(): sd_argtype");
+ /* NOTREACHED */
+ }
+
+ /*
+ * If we get here, there is a missing or incorrect argument.
+ */
+ badarg(*fmt, di);
+ return;
+
+array:
+ ip = (i32 *)malloc((unsigned)(room = 10) * sizeof(i32));
+ if (ip == NULL)
+ goto nomem;
+ n = 0;
+ while (!di->di_call && word(di, 0) != NULL) {
+ if (scan_i(di->di_word, f1, &i[0])) {
+ badarg(f1, di);
+ free((char *)ip);
+ return;
+ }
+ if (n == room) {
+ room += 10;
+ ip = (i32 *)realloc((char *)ip,
+ (unsigned)room * sizeof(i32));
+ if (ip == NULL)
+ goto nomem;
+ }
+ ip[n++] = i[0];
+ }
+ (*tp->sd_fn)(tp->sd_name, n, ip);
+ free((char *)ip);
+ return;
+nomem:
+ /*
+ * might as well stop: if malloc() failed, we will probably get
+ * nowhere fast anyway.
+ */
+ error(1, -1,
+ "ran out of memory allocating %d bytes for \\special `%s'",
+ n * sizeof(i32), di->di_kw);
+ /* NOTREACHED */
+
+}
+
+/*
+ * Complain about an argument. Scan() has set di_word to NULL if
+ * it was missing; otherwise it is incorrect.
+ */
+static void badarg(int c, struct decode_info *di)
+{
+ char *s;
+
+ switch (c) {
+
+ case 'd':
+ s = "decimal";
+ break;
+
+ case 'f':
+ s = "floating";
+ break;
+
+ case 's':
+ s = "string"; /* must be `missing', not `bad' */
+ break;
+
+ case 'x':
+ s = "hexadecimal";
+ break;
+
+ default:
+ panic("sdecode badarg(%c)", c);
+ /* NOTREACHED */
+ }
+ if (di->di_word == NULL)
+ error(0, 0, "missing %s argument for \\special `%s'",
+ s, di->di_kw);
+ else {
+ error(0, 0, "bad %s argument to \\special `%s': `%s'",
+ s, di->di_kw, di->di_word);
+ error(0, 0, "(this part of the \\special will be ignored)");
+ while (!di->di_call)
+ (void) word(di, 1);
+ }
+}
+
+static int scan(struct decode_info* di, char** fmtp, ...)
+{
+ register char *fmt;
+ register int c;
+ va_list ap;
+
+ va_start(ap, fmtp);
+ fmt = *fmtp;
+ while ((c = *fmt++) != 0) {
+ if (di->di_call || word(di, 0) == NULL) {
+ di->di_word = NULL;
+ goto out;
+ }
+ switch (c) {
+
+ /* BEWARE, can only handle one string */
+ case 's': /* always accepted */
+ break;
+
+ case 'd':
+ case 'x':
+ if (scan_i(di->di_word, c, va_arg(ap, i32 *)))
+ goto out;
+ break;
+
+ case 'f':
+ if (scan_d(di->di_word, va_arg(ap, double *)))
+ goto out;
+ break;
+
+ default:
+ panic("sdecode scan() *fmt=%c", c);
+ /* NOTREACHED */
+ }
+ }
+ c = 0;
+out:
+ va_end(ap);
+ *fmtp = fmt - 1;
+ return (c);
+}
+
+static int scan_i(char *p, int c, i32 *result)
+{
+#ifdef HAVE_STRTOL
+ char *end;
+ long strtol();
+
+ *result = strtol(p, &end, c == 'x' ? 16 : 10);
+ return (*end);
+#else
+ long l;
+ char junk;
+
+ if (sscanf(p, c == 'x' ? "%lx%c" : "%ld%c", &l, &junk) != 1)
+ return (1);
+ *result = l;
+ return (0);
+#endif
+}
+
+static int scan_d(char *p, double *result)
+{
+#ifdef HAVE_STRTOD
+ char *end;
+ double strtod();
+
+ *result = strtod(p, &end);
+ return (*end);
+#else
+ char junk;
+
+ return (sscanf(p, "%lf%c", result, &junk) != 1);
+#endif
+}
diff --git a/dviware/epson/eps-0.2/lib/search.c b/dviware/epson/eps-0.2/lib/search.c
new file mode 100644
index 0000000000..3484bf5697
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/search.c
@@ -0,0 +1,173 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/search.c,v 3.1 89/08/22 21:58:14 chris Exp $";
+#endif
+
+/*
+ * Key search routines (for a 32 bit key)
+ *
+ * SCreate initializes the search control area.
+ *
+ * SSearch returns the address of the data area (if found or created)
+ * or a null pointer (if not). The last argument controls the disposition
+ * in various cases, and is a ``value-result'' parameter.
+ *
+ * SEnumerate calls the given function on each data object within the
+ * search table. Note that no ordering is specified (though currently
+ * it runs in increasing-key-value sequence).
+ */
+
+#include "types.h"
+#include "search.h"
+
+#if vax || mc68000 || ns32000 || pyr
+#define HARD_ALIGNMENT 4
+#else
+#define HARD_ALIGNMENT 16 /* should suffice for most everyone */
+#endif
+
+static int DOffset; /* part of alignment code */
+
+/* char *malloc(), *realloc(); */
+#include <stdlib.h> /* malloc, realloc */
+
+extern struct search *SCreate(register unsigned int dsize)
+{
+ register struct search *s;
+
+ if ((s = (struct search *) malloc(sizeof *s)) == 0)
+ return (0);
+
+ if (DOffset == 0) {
+#ifndef HARD_ALIGNMENT
+ DOffset = sizeof(i32);
+#else
+ DOffset = (sizeof(i32) + HARD_ALIGNMENT - 1) &
+ ~(HARD_ALIGNMENT - 1);
+#endif
+ }
+ dsize += DOffset; /* tack on space for keys */
+
+#ifdef HARD_ALIGNMENT
+ /*
+ * For machines with strict alignment constraints, it may be
+ * necessary to align the data at a multiple of some positive power
+ * of two. In general, it would suffice to make dsize a power of
+ * two, but this could be very space-wasteful, so instead we align it
+ * to HARD_ALIGNMENT. 64 bit machines might ``#define HARD_ALIGNMENT
+ * 8'', for example. N.B.: we assume that HARD_ALIGNMENT is a power
+ * of two.
+ */
+
+ dsize = (dsize + HARD_ALIGNMENT - 1) & ~(HARD_ALIGNMENT - 1);
+#endif
+
+ s->s_dsize = dsize; /* save data object size */
+ s->s_space = 10; /* initially, room for 10 objects */
+ s->s_n = 0; /* and none in the table */
+ if ((s->s_data = (char*)malloc(s->s_space * dsize)) == 0) {
+ free((char *)s);
+ return (0);
+ }
+ return (s);
+}
+
+/*
+ * We actually use a binary search right now - this may change.
+ */
+extern char *SSearch(register struct search *s, register i32 key, int *disp)
+{
+ register char *keyaddr;
+ int itemstomove;
+
+ *disp &= S_CREATE | S_EXCL; /* clear return codes */
+ if (s->s_n) { /* look for the key */
+ register int h, l, m;
+
+ h = s->s_n - 1;
+ l = 0;
+ while (l <= h) {
+ m = (l + h) >> 1;
+ keyaddr = s->s_data + m * s->s_dsize;
+ if (*(i32 *) keyaddr > key)
+ h = m - 1;
+ else if (*(i32 *) keyaddr < key)
+ l = m + 1;
+ else { /* found it, now what? */
+ if (*disp & S_EXCL) {
+ *disp |= S_COLL;
+ return (0); /* collision */
+ }
+ *disp |= S_FOUND;
+ return (keyaddr + DOffset);
+ }
+ }
+ keyaddr = s->s_data + l * s->s_dsize;
+ } else
+ keyaddr = s->s_data;
+
+ /* keyaddr is now where the key should have been found, if anywhere */
+ if ((*disp & S_CREATE) == 0)
+ return (0); /* not found */
+
+ /* avoid using realloc so as to retain old data if out of memory */
+ if (s->s_space <= 0) { /* must expand; double it */
+ register char *New;
+
+ if ((New = (char*)malloc((s->s_n << 1) * s->s_dsize)) == 0) {
+ *disp |= S_ERROR; /* no space */
+ return (0);
+ }
+ keyaddr = (keyaddr - s->s_data) + New; /* relocate */
+ bcopy(s->s_data, New, s->s_n * s->s_dsize);
+ free(s->s_data);
+ s->s_data = New;
+ s->s_space = s->s_n;
+ }
+ /* now move any keyed data that is beyond keyaddr down */
+ itemstomove = s->s_n - (keyaddr - s->s_data) / s->s_dsize;
+ if (itemstomove) {
+#ifndef BLOCK_COPY
+ register char *from, *to;
+
+ from = s->s_data + s->s_n * s->s_dsize;
+ to = from + s->s_dsize;
+ while (from > keyaddr)
+ *--to = *--from;
+#else
+ BLOCK_COPY(keyaddr, keyaddr + s->s_dsize,
+ itemstomove * s->s_dsize);
+#endif
+ }
+ *disp |= S_NEW;
+ s->s_n++;
+ s->s_space--;
+ *(i32 *) keyaddr = key;
+ keyaddr += DOffset; /* now actually dataaddr */
+ /* the bzero is just a frill... */
+ bzero(keyaddr, s->s_dsize - DOffset);
+ return (keyaddr);
+}
+
+/*
+ * Call function `f' for each element in the search table `s'.
+ */
+extern void SEnumerate(register struct search *s, register void (*f)(char*, i32))
+{
+ register int n;
+ register char *p;
+
+ n = s->s_n;
+ p = s->s_data;
+ while (--n >= 0) {
+ (*f)(p + DOffset, *(i32 *)p);
+ p += s->s_dsize;
+ }
+}
diff --git a/dviware/epson/eps-0.2/lib/seek.c b/dviware/epson/eps-0.2/lib/seek.c
new file mode 100644
index 0000000000..51cfa878a6
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/seek.c
@@ -0,0 +1,159 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/seek.c,v 3.1 89/08/22 21:59:04 chris Exp $";
+#endif
+
+/*
+ * SeekFile copies an input stdio file, if necessary, so that
+ * it produces a stdio file on which fseek() works properly.
+ * It returns NULL if this cannot be done; in that case, the
+ * input file is closed (or otherwise rendered worthless).
+ *
+ * CopyFile copies an input file unconditionally. (On non-Unix
+ * machines, it might `accidentally' not copy it.)
+ *
+ * On Unix machines, this means `if the input is a pipe or tty,
+ * copy it to a temporary file'. On other systems, all stdio files
+ * might happen to be seekable.
+ */
+
+#include <stdio.h>
+#include "types.h" /* for BSD_FILE_SYSTEM */
+#include "seek.h"
+
+#ifdef EASY_BUT_NOT_GOOD
+
+FILE *CopyFile(FILE* f){ return (f); }
+FILE *SeekFile(FILE* f){ return (f); }
+
+#else
+
+#include <errno.h>
+#ifdef BSD_FILE_SYSTEM
+#include <sys/param.h> /* want MAXBSIZE */
+#else
+#include <sys/types.h>
+#endif
+#include <sys/stat.h>
+
+/* long lseek();
+char *malloc(); */
+#include <stdlib.h> /* for malloc */
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+# include <io.h>
+#else
+# include <osfcn.h> /* for lseek */
+#endif
+
+extern int errno;
+
+/*
+ * Make and return a version of `f' on which fseek works (unconditionally).
+ * This code is somewhat Unix-specific.
+ */
+extern FILE *CopyFile(FILE *f)
+{
+ register int tf, n, ifd, w;
+ register char *p, *buf;
+ register int blksize;
+ struct stat st;
+ int e;
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+#define BSIZE L_tmpnam
+#else
+#ifdef MAXBSIZE
+#define BSIZE MAXBSIZE
+#else
+#define BSIZE BUFSIZ
+#endif
+#endif
+ char stackbuf[BSIZE];
+
+ /* get a read/write temp file which will vanish when closed */
+ if ((tf = MakeRWTempFile(stackbuf)) < 0) {
+ e = errno;
+ (void) fclose(f);
+ errno = e;
+ return (NULL);
+ }
+
+ /* compute buffer size and choose buffer */
+ ifd = fileno(f);
+ buf = stackbuf;
+ blksize = sizeof stackbuf;
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+ blksize = 1024;
+ buf = (char*)malloc( blksize );
+#endif
+#ifdef BSD_FILE_SYSTEM
+ if (fstat(tf, &st) == 0 && st.st_blksize > blksize) {
+ /*
+ * The output block size is the important one,
+ * but the input block size is not irrelevant.
+ *
+ * This should actually compute the lcm, but we
+ * will rely on block sizes being powers of two
+ * (so that the larger is the lcm).
+ */
+ blksize = st.st_blksize;
+ if (fstat(ifd, &st) == 0 && st.st_blksize > blksize)
+ blksize = st.st_blksize;
+ if ((buf = (char*)malloc((unsigned)blksize)) == NULL) {
+ buf = stackbuf;
+ blksize = sizeof stackbuf;
+ }
+ }
+#endif
+ /* copy from input file to temp file */
+ (void) lseek(ifd, 0L, 0); /* paranoia */
+ while ((n = read(ifd, p = buf, blksize)) > 0) {
+ do {
+ if ((w = write(tf, buf, n)) < 0) {
+ (void) close(tf);
+ (void) fclose(f);
+ return (NULL);
+ }
+ p += w;
+ } while ((n -= w) > 0);
+ }
+ e = errno; /* in case n < 0 */
+ if (buf != stackbuf)
+ free(buf);
+ if (n < 0) {
+ (void) close(tf);
+ (void) fclose(f);
+ errno = e;
+ return (NULL);
+ }
+
+ /* discard the input file, and rewind and open the temporary */
+ (void) fclose(f);
+ (void) lseek(tf, 0L, 0);
+ errno = 0;
+ if ((f = fdopen(tf, "r")) == NULL) {
+ if (errno == 0)
+ e = EMFILE;
+ (void) close(tf);
+ errno = e;
+ }
+ return (f);
+}
+
+/*
+ * Copy an input file, but only if necessary.
+ */
+extern FILE *SeekFile(FILE *f)
+{
+ int fd = fileno(f);
+
+ return (lseek(fd, 0L, 1) >= 0 && !isatty(fd) ? f : CopyFile(f));
+}
+
+#endif /* EASY_BUT_NOT_GOOD */
diff --git a/dviware/epson/eps-0.2/lib/skip.c b/dviware/epson/eps-0.2/lib/skip.c
new file mode 100644
index 0000000000..3e62a263b3
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/skip.c
@@ -0,0 +1,30 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/skip.c,v 3.1 89/08/22 21:45:13 chris Exp $";
+#endif
+
+#include <stdio.h>
+#include "types.h"
+#include "fio.h"
+
+/*
+ * Skip a font definition. The font number has already been consumed.
+ */
+extern void SkipFontDef(register FILE *fp)
+{
+ register int i;
+
+ (void) GetLong(fp); /* checksum */
+ (void) GetLong(fp); /* mag */
+ (void) GetLong(fp); /* designsize */
+ i = UnSign8(GetByte(fp)) + UnSign8(GetByte(fp));
+ while (--i >= 0)
+ (void) GetByte(fp);
+}
diff --git a/dviware/epson/eps-0.2/lib/split.c b/dviware/epson/eps-0.2/lib/split.c
new file mode 100644
index 0000000000..766b8ba824
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/split.c
@@ -0,0 +1,224 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/split.c,v 3.1 89/08/22 21:59:36 chris Exp $";
+#endif
+
+#include <ctype.h>
+
+/*
+ * Split a line into an array of words. This is destructive of
+ * the original line; the word pointers point to places within
+ * that line.
+ *
+ * The pound-sign character `#', at the beginning of the line or
+ * after white space, marks the end of the line.
+ *
+ * Return the number of words made, or -1 for overflow.
+ */
+
+/*
+ * The lexical states are much like `sh's, except that we also do
+ * C-style backslash-escapes.
+ */
+enum lexstate {
+ S_BLANK, /* outside a word */
+ S_WORD, /* inside a word, no quoting */
+ S_SQUOTE, /* inside a single quote */
+ S_DQUOTE, /* inside a double quote */
+ S_BKSL0, /* last char was \ */
+ S_BKSL1, /* last chars were \, [0-7] */
+ S_BKSL2 /* last chars were \, [0-7][0-7] */
+};
+
+extern int split(register char *s, register char **w, int nw)
+{
+ register int c;
+ register char *canon = s;
+ register int wleft = nw;
+ enum lexstate state, prebkstate;
+
+ /*
+ * Start out in the `blank' state (outside a word). Handle
+ * quotes and things. Backslashes are handled by saving the
+ * `pre-backslash' state, doing the backslash, and restoring
+ * that state at the end of the backslash sequence.
+ */
+ state = S_BLANK;
+ while ((c = *s++) != 0) {
+reswitch:
+ switch (state) {
+
+ /*
+ * Blanks: spaces stay in blank state; '#' ends the line;
+ * anything else starts a word. However, quotes may put
+ * us into quote states, rather than word states.
+ */
+ case S_BLANK:
+ if (isspace(c))
+ continue;
+ if (c == '#')
+ goto stopped_by_comment;
+ if (--wleft < 0)
+ return (-1);
+ *w++ = canon;
+ state = S_WORD;
+ /* FALLTHROUGH */
+
+ /*
+ * In a word. Spaces take us out (and end the
+ * current word). Quotes, however, put us into
+ * quote states.
+ */
+ case S_WORD:
+ if (isspace(c)) {
+ *canon++ = 0;
+ state = S_BLANK;
+ break;
+ }
+ if (c == '\'') {
+ state = S_SQUOTE;
+ break;
+ }
+ if (c == '"') {
+ state = S_DQUOTE;
+ break;
+ }
+ if (c == '\\') {
+ prebkstate = S_WORD;
+ state = S_BKSL0;
+ break;
+ }
+ *canon++ = c;
+ break;
+
+ /*
+ * Inside a single quote, the only special character
+ * is another single quote. This matches the Bourne
+ * shell quoting convention exactly.
+ */
+ case S_SQUOTE:
+ if (c == '\'')
+ state = S_WORD;
+ else
+ *canon++ = c;
+ break;
+
+ /*
+ * Inside a double quote, double quotes get us out,
+ * but backslashes must be interpreted.
+ */
+ case S_DQUOTE:
+ if (c == '\\') {
+ prebkstate = S_DQUOTE;
+ state = S_BKSL0;
+ } else if (c == '"')
+ state = S_WORD;
+ else
+ *canon++ = c;
+ break;
+
+ /*
+ * If we are handling a backslash, we will either
+ * restore the state, or go to BKSL1 state. In
+ * the latter case, do not advance the canonicalisation
+ * pointer, since we might have more octal digits
+ * to insert.
+ */
+ case S_BKSL0:
+ state = prebkstate; /* probably */
+ switch (c) {
+
+ case 'b':
+ *canon++ = '\b';
+ break;
+
+ case 'f':
+ *canon++ = '\f';
+ break;
+
+ case 'n':
+ *canon++ = '\n';
+ break;
+
+ case 'r':
+ *canon++ = '\r';
+ break;
+
+ case 't':
+ *canon++ = '\t';
+ break;
+
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ *canon = c - '0';
+ state = S_BKSL1;
+ break;
+
+ default:
+ *canon++ = c;
+ break;
+ }
+ break;
+
+
+ /*
+ * In BKSL1, we have seen backslash and one octal
+ * digit. There may be more (in which case just
+ * count them on in), or there might be something
+ * that requires we restore the state and try again.
+ */
+ case S_BKSL1:
+ switch (c) {
+
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ *canon <<= 3;
+ *canon |= c - '0';
+ state = S_BKSL2;
+ break;
+
+ default:
+ canon++;
+ state = prebkstate;
+ goto reswitch;
+ }
+ break;
+
+ /*
+ * BKSL2 is like BKSL1, except that it cannot
+ * help but restore the original state, since
+ * there are no four-character octal sequences.
+ */
+ case S_BKSL2:
+ state = prebkstate; /* assuredly */
+ switch (c) {
+
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ *canon <<= 3;
+ *canon++ |= c - '0';
+ break;
+
+ default:
+ canon++;
+ goto reswitch;
+ }
+ break;
+ }
+ }
+stopped_by_comment:
+#ifdef notdef
+ if (state != S_WORD && state != S_BLANK)
+ error(0, 0, "warning: unclosed quote");
+#endif
+ if (state != S_BLANK)
+ *canon = 0;
+ return (nw - wleft);
+}
diff --git a/dviware/epson/eps-0.2/lib/strsave.c b/dviware/epson/eps-0.2/lib/strsave.c
new file mode 100644
index 0000000000..97f8cc96cb
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/strsave.c
@@ -0,0 +1,31 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+/*
+ * Save a string in managed memory.
+ */
+
+/* char *malloc(), *realloc(); */
+#include <stdlib.h> /* for malloc, realloc */
+#include <string.h> /* for strlen */
+
+extern int errno;
+
+#include "types.h" /* for bcopy */
+#include "error.h"
+
+extern char *strsave(register char *s)
+{
+ register int l = strlen(s) + 1;
+ register char *p = (char*)malloc((unsigned) l);
+
+ if (p == 0)
+ error(1, errno, "no room for %d bytes of string", l);
+ bcopy(s, p, l);
+ return (p);
+}
diff --git a/dviware/epson/eps-0.2/lib/tempfile.c b/dviware/epson/eps-0.2/lib/tempfile.c
new file mode 100644
index 0000000000..cbf54100e1
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/tempfile.c
@@ -0,0 +1,97 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/tempfile.c,v 3.1 89/08/22 21:45:20 chris Exp $";
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#if !defined( __MSDOS__ ) || defined( __GNUC__ )
+# include <sys/file.h>
+#else
+# include <fcntl.h>
+#endif
+
+/* char *getenv(); */
+#include <stdlib.h> /* for getenv */
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+# include <io.h>
+#else
+# include <osfcn.h> /* for getpid, unlink, open */
+#endif
+
+/*
+ * Create an open but unlinked (i.e., remove-on-exit-or-file-close)
+ * file. Return the file descriptor, or -1 if unable to create such
+ * a file. The buffer `name' is used to hold the file name (so that
+ * if this returns -1, it is useful for error messages).
+ *
+ * We use the despicable trick of unlinking an open temporary file.
+ * The alternatives are too painful. If it becomes necessary to
+ * do this another way, however, here is a method suggested by Fred
+ * Blonder: fork, and have the parent wait for the child to exit.
+ * (The parent must avoid being killed during this phase.) When
+ * the child exits, the parent should then remove the temporary file,
+ * then exit with the same status, or send itself the same signal.
+ */
+#ifdef __MSDOS__
+extern int MakeRWTempFile(register char *name)
+{
+ FILE* td = tmpfile();
+ if( td == NULL )
+ return -1;
+ else
+ return fileno( td );
+}
+#else /* MSDOS */
+extern int MakeRWTempFile(register char *name)
+{
+ register int tf, n;
+ int mypid, tries;
+ char *tmpdir;
+
+ if ((tmpdir = getenv("TMPDIR")) == NULL)
+ tmpdir = "/tmp";
+
+ /* compose a suitable temporary file name, and get an r/w descriptor */
+ mypid = getpid();
+ n = 0;
+ tries = 0;
+ do {
+ (void) sprintf(name, "%s/#%d.%d", tmpdir, mypid, n++);
+ (void) unlink(name);
+#ifdef O_CREAT /* have three-argument open syscall */
+ tries++;
+ tf = open(name, O_RDWR | O_CREAT | O_EXCL, 0666);
+#else
+ if (access(name, 0) == 0) {
+ /*
+ * Skip existing files. Note that tf might
+ * not be set yet.
+ */
+ tf = -1;
+ continue;
+ }
+ tries++;
+ tf = creat(name, 0666);
+ if (tf >= 0) {
+ (void) close(tf);
+ tf = open(name, 2);
+ if (tf < 0)
+ (void) unlink(name);
+ }
+#endif
+ } while (tf < 0 && tries < 20);
+ if (tf < 0) /* probably unrecoverable user error */
+ return (-1);
+
+ (void) unlink(name);
+ return (tf);
+}
+#endif /* MSDOS */
diff --git a/dviware/epson/eps-0.2/lib/tfm.c b/dviware/epson/eps-0.2/lib/tfm.c
new file mode 100644
index 0000000000..89cf1eadb2
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/tfm.c
@@ -0,0 +1,109 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/tfm.c,v 3.1 89/08/22 22:00:12 chris Exp $";
+#endif
+
+/*
+ * TFM file reading routines.
+ *
+ * TODO:
+ * finish
+ */
+
+#include <stdio.h>
+#include "types.h"
+#include "fio.h"
+#include "tfm.h"
+
+static int trd_header(), trd_ci(), trd_fix();
+
+/* char *malloc(); */
+#include <stdlib.h> /* for malloc */
+
+#define ALLOC(n, type) ((type *)malloc((unsigned)((n) * sizeof(type))))
+
+extern int readtfmfile(register FILE *f, register struct tfmdata *t, int stopafterwidth)
+{
+ i32 nc;
+
+ if (trd_header(f, &t->t_hdr))
+ return (-1);
+ nc = t->t_hdr.th_ec - t->t_hdr.th_bc + 1;
+
+ t->t_ci = NULL;
+ t->t_width = NULL;
+ t->t_height = NULL;
+ t->t_depth = NULL;
+
+ (void) fseek(f, t->t_hdr.th_lh * 4L, 1); /* XXX */
+
+ if ((t->t_ci = ALLOC(nc, struct char_info_word)) == NULL ||
+ trd_ci(f, nc, t->t_ci) ||
+ (t->t_width = ALLOC(t->t_hdr.th_nw, i32)) == NULL ||
+ trd_fix(f, t->t_hdr.th_nw, t->t_width))
+ goto bad;
+ if (stopafterwidth)
+ return (0);
+ if ((t->t_height = ALLOC(t->t_hdr.th_nh, i32)) == NULL ||
+ trd_fix(f, t->t_hdr.th_nh, t->t_height) ||
+ (t->t_depth = ALLOC(t->t_hdr.th_nd, i32)) == NULL ||
+ trd_fix(f, t->t_hdr.th_nd, t->t_depth))
+ goto bad;
+ return (0);
+
+bad:
+ if (t->t_ci != NULL)
+ free((char *) t->t_ci);
+ if (t->t_width != NULL)
+ free((char *) t->t_width);
+ if (t->t_height != NULL)
+ free((char *) t->t_height);
+ if (t->t_depth != NULL)
+ free((char *) t->t_depth);
+ return (-1);
+}
+
+static int trd_header(register FILE *f, register struct tfmheader *th)
+{
+ register i32 *p;
+
+ for (p = &th->th_lf; p <= &th->th_np; p++)
+ fGetWord(f, *p);
+ if (feof(f))
+ return (-1);
+ return (0);
+}
+
+static int trd_ci(register FILE *f, register int nc, register struct char_info_word *ci)
+{
+
+ while (--nc >= 0) {
+ ci->ci_width = fgetbyte(f);
+ ci->ci_h_d = fgetbyte(f);
+ ci->ci_i_t = fgetbyte(f);
+ ci->ci_remainder = fgetbyte(f);
+ ci++;
+ }
+ if (feof(f))
+ return (-1);
+ return (0);
+}
+
+static int trd_fix(register FILE *f, register int nf, register i32 *p)
+{
+
+ while (--nf >= 0) {
+ fGetLong(f, *p);
+ p++;
+ }
+ if (feof(f))
+ return (-1);
+ return (0);
+}
diff --git a/dviware/epson/eps-0.2/lib/tfmfont.c b/dviware/epson/eps-0.2/lib/tfmfont.c
new file mode 100644
index 0000000000..ca3f5e4bc5
--- /dev/null
+++ b/dviware/epson/eps-0.2/lib/tfmfont.c
@@ -0,0 +1,243 @@
+#include "PROTO.h"
+/*
+ * Copyright (c) 1987, 1989 University of Maryland
+ * Department of Computer Science. All rights reserved.
+ * Permission to copy for any purpose is hereby granted
+ * so long as this copyright notice remains intact.
+ */
+
+#ifndef lint
+static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/tfmfont.c,v 3.4 89/11/29 02:29:58 chris Exp $";
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "types.h"
+#include "conv.h"
+#include "font.h"
+#include "tfm.h"
+#include <stdlib.h> /* for malloc */
+#if defined( __MSDOS__ ) && !defined( __GNUC__ )
+# include <io.h >
+#else
+# include <osfcn.h> /* for close */
+#endif
+
+/*
+ * TFM font operations. This defines three fonts:
+ *
+ * box - prints as little square boxes, outlining what TeX
+ * thinks is the character; carries a warning.
+ * blank - prints as entirely blank; carries a warning.
+ * tfm - prints as entirely blank; can be used for built-in fonts.
+ * invis - an alias for tfm.
+ *
+ * The first two also complain that no font is available in the
+ * requested size; these are intended to be used as a last resort
+ * so that users can always print DVI files. You should configure
+ * in exactly one of box or blank.
+ *
+ * TODO:
+ * base box edge widths on Conversion.c_dpi
+ */
+
+ /* magnifications are unused in tfm fonts */
+struct fontops boxops = /* `boxtops'? Is this a cereal driver? */
+ { "box", 1, 0.0, box_read, tfm_getgly, tfm_rasterise, tfm_freefont };
+struct fontops blankops =
+ { "blank", 2, 0.0, blank_read, tfm_getgly, tfm_rasterise, tfm_freefont };
+struct fontops tfmops =
+ { "tfm", 0, 0.0, tfm_read, tfm_getgly, tfm_rasterise, tfm_freefont };
+struct fontops invisops =
+ { "invis", 0, 0.0, tfm_read, tfm_getgly, tfm_rasterise, tfm_freefont };
+
+/*
+ * Local info.
+ */
+struct tfm_details {
+ int tfm_edge; /* box edge widths, in pixels */
+ struct tfmdata tfm_data; /* the TFM file data */
+};
+
+/*
+ * Get the tfm_details from font f.
+ */
+#define ftotfm(f) ((struct tfm_details *)(f)->f_details)
+
+static int do_read();
+
+extern int errno;
+/* char *malloc(); */
+
+/*
+ * Read a Box font.
+ */
+static int box_read(struct font *f, int fd)
+{
+
+ return (do_read(f, fd, 0));
+}
+
+/*
+ * Read a Blank font.
+ */
+static int blank_read(struct font *f, int fd)
+{
+
+ return (do_read(f, fd, 1));
+}
+
+/*
+ * Read a TFM font.
+ */
+static int tfm_read(struct font *f, int fd)
+{
+
+ return (do_read(f, fd, 1));
+}
+
+/*
+ * Read a TFM font. It is blank if `blank'.
+ */
+static int do_read(register struct font *f, int fd, int blank)
+{
+ register struct tfm_details *tfm;
+ FILE *fp;
+
+ if ((fp = fdopen(fd, "r")) == NULL) {
+ (void) close(fd);
+ return (-1);
+ }
+ if ((tfm = (struct tfm_details *)malloc(sizeof *tfm)) == NULL)
+ goto fail;
+ if (readtfmfile(fp, &tfm->tfm_data, blank))
+ goto fail;
+ if (blank)
+ tfm->tfm_edge = 0;
+ else
+ tfm->tfm_edge = 2; /* XXX should be based on dpi */
+ if (FontHasGlyphs(f, tfm->tfm_data.t_hdr.th_bc,
+ tfm->tfm_data.t_hdr.th_ec + 1))
+ goto fail;
+ f->f_checksum = 0; /* ??? */
+ f->f_design_size = 0; /* ??? */
+ f->f_hppp = 0;
+ f->f_vppp = 0;
+ f->f_details = (char *)tfm;
+ (void) fclose(fp);
+ return (0);
+
+fail:
+ (void) fclose(fp);
+ if (tfm != NULL)
+ free((char *)tfm);
+ return (-1);
+}
+
+/*
+ * Obtain the specified range of glyphs.
+ */
+static int tfm_getgly(register struct font *f, int l, register int h)
+{
+ register struct tfm_details *tfm = ftotfm(f);
+ register struct glyph *g;
+ register int i;
+ register struct char_info_word *ci;
+#define t (&tfm->tfm_data)
+#define ftoph(fix) fromSPh(ScaleOneWidth(fix, f->f_dvimag))
+#define ftopv(fix) fromSPv(ScaleOneWidth(fix, f->f_dvimag))
+
+ for (i = l; i < h; i++) {
+ ci = &t->t_ci[i - t->t_hdr.th_bc];
+ /* zero widths mark invalid characters */
+ if (ci->ci_width == 0)
+ continue;
+ g = f->f_gly[i];
+ g->g_flags = GF_VALID;
+ g->g_rawtfmwidth = t->t_width[UnSign8(ci->ci_width)];
+ g->g_xorigin = 0;
+ if (tfm->tfm_edge != 0) {
+ g->g_yorigin = ftopv(t->t_height[T_CI_H(ci)]);
+ g->g_width = ftoph(g->g_rawtfmwidth);
+ g->g_height = g->g_yorigin +
+ ftopv(t->t_depth[T_CI_D(ci)]);
+ } else {
+ g->g_yorigin = 0;
+ g->g_width = 0;
+ g->g_height = 0;
+ }
+ }
+ return (0);
+#undef t
+}
+
+/*
+ * Obtain rasters for the specified glyphs.
+ *
+ * IGNORES tfm->tfm_edge: 2 HARDCODED FOR NOW
+ */
+static int tfm_rasterise(struct font *f, int l, int h)
+{
+ register struct glyph *g;
+ register char *p;
+ register int w, j, i;
+ struct tfm_details *tfm = ftotfm(f);
+#define EDGE 2
+
+ if (tfm->tfm_edge == 0)
+ return (0);
+if (tfm->tfm_edge != 2) panic("tfm_rasterise");
+ for (i = l; i < h; i++) {
+ g = f->f_gly[i];
+ if ((g->g_flags & GF_VALID) == 0 || !HASRASTER(g))
+ continue;
+ w = (g->g_width + 7) >> 3;
+ p = (char*)malloc((unsigned) (g->g_height * w));
+ if (p == NULL)
+ return (-1);
+ g->g_raster = p;
+ g->g_rotation = ROT_NORM;
+ if (g->g_width < 2 * EDGE) {
+ w = 2 * EDGE - g->g_width;
+ for (j = g->g_height; --j >= 0;)
+ *p++ = 0xf0 << w;
+ } else {
+ bzero(p, g->g_height * w);
+ for (j = 0; j < g->g_height;) {
+ if (j < EDGE || j >= g->g_height - EDGE) {
+ register int k = w;
+
+ while (--k > 0)
+ *p++ = 0xff;
+ *p++ = 0xff << ((8 - g->g_width) & 7);
+ j++;
+ continue;
+ }
+ /* the following depends on EDGE==2 */
+ *p = 0xc0;
+ p += w - ((g->g_width & 7) == 1 ? 2 : 1);
+ *p++ |= 0xc0 >> ((g->g_width - EDGE) & 7);
+ if ((g->g_width & 7) == 1)
+ *p++ = 0x80;
+ /* end dependencies */
+ if (++j == EDGE && g->g_height >= 2 * EDGE) {
+ register int n = g->g_height - EDGE;
+
+ p += (n - j) * w;
+ j = n;
+ }
+ }
+ }
+ }
+ return (0);
+}
+
+/*
+ * Discard the font details.
+ */
+static void tfm_freefont(struct font *f)
+{
+
+ free(f->f_details);
+}
diff --git a/dviware/epson/epson/240/cmcsc10.pk b/dviware/epson/epson/240/cmcsc10.pk
new file mode 100644
index 0000000000..05a0e03d16
--- /dev/null
+++ b/dviware/epson/epson/240/cmcsc10.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmmi10.pk b/dviware/epson/epson/240/cmmi10.pk
new file mode 100644
index 0000000000..b5e289e87c
--- /dev/null
+++ b/dviware/epson/epson/240/cmmi10.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmmi7.pk b/dviware/epson/epson/240/cmmi7.pk
new file mode 100644
index 0000000000..0463e82c6f
--- /dev/null
+++ b/dviware/epson/epson/240/cmmi7.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmr10.pk b/dviware/epson/epson/240/cmr10.pk
new file mode 100644
index 0000000000..d37e02ab65
--- /dev/null
+++ b/dviware/epson/epson/240/cmr10.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmr12.pk b/dviware/epson/epson/240/cmr12.pk
new file mode 100644
index 0000000000..ddee17d4ad
--- /dev/null
+++ b/dviware/epson/epson/240/cmr12.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmr17.pk b/dviware/epson/epson/240/cmr17.pk
new file mode 100644
index 0000000000..c507b2960a
--- /dev/null
+++ b/dviware/epson/epson/240/cmr17.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmr6.pk b/dviware/epson/epson/240/cmr6.pk
new file mode 100644
index 0000000000..72a577823e
--- /dev/null
+++ b/dviware/epson/epson/240/cmr6.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmr7.pk b/dviware/epson/epson/240/cmr7.pk
new file mode 100644
index 0000000000..c5a9784d6d
--- /dev/null
+++ b/dviware/epson/epson/240/cmr7.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmr8.pk b/dviware/epson/epson/240/cmr8.pk
new file mode 100644
index 0000000000..1ad72c6149
--- /dev/null
+++ b/dviware/epson/epson/240/cmr8.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmsy10.pk b/dviware/epson/epson/240/cmsy10.pk
new file mode 100644
index 0000000000..49bd808288
--- /dev/null
+++ b/dviware/epson/epson/240/cmsy10.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmsy7.pk b/dviware/epson/epson/240/cmsy7.pk
new file mode 100644
index 0000000000..5d2a6af75a
--- /dev/null
+++ b/dviware/epson/epson/240/cmsy7.pk
Binary files differ
diff --git a/dviware/epson/epson/240/cmti10.pk b/dviware/epson/epson/240/cmti10.pk
new file mode 100644
index 0000000000..50d5e95c4f
--- /dev/null
+++ b/dviware/epson/epson/240/cmti10.pk
Binary files differ
diff --git a/dviware/epson/epson/346/cmbx10.pk b/dviware/epson/epson/346/cmbx10.pk
new file mode 100644
index 0000000000..1f5eb3687d
--- /dev/null
+++ b/dviware/epson/epson/346/cmbx10.pk
Binary files differ