[alt.sources] DVI2TTY: Part 1 of 2; supports VMS and symbol fonts

marcel@duteca (Marcel Mol) (04/11/90)

This is a new verion of dvi2tty. It includes a port to support VMS. I cannot
test it on VMS so I hope it still works. Furthermore this version supports
symbol fonts to a certain extend. Output of itemized lists and math (although
not right yet) are much more readable now.

-Marcel

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 2)."
# Contents:  README README.ORG DVI.format MANIFEST Makefile disdvi.c
#   dvi2tty.c commands.h
# Wrapped by marcel@duteca on Thu Mar  1 23:08:07 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1999 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X                DVI2TTY
X
X
Xdvi2tty is intended for previewing dvi-files on text-only
Xdevices (terminals and lineprinters).
XThe program is basicly an improved C version of the pascal
Xprogram written by Svante Lindahl (see README.ORG).
XI translated it because I could not find a pascal compiler 
Xon our machine that could compile it.
XThe program runs under UNIX and MSDOS without problems
XIt should also run under VMS. 
X(you may need some site dependend redefinitions, see below).
XUndocumented option: the -e option can be used to influence
Xthe width of spaces. With a negative value the number of spaces 
Xbetween words becomes less, with a positive value it becomes more.
XJust play around if you like, -e-11 worked nice with me.
X
X
X                DISDVI
X
XDisdvi is a simple hack that dumps a dvi file in a more readable form.
XIt is not a spectacular program but use it and improve as you wish.
XI'd appreciate any enhancements made, bug reports etc. mailed to me.
X  
X
X    COMPILING THE PROGRAMS
X
XDisdvi is rather simple and does not need any modifications.
XTo compile under VMS, you might need to define an extra macro:
XAdd a -DVMS on the command line, or add a line
X#define VMS
Xin the dvi2tty.h file.
XFor dvi2tty you may find the following problems:
X
X function strchr() can not be found:
X      Your are probably a BSD UNIX or alike.
X      Solution: #define strchr index
X '/usr/bin/pg' program not found.
X      Solution: change the DEFPAGER macro in dvi2tty.c
X To compile under VMS, you might need to define an extra macro:
X  Add a -DVMS on the command line, or add a line
X  #define VMS
X
XThats all, good luck.
X
X
X- Marcel 
X-----------------------------------------
X| Marcel J.E. Mol                       | They hate you if your're clever
X| Delft University of Technology        | And they despise the fool
X| The Netherlands                       | Till you're so fucking crazy
X| UUCP: marcel@duteca.tudelft.nl        | You can't follow the rules.
X-----------------------------------------			 - Lennon
END_OF_FILE
echo shar: 1 control character may be missing from \"'README'\"
if test 1999 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'README.ORG' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README.ORG'\"
else
echo shar: Extracting \"'README.ORG'\" \(1051 characters\)
sed "s/^X//" >'README.ORG' <<'END_OF_FILE'
X
Xdvitty is intended for previewing dvi-files on text-only devices
X(terminals and lineprinters). The output is not very pretty many
Xtimes, but it still saves quite a lot of work, especially if you
Xhave a little ways to walk to a laserprinter, for example.
X
XThe program was originally written in Hedrick-Pascal, running on
XTOPS-20, and was later ported to UNIX (BSD, Berkeley-pascal).
X
XIt is not very smart in all situations, but still serves it pur-
Xpose fairly well.
X
XFor information on how to use see the man-page.
X
XBefore compiling and installing inspect the  "compile-time cust-
Xomization constants" and change them to suit your site.
XThese constants configure default pager and a little more.
X
XPlease report complaints, suggestions, bugs and/or fixes to:
X
XSvante Lindahl, NADA, KTH            Numerical Analysis & Computer Science 
XUUCP: {seismo,mcvax}!enea!ttds!zap   Royal Institute of Technology, Sweden
XARPA: enea!ttds!zap@seismo.CSS.GOV   EAN: zap@cs.kth.sunet
X
XThe TOPS-20 version of the program can also be obtained from the above
Xaddress.
END_OF_FILE
if test 1051 -ne `wc -c <'README.ORG'`; then
    echo shar: \"'README.ORG'\" unpacked with wrong size!
fi
# end of 'README.ORG'
fi
if test -f 'DVI.format' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'DVI.format'\"
else
echo shar: Extracting \"'DVI.format'\" \(2573 characters\)
sed "s/^X//" >'DVI.format' <<'END_OF_FILE'
X/*
X
X
X================================================================================
X==                          DVI file format                                   ==
X================================================================================
Xno_ops          >= 0 bytes     (NOP, nops before the preamble)
Xpreamble_marker    1 ubyte     (PRE)
Xversion_id         1 ubyte     (should be version 2)
Xnumerator          4 ubytes    (numerater must equal the one in postamble)
Xdenominator        4 ubytes    (denominator must equal the one in postamble)
Xmagnification      4 ubytes    (magnification must equal the one in postamble)
Xid_len             1 ubyte     (lenght of identification string)
Xid_string     id_len ubytes    (identification string)
X
Xno_ops          >= 0 bytes     (NOP, nops before a page)
Xbegin_of_page      1 ubyte     (BOP)
Xpage_nr            4 sbytes    (page number)
Xdo_be_do          36 bytes     (filler ????)
Xprev_page_offset   4 sbytes    (offset in file where previous page starts, -1 for none)
X... PAGE DATA ...
Xend_of_page        1 ubyte     (EOP)
X
Xno_ops ???      >= 0 bytes     (NOPS, I think they are allowed here...)
Xpostamble_marker   1 ubyte     (POST)
Xlast_page_offset   4 sbytes    (offset in file where last page starts)
Xnumerator          4 ubytes    (numerater must equal the one in preamble)
Xdenominator        4 ubytes    (denominator must equal the one in preamble)
Xmagnification      4 ubytes    (magnification must equal the one in preamble)
Xmax_page_height    4 ubytes    (maximum page height)
Xmax_page_width     4 ubytes    (maximum page width)
Xmax_stack          2 ubytes    (maximum stack depth needed)
Xtotal_pages        2 ubytes    (number of pages in file)
X... FONT DEFINITIONS ...
X
Xpostamble_offset   4 sbytes    (offset in file where postamble starts)
Xversion_id         1 ubyte     (should be version 2)
Xtrailer         >= 4 ubytes    (TRAILER)
X<EOF>
X
X
XFONT DEFINITIONS:
X   do {
X      switch (c = getc(dvi_fp) {
X          case FNTDEF1  :
X          case FNTDEF2  :
X          case FNTDEF3  :
X          case FNTDEF4  :  define_font(c);
X          case POSTPOST : break;
X          default       : error;
X      }
X   } while (c != POSTPOST);
X
X===== A font def looks like:
X
X1,2,3 or 4 ubytes TeXfontnumber for FNTDEF1 .. FNTDEF4
X4 ubytes checksum
X4 ubytes scale
X4 ubytes design size
X1 byte deflen1
X1 byte deflen2
Xdeflen1 + deflen2 bytes fontname.
X
X===== A special looks like:
X
X1,2,3 or 4 ubytes telling length of special command for XXX1 .. XXX4
Xall bytes in the special command are used as defined in the dvi driver.
X
X
X*/
END_OF_FILE
if test 2573 -ne `wc -c <'DVI.format'`; then
    echo shar: \"'DVI.format'\" unpacked with wrong size!
fi
# end of 'DVI.format'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(437 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X README                     1	
X README.ORG                 1	
X DVI.format                 1	
X MANIFEST                   1	
X Makefile                   1	
X disdvi.c                   1	
X dvi2tty.c                  1	
X dvistuff.c                 2	
X commands.h                 1	
X dvi2tty.h                  2	
X dvi2tty.1                  2	
END_OF_FILE
if test 437 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(454 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Makefile for dvi2tty and disdvi       23/01/89   M.J.E. Mol
X#
X# For BSD Unix use the following CFLAGS definition
X# CFLAGS = -Dstrchr=index
X#
X# This Makefile does not work for MSDOS. Make your 
X# own one, or compile by hand.
X#
XCFLAGS = 
X
Xall:	dvi2tty disdvi
X
Xdvi2tty:dvi2tty.o dvistuff.o
X	cc -o dvi2tty dvi2tty.o dvistuff.o
X
Xdisdvi:disdvi.c commands.h
X	cc -o disdvi disdvi.o
X
Xdvi2tty.o: dvi2tty.c dvi2tty.h
X
Xdvistuff.o: dvistuff.c dvi2tty.h commands.h
X
END_OF_FILE
if test 454 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'disdvi.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'disdvi.c'\"
else
echo shar: Extracting \"'disdvi.c'\" \(14923 characters\)
sed "s/^X//" >'disdvi.c' <<'END_OF_FILE'
X/*****************************************************************************/
X/*                                                                           */
X/*   disdvi  ---  disassembles TeX dvi files.                                */
X/*                                                                           */
X/*                                                                           */
X/*    2.0 23/01/89 M.J.E. Mol (c) 1989              marcel@duteca.tudelft.nl */
X/*    2.1 19/01/90 M.J.E. Mol    Maintain a list of fonts and                */
X/*                               show fontnames in font changes.             */
X/*                               Show character code when printing ligatures */
X/*                                                                           */
X/*                                                                           */
X/*****************************************************************************/
X
X
Xchar *disdvi = "@(#) disdvi.c  2.1 19/01/90 M.J.E. Mol (c) 1989, 1990";
X
X#include <stdio.h>
X#include <ctype.h>
X#include "commands.h"
X#if defined(MSDOS)
X#include <stdlib.h>
X#include <string.h>
X#include <fcntl.h>
X#endif
X
X#define LASTCHAR        127    /* max dvi character, above are commands    */
X
X#define get1()           num(1)
X#define get2()           num(2)
X#define get3()           num(3)
X#define get4()           num(4)
X#define sget1()         snum(1)
X#define sget2()         snum(2)
X#define sget3()         snum(3)
X#define sget4()         snum(4)
X
Xtypedef struct _font {
X    long    num;
X    struct _font * next;
X    char  * name;
X} font;
X
Xfont * fonts = NULL;
XFILE * dvifp;
Xchar * dvi_name;
Xlong   pc = 0;
X
Xchar *          malloc          ();
X
Xvoid            main            ();
Xvoid            bop             ();
Xvoid            preamble        ();
Xvoid            postamble       ();
Xvoid            postpostamble   ();
Xvoid            fontdef         ();
Xchar *          fontname        ();
Xvoid            special         ();
Xvoid            printnonprint   ();
Xunsigned long   num             ();
Xlong            snum            ();
X
X
X
X
X/*---------------------------------------------------------------------------*/
X
Xvoid main(argc, argv)
Xint argc;
Xchar **argv;
X{
X    register int opcode;                /* dvi opcode                        */
X    register int i;
X    int fontnum;
X
X    if (argc > 2) {
X        fprintf(stderr, "To many arguments\n");
X        fprintf(stderr, "Usage: %s [dvi-file]\n", *argv);
X        exit(1);
X    }
X
X    if (argc == 2) {
X        if ((i = strlen(argv[1])) == 0) {
X            fprintf(stderr, "Illegal empty filename\n");
X            fprintf(stderr, "Usage: %s [dvi-file]\n", *argv);
X            exit(2);
X        }
X        if ((i >= 5) && (argv[1][i-4] == '.') && (argv[1][i-3] == 'd') &&
X              (argv[1][i-2] == 'v') && (argv[1][i-1] == 'i'))
X            dvi_name = argv[1];
X        else {
X            dvi_name = malloc((i+5) * sizeof(char));
X            strcpy(dvi_name, argv[1]);
X            strcat(dvi_name, ".dvi");
X        }
X        if ((dvifp = fopen(dvi_name, "r")) == NULL) {
X            perror(dvi_name);
X            exit(3);
X        }
X    }
X    else
X        dvifp = stdin;
X
X#if defined(MSDOS)
X    setmode(fileno(dvifp), O_BINARY);
X#endif
X
X    while ((opcode = (int) get1()) != EOF) {    /* process until end of file */
X        printf("%06ld: ", pc - 1);
X        if ((opcode <= LASTCHAR) && isprint(opcode)) {
X            printf("Char:     ");
X            while ((opcode <= LASTCHAR) && isprint(opcode)) {
X                putchar(opcode);
X                opcode = (int) get1();
X            }
X            putchar('\n');
X            printf("%06ld: ", pc - 1);
X        }
X
X        if (opcode <= LASTCHAR) 
X            printnonprint(opcode);              /* it must be a non-printable */
X        else if ((opcode >= FONT_00) && (opcode <= FONT_63)) 
X            printf("FONT_%02d              /* %s */\n", opcode - FONT_00,
X                                    fontname(opcode - FONT_00));
X        else
X            switch (opcode) {
X                case SET1     :
X                case SET2     : 
X                case SET3     :
X                case SET4     : printf("SET%d:    %ld\n", opcode - SET1 + 1,
X                                                       num(opcode - SET1 + 1));
X                                break;
X                case SET_RULE : printf("SET_RULE: height: %ld\n", sget4());
X                                printf("%06ld: ", pc);
X                                printf("          length: %ld\n", sget4());
X                                break;
X                case PUT1     :
X                case PUT2     :
X                case PUT3     :
X                case PUT4     : printf("PUT%d:     %ld\n", opcode - PUT1 + 1,
X                                                       num(opcode - PUT1 + 1));
X                                break;
X                case PUT_RULE : printf("PUT_RULE: height: %ld\n", sget4());
X                                printf("%06ld: ", pc);
X                                printf("          length: %ld\n", sget4());
X                                break;
X                case NOP      : printf("NOP\n");  break;
X                case BOP      : bop();            break;
X                case EOP      : printf("EOP\n");  break;
X                case PUSH     : printf("PUSH\n"); break;
X                case POP      : printf("POP\n");  break;
X                case RIGHT1   :
X                case RIGHT2   : 
X                case RIGHT3   : 
X                case RIGHT4   : printf("RIGHT%d:   %ld\n", opcode - RIGHT1 + 1,
X                                                     snum(opcode - RIGHT1 + 1));
X                                break;
X                case W0       : printf("W0\n");   break;
X                case W1       : 
X                case W2       :
X                case W3       :
X                case W4       : printf("W%d:       %ld\n", opcode - W0,
X                                                      snum(opcode - W0));
X                                break;
X                case X0       : printf("X0\n");   break;
X                case X1       :
X                case X2       :
X                case X3       :
X                case X4       : printf("X%d:       %ld\n", opcode - X0,
X                                                      snum(opcode - X0));
X                                break;
X                case DOWN1    : 
X                case DOWN2    : 
X                case DOWN3    :
X                case DOWN4    : printf("DOWN%d:    %ld\n", opcode - DOWN1 + 1,
X                                                      snum(opcode - DOWN1 + 1));
X                                break;
X                case Y0       : printf("Y0\n");   break;
X                case Y1       :
X                case Y2       :
X                case Y3       :
X                case Y4       : printf("Y%d:       %ld\n", opcode - Y0,
X                                                      snum(opcode - Y0));
X                                break;
X                case Z0       : printf("Z0\n");   break;
X                case Z1       :
X                case Z2       :
X                case Z3       : 
X                case Z4       : printf("Z%d:       %ld\n", opcode - Z0,
X                                                      snum(opcode - Z0));
X                                break;
X                case FNT1     :
X                case FNT2     :
X                case FNT3     :
X                case FNT4     : fontnum = num(opcode -FNT1 + 1);
X                                printf("FNT%d:     %ld    /* %s */\n",
X                                       opcode - FNT1 + 1, fontnum,
X                                       fontname(fontnum));
X                                break;
X                case XXX1     : 
X                case XXX2     : 
X                case XXX3     :
X                case XXX4     : special(opcode - XXX1 + 1);     break;
X                case FNT_DEF1 :
X                case FNT_DEF2 :
X                case FNT_DEF3 :
X                case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1); break;
X                case PRE      : preamble();                     break;
X                case POST     : postamble();                    break;
X                case POST_POST: postpostamble();                break;
X            }
X    }
X
X} /* main */
X
X
X/*----------------------------------------------------------------------------*/
X
X
Xvoid bop()
X{
X    int i;
X
X    printf("BOP       page number      : %ld", sget4());
X    for (i=0; i < 9; i++) {
X        if (i % 3 == 0)
X            printf("\n%06ld:         ", pc);
X        printf("  %6ld", sget4()); 
X    }
X    printf("\n%06ld: ", pc);
X    printf("          prev page offset : %06ld\n", sget4()); 
X
X} /* bop */
X
X
X/*---------------------------------------------------------------------------*/
X
Xvoid postamble() 
X{
X
X    printf("POST      last page offset : %06ld\n", sget4());
X    printf("%06ld: ", pc);
X    printf("          numerator        : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          denominator      : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          magnification    : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          max page height  : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          max page width   : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          stack size needed: %d\n", (int) get2());
X    printf("%06ld: ", pc);
X    printf("          number of pages  : %d\n", (int) get2());
X
X} /* postamble */
X
Xvoid preamble()
X{
X    register int i;
X
X    printf("PRE       version          : %d\n", (int) get1());
X    printf("%06ld: ", pc);
X    printf("          numerator        : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          denominator      : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          magnification    : %ld\n", get4());
X    printf("%06ld: ", pc);
X    i = (int) get1();
X    printf("          job name (%3d)   :", i);
X    while (i-- > 0)
X        putchar((int) get1());
X    putchar('\n');
X
X} /* preamble */
X
X
Xvoid postpostamble()
X{
X    register int i;
X 
X    printf("POSTPOST  postamble offset : %06ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          version          : %d\n", (int) get1());
X    while ((i = (int) get1()) == TRAILER) {
X        printf("%06d: ", pc - 1);
X        printf("TRAILER\n");
X    }
X    while (i != EOF) {
X        printf("%06ld: ", pc - 1);
X        printf("BAD DVI FILE END: 0x%02X\n", i);
X        i = (int) get1();
X    }
X
X} /* postpostamble */
X
X
X
Xvoid special(x)
Xregister int x;
X{
X    register long len;
X    register long i;
X
X    len = num(x);
X    printf("XXX%d:     %ld bytes\n", x, len);
X    printf("%06ld: ", pc);
X    for (i = 0; i < len; i++)      /* a bit dangerous ... */
X        putchar((int) get1());     /*   can be non-printables */
X    putchar('\n');
X
X} /* special */
X
X
X
Xvoid fontdef(x)
Xregister int x;
X{
X    register int i;
X    char * name;
X    font * fnt;
X    int namelen;
X    long fntnum;
X    int new = 0;
X
X    fntnum = num(x);
X    printf("FNT_DEF%d: %ld\n", x, fntnum);
X    printf("%06ld: ", pc);           /* avoid side-effect on pc in get4() */
X    printf("          checksum         : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          scale            : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          design           : %ld\n", get4());
X    printf("%06ld: ", pc);
X    printf("          name             : ");
X    namelen = (int) get1() + (int) get1();
X    fnt = fonts;
X    while (fnt != NULL && fnt->num != fntnum)
X        fnt = fnt->next;
X    if (fnt == NULL) {
X        if ((fnt = (font *) malloc(sizeof(font))) == NULL) {
X            perror("fontdef");
X            exit(1);
X        }
X        fnt->num = fntnum;
X        new = 1;
X    }
X    else
X        free(fnt->name);    /* free old name */
X    if ((name = (char *) malloc(namelen * sizeof(char))) == NULL) {
X        perror("fontdef");
X        exit(1);
X    }
X    
X    for (i = 0; i < namelen; i++)
X        name[i] = get1();
X    fnt->name = name;
X    if (new) {
X        fnt->next = fonts;
X        fonts = fnt;
X    }
X
X    printf("%s\n", name);
X
X} /* fontdef */
X
X
X
Xchar * fontname(fntnum)
Xlong fntnum;
X{
X    font * fnt;
X
X    fnt = fonts;
X    while (fnt != NULL && fnt->num != fntnum)
X        fnt = fnt->next;
X    if (fnt != NULL)
X        return fnt->name;
X    else
X        return "unknown fontname";
X   
X} /* fontname */
X
X
X
Xvoid printnonprint(ch)
Xregister int ch;
X{
X
X    printf("Char:     ");
X    switch (ch) {
X        case 11  :  printf("ff         /* ligature (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 12  :  printf("fi         /* ligature (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 13  :  printf("fl         /* ligature (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 14  :  printf("ffi        /* ligature (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 15  :  printf("ffl        /* ligature (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 16  :  printf("i          /* (non-printing) 0x%02X */", ch);
X                    break;
X        case 17  :  printf("j          /* (non-printing) 0x%02X */", ch);
X                    break;
X        case 25  :  printf("ss         /* german (non-printing) 0x%02X */", ch);
X                    break;
X        case 26  :  printf("ae         /* scadinavian (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 27  :  printf("oe         /* scadinavian (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 28  :  printf("o          /* scadinavian (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 29  :  printf("AE         /* scadinavian (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 30  :  printf("OE         /* scadinavian (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        case 31  :  printf("O          /* scadinavian (non-printing) 0x%02X */",
X                           ch);
X                    break;
X        default  :  printf("0x%02X", ch); break;
X    }
X    putchar('\n');
X
X}
X
X
X
Xunsigned long num(size)
Xregister int size;
X{
X    register int i;
X    register long x = 0;
X
X    pc += size;
X    for (i = 0; i < size; i++)
X        x = (x << 8) + (unsigned) getc(dvifp);
X    return x;
X
X} /* num */
X
X
X
Xlong snum(size)
Xregister int size;
X{
X    register int i;
X    register long x = 0;
X
X    pc += size;
X    x = getc(dvifp);
X    if (x & 0x80)
X        x -= 0x100;
X    for (i = 1; i < size; i++)
X        x = (x << 8) + (unsigned) getc(dvifp);
X    return x;
X
X} /* snum */
X
X
X
END_OF_FILE
if test 14923 -ne `wc -c <'disdvi.c'`; then
    echo shar: \"'disdvi.c'\" unpacked with wrong size!
fi
# end of 'disdvi.c'
fi
if test -f 'dvi2tty.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dvi2tty.c'\"
else
echo shar: Extracting \"'dvi2tty.c'\" \(24434 characters\)
sed "s/^X//" >'dvi2tty.c' <<'END_OF_FILE'
X/******************************************************************************
X * Marcel Mol: 1990-02-04  (UUCP: marcel@duteca.tudelft.nl)
X *               First attempt to recognize symbol fonts, so bullets (in
X *               itemized lists) are translated to a proper character instead
X *               an awfull ligature.
X *               Version 4.0.
X * Marcel Mol: 1990-02-01  (UUCP: marcel@duteca.tudelft.nl)
X *               Included port to VMS (off Joseph Vasallo and Seppo Rantala)
X *               into latest version. Hope things still work, cannot test it ...
X * Joseph Vasallo & Seppo Rantala: 1989-09-05 (Internet: rantala@tut.FI)
X *		 Ported to work under VAX/VMS V4.4 & VAXC V2.4 or higher.
X *		 Fixed bugs in using Swedish/Finnish characters.
X * Marcel Mol: 1989-02-14  (UUCP: duteca!marcel)
X *               Fixed check for .dvi extension.
X *               Allowed more ligatures.
X *               Fixed side effect bugs (2 gets as function arguments).
X *               Version 3.2.
X * Marcel Mol: 1989-01-19  (UUCP: duteca!marcel)
X *               Changed in option handling, no change
X *               in user interface (only the undocumented 
X *               feature -e).
X *               Version 3.1.
X * Marcel Mol: 1989-01-11  (UUCP: duteca!marcel)
X *               Changed some longs to ints.
X *               It now also runs on MSDOS Microsoft C 5.1
X *               New version: 3.0
X * Marcel Mol: 1989-01-03  (UUCP: duteca!marcel)
X *               Fixed a bugs concerning pager programs
X *               and scanning environment variable DVI2TTY.
X * Marcel Mol: 1988-10-25  (UUCP: duteca!marcel)
X *        dvi2tty.c dvi2tty.h dvistuff.c commands.h
X *               Converted program to C.
X *               improved spacing between words/characters.
X * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-08-15 20:24:31,
X *               Version to be sent to mod.sources ready.
X * New option since last version:
X *   -Fprog      Pipe output to prog. Can be used to get a different
X *               pager than the default.
X * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-01-13 21:49:31,
X *   Environment variable DVITTY is read and options can be set from it.
X *   These are the currently implemented options:
X *      -ofile   Write output to file, else write to stdout,
X *               possibly piped through a pager if stdout is a tty.
X *      -plist   Print pages whos TeX-page-number are in list.
X *               List is on the form  1,3:6,8  to choose pages
X *               1,3-6 and 8. TeX-nrs can be negative: -p-1:-4,4
X *      -Plist   Print pages whos sequential number are in list.
X *      -wn      Print the lines with width n characters, default is
X *               80. Wider lines gives better results.
X *      -q       Don't try to pipe to a pager.
X *      -f       Try to pipe to a pager if output is a tty.
X *      -Fname   Specify a pager program.                  
X *               Default of -q and -f is a compile time option, a constant.
X *      -l       Write '^L' instead of formfeed between pages.
X *      -u       Don't try to find Scandinavian characters (they will
X *               print as a:s and o:s if this option is choosen).
X *      -s       Scandinavian characters printed as }{|][\.
X *               Default of -s and -u is a compile time option, a constant.
X * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-01-10 18:51:03,
X *   Argument parsing, and random access functions (external, in C)
X *   and other OS-dependent stuff (in C). Removed private 'pager' &
X *   tries to pipe through PAGER (environment var) or, if PAGER not
X *   defined, /usr/ucb/more. Some changes for efficency.
X * bogart:/usr/alla/svante/dvitty/dvitty.p  1985-07-15 20:51:00,
X *   The code for processing dvi-files running on UNIX (UCB-Pascal)
X *   but no argument parsing.
X * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.140, 30-Mar-85 05:43:56,
X *   Edit: Svante Lindahl
X * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.136, 15-Jan-85 13:52:59,
X *   Edit: Svante Lindahl, final Twenex version !!!??
X * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.121, 14-Jan-85 03:10:22,
X *   Edit: Svante Lindahl, cleaned up and fixed a lot of little things
X * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.25, 15-Dec-84 05:29:56,
X *   Edit: Svante Lindahl, COMND-interface, including command line scanning
X * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.23, 10-Dec-84 21:24:41,
X *   Edit: Svante Lindahl, added command line scanning with Rscan-JSYS
X * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.48,  8-Oct-84 13:26:30,
X *  Edit: Svante Lindahl, fixed switch-parsing, destroyed by earlier patches
X * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.45, 29-Sep-84 18:29:53,
X *  Edit: Svante Lindahl
X *
X * dvitty - get an ascii representation of a dvi-file, suitable for ttys
X *
X * This program, and any documentation for it, is copyrighted by Svante
X * Lindahl. It may be copied for non-commercial use only, provided that
X * any and all copyright notices are preserved.
X *
X * Please report any bugs and/or fixes to:
X *
X * UUCP: {seismo,mcvax,cernvax,diku,ukc,unido}!enea!ttds!zap
X * ARPA: enea!ttds!zap@seismo.CSS.GOV
X *  or   Svante_Lindahl_NADA%QZCOM.MAILNET@MIT-MULTICS.ARPA
X * EAN:  zap@cs.kth.sunet
X */
X
X
X#include "dvi2tty.h"
X#if defined(VMS)
X#include unixio
X#endif
X
X    /*-----------------------------------------------------------------------*/
X    /* The following constants may be toggled before compilation to          */
X    /* customize the default behaviour of the program for your site.         */
X    /* Whichever their settings are, the defaults can be overridden at       */
X    /* runtime.                                                              */
X    /*-----------------------------------------------------------------------*/
X
X#define DEFSCAND    FALSE     /* default is Scandinavian, toggle this if you */
X                              /* don't have terminals with Scand. nat. chars */
X#define WANTPAGER   TRUE      /* default: try to pipe through a pager (like  */
X                              /* more) if stdout is tty and no -o switch     */
X#define DEFPAGER    "/usr/bin/pg"   /* CHANGE TO YOUR LOCAL PAGER            */
X
X    /*------------------ end of customization constants ---------------------*/
X
X#define MAXLEN          100    /* size of char-arrays for strings            */
X#if defined(MSDOS) || defined(VMS)
X#define OPTSET      "wepPousl"   /* legal options                            */
X#define OPTWARG     "wepPo"      /* options with argument                    */
X#else
X#define OPTSET      "wepPousqlfF"/* legal options                            */
X#define OPTWARG     "wepPoF"     /* options with argument                    */
X#endif
X
X/*
X * USAGE CODES
X */
X
X#define wrnge  1                /* width switch arg out of range     */
X#define ign    2                /* ignore cause, print 'Usage:..'    */
X#define nan    3                /* not a number where one expected   */
X#define gae    4                /* garbage at end                    */
X#define bdlst  5                /* bad page-numberlist               */
X#define onef   6                /* only one dvifile allowed          */
X#define bdopt  7                /* bad option                        */
X#define onepp  8                /* only one page list allowed        */
X#define noarg  9                /* argument expected                 */
X
Xchar *dvi2tty = "@(#) dvi2tty.c  4.0 04/02/90 M.J.E. Mol (c) 1989, 1990";
X
X/*---------------------------------------------------------------------------*/
X
Xprintlisttype * currentpage;    /* current page to print                     */
Xprintlisttype * firstpage;      /* first page selected                       */
Xprintlisttype * lastpage;       /* last page selected                        */
X
XFILE *          DVIfile;
XFILE *          output;
Xbool            outputtofile;   /* tells if output goes to file or stdout    */
Xint             ttywidth;       /* max nr of chars per printed line          */
Xint             espace;         /* to fake calcs with ttywidth               */
X
Xlong            foo;            /* utility variable, "register"              */
X#if !defined(MSDOS) && !defined(VMS)
Xbool            pager;          /* tells if output is piped to a pager       */
Xchar  *         path;           /* name of the pager to run                  */
X#endif
Xchar  *         progname;       /* our name                                  */
Xint             Argc;
Xchar **         Argv;
Xchar            DVIfilename[MAXLEN];
Xchar *          OUTfilename;
Xchar            optch;          /* for option handling                       */
X
X/*---------------------------------------------------------------------------*/
X
X#if defined(MSDOS)
Xvoid    main      (int, char **); 
Xvoid    setoption (char *);
Xvoid    getargs   (void);
Xvoid    getpages  (int, char *);
Xvoid    plcnxt    (int);
Xvoid    getfname   (char *);
Xint     getinteger(int *, int *, char *);
Xvoid    usage     (int);
X#else
Xchar *  getenv    ();
XFILE *  popen     ();
X
Xvoid    main      (); 
Xvoid    setoption ();
Xvoid    getargs   ();
Xvoid    getpages  ();
Xvoid    plcnxt    ();
Xvoid    getfname   ();
Xint     getinteger();
Xvoid    usage     ();
X#endif
X
X
X/****************************************************************************/
X/*                                                                          */
X/*                                 M A I N                                  */
X/*                                                                          */
X/****************************************************************************/
X
Xvoid main(argc, argv)
Xint argc;
Xchar ** argv;
X{
X
X    progname = *argv;
X    Argc = argc;
X    Argv = argv;
X
X    getargs();                              /* read command line arguments   */
X#if defined(MSDOS)
X    if ((DVIfile = fopen(DVIfilename, "rb")) == NULL)
X#else
X#if defined(VMS)
X    if ((DVIfile = fopen(DVIfilename, "r","ctx=rec")) == NULL)
X#else
X    if ((DVIfile = fopen(DVIfilename, "r")) == NULL)
X#endif
X#endif
X        errorexit(filop);                   /* can't open dvifile            */
X
X    if (outputtofile) {                     /* open the outfile, if needed   */
X        if ((output = fopen(OUTfilename, "w")) == NULL)
X            errorexit(filcr);
X#if !defined(MSDOS) && !defined(VMS)
X        pager = FALSE;
X#endif
X    }
X    else {
X        output = stdout;
X#if !defined(MSDOS) && !defined(VMS)
X        if (isatty(fileno(output)) && pager) {   /* try to pipe to a pager   */
X            if ((output = popen(path, "w")) == NULL) /* get pipe to pager    */
X                errorexit(pipcr);                /* make output to output    */
X        }
X        else
X            pager = FALSE;
X#endif
X    }
X
X    dvimain();
X
X#if !defined(MSDOS) && !defined(VMS)
X    if (pager)
X        pclose(output);                     /* close pipe to pager            */
X#endif
X
X    exit(0);
X
X} /* main */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid setoption(optarg)
Xchar *optarg;
X{
X    int j = 0;
X    int ret;
X   
X    while (strchr(OPTSET, optch) != NULL) {
X        switch (optch) {
X#if !defined(MSDOS) && !defined(VMS)
X	    case 'q' : pager = FALSE; break;
X	    case 'f' : pager = TRUE; break;
X#endif
X	    case 'l' : noffd = TRUE; break;
X	    case 's' : scascii = TRUE; break;
X	    case 'u' : scascii = FALSE; break;
X            case 'P' :
X		       sequenceon = TRUE;     /* fall through */
X            case 'p' :
X                       if (pageswitchon)
X                           usage(onepp);
X                       getpages(j, optarg);
X                       break;
X            case 'w' :
X		       if (getinteger(&ttywidth, &j, optarg))
X                           usage(nan);
X                       if (optarg[j] != '\0') 
X                           usage(gae);
X                       if ((ttywidth < 16) || (ttywidth > 132))
X                           usage(wrnge);
X                       break;
X            case 'e' :
X		       if (getinteger(&espace, &j, optarg))
X                           usage(nan);
X                       if (optarg[j] != '\0') 
X                           usage(gae);
X                       break;
X            case 'o' :
X                       OUTfilename = optarg;
X		       outputtofile = TRUE;
X                       j = strlen(optarg);
X                       break;
X#if !defined(MSDOS) && !defined(VMS)
X            case 'F' :
X                       pager = TRUE;
X                       path = optarg;
X                       j = strlen(optarg);
X                       break;
X#endif
X            default  : 
X                       usage(bdopt);
X        }
X        if ((optch = optarg[j]) == '\0')
X            break;
X        j++;
X        if ((strchr(OPTWARG, optch) != NULL) && (optarg[j]='\0')) {
X                if (--Argc <= 0)
X                    usage(noarg);
X                optarg = *++Argv;
X                j = 0;
X            }
X    }
X} /* setoption */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid getargs()
X{
X    char *str, *envp;
X    bool DVIfound;                      /* if a dvi filename found           */
X
X    if (Argc <= 1)
X        usage(ign);
X
X    pageswitchon = FALSE;       /* show all pages                            */
X    sequenceon   = FALSE;       /* selected pages are TeX-numbered           */
X    outputtofile = FALSE;       /* write to stdout                           */
X#if !defined(MSDOS) && !defined(VMS)
X    pager        = WANTPAGER;   /* want paging, compile time option          */
X#endif
X    noffd        = FALSE;       /* print formfeed between pages              */
X    scascii      = DEFSCAND;    /* scandinavian, compile time option         */
X    ttywidth     = 80;          /* default terminal width                    */
X    espace       = 0;           /* to fake ttywith calcs                     */
X    DVIfound     = FALSE;
X
X#if !defined(MSDOS) && !defined(VMS)
X    if ((path = getenv("PAGER")) == NULL)   /* find default pathname of page */
X            path = DEFPAGER;             /* program in case paging is wanted */
X#endif
X
X    if ((envp = getenv("DVI2TTY")) != NULL) {
X        while (*envp == ' ')
X             envp++;
X        while (*envp) {                     /* environment var args          */
X            if (strchr(OPTSET, optch = *envp++) != NULL) {
X                /*
X                 * we always pass one option, and arrange for optarg ourselfves,
X                 * so setoption does not mesh up Argv
X                 */
X                if (strchr(OPTWARG, optch) != NULL) {
X                    while (*envp == ' ') 
X                        envp++;
X                    if (*envp == '\0')
X                        usage(noarg);
X                    str = envp;             /* str points to optarg          */
X                    while ((*envp != ' ') && (*envp != '\0'))
X                        *envp++;            /* set envp just after optarg    */
X                    if (*envp != '\0')
X                        *envp++ = '\0';     /* end optarg string             */
X                }
X                else
X                    str = "";
X                setoption(str);
X            }
X            else
X                usage(bdopt);
X            while (*envp == ' ')
X                 envp++;
X        }
X    }
X
X    while (--Argc > 0) {                    /* command line args             */
X        str = *++Argv;
X        if (*str != '-') {                  /* argument is not an option     */
X            if (DVIfound)                   /* only one dvi file allowed     */
X                usage(onef);
X            getfname(str);
X            DVIfound = TRUE;
X        }
X        else if (strchr(OPTSET, optch = *++str) != NULL) {
X            str++;                      /* point to rest of argument if any  */
X            if ((strchr(OPTWARG, optch) != NULL) && (*str == '\0')) {
X                if (--Argc <= 0)
X                    usage(noarg);
X                str = *++Argv;
X            }
X            setoption(str);
X        }
X        else
X            usage(bdopt);
X    }
X
X    if (!DVIfound)
X        usage(ign);
X
X} /* getargs */
X
X/*---------------------------------------------------------------------------*/
X
Xvoid getpages(j, str)
Xint j;
Xchar *str;
X{
X    int i, c;
X    int num;
X
X    pageswitchon = TRUE;
X    firstpage = (printlisttype *) malloc(sizeof(printlisttype));
X    firstpage->all = FALSE;
X    firstpage->nxt = nil;
X    firstpage->pag = 0;
X    lastpage = firstpage;
X    currentpage = firstpage;
X    if (getinteger(&num, &j, str))
X        usage(nan);
X    plcnxt((int) num);
X    while (str[j]) {
X        c = str[j];
X        if (c == ',' || c == ':') {
X            j++;
X            if (getinteger(&num, &j, str))
X                usage(nan);
X        }
X        else
X            break;
X        if (c == ',')
X            plcnxt(num);
X        else {
X            if (currentpage->pag < 0) {
X                if (num > 0) {
X                    currentpage->all = TRUE;
X                    plcnxt(num);
X                }
X                else if (num < currentpage->pag)
X                    for (i = currentpage->pag - 1; i >= num; i--)
X                        plcnxt(i);
X                else
X                    usage(bdlst);
X            }
X            else {
X                if (num < currentpage->pag)
X                    usage(bdlst);
X                for (i = currentpage->pag + 1; i <= num; i++)
X                    plcnxt(i);
X            }
X        }
X    }
X    if ((str[j] != ' ') && (str[j] != NULL)) {
X        usage(gae);
X    }
X    currentpage = firstpage;
X
X} /* getpages */
X
X
Xvoid plcnxt(pagnr)      /* place page-nr next in list */
Xint pagnr;
X{
X    currentpage = lastpage;
X    currentpage->pag = pagnr;
X    lastpage = (printlisttype *) malloc(sizeof(printlisttype));
X    lastpage->all = FALSE;
X    lastpage->nxt = nil;
X    lastpage->pag = 0;
X    currentpage->nxt = lastpage;
X
X} /* plcnxt */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid getfname(str)
Xchar *str;
X{
X    int   i;
X
X    i = strlen(str);
X    if (i == 0)
X        usage(ign);
X    strcpy(DVIfilename, str);
X    if (!((i >= 5) && (str[i-1] == 'i') && (str[i-2] == 'v') &&
X          (str[i-3] == 'd') && (str[i-4] == '.'))) {
X        strcat(DVIfilename, ".dvi");
X    }
X
X} /* getfname */
X
X/*----------------------------------------------------------------------------*/
X
Xint getinteger(dest, j, str)
Xint *dest;
Xint *j;
Xchar *str;
X{
X    int  cum;
X    int  sgn;
X    char ch;
X
X    ch = str[*j];
X    if (ch == '-') {
X        sgn = -1;
X        ch  = str[++(*j)];
X    }
X    else
X        sgn = 1;
X    if ((ch >= '0') && (ch <= '9')) {
X        cum = 0;
X        while ((ch >= '0') && (ch <= '9')) {
X            cum = cum*10 + ch - '0';
X            ch = str[++(*j)];
X        }
X        *dest = sgn * cum;
X        return 0;                   /* return ok */
X    }
X    return 1;                       /* return error */
X
X}   /* getinteger */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid errorexit(errorcode)
Xint errorcode;
X{
X
X    fprintf(stderr, "%s: ", progname);
X    switch (errorcode) {
X        case  illop : fprintf(stderr, "Illegal op-code found: %d\n", opcode);
X                      break;
X        case  stkof : fprintf(stderr, "Stack overflow\n");
X                      break;
X        case  stkuf : fprintf(stderr, "Stack underflow\n");
X                      break;
X        case  stkrq : fprintf(stderr, "Cannot create dvi stack\n");
X                      break;
X        case  lnerq : fprintf(stderr, "Cannot allocate memory\n");
X                      break;
X        case  badid : fprintf(stderr, "Id-byte is not correct: %d\n ", opcode);
X                      break;
X        case  bdsgn : fprintf(stderr, "Bad signature: %d (not 223)\n",
X                                      (int) foo);
X                      break;
X        case  fwsgn : fprintf(stderr, "%d signature bytes (min. 4)\n",
X                                      (int) foo);
X                      break;
X        case  nopre : fprintf(stderr, "Missing preamble\n");
X                      break;
X        case  nobop : fprintf(stderr, "Missing beginning-of-page command\n");
X                      break;
X        case  nopp  : fprintf(stderr, "Missing post-post command\n");
X                      break;
X        case  bdpre : fprintf(stderr, "Preamble occured inside a page\n");
X                      break;
X        case  bdbop : fprintf(stderr, "BOP-command occured inside a page\n");
X                      break;
X        case  bdpst : fprintf(stderr, "Postamble occured before end-of-page\n");
X                      break;
X        case  bdpp  : fprintf(stderr, "Postpost occured before post-command\n");
X                      break;
X        case  nopst : fprintf(stderr, "Missing postamble\n");
X                      break;
X        case  illch : fprintf(stderr, "Character code out of range, 0..127\n");
X                      break;
X        case  filop : fprintf(stderr, "Cannot open dvifile\n");
X                      break;
X        case  filcr : fprintf(stderr, "Cannot create outfile\n");
X                      break;
X#if !defined(MSDOS) && !defined(VMS)
X        case  pipcr : fprintf(stderr, "Cannot create pipe to pager\n");
X                      break;
X#endif
X        default     : fprintf(stderr, "Unkown error code\n");
X                      break;
X    };
X    if (outputtofile)
X#if defined(VMS)
X        remove(OUTfilename);
X#else
X        unlink(OUTfilename);
X#endif
X    exit(errorcode);
X
X}  /* errorexit */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid usage(uerr)
Xint uerr;
X{
X
X    if (uerr != ign) {
X        fprintf(stderr,"%s: ", progname);
X        switch (uerr) {
X            case   ign    : fprintf(stderr, "%s", Copyright);
X                            break;
X            case   wrnge  : fprintf(stderr, "width arg out of range:16-132");
X                            break;
X            case   nan    : fprintf(stderr, "numeric argument expected for option %c",
X                                            optch);
X                            break;
X            case   gae    : fprintf(stderr, "garbage in argument for option %c",
X                                            optch);
X                            break;
X            case   bdlst  : fprintf(stderr, "mal-formed list of pagenumbers");
X                            break;
X            case   onef   : fprintf(stderr, "only one infile argument allowed");
X                            break;
X            case   noarg  : fprintf(stderr, "option argument expected for option %c",
X                                            optch);
X                            break;
X            case   bdopt  : fprintf(stderr, "bad option %c", optch);
X                            break;
X            case   onepp  : fprintf(stderr, "only one pagelist allowed");
X                            break;
X            default       : fprintf(stderr, "unknown usage error");
X                            break;
X        }
X        fprintf(stderr, "\n");
X    }
X    fprintf(stderr, "Usage: %s [ options ] dvifile[.dvi]\n", progname);
X    fprintf(stderr, "Options are:\n");
X    fprintf(stderr,
X            " -ofile   Write output to file, else write to stdout.\n");
X    fprintf(stderr,
X            " -plist   Print pages whos TeX-page-number are in list.\n");
X    fprintf(stderr,
X            " -Plist   Print pages whos sequential number are in list.\n");
X    fprintf(stderr,
X            " -wn      Print the lines with width n characters, default 80.\n");
X#if !defined(MSDOS) && !defined(VMS)
X    fprintf(stderr, " -f       Try to pipe to a pager if output is a tty");
X    if (WANTPAGER)
X        fprintf(stderr, " (default).\n");
X    else
X        fprintf(stderr, ".\n");
X    fprintf(stderr, " -q       Don't try to pipe to a pager");
X    if (WANTPAGER)
X        fprintf(stderr, ".\n");
X    else
X        fprintf(stderr, " (default).\n");
X    fprintf(stderr, " -Fprog   Pipe output to pager prog.\n");
X#endif
X    fprintf(stderr,
X            " -l       Write ''^L'' instead of formfeed between pages.\n");
X    fprintf(stderr,
X            " -u       National Swedish/Finnish characters printed as aaoAAO");
X    if (DEFSCAND)
X        fprintf(stderr, ".\n");
X    else
X        fprintf(stderr, " (default).\n");
X    fprintf(stderr,
X            " -s       National Swedish/Finnish characters printed as }{|][\\");
X    if (DEFSCAND)
X        fprintf(stderr, " (default).\n");
X    else
X        fprintf(stderr, ".\n");
X    exit(uerr);
X
X} /* usage */
X
END_OF_FILE
if test 24434 -ne `wc -c <'dvi2tty.c'`; then
    echo shar: \"'dvi2tty.c'\" unpacked with wrong size!
fi
# end of 'dvi2tty.c'
fi
if test -f 'commands.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'commands.h'\"
else
echo shar: Extracting \"'commands.h'\" \(3506 characters\)
sed "s/^X//" >'commands.h' <<'END_OF_FILE'
X/* DVI COMMANDS */
X#define  SETC_000         0     /* typeset character 0 and move right */
X#define  SETC_127       127     /* typeset character 127 and move right */
X#define  SET1           128     /* typeset a character and move right */
X#define  SET2           129     /* ??? */
X#define  SET3           130     /* ??? */
X#define  SET4           131     /* ??? */
X#define  SET_RULE       132     /* typeset a rule and move right */
X#define  PUT1           133     /* typeset a character */
X#define  PUT2           134     /* ??? */
X#define  PUT3           135     /* ??? */
X#define  PUT4           136     /* ??? */
X#define  PUT_RULE       137     /* typeset a rule */
X#define  NOP            138     /* no operation */
X#define  BOP            139     /* beginning of page */
X#define  EOP            140     /* ending of page */
X#define  PUSH           141     /* save the current positions */
X#define  POP            142     /* restore previous positions */
X#define  RIGHT1         143     /* move right */
X#define  RIGHT2         144     /* ??? */
X#define  RIGHT3         145     /* ??? */
X#define  RIGHT4         146     /* ??? */
X#define  W0             147     /* move right by |w| */
X#define  W1             148     /* move right and set |w| */
X#define  W2             149     /* ??? */
X#define  W3             150     /* ??? */
X#define  W4             151     /* ??? */
X#define  X0             152     /* move right by |x| */
X#define  X1             153     /* move right and set |x| */
X#define  X2             154     /* ??? */
X#define  X3             155     /* ??? */
X#define  X4             156     /* ??? */
X#define  DOWN1          157     /* move down */
X#define  DOWN2          158     /* ??? */
X#define  DOWN3          159     /* ??? */
X#define  DOWN4          160     /* ??? */
X#define  Y0             161     /* move down by |y| */
X#define  Y1             162     /* move down and set |y| */
X#define  Y2             163     /* ??? */
X#define  Y3             164     /* ??? */
X#define  Y4             165     /* ??? */
X#define  Z0             166     /* move down by |z| */
X#define  Z1             167     /* move down and set |z| */
X#define  Z2             168     /* ??? */
X#define  Z3             169     /* ??? */
X#define  Z4             170     /* ??? */
X#define  FONT_00        171     /* set current font to 0 */
X#define  FONT_63        234     /* set current font to 0 */
X#define  FNT1           235     /* set current font */
X#define  FNT2           236     /* Same as FNT1, except that arg is 2 bytes */
X#define  FNT3           237     /* Same as FNT1, except that arg is 3 bytes */
X#define  FNT4           238     /* Same as FNT1, except that arg is 4 bytes */
X#define  XXX1           239     /* extension to \.DVI primitives */
X#define  XXX2           240     /* Like XXX1, but 0<=k<65536 */
X#define  XXX3           241     /* Like XXX1, but 0<=k<@t$2^{24}$@> */
X#define  XXX4           242     /* potentially long extension to \.DVI
X                                   primitives */
X#define  FNT_DEF1       243     /* define the meaning of a font number */
X#define  FNT_DEF2       244     /* ??? */
X#define  FNT_DEF3       245     /* ??? */
X#define  FNT_DEF4       246     /* ??? */
X#define  PRE            247     /* preamble */
X#define  POST           248     /* postamble beginning */
X#define  POST_POST      249     /* postamble ending */
X#define  TRAILER        223     /* trailer bytes in dvi file */
X
X        /*  undefined_commands           250,251,252,253,254,255 */
END_OF_FILE
if test 3506 -ne `wc -c <'commands.h'`; then
    echo shar: \"'commands.h'\" unpacked with wrong size!
fi
# end of 'commands.h'
fi
echo shar: End of archive 1 \(of 2\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
#########################################
# Marcel J.E. Mol                       ######################################
# Delft University of Technology          Pink Elephant Management Services  #
# The Netherlands                         Voorburg                           #
# UUCP: marcel@duteca.tudelft.nl          Tel: 070-694231                    #
#                                      	######################################
#########################################

marcel@duteca (Marcel Mol) (04/11/90)

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 2 (of 2)."
# Contents:  dvistuff.c dvi2tty.h dvi2tty.1
# Wrapped by marcel@duteca on Thu Mar  1 23:08:08 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'dvistuff.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dvistuff.c'\"
else
echo shar: Extracting \"'dvistuff.c'\" \(38176 characters\)
sed "s/^X//" >'dvistuff.c' <<'END_OF_FILE'
X
X#include "dvi2tty.h"
X#include <sys/types.h>
X#include <sys/stat.h>
X#if defined(VMS) 
X#include types.h
X#include stat
X#endif
X#if defined(MSDOS)
X#include <math.h>
X#endif
X#include "commands.h"
X
X#if defined(VMS) 
X#define mseek vmsseek
X#define ROUND(a)        (a>=0.0 ?  (int) (a + 0.5) : (int) (a - 0.5) )
X#else
X#define mseek fseek
X#endif
X
X#define VERSIONID            2 /* dvi version number that pgm handles      */
X#define VERTICALEPSILON 450000L /* crlf when increasing v more than this   */
X
X#define rightmargin     152    /* nr of columns allowed to the right of h=0*/
X#define leftmargin      -50    /* give some room for negative h-coordinate */
X#define LINELEN         203    /* rightmargin - leftmargin + 1 */
X
X#define MOVE            TRUE   /* if advancing h when outputing a rule     */
X#define STAY            FALSE  /* if not advancing h when outputing a rule */
X
X#define absolute        0      /* for seeking in files                     */
X#define relative        1
X
X#define FORM             12    /* formfeed                                 */
X#define SPACE            32    /* space                                    */
X#define DEL             127    /* delete                                   */
X
X#define LASTCHAR        127    /* max dvi character, above are commands    */
X
X#define IMIN(a, b)      (a<b ? a : b)
X#define IMAX(a, b)      (a>b ? a : b)
X
X#define get1()          num(1)
X#define get2()          num(2)
X#define get3()          num(3)
X#define get4()          num(4)
X#define sget1()         snum(1)
X#define sget2()         snum(2)
X#define sget3()         snum(3)
X#define sget4()         snum(4)
X
Xchar *dvistuff = "@(#) dvistuff.c  4.0 04/02/90 M.J.E. Mol (c) 1989, 1990";
X
X/*---------------------------------------------------------------------------*/
X
Xtypedef struct {
X    long hh;
X    long vv;
X    long ww;
X    long xx;
X    long yy;
X    long zz;
X} stackitem;
X
Xtypedef struct lineptr {        /* the lines of text to be output to outfile */
X    long            vv;                 /* vertical position of the line     */
X    int             charactercount;     /* pos of last char on line          */
X    struct lineptr *prev;               /* preceding line                    */
X    struct lineptr *next;               /* succeeding line                   */
X    char            text[LINELEN+1];    /* leftmargin...rightmargin          */
X} linetype;
X
Xtypedef struct _font {
X    long    num;
X    struct _font * next;
X    char  * name;
X} font;
X
X
X/*---------------------------------------------------------------------------*/
X
Xbool        pageswitchon;       /* true if user-set pages to print           */
Xbool        sequenceon;         /* false if pagesw-nrs refers to TeX-nrs     */
Xbool        scascii;            /* if true make Scand. nat. chars right      */
Xbool        noffd;              /* if true output ^L instead of formfeed     */
X
Xint         opcode;             /* dvi-opcodes                               */
X
Xlong        h, v;               /* coordinates, horizontal and vertical      */
Xlong        w, x, y, z;         /* horizontal and vertical amounts           */
X
Xlong        pagecounter;        /* sequence page number counter              */
Xlong        backpointer;        /* pointer for offset to previous page       */
Xlong        pagenr;             /* TeX page number                           */
Xint         stackmax;           /* stacksize required                        */
X
Xlong        maxpagewidth;       /* width of widest page in file              */
Xlong        charwidth;          /* aprox width of character                  */
X
Xlinetype *  currentline;        /* pointer to current line on current page   */
Xlinetype *  firstline;          /* pointer to first line on current page     */
Xlinetype *  lastline;           /* pointer to last line on current page      */
Xint         firstcolumn;        /* 1st column with something to print        */
X
Xstackitem * stack;              /* stack for dvi-pushes                      */
Xint         sptr;               /* stack pointer                             */
X
Xfont * fonts = NULL;            /* List of fontnames defined                 */
Xint  symbolfont = FALSE;        /* true if font is a symbol font             */
X
X/*---------------------------------------------------------------------------*/
X
X#if defined(MSDOS)
Xvoid            postamble       (void);
Xvoid            preamble        (void);
Xvoid            walkpages       (void);
Xvoid            initpage        (void);
Xvoid            dopage          (void);
Xvoid            skippage        (void);
Xvoid            printpage       (void);
Xbool            inlist          (long);
Xvoid            rule            (bool, long, long);
Xvoid            ruleaux         (long, long, char);
Xlong            horizontalmove  (long);
Xint             skipnops        (void);
Xlinetype    *   getline         (void);
Xlinetype    *   findline        (void);
Xunsigned long   num             (int);
Xlong            snum            (int);
Xvoid            dochar          (char);
Xvoid            symchar         (char);
Xvoid            normchar        (char);
Xvoid            outchar         (char);
Xvoid            putcharacter    (long);
Xvoid            setchar         (long);
Xvoid            fontdef         (int);
Xvoid            setfont         (long);
X#else
Xvoid            postamble       ();
Xvoid            preamble        ();
Xvoid            walkpages       ();
Xvoid            initpage        ();
Xvoid            dopage          ();
Xvoid            skippage        ();
Xvoid            printpage       ();
Xbool            inlist          ();
Xvoid            rule            ();
Xvoid            ruleaux         ();
Xlong            horizontalmove  ();
Xint             skipnops        ();
Xlinetype    *   getline         ();
Xlinetype    *   findline        ();
Xunsigned long   num             ();
Xlong            snum            ();
Xvoid            dochar          ();
Xvoid            symchar         ();
Xvoid            normchar        ();
Xvoid            outchar         ();
Xvoid            putcharacter    ();
Xvoid            setchar         ();
Xvoid            fontdef         ();
Xvoid            setfont         ();
X#if defined(VMS)
Xlong		vmsseek		();
Xlong		vms_ftell	();
Xlong		vms_ungetc	();
X#endif
X#endif
X
X
X/*---------------------------------------------------------------------------*/
X/*---------------------------------------------------------------------------*/
X
X/*
X * The main function for processing the dvi file.
X * Here we assume there are to file pointers: DVIfile and output.
X * Also we have a list of pages pointed to by 'currentpage',
X * which is only used (in 'inlist()') when a page list is given.
X */
X
Xvoid dvimain()
X{
X
X    postamble();                            /* seek and process the postamble */
X    /* note that walkpages *must* immediately follow preamble */
X    preamble();                             /* process preamble               */
X    walkpages();                            /* time to do the actual work!    */
X
X} /* dvimain */
X
X/*---------------------------------------------------------------------------*/
X
Xvoid postamble()            /* find and process postamble, use random access */
X{
X    register long size;
X    register int  count;
X    struct stat st;
X
X    fstat (fileno(DVIfile), &st);
X    size = (long) st.st_size;                   /* get size of file          */
X    count = -1;
X    do {              /* back file up past signature bytes (223), to id-byte */
X        if (size == 0)
X            errorexit(nopst);
X        size--;
X        mseek(DVIfile, size, absolute);
X        opcode = (int) get1();
X        count++;
X    } while (opcode == TRAILER);
X    if (count < 4) {                            /* must have 4 trailer bytes */
X         foo = count;
X         errorexit(fwsgn);
X    }
X    if (opcode != VERSIONID)
X        errorexit(badid);
X    mseek(DVIfile, size-4, absolute);       /* back up to back-pointer       */
X    mseek(DVIfile, sget4(), absolute);      /* and to start of postamble   */
X    if (get1() != POST)
X        errorexit(nopst);
X    mseek(DVIfile, 20L, relative); /* lastpageoffset, numerator, denominator */
X                                   /* magnification, maxpageheight           */
X    maxpagewidth = sget4();
X    charwidth = maxpagewidth / (ttywidth + espace); 
X    stackmax = (int) get2();
X    if ((stack = (stackitem *) malloc(stackmax * sizeof(stackitem))) == NULL)
X       errorexit(stkrq);
X
X    /* get2() -- totalpages */
X    /* fontdefs  do fontdefs in flight ... */
X
X} /* postamble */
X
X/*---------------------------------------------------------------------------*/
X
Xvoid preamble()                 /* process preamble, use random access       */
X{
X
X    mseek(DVIfile, 0L, absolute);       /* read the dvifile from the start   */
X    if ((opcode = skipnops()) != PRE)
X        errorexit(nopre);
X    opcode = (int) get1();        /* check id in preamble, ignore rest of it */
X    if (opcode != VERSIONID)
X        errorexit(badid);
X    mseek(DVIfile, 12L, relative);  /* numerator, denominator, magnification */
X    mseek(DVIfile, get1(), relative);         /* skip job identification     */
X
X} /* preamble */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid walkpages()                  /* process the pages in the DVI-file */
X{
X    register bool wantpage;
X
X    pagecounter = 0L;
X    while ((opcode = skipnops()) != POST) {
X        if (opcode != BOP)              /* should be at start of page now    */
X            errorexit(nobop);
X        else {
X            pagecounter++;
X            pagenr = sget4();           /* get TeX page number               */
X            mseek(DVIfile, 36L, relative); /* skip page header */
X            backpointer = sget4();      /* get previous page offset          */
X            if (pageswitchon)
X                if (sequenceon)
X                    wantpage = inlist(pagecounter);
X                else
X                    wantpage = inlist(pagenr);
X            else
X                wantpage = TRUE;
X
X            if (wantpage) {
X                initpage();
X                dopage();
X                printpage();
X            }
X            else {
X                skippage();
X            }
X        }
X    }
X
X} /* walkpages */
X
X/*---------------------------------------------------------------------------*/
X
Xvoid initpage()
X{
X
X    h = 0L;  v = 0L;                        /* initialize coordinates   */
X    x = 0L;  w = 0L;  y = 0L;  z = 0L;      /* initialize amounts       */
X    sptr = 0;                               /* initialize stack         */
X    currentline = getline();                /* initialize list of lines */
X    currentline->vv = 0L;
X    firstline   = currentline;
X    lastline    = currentline;
X    firstcolumn = rightmargin;
X    if (pageswitchon) {
X        if ((sequenceon && (pagecounter != firstpage->pag)) ||
X            (!sequenceon && (pagenr != firstpage->pag)))
X            if (noffd)
X                fprintf(output, "^L\n");
X            else
X                putc(FORM, output);
X    }
X    else
X        if (backpointer != -1)              /* not FORM at first page   */
X            if (noffd)
X                fprintf(output, "^L\n");
X            else
X                putc(FORM, output);
X
X} /* initpage */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid dopage()
X{
X
X    while ((opcode = (int) get1()) != EOP) {    /* process page until eop */
X        if (opcode <= LASTCHAR)
X            dochar((char) opcode);
X        else if ((opcode >= FONT_00) && (opcode <= FONT_63)) 
X            setfont(opcode - FONT_00);
X        else if (opcode > POST_POST)
X            errorexit(illop);
X        else
X            switch (opcode) {
X                case SET1     : setchar(get1()); break;
X                case SET2     : setchar(get2()); break;
X                case SET3     : setchar(get3()); break;
X                case SET4     : setchar(get4()); break;
X                case SET_RULE : { long height = sget4();
X                                  rule(MOVE, sget4(), height); break;
X                                }
X                case PUT1     : putcharacter(get1()); break;
X                case PUT2     : putcharacter(get2()); break;
X                case PUT3     : putcharacter(get3()); break;
X                case PUT4     : putcharacter(get4()); break;
X                case PUT_RULE : { long height = sget4();
X                                  rule(STAY, sget4(), height); break;
X                                }
X                case NOP      : break;  /* no-op */
X                case BOP      : errorexit(bdbop); break;
X/*              case EOP      : break;  strange place to have EOP */
X                case PUSH     : if (sptr >= stackmax)            /* push */
X                                     errorexit(stkof);
X                                stack[sptr].hh = h;
X                                stack[sptr].vv = v;
X                                stack[sptr].ww = w;
X                                stack[sptr].xx = x;
X                                stack[sptr].yy = y;
X                                stack[sptr].zz = z;
X                                sptr++;
X                                break;
X                case POP      : if (sptr == 0)                   /* pop */
X                                    errorexit(stkuf);
X                                sptr--;
X                                h = stack[sptr].hh;
X                                v = stack[sptr].vv;
X                                w = stack[sptr].ww;
X                                x = stack[sptr].xx;
X                                y = stack[sptr].yy;
X                                z = stack[sptr].zz;
X                                break;
X                case RIGHT1   : (void) horizontalmove(sget1()); break;
X                case RIGHT2   : (void) horizontalmove(sget2()); break;
X                case RIGHT3   : (void) horizontalmove(sget3()); break;
X                case RIGHT4   : (void) horizontalmove(sget4()); break;
X                case W0       : h += w; break;
X                case W1       : w = horizontalmove(sget1()); break;
X                case W2       : w = horizontalmove(sget2()); break;
X                case W3       : w = horizontalmove(sget3()); break;
X                case W4       : w = horizontalmove(sget4()); break;
X                case X0       : h += x; break;
X                case X1       : x = horizontalmove(sget1()); break;
X                case X2       : x = horizontalmove(sget2()); break;
X                case X3       : x = horizontalmove(sget3()); break;
X                case X4       : x = horizontalmove(sget4()); break;
X                case DOWN1    : v += sget1(); break;
X                case DOWN2    : v += sget2(); break;
X                case DOWN3    : v += sget3(); break;
X                case DOWN4    : v += sget4(); break;
X                case Y0       : v += y; break;
X                case Y1       : y = sget1(); v += y; break;
X                case Y2       : y = sget2(); v += y; break;
X                case Y3       : y = sget3(); v += y; break;
X                case Y4       : y = sget4(); v += y; break;
X                case Z0       : v += z; break;
X                case Z1       : z = sget1(); v += z; break;
X                case Z2       : z = sget2(); v += z; break;
X                case Z3       : z = sget3(); v += z; break;
X                case Z4       : z = sget4(); v += z; break;
X                case FNT1     :
X                case FNT2     :
X                case FNT3     :
X                case FNT4     : setfont(num(opcode - FNT1 + 1));
X                                break;
X                case XXX1     : mseek(DVIfile, get1(), relative); break;
X                case XXX2     : mseek(DVIfile, get2(), relative); break;
X                case XXX3     : mseek(DVIfile, get3(), relative); break;
X                case XXX4     : mseek(DVIfile, get4(), relative); break;
X                case FNT_DEF1 :
X                case FNT_DEF2 :
X                case FNT_DEF3 :
X                case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1);
X                                break;
X                case PRE      : errorexit(bdpre); break;
X                case POST     : errorexit(bdpst); break;
X                case POST_POST: errorexit(bdpp); break;
X            }
X    }
X
X} /* dopage */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid skippage()                /* skip past one page */
X{
X    register int opcode;
X
X    while ((opcode = (int) get1()) != EOP) {
X        if (opcode > POST_POST)
X            errorexit(illop);
X        else
X            switch (opcode) {
X                case SET1     :
X                case PUT1     :
X                case RIGHT1   :
X                case W1       :
X                case X1       :
X                case DOWN1    :
X                case Y1       :
X                case Z1       : /* assume FNT change can also be skipped */
X                case FNT1     : mseek(DVIfile, 1L, relative); break;
X                case SET2     :
X                case PUT2     :
X                case RIGHT2   :
X                case W2       :
X                case X2       :
X                case DOWN2    :
X                case Y2       :
X                case Z2       :
X                case FNT2     : mseek(DVIfile, 2L, relative); break;
X                case SET3     :
X                case PUT3     :
X                case RIGHT3   :
X                case W3       :
X                case X3       :
X                case DOWN3    :
X                case Y3       :
X                case Z3       :
X                case FNT3     : mseek(DVIfile, 3L, relative); break;
X                case SET4     :
X                case PUT4     :
X                case RIGHT4   :
X                case W4       :
X                case X4       :
X                case DOWN4    :
X                case Y4       :
X                case Z4       :
X                case FNT4     : mseek(DVIfile, 4L, relative); break;
X                case SET_RULE :
X                case PUT_RULE : mseek(DVIfile, 8L, relative); break;
X                case BOP      : errorexit(bdbop); break;
X                case XXX1     : mseek(DVIfile, get1(), relative); break;
X                case XXX2     : mseek(DVIfile, get2(), relative); break;
X                case XXX3     : mseek(DVIfile, get3(), relative); break;
X                case XXX4     : mseek(DVIfile, get4(), relative); break;
X                case FNT_DEF1 :
X                case FNT_DEF2 :
X                case FNT_DEF3 :
X                case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1); break;
X                case PRE      : errorexit(bdpre); break;
X                case POST     : errorexit(bdpst); break;
X                case POST_POST: errorexit(bdpp); break;
X        }
X    }
X
X} /* skippage */
X
X/*---------------------------------------------------------------------------*/
X
Xvoid printpage()       /* 'end of page', writes lines of page to output file */
X{
X    register int  i, j;
X    register char ch;
X
X    if (sptr != 0)
X        fprintf(stderr, "dvi2tty: warning - stack not empty at eop.\n");
X    for (currentline = firstline; currentline != nil;
X          currentline = currentline->next) {
X        if (currentline != firstline) {
X            foo = ((currentline->vv - currentline->prev->vv)/VERTICALEPSILON)-1;
X            if (foo > 3)
X                foo = 3;        /* linespacings not too large */
X            for (i = 1; i <= (int) foo; i++)
X                putc('\n', output);
X        }
X        if (currentline->charactercount >= leftmargin) {
X            foo = ttywidth - 2;
X            for (i = firstcolumn, j = 1; i <= currentline->charactercount;
X                   i++, j++) {
X                ch = currentline->text[i - leftmargin];
X                if (ch >= SPACE)
X                    putc(ch, output);
X                if ((j > (int) foo) && (currentline->charactercount > i+1)) {
X                        fprintf(output, "*\n");         /* if line to large */
X                        fprintf(output, " *");          /* mark output      */
X                        j = 2;
X                }
X            } 
X        }
X        putc('\n', output);
X    } 
X
X    currentline = firstline;
X    while (currentline->next != nil) {
X        currentline = currentline->next;
X        free(currentline->prev);
X    }
X    free(currentline);              /* free last line */
X    currentline = nil;
X
X} /* printpage */
X
X/*----------------------------------------------------------------------------*/
X
Xbool inlist(pagenr)                         /* ret true if in list of pages */
Xregister long pagenr;
X{
X
X    while ((currentpage->pag < 0) && (currentpage->pag != pagenr) &&
X           !currentpage->all && (currentpage->nxt != nil))
X        currentpage = currentpage->nxt;
X    if ((currentpage->all && (pagenr < currentpage->pag)) ||
X         (currentpage->pag == pagenr))
X            return TRUE;
X    else if (pagenr > 0) {
X        while ((currentpage->pag < pagenr) && (currentpage->nxt != nil))
X            currentpage = currentpage->nxt;
X        if (currentpage->pag == pagenr)
X            return TRUE;
X    }
X    return FALSE;
X
X} /* inlist */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid rule(moving, rulewt, ruleht)
Xregister bool moving;
Xregister long rulewt, ruleht;
X{   /* output a rule (vertical or horizontal), increment h if moving is true */
X
X    register char ch;               /* character to set rule with            */
X    register long saveh, savev;
X                              /* rule   --   starts up the recursive routine */
X    if (!moving)
X        saveh = h;
X    if ((ruleht <= 0) || (rulewt <= 0))
X        h += rulewt;
X    else {
X        savev = v;
X        if ((ruleht / rulewt) > 0)         /* value < 1 truncates to 0 */
X            ch = '|';
X        else if (ruleht > (VERTICALEPSILON / 2))
X            ch = '=';
X        else
X            ch = '_';
X        ruleaux(rulewt, ruleht, ch);
X        v = savev;
X    }
X    if (!moving)
X        h = saveh;
X
X} /* rule */
X
X
X
Xvoid ruleaux(rulewt, ruleht, ch)     /* recursive  that does the job */
Xregister long rulewt, ruleht;
Xregister char ch;
X{
X    register long wt, lmh, rmh;
X
X    wt = rulewt;
X    lmh = h;                        /* save left margin                      */
X    if (h < 0) {                    /* let rules that start at negative h    */
X        wt -= h;                    /* start at coordinate 0, but let it     */
X        h = 0;                      /*   have the right length               */
X    }
X    while (wt > 0) {                /* output the part of the rule that      */
X        rmh = h;                    /*   goes on this line                   */
X        outchar(ch);
X        wt -= (h-rmh);              /* decrease the width left on line       */
X    }
X    ruleht -= VERTICALEPSILON;      /* decrease the height                   */
X    if (ruleht > VERTICALEPSILON) { /* still more vertical?                  */
X        rmh = h;                    /* save current h (right margin)         */
X        h = lmh;                    /* restore left margin                   */
X        v -= (VERTICALEPSILON + VERTICALEPSILON / 10);
X        ruleaux(rulewt, ruleht, ch);
X        h = rmh;                    /* restore right margin                  */
X    }
X
X} /* ruleaux */
X
X/*----------------------------------------------------------------------------*/
X
Xlong horizontalmove(amount)
Xregister long amount;
X{
X
X#if defined(MSDOS)
X    if (labs(amount) > charwidth / 4L) {
X#else
X    if (abs(amount) > charwidth / 4L) {
X#endif
X        foo = 3*charwidth / 4;
X        if (amount > 0)
X            amount = ((amount+foo) / charwidth) * charwidth;
X        else
X#if defined(VMS)
X            amount = (ROUND( (float) (amount-foo) / charwidth) + 1)* charwidth;
X#else
X            amount = ((amount-foo) / charwidth) * charwidth;
X#endif
X        h += amount;
X        return amount;
X    }
X    else
X        return 0;
X
X}   /* horizontalmove */
X
X/*----------------------------------------------------------------------------*/
X
Xint skipnops()                      /* skips by no-op commands  */
X{
X    register int opcode;
X
X    while ((opcode = (int) num(1)) == NOP);
X    return opcode;
X
X} /* skipnops */
X
X/*----------------------------------------------------------------------------*/
X
Xlinetype *getline()             /* returns an initialized line-object */
X{
X    register int  i;
X    register linetype *temp;
X
X    if ((temp = (linetype *) malloc(sizeof(linetype))) == NULL) 
X        errorexit(lnerq);
X    temp->charactercount = leftmargin - 1;
X    temp->prev = nil;
X    temp->next = nil;
X    for (i = 0; i < LINELEN; i++)
X        temp->text[i] = ' ';
X    temp->text[i] = '\0';
X    return temp;
X
X} /* getline */
X
X/*----------------------------------------------------------------------------*/
X
Xlinetype *findline()            /* find best fit line were text should go */
X{                               /* and generate new line if needed        */
X    register linetype *temp;
X    register long topd, botd;
X
X    if (v <= firstline->vv) {                      /* above first line */
X        if (firstline->vv - v > VERTICALEPSILON) {
X            temp = getline();
X            temp->next = firstline;
X            firstline->prev = temp;
X            temp->vv = v;
X            firstline = temp;
X        }
X        return firstline;
X    }
X
X    if (v >= lastline->vv) {                       /* below last line */
X        if (v - lastline->vv > VERTICALEPSILON) {
X            temp = getline();
X            temp->prev = lastline;
X            lastline->next = temp;
X            temp->vv = v;
X            lastline = temp;
X        }
X        return lastline;
X    }
X
X    temp = lastline;                               /* in between two lines */
X    while ((temp->vv > v) && (temp != firstline))
X        temp = temp->prev;
X
X    /* temp->vv < v < temp->next->vv --- temp is above, temp->next is below */
X    topd = v - temp->vv;
X    botd = temp->next->vv - v;
X    if ((topd < VERTICALEPSILON) || (botd < VERTICALEPSILON))
X        if (topd < botd)                           /* take best fit */
X            return temp;
X        else
X            return temp->next;
X
X    /* no line fits suitable, generate a new one */
X    currentline = getline();
X    currentline->next = temp->next;
X    currentline->prev = temp;
X    temp->next->prev = currentline;
X    temp->next = currentline;
X    currentline->vv = v;
X    return currentline;
X
X} /* findline */
X
X/*----------------------------------------------------------------------------*/
X
Xunsigned long num(size)
Xregister int size;
X{
X    register int i;
X    register long x = 0;
X
X    for (i = 0; i < size; i++)
X        x = (x << 8) + (unsigned) getc(DVIfile);
X    return x;
X
X} /* num */
X
X
Xlong snum(size)
Xregister int size;
X{
X    register int i;
X    register long x = 0;
X
X    x = getc(DVIfile);
X    if (x & 0x80)
X        x -= 0x100;
X    for (i = 1; i < size; i++)
X        x = (x << 8) + (unsigned) getc(DVIfile);
X    return x;
X
X} /* snum */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid dochar(ch)
Xregister char ch;
X{
X
X    if (symbolfont == TRUE)
X        symchar(ch);
X    else
X        normchar(ch);
X
X    return;
X
X} /* dochar */
X
X
X
Xvoid symchar(ch)                     /* output ch to appropriate line */
Xregister char ch;
X{
X
X    switch (ch) {       /* can do a lot more on MSDOS machines ... */
X       case   0: ch = '-'; break;
X       case   1: ch = '.'; break;
X       case   2: ch = 'x'; break;
X       case   3: ch = '*'; break;
X       case  13: ch = 'O'; break;
X       case  14: ch = 'O'; break;
X       case  15: ch = 'o'; break;
X       case  24: ch = '~'; break;
X       case 102: ch = '{'; break;
X       case 103: ch = '}'; break;
X       case 104: ch = '<'; break;
X       case 105: ch = '>'; break;
X       case 106: ch = '|'; break;
X       case 110: ch = '\\'; break;
X    }
X    outchar(ch);
X
X    return;
X
X} /* symchar */
X
X
X
Xvoid normchar(ch)
Xregister char ch;
X{
X
X    switch (ch) {
X        case 11  :  outchar('f'); ch = 'f'; break;  /* ligature        */
X        case 12  :  outchar('f'); ch = 'i'; break;  /* ligature        */
X        case 13  :  outchar('f'); ch = 'l'; break;  /* ligature        */
X        case 14  :  outchar('f'); outchar('f');
X                                  ch = 'i'; break;  /* ligature        */
X        case 15  :  outchar('f'); outchar('f');
X                                  ch = 'l'; break;  /* ligature        */
X        case 16  :  ch = 'i'; break;
X        case 17  :  ch = 'j'; break;
X        case 25  :  outchar('s'); ch = 's'; break;  /* German double s */
X        case 26  :  outchar('a'); ch = 'e'; break;  /* Dane/Norw ae    */
X        case 27  :  outchar('o'); ch = 'e'; break;  /* Dane/Norw oe    */
X        case 28  :  if (scascii)
X                        ch = '|';                   /* Dane/Norw /o    */
X                    else
X                        ch = 'o';
X                    break;
X        case 29  :  outchar('A'); ch = 'E'; break;  /* Dane/Norw AE    */
X        case 30  :  outchar('O'); ch = 'E'; break;  /* Dane/Norw OE    */
X        case 31  :  if (scascii)
X                        ch = '\\';                  /* Dane/Norw /O    */
X                    else
X                        ch = 'O';
X                    break;
X        case 92  :  ch = '"'; break;  /* \ from `` */
X        case 123 :  ch = '-'; break;  /* { from -- */
X        case 124 :  ch = '_'; break;  /* | from --- */
X        case 125 :  ch = '"'; break;  /* } from \H */
X        case 126 :  ch = '"'; break;  /* ~ from \~ */
X        case 127 :  ch = '"'; break;  /* DEL from \" */
X#if 0
X        case 18  :  ch = '`'; break   /* from \` */
X        case 19  :  ch = ''''; break  /* from \' */
X        case 20  :  ch = '~'; break   /* from \v */
X        case 21  :  ch = '~'; break   /* from \u */
X        case 22  :  ch = '~'; break   /* from \= */
X        case 24  :  ch = ','; break   /* from \c */
X        case 94  :  ch = '^'; break   /* ^ from \^ */
X        case 95  :  ch = '`'; break   /* _ from \. */
X#endif
X    }
X    outchar(ch); 
X
X    return;
X
X} /*normchar */
X
X
X
Xvoid outchar(ch)                     /* output ch to appropriate line */
Xregister char ch;
X{
X    register int i, j;
X
X/*     fprintf(stderr, "hor: %ld, ver: %ld\n", h, v); */
X#if defined(MSDOS)
X    if (labs(v - currentline->vv) > VERTICALEPSILON / 2L)
X#else
X    if (abs(v - currentline->vv) > VERTICALEPSILON / 2L)
X#endif
X        currentline = findline();
X
X#if 0
X    j = (int) (((double) h / (double) maxpagewidth) * (ttywidth-1)) + 1;
X#else
X    j = (int) (h / charwidth);
X#endif
X    if (j > rightmargin)     /* leftmargin <= j <= rightmargin */
X        j = rightmargin;
X    else if (j < leftmargin)
X        j = leftmargin;
X    foo = leftmargin - 1;
X    /*
X    /* This code does not really belong here ...
X    /*
X    /*-------------------------------------------------------------*/
X    /* The following is very specialized code, it handles national */
X    /* Swe/Fin characters. They are respectively: a and o with two */
X    /* dots ("a & "o) and a with a circle (Oa). In Swe/Fin "ASCII" */
X    /* these characters replace }{|][ and \.  TeX outputs these by */
X    /* first issuing the dots or circle and then backspace and set */
X    /* the a or o.  When dvitty finds an a or o it searches in the */
X    /* near vicinity for the character codes that represent circle */
X    /* or dots and if one is found the corresponding national char */
X    /* replaces the special character codes.                       */
X    /*-------------------------------------------------------------*/
X    if (scascii) {
X        if ((ch == 'a') || (ch == 'A') || (ch == 'o') || (ch == 'O')) {
X            for (i = IMAX(leftmargin, j-2);
X                 i <= IMIN(rightmargin, j+2);
X                 i++)
X                if ((currentline->text[i - leftmargin] == 127) ||
X                    (currentline->text[i - leftmargin] == 34) ||
X                    (currentline->text[i - leftmargin] == 23))
X                    foo = i;
X            if (foo >= leftmargin) {
X                j = (int) foo;
X                switch (currentline->text[j - leftmargin]) {
X                    case 127 : case 34:
X                               if (ch == 'a')
X                                   ch = '{';
X                               else if (ch == 'A')      /* dots ... */
X                                   ch = '[';
X                               else if (ch == 'o')
X                                   ch = '|';
X                               else if (ch == 'O')
X                                   ch = '\\';
X                               break;
X                    case 23  : if (ch == 'a')
X                                   ch = '}';
X                               else if (ch == 'A')      /* circle */
X                                   ch = ']';
X                               break;
X                }
X            }
X        }
X    }
X    /*----------------- end of 'Scandinavian code' ----------------*/
X    if (foo == leftmargin-1)
X        while ((currentline->text[j - leftmargin] != SPACE)
X               && (j < rightmargin)) {
X            j++;
X            h += charwidth;
X        }
X    if ( ((ch >= SPACE) && (ch != DEL)) ||
X         (scascii && (ch == 23)) ) {
X          /*  (scascii && (ch == DEL)) ) {    if VMS ??? */
X        if (j < rightmargin)
X            currentline->text[j - leftmargin] = ch;
X        else
X            currentline->text[rightmargin - leftmargin] = '@';
X        if (j > currentline->charactercount)
X            currentline->charactercount = j;
X        if (j < firstcolumn)
X            firstcolumn = j;
X        h += charwidth;
X    }
X
X} /* outchar */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid putcharacter(charnr)            /* output character, don't change h */
Xregister long charnr;
X{
X    register long saveh;
X
X    saveh = h;
X    if ((charnr >= 0) && (charnr <= LASTCHAR))
X        outchar((char) charnr);
X    else
X        setchar(charnr);
X    h = saveh;
X
X} /* putcharacter */
X
X/*----------------------------------------------------------------------------*/
X
Xvoid setchar(charnr)
Xlong charnr;
X{    /* should print characters with character code>127 from current font */
X     /* note that the parameter is a dummy, since ascii-chars are<=127    */
X
X    outchar('#');
X
X} /* setchar */
X
X
X/*----------------------------------------------------------------------------*/
X
X
Xvoid fontdef(x)
Xregister int x;
X{
X    register int i;
X    char * name;
X    font * fnt;
X    int namelen;
X    long fntnum;
X    int new = 0;
X
X    fntnum = num(x);
X    (void) get4();                      /* checksum */
X    (void) get4();                      /* scale */
X    (void) get4();                      /* design */
X    namelen = (int) get1() + (int) get1();
X    fnt = fonts;
X    while (fnt != NULL && fnt->num != fntnum)       /* does fontnum exist */
X        fnt = fnt->next;
X    if (fnt == NULL) {
X        if ((fnt = (font *) malloc(sizeof(font))) == NULL) {
X            perror("fontdef");
X            exit(1);
X        }
X        fnt->num = fntnum;
X        new = 1;
X    }
X    else
X        free(fnt->name);    /* free old name */
X    if ((name = (char *) malloc(namelen * sizeof(char))) == NULL) {
X        perror("fontdef");
X        exit(1);
X    }
X    
X    for (i = 0; i < namelen; i++)
X        name[i] = get1();
X    fnt->name = name;
X    if (new) {
X        fnt->next = fonts;
X        fonts = fnt;
X    }
X
X    return;
X
X} /* fontdef */
X
X
X
Xvoid setfont(fntnum)
Xlong fntnum;
X{
X    font * fnt;
X    char * s;
X
X    fnt = fonts;
X    while (fnt != NULL && fnt->num != fntnum)
X        fnt = fnt->next;
X    if (fnt == NULL) {
X        /* error : font not found */
X        symbolfont = FALSE;
X        return;
X    }
X
X    s = fnt->name;
X    while ((s = strchr(s, 's')) != NULL) {
X        if (strncmp("sy", s, 2) == 0) {
X            symbolfont = TRUE;
X            return;
X        }
X    }
X   
X    symbolfont = FALSE;
X    return;
X
X} /* setfont */
X
X
X/*----------------------------------------------------------------------------*/
X
X
X#if defined(VMS)
Xlong vmsseek(fp,n,dir)
XFILE *fp;
Xlong n;
Xlong dir;
X{
X    long k,m,pos,val,oldpos;
X    struct stat buffer;
X
X    for (;;) {                     /*loops only once or twice*/
X        switch (dir) {
X            case 0:            /*from BOF*/
X                    oldpos = vms_ftell(fp);
X                    k = n & 511;
X                    m = n >> 9;
X                    if (((*fp)->_cnt) && ((oldpos >> 9) == m)) {
X                        val = 0; /* still in */
X                        (*fp)->_ptr = ((*fp)->_base) + k;
X                        (*fp)->_cnt = 512 - k;
X                    }
X                    else {
X                        val = fseek(fp, m << 9, 0);
X                        if (val == 0) {
X                            (*fp)->_cnt = 0;
X                            (void) fgetc(fp);
X                            (*fp)->_ptr = ((*fp)->_base) + k;
X                            (*fp)->_cnt = 512 - k;
X                        }
X                    }
X                    return(val);
X
X            case 1: pos = vms_ftell(fp);
X                    if (pos == EOF)
X                        return (EOF);
X                    n += pos;
X                    dir = 0;
X                    break;
X
X            case 2: val = fstat(fileno(fp), &buffer);
X                    if (val == EOF)
X                        return (EOF);
X                    n += buffer.st_size - 1;
X
X                    dir = 0;
X                    break;
X
X            default : return (EOF);
X        }
X    }
X
X} /* vmsseek */
X        
X
X
Xlong vms_ftell(fp)
XFILE *fp;
X{
X    char c;
X    long pos;
X    long val;
X    if ((*fp)->_cnt == 0) {
X        c = fgetc(fp);
X        val = vms_ungetc(c, fp);
X        if (val != c)
X            return (EOF);
X    }
X    pos = ftell(fp);
X    if (pos >= 0)
X        pos += ((*fp)->_ptr) - ((*fp)->_base);
X    return (pos);
X
X} /* vms_ftell */
X
X
X
Xlong vms_ungetc(c,fp)
Xchar c;
XFILE *fp;
X{
X    if ((c == EOF) && feof(fp))
X        return (EOF);
X    else if ((*fp)->_cnt >= 512)
X        return (EOF);
X    else {
X        (*fp)->_cnt++;
X        (*fp)->_ptr--;
X        *((*fp)->_ptr) = c;
X        return (c);
X    }
X
X} /*vms_ungetc */
X#endif
END_OF_FILE
if test 38176 -ne `wc -c <'dvistuff.c'`; then
    echo shar: \"'dvistuff.c'\" unpacked with wrong size!
fi
# end of 'dvistuff.c'
fi
if test -f 'dvi2tty.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dvi2tty.h'\"
else
echo shar: Extracting \"'dvi2tty.h'\" \(3789 characters\)
sed "s/^X//" >'dvi2tty.h' <<'END_OF_FILE'
X#define Copyright "dvi2tty.c  Copyright (C) 1984, 1985, 1986 Svante Lindahl.\n\
XCopyright (C) 1988 M.J.E. Mol 1989, 1990"
X
X#include <stdio.h>
X#include <string.h>
X#if defined(MSDOS)
X#include <stdlib.h>
X#include <malloc.h>
X#endif
X
X#define TRUE        1
X#define FALSE       0
X#define nil         NULL
X
X/*
X * ERROR CODES , don't start with 0
X */
X
X#define illop    1              /* illegal op-code                   */
X#define stkof    2              /* stack over-flow                   */
X#define stkuf    3              /* stack under-flow                  */
X#define stkrq    4              /* stack requirement                 */
X#define lnerq    5              /* line allocation                   */
X#define badid    6              /* id is not right                   */
X#define bdsgn    7              /* signature is wrong                */
X#define fwsgn    8              /* too few signatures                */
X#define nopre    9              /* no pre-amble where expected       */
X#define nobop   10              /* no bop-command where expected     */
X#define nopp    11              /* no postpost where expected        */
X#define bdpre   12              /* unexpected preamble occured       */
X#define bdbop   13              /* unexpected bop-command occured    */
X#define bdpst   14              /* unexpected post-command occured   */
X#define bdpp    15              /* unexpected postpost               */
X#define nopst   16              /* no post-amble where expected      */
X#define illch   17              /* character code out of range       */
X#define filop   18              /* cannot access file                */
X#define filcr   19              /* cannot creat file                 */
X#if !defined(MSDOS)
X#define pipcr   20              /* cannot creat pipe                 */
X#endif
X
X/*---------------------------------------------------------------------------*/
X
Xtypedef char bool;
X
Xtypedef struct prlistptr {      /* list of pages selected for output         */
X    int       pag;                      /* number of pages                   */
X    bool      all;                      /* pages in interval selected        */
X    struct prlistptr *prv;              /* previous item in list             */
X    struct prlistptr *nxt;              /* next item in list                 */
X} printlisttype;
X
X/*---------------------------------------------------------------------------*/
X
Xextern bool   outputtofile;            /* output to file or stdout(dvi2tty.c)*/
Xextern bool   pageswitchon;            /* user-set pages to print(dvistuff.c)*/
Xextern bool   sequenceon;              /* not TeX pagenrs (dvistuff.c)       */
Xextern bool   scascii;                 /* Scand. nat. chars (dvistuff.c)     */
Xextern bool   noffd;                   /* output ^L or formfeed (dvistuff.c) */
X
Xextern printlisttype *currentpage;     /* current page to print (dvi2tty.c)  */
Xextern printlisttype *firstpage;       /* first page selected (dvi2tty.c)    */
Xextern printlisttype *lastpage;        /* last page selected (dvi2tty.c)     */
X
Xextern int            ttywidth;        /* screen width (dvi2tty.c)           */
Xextern int            espace;          /* extra screen width (dvi2tty.c)     */
Xextern long           foo;             /* temporary 'register' (dvi2tty.c)   */
Xextern int            opcode;          /* dvi opcode (dvistuff.c)            */
X
Xextern FILE *DVIfile;                  /* dvi file (dvi2tty.c)               */
Xextern FILE *output;                   /* output file (dvi2tty.c)            */
X
X/*---------------------------------------------------------------------------*/
X
X/* dvi2tty.c */
X#if defined(MSDOS)
Xvoid errorexit(int);
X#else
Xvoid errorexit();
X#endif
X
X/* dvistuff.c */
X#if defined(MSDOS)
Xvoid dvimain(void);
X#else
Xvoid dvimain();
X#endif
END_OF_FILE
if test 3789 -ne `wc -c <'dvi2tty.h'`; then
    echo shar: \"'dvi2tty.h'\" unpacked with wrong size!
fi
# end of 'dvi2tty.h'
fi
if test -f 'dvi2tty.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dvi2tty.1'\"
else
echo shar: Extracting \"'dvi2tty.1'\" \(4291 characters\)
sed "s/^X//" >'dvi2tty.1' <<'END_OF_FILE'
X.TH DVI2TTY Local "7 June 1986"
X.SH NAME
Xdvi2tty \- preview a dvi\-file on an ordinary ascii terminal
X.SH SYNOPSIS
X.B dvi2tty
X[ options ] dvi\-file
X.SH DESCRIPTION
X.I dvi2tty
Xconverts a TeX DVI\-file to a format that is apprporiate for terminals
Xand lineprinters. The program is intended to be used for
Xpreliminary proofreading of TeX-ed documents.
XBy default the output is directed to the terminal,
Xpossibly through a pager (depending on how the program was installed),
Xbut it can be directed to a file or a pipe.
X.PP
XThe output leaves much to be desired, but is still
Xusefull if you want to avoid walking to the
Xlaserprinter (or whatever) for each iteration of your
Xdocument.
X.br
XSince
X.I dvi2tty
Xproduces output for terminals and lineprinters the
Xrepresentation of documents is naturally quite primitive.
XFontchanges are totally ignored, which implies that
Xspecial symbols, such as mathematical symbols, get mapped into the 
Xcharacters at the corresponding positions in the "standard" fonts.
X.PP
XIf the width of the output text requires more columns than fits
Xin one line (c.f. the \-w option) it is broken into several lines by
X.I dvi2tty
Xalthough they will be printed as one line on regular TeX output
Xdevices (e.g.laserprinters). To show that a broken line is really
Xjust one logical line an asterisk (``*'') in the last position
Xmeans that the logical line is continued on the next physical
Xline output by
X.I dvi2tty.
XSuch a continuation line is started with a a space and an asterisk
Xin the first two columns.
X.PP
XOptions may be specified in the environment variable DVI2TTY.
XAny option on the commandline, conflicting with one in the
Xenvironment, will override the one from the environment.
X.PP
X.B Options:
X.PP
X.TP
X.B \-o file
XWrite output to file ``file''.
X.TP
X.B \-p list
XPrint the pages chosen by list.
XNumbers refer to TeX\-page numbers (known as \\count0).
XAn example of format for list is ``1,3:6,8''
Xto choose pages 1, 3 through 6 and 8.
XNegative numbers can be used exactly as in TeX,
Xe g \-1 comes before \-4 as in ``\-p-1:-4,17''.
X.TP
X.B \-P list
XLike \-p except that page numbers refer to
Xthe sequential ordering of the pages in the dvi\-file.
XNegative numbers don't make a lot of sense here...
X.TP
X.B \-w n
XSpecify terminal width
X.I n.
XLegal range 16\-132.
XDefault is 80. If your terminal has the
Xability to display in 132 columns it might
Xbe a good idea to use \-w132 and toggle the
Xterminal into this mode as output will
Xprobably look somewhat better.
X.TP
X.B \-q
XDon't pipe the output through a pager.
XThis may be the default on some systems
X(depending on the whims of the SA installing the program).
X.TP
X.B \-f
XPipe through a pager, $PAGER if defined, or whatever your SA compiled
Xin (often ``more''). This may be the default, but it is still okay
Xto redirect output with ``>'', the pager will not be used if output
Xis not going to a terminal.
X.TP
X.B \-F
XSpecify the pager program to be used.
XThis overides the $PAGER and the default pager.
X.TP
X.B \-Fprog
XUse ``prog'' as program to pipe output into. Can be used to choose an
Xalternate pager (e g ``-Fless'').
X.TP
X.B \-l
XMark pagebreaks with the two-character sequence ``^L''. The default is
Xto mark them with a formfeed character.
X.TP
X.B \-u
XDon't make any attempts to find special Scandinavian characters.
XIf such characters are in the text they will map to ``a'' and ``o''.
XThis is probably the default outside of Scandinavia. (The SA made
Xthe decision when  the program was installed.)
X.TP
X.B \-s
XTry to find the special Scandinavian characters that on most (?)
Xterminals in Scandinavia are mapped to ``{|}[\\]''.
XThis can be the default, and output from files not containing these
Xspecial characters will be identical regardless of this option.
X.SH FILES
X/usr/ucb/more \ \ \ \ 
Xprobably the default pager.
X.SH ENVIRONMENT
XPAGER \ \ \ \ \ \ \ \ \ \ \ \ 
Xthe pager to use.
X.br
XDVI2TTY \ \ \ \ \ \ \ \ \ \ \ 
Xcan be set to hold commandline options.
X.SH "SEE ALSO"
XTeX, dvi2ps
X.SH AUTHOR
XSvante Lindahl, Royal Institute of Technology, Stockholm
X.br
XImproved C version: Marcel Mol
X.br
X{seismo, mcvax}!enea!ttds!zap
X.br
Xmarcel@duteca.UUCP
X.SH BUGS
XBlanks between words get lost quite easy. This is less
Xlikely if you are using a wider output than the default 80.
X.PP
XOnly one file may be specified on the commandline.
END_OF_FILE
if test 4291 -ne `wc -c <'dvi2tty.1'`; then
    echo shar: \"'dvi2tty.1'\" unpacked with wrong size!
fi
# end of 'dvi2tty.1'
fi
echo shar: End of archive 2 \(of 2\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
#########################################
# Marcel J.E. Mol                       ######################################
# Delft University of Technology          Pink Elephant Management Services  #
# The Netherlands                         Voorburg                           #
# UUCP: marcel@duteca.tudelft.nl          Tel: 070-694231                    #
#                                      	######################################
#########################################

marcel@duteca (Marcel Mol) (04/11/90)

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  difs
# Wrapped by marcel@duteca on Tue Mar 27 23:38:20 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'difs' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'difs'\"
else
echo shar: Extracting \"'difs'\" \(2348 characters\)
sed "s/^X//" >'difs' <<'END_OF_FILE'
X*** ORG/dvi2tty.c	Fri Mar  2 00:41:11 1990
X--- dvi2tty.c	Tue Mar 27 23:34:33 1990
X***************
X*** 1,4 ****
X--- 1,8 ----
X  /******************************************************************************
X+  * Marcel Mol: 1990-03-27  (UUCP: marcel@duteca.tudelft.nl)
X+  *               Fixed bug that causes the program to hang when it finds a
X+  *               fontname with an 's' in it not followed by an 'y'.
X+  *               Thanks to Paul Orgren (orgren@Stars.Reston.Unisys.COM).
X   * Marcel Mol: 1990-02-04  (UUCP: marcel@duteca.tudelft.nl)
X   *               First attempt to recognize symbol fonts, so bullets (in
X   *               itemized lists) are translated to a proper character instead
X***************
X*** 137,143 ****
X  #define onepp  8                /* only one page list allowed        */
X  #define noarg  9                /* argument expected                 */
X  
X! char *dvi2tty = "@(#) dvi2tty.c  4.0 04/02/90 M.J.E. Mol (c) 1989, 1990";
X  
X  /*---------------------------------------------------------------------------*/
X  
X--- 141,147 ----
X  #define onepp  8                /* only one page list allowed        */
X  #define noarg  9                /* argument expected                 */
X  
X! char *dvi2tty = "@(#) dvi2tty.c  4.1 27/03/90 M.J.E. Mol (c) 1989, 1990";
X  
X  /*---------------------------------------------------------------------------*/
X  
X*** ORG/dvistuff.c	Fri Mar  2 00:41:14 1990
X--- dvistuff.c	Tue Mar 27 23:29:28 1990
X***************
X*** 49,55 ****
X  #define sget3()         snum(3)
X  #define sget4()         snum(4)
X  
X! char *dvistuff = "@(#) dvistuff.c  4.0 04/02/90 M.J.E. Mol (c) 1989, 1990";
X  
X  /*---------------------------------------------------------------------------*/
X  
X--- 49,55 ----
X  #define sget3()         snum(3)
X  #define sget4()         snum(4)
X  
X! char *dvistuff = "@(#) dvistuff.c  4.1 27/03/90 M.J.E. Mol (c) 1989, 1990";
X  
X  /*---------------------------------------------------------------------------*/
X  
X***************
X*** 1036,1047 ****
X--- 1036,1049 ----
X              symbolfont = TRUE;
X              return;
X          }
X+ 	s++;	/* New line to fix bug; font names with 's' would hang */
X      }
X     
X      symbolfont = FALSE;
X      return;
X  
X  } /* setfont */
X+    
X  
X  
X  /*----------------------------------------------------------------------------*/
END_OF_FILE
if test 2348 -ne `wc -c <'difs'`; then
    echo shar: \"'difs'\" unpacked with wrong size!
fi
# end of 'difs'
fi
echo shar: End of shell archive.
exit 0
-- 
#########################################
# Marcel J.E. Mol                       ######################################
# Delft University of Technology          Pink Elephant Management Services  #
# The Netherlands                         Voorburg                           #
# UUCP: marcel@duteca.tudelft.nl          Tel: 070-694231                    #
#                                      	######################################
#########################################