\input webmac
% This is DVIDOC, a TeX device driver for text files.  It was written
% at OSU in April, 1983, by modifying the TeX utility DVItype.
% Modified to work under 4.3 BSD by Ken Yap (ken@cs.rochester.edu)

% Here is TeX material that gets inserted after \input webmac
\def\hang{\hangindent 3em\indent\ignorespaces}
\font\ninerm=cmr9
\let\mc=\ninerm % medium caps for names like SAIL
\def\PASCAL{Pascal}

\def\(#1){} % this is used to make section names sort themselves better
\def\9#1{} % this is used for sort keys in the index

\def\title{DVIDOC}
\def\contentspagenumber{1}
\def\topofcontents{\null
  \def\titlepage{F} % include headline on the contents page
  \def\rheader{\mainfont\hfil \contentspagenumber}
  \vfill
  \centerline{\titlefont The {\ttitlefont DVIDOC} processor}
  \vskip 15pt
  \centerline{(Version 2, July 1987)}
  \vfill}
\def\botofcontents{\vfill
  \centerline{\hsize 5in\baselineskip9pt
    \vbox{\ninerm\noindent
   `\TeX' is a
    trademark of the American Mathematical Society.}}}
\pageno=\contentspagenumber \advance\pageno by 1


\N1.  Introduction.
The \.{DVIDOC} utility program reads binary device-independent (``\.{DVI}'')
files that are produced by document compilers such as \TeX, and
approximates the intended document as a text file suitable for typing at
a terminal or on a line printer.

This program is based on the program \.{DVItype}, which was written by
Donald Knuth and David Fuchs.
It contained a great deal of code checking for malformed \.{DVI}
files.  Most of that code remains in \.{DVIDOC}, not because it is
important (we trust \TeX) to produce correct \.{DVI} files), but
because is was easier not to disturb the logic in modifying
\.{DVItype} to produce \.{DVIDOC}.

The \\{banner} string defined here should be changed whenever \.{DVIDOC}
gets modified.

\Y\P\D \37$\\{banner}\S\.{\'This\ is\ DVIDOC,\ Version\ 2\ for\ 4.3\ BSD\'}$%
\C{printed when the program starts}\par
\fi

\M2. This program is written in standard \PASCAL, except where it is necessary
to use extensions; for example, \.{DVIDOC} must read files whose names
are dynamically specified, and that would be impossible in pure \PASCAL.
All places where nonstandard constructions are used have been listed in
the index under ``system dependencies.''

One of the extensions to standard \PASCAL\ that we shall deal with is the
ability to move to a random place in a binary file.

Another extension is to use a default   \&{case}  as in \.{TANGLE}, \.{WEAVE},
etc.

\Y\P\D \37$\\{othercases}\S\\{others}$: \37\C{default for cases not listed
explicitly}\par
\P\D \37$\\{endcases}\S$\ \&{end} \C{follows the default case in an extended   %
\&{case}  statement}\par
\P\F \37$\\{othercases}\S\\{else}$\par
\P\F \37$\\{endcases}\S\\{end}$\par
\fi

\M3. The binary input comes from \\{dvi\_file}, and the symbolic output is
written
to stdout. The term \\{print} is used instead of
\\{write} when this program writes on \\{err\_file}, so that all such output
could easily be redirected if desired.

\Y\P\D \37$\\{print}(\#)\S\\{write}(\\{err\_file},\39\#)$\par
\P\D \37$\\{print\_ln}(\#)\S\\{write\_ln}(\\{err\_file},\39\#)$\par
\P\D \37$\\{error}(\#)\S\\{print\_ln}(\#)$\par
\P\D \37$\\{doc\_file}\S\\{output}$\par
\P\D \37$\\{eof}(\#)\S\\{eof\_dvi\_file}$\par
\Y\P\4\&{program}\1\  \37$\\{DVIDOC}(\\{input},\39\\{output},\39\\{dvi\_file},%
\39\\{err\_file})$;\6
\4\&{label} \37\X4:Labels in the outer block\X\6
\4\&{const} \37\X5:Constants in the outer block\X\6
\4\&{type} \37\X9:Types in the outer block\X\6
\4\&{var} \37\X11:Globals in the outer block\X\6
\]\={\#include\ "dvityext.h"}\]\C{declarations for external C procedures}\6
\4\&{procedure}\1\  \37\\{initialize};\C{this procedure gets things started
properly}\6
\4\&{var} \37\|i: \37\\{integer};\2\6
\&{begin} \37\\{setpaths};\5
\X12:Set initial values\X\6
\&{end};\par
\fi

\M4. If the program has to stop prematurely, it goes to the
`\\{final\_end}'. Another label, \\{done}, is used when stopping normally.

\Y\P\D \37$\\{final\_end}=9999$\C{label for the end of it all}\par
\P\D \37$\\{done}=30$\C{go here when finished with a subtask}\par
\Y\P$\4\X4:Labels in the outer block\X\S$\6
$\\{final\_end},\39\\{done}$;\par
\U3.\fi

\M5. The following parameters can be changed at compile time to extend or
reduce \.{DVIDOC}'s capacity.

\Y\P$\4\X5:Constants in the outer block\X\S$\6
$\\{max\_fonts}=100$;\C{maximum number of distinct fonts per \.{DVI} file}\6
$\\{max\_widths}=10000$;\C{maximum number of different characters among all
fonts}\6
$\\{terminal\_line\_length}=150$;\C{maximum number of characters input in a
single   line of input from the terminal}\6
$\\{stack\_size}=100$;\C{\.{DVI} files shouldn't \\{push} beyond this depth}\6
$\\{name\_size}=1000$;\C{total length of all font file names}\6
$\\{name\_length}=100$;\C{a file name shouldn't be longer than this}\6
$\\{page\_width\_max}=132$;\C{maximum number of characters per line in the
document}\6
$\\{page\_length\_max}=88$;\C{maximum number of lines per page in the document}%
\par
\U3.\fi

\M6. Here are some macros for common programming idioms.

\Y\P\D \37$\\{incr}(\#)\S\#\K\#+1$\C{increase a variable by unity}\par
\P\D \37$\\{decr}(\#)\S\#\K\#-1$\C{decrease a variable by unity}\par
\P\D \37$\\{do\_nothing}\S$\C{empty statement}\par
\fi

\M7. If the \.{DVI} file is badly malformed, the whole process must be aborted;
\.{DVIDOC} will give up, after issuing an error message about the symptoms
that were noticed.

Such errors might be discovered inside of subroutines inside of subroutines,
so a procedure called \\{jump\_out} has been introduced. This procedure, which
simply transfers control to the label \\{final\_end} at the end of the program,
contains the only non-local \&{goto}  statement in \.{DVIDOC}.

\Y\P\D \37$\\{abort}(\#)\S$\1\6
\&{begin} \37$\\{message}(\.{\'\ \'},\39\#)$;\5
\\{jump\_out};\6
\&{end}\2\par
\P\D \37$\\{bad\_dvi}(\#)\S\\{abort}(\.{\'Bad\ DVI\ file:\ \'},\39\#,\39\.{\'!%
\'})$\par
\Y\P\4\&{procedure}\1\  \37\\{jump\_out};\2\6
\&{begin} \37\&{goto} \37\\{final\_end};\6
\&{end};\par
\fi

\M8. If the wrong options have been given to \.{DVIDOC}, we print a reminder
message and exit.

\Y\P\D \37$\\{cannot\_start}(\#)\S$\1\6
\&{begin} \37$\\{message}(\#)$;\5
\&{goto} \37\\{done}\6
\&{end}\2\par
\fi

\N9.  The character set.
Like all programs written with the  \.{WEB} system, \.{DVIDOC} can be
used with any character set. But it uses ASCII code internally, because
the programming for portable input-output is easier when a fixed internal
code is used, and because \.{DVI} files use ASCII code for file names
and certain other strings.

The next few modules of \.{DVIDOC} have therefore been copied from the
analogous ones in the \.{WEB} system routines. They have been considerably
simplified, since \.{DVIDOC} need not deal with the controversial
ASCII codes less than \O{40}. If such codes appear in the \.{DVI} file,
they will be printed as question marks.

\Y\P$\4\X9:Types in the outer block\X\S$\6
$\\{ASCII\_code}=\.{"\ "}\to\.{"\~"}$;\C{a subrange of the integers}\par
\As10\ET22.
\U3.\fi

\M10. The original \PASCAL\ compiler was designed in the late 60s, when six-bit
character sets were common, so it did not make provision for lower case
letters. Nowadays, of course, we need to deal with both upper and lower case
alphabets in a convenient way, especially in a program like \.{DVIDOC}.
So we shall assume that the \PASCAL\ system being used for \.{DVIDOC}
has a character set containing at least the standard visible characters
of ASCII code (\.{"!"} through \.{"\~"}).

Some \PASCAL\ compilers use the original name \\{char} for the data type
associated with the characters in text files, while other \PASCAL s
consider \\{char} to be a 64-element subrange of a larger data type that has
some other name.  In order to accommodate this difference, we shall use
the name \\{text\_char} to stand for the data type of the characters in the
output file.  We shall also assume that \\{text\_char} consists of
the elements $\\{chr}(\\{first\_text\_char})$ through $\\{chr}(\\{last\_text%
\_char})$,
inclusive. The following definitions should be adjusted if necessary.

\Y\P\D \37$\\{text\_char}\S\\{char}$\C{the data type of characters in text
files}\par
\P\D \37$\\{first\_text\_char}=0$\C{ordinal number of the smallest element of %
\\{text\_char}}\par
\P\D \37$\\{last\_text\_char}=127$\C{ordinal number of the largest element of %
\\{text\_char}}\par
\Y\P$\4\X9:Types in the outer block\X\mathrel{+}\S$\6
$\\{text\_file}=$\1\5
\&{packed} \37\&{file} \1\&{of}\5
\\{text\_char};\2\2\par
\fi

\M11. The \.{DVIDOC} processor converts between ASCII code and
the user's external character set by means of arrays \\{xord} and \\{xchr}
that are analogous to \PASCAL's \\{ord} and \\{chr} functions.

\Y\P$\4\X11:Globals in the outer block\X\S$\6
\4\\{xord}: \37\&{array} $[\\{text\_char}]$ \1\&{of}\5
\\{ASCII\_code};\C{specifies conversion of input characters}\2\6
\4\\{xchr}: \37\&{array} $[0\to255]$ \1\&{of}\5
\\{text\_char};\C{specifies conversion of output characters}\2\par
\As23, 27, 28, 32, 35, 41, 43, 44, 47, 49, 54, 61, 64, 70, 71, 76, 93, 97%
\ETs103.
\U3.\fi

\M12. Under our assumption that the visible characters of standard ASCII are
all present, the following assignment statements initialize the
\\{xchr} array properly, without needing any system-dependent changes.

\Y\P$\4\X12:Set initial values\X\S$\6
\&{for} $\|i\K0\mathrel{\&{to}}\O{37}$ \1\&{do}\5
$\\{xchr}[\|i]\K\.{\'?\'}$;\2\6
$\\{xchr}[\O{40}]\K\.{\'\ \'}$;\5
$\\{xchr}[\O{41}]\K\.{\'!\'}$;\5
$\\{xchr}[\O{42}]\K\.{\'"\'}$;\5
$\\{xchr}[\O{43}]\K\.{\'\#\'}$;\5
$\\{xchr}[\O{44}]\K\.{\'\$\'}$;\5
$\\{xchr}[\O{45}]\K\.{\'\%\'}$;\5
$\\{xchr}[\O{46}]\K\.{\'\&\'}$;\5
$\\{xchr}[\O{47}]\K\.{\'\'}\.{\'\'}$;\6
$\\{xchr}[\O{50}]\K\.{\'(\'}$;\5
$\\{xchr}[\O{51}]\K\.{\')\'}$;\5
$\\{xchr}[\O{52}]\K\.{\'*\'}$;\5
$\\{xchr}[\O{53}]\K\.{\'+\'}$;\5
$\\{xchr}[\O{54}]\K\.{\',\'}$;\5
$\\{xchr}[\O{55}]\K\.{\'-\'}$;\5
$\\{xchr}[\O{56}]\K\.{\'.\'}$;\5
$\\{xchr}[\O{57}]\K\.{\'/\'}$;\6
$\\{xchr}[\O{60}]\K\.{\'0\'}$;\5
$\\{xchr}[\O{61}]\K\.{\'1\'}$;\5
$\\{xchr}[\O{62}]\K\.{\'2\'}$;\5
$\\{xchr}[\O{63}]\K\.{\'3\'}$;\5
$\\{xchr}[\O{64}]\K\.{\'4\'}$;\5
$\\{xchr}[\O{65}]\K\.{\'5\'}$;\5
$\\{xchr}[\O{66}]\K\.{\'6\'}$;\5
$\\{xchr}[\O{67}]\K\.{\'7\'}$;\6
$\\{xchr}[\O{70}]\K\.{\'8\'}$;\5
$\\{xchr}[\O{71}]\K\.{\'9\'}$;\5
$\\{xchr}[\O{72}]\K\.{\':\'}$;\5
$\\{xchr}[\O{73}]\K\.{\';\'}$;\5
$\\{xchr}[\O{74}]\K\.{\'<\'}$;\5
$\\{xchr}[\O{75}]\K\.{\'=\'}$;\5
$\\{xchr}[\O{76}]\K\.{\'>\'}$;\5
$\\{xchr}[\O{77}]\K\.{\'?\'}$;\6
$\\{xchr}[\O{100}]\K\.{\'@\'}$;\5
$\\{xchr}[\O{101}]\K\.{\'A\'}$;\5
$\\{xchr}[\O{102}]\K\.{\'B\'}$;\5
$\\{xchr}[\O{103}]\K\.{\'C\'}$;\5
$\\{xchr}[\O{104}]\K\.{\'D\'}$;\5
$\\{xchr}[\O{105}]\K\.{\'E\'}$;\5
$\\{xchr}[\O{106}]\K\.{\'F\'}$;\5
$\\{xchr}[\O{107}]\K\.{\'G\'}$;\6
$\\{xchr}[\O{110}]\K\.{\'H\'}$;\5
$\\{xchr}[\O{111}]\K\.{\'I\'}$;\5
$\\{xchr}[\O{112}]\K\.{\'J\'}$;\5
$\\{xchr}[\O{113}]\K\.{\'K\'}$;\5
$\\{xchr}[\O{114}]\K\.{\'L\'}$;\5
$\\{xchr}[\O{115}]\K\.{\'M\'}$;\5
$\\{xchr}[\O{116}]\K\.{\'N\'}$;\5
$\\{xchr}[\O{117}]\K\.{\'O\'}$;\6
$\\{xchr}[\O{120}]\K\.{\'P\'}$;\5
$\\{xchr}[\O{121}]\K\.{\'Q\'}$;\5
$\\{xchr}[\O{122}]\K\.{\'R\'}$;\5
$\\{xchr}[\O{123}]\K\.{\'S\'}$;\5
$\\{xchr}[\O{124}]\K\.{\'T\'}$;\5
$\\{xchr}[\O{125}]\K\.{\'U\'}$;\5
$\\{xchr}[\O{126}]\K\.{\'V\'}$;\5
$\\{xchr}[\O{127}]\K\.{\'W\'}$;\6
$\\{xchr}[\O{130}]\K\.{\'X\'}$;\5
$\\{xchr}[\O{131}]\K\.{\'Y\'}$;\5
$\\{xchr}[\O{132}]\K\.{\'Z\'}$;\5
$\\{xchr}[\O{133}]\K\.{\'[\'}$;\5
$\\{xchr}[\O{134}]\K\.{\'\\\'}$;\5
$\\{xchr}[\O{135}]\K\.{\']\'}$;\5
$\\{xchr}[\O{136}]\K\.{\'\^\'}$;\5
$\\{xchr}[\O{137}]\K\.{\'\_\'}$;\6
$\\{xchr}[\O{140}]\K\.{\'\`\'}$;\5
$\\{xchr}[\O{141}]\K\.{\'a\'}$;\5
$\\{xchr}[\O{142}]\K\.{\'b\'}$;\5
$\\{xchr}[\O{143}]\K\.{\'c\'}$;\5
$\\{xchr}[\O{144}]\K\.{\'d\'}$;\5
$\\{xchr}[\O{145}]\K\.{\'e\'}$;\5
$\\{xchr}[\O{146}]\K\.{\'f\'}$;\5
$\\{xchr}[\O{147}]\K\.{\'g\'}$;\6
$\\{xchr}[\O{150}]\K\.{\'h\'}$;\5
$\\{xchr}[\O{151}]\K\.{\'i\'}$;\5
$\\{xchr}[\O{152}]\K\.{\'j\'}$;\5
$\\{xchr}[\O{153}]\K\.{\'k\'}$;\5
$\\{xchr}[\O{154}]\K\.{\'l\'}$;\5
$\\{xchr}[\O{155}]\K\.{\'m\'}$;\5
$\\{xchr}[\O{156}]\K\.{\'n\'}$;\5
$\\{xchr}[\O{157}]\K\.{\'o\'}$;\6
$\\{xchr}[\O{160}]\K\.{\'p\'}$;\5
$\\{xchr}[\O{161}]\K\.{\'q\'}$;\5
$\\{xchr}[\O{162}]\K\.{\'r\'}$;\5
$\\{xchr}[\O{163}]\K\.{\'s\'}$;\5
$\\{xchr}[\O{164}]\K\.{\'t\'}$;\5
$\\{xchr}[\O{165}]\K\.{\'u\'}$;\5
$\\{xchr}[\O{166}]\K\.{\'v\'}$;\5
$\\{xchr}[\O{167}]\K\.{\'w\'}$;\6
$\\{xchr}[\O{170}]\K\.{\'x\'}$;\5
$\\{xchr}[\O{171}]\K\.{\'y\'}$;\5
$\\{xchr}[\O{172}]\K\.{\'z\'}$;\5
$\\{xchr}[\O{173}]\K\.{\'\{\'}$;\5
$\\{xchr}[\O{174}]\K\.{\'|\'}$;\5
$\\{xchr}[\O{175}]\K\.{\'\}\'}$;\5
$\\{xchr}[\O{176}]\K\.{\'\~\'}$;\6
\&{for} $\|i\K\O{177}\mathrel{\&{to}}255$ \1\&{do}\5
$\\{xchr}[\|i]\K\.{\'?\'}$;\2\par
\As13, 33, 45, 55, 62, 72\ETs94.
\U3.\fi

\M13. The following system-independent code makes the \\{xord} array contain a
suitable inverse to the information in \\{xchr}.

\Y\P$\4\X12:Set initial values\X\mathrel{+}\S$\6
\&{for} $\|i\K\\{first\_text\_char}\mathrel{\&{to}}\\{last\_text\_char}$ \1%
\&{do}\5
$\\{xord}[\\{chr}(\|i)]\K\O{40}$;\2\6
\&{for} $\|i\K\.{"\ "}\mathrel{\&{to}}\.{"\~"}$ \1\&{do}\5
$\\{xord}[\\{xchr}[\|i]]\K\|i$;\2\par
\fi

\N14.  Device-independent file format.
Before we get into the details of \.{DVItype}, we need to know exactly
what \.{DVI} files are. The form of such files was designed by David R.
Fuchs in 1979. Almost any reasonable typesetting device can be driven by
a program that takes \.{DVI} files as input, and dozens of such
\.{DVI}-to-whatever programs have been written. Thus, it is possible to
print the output of document compilers like \TeX\ on many different kinds
of equipment.

A \.{DVI} file is a stream of 8-bit bytes, which may be regarded as a
series of commands in a machine-like language. The first byte of each command
is the operation code, and this code is followed by zero or more bytes
that provide parameters to the command. The parameters themselves may consist
of several consecutive bytes; for example, the `\\{set\_rule}' command has two
parameters, each of which is four bytes long. Parameters are usually
regarded as nonnegative integers; but four-byte-long parameters,
and shorter parameters that denote distances, can be
either positive or negative. Such parameters are given in two's complement
notation. For example, a two-byte-long distance parameter has a value between
$-2^{15}$ and $2^{15}-1$.

A \.{DVI} file consists of a ``preamble,'' followed by a sequence of one
or more ``pages,'' followed by a ``postamble.'' The preamble is simply a
\\{pre} command, with its parameters that define the dimensions used in the
file; this must come first.  Each ``page'' consists of a \\{bop} command,
followed by any number of other commands that tell where characters are to
be placed on a physical page, followed by an \\{eop} command. The pages
appear in the order that they were generated, not in any particular
numerical order. If we ignore \\{nop} commands and \\{fnt\_def} commands
(which are allowed between any two commands in the file), each \\{eop}
command is immediately followed by a \\{bop} command, or by a \\{post}
command; in the latter case, there are no more pages in the file, and the
remaining bytes form the postamble.  Further details about the postamble
will be explained later.

Some parameters in \.{DVI} commands are ``pointers.'' These are four-byte
quantities that give the location number of some other byte in the file;
the first byte is number~0, then comes number~1, and so on. For example,
one of the parameters of a \\{bop} command points to the previous \\{bop};
this makes it feasible to read the pages in backwards order, in case the
results are being directed to a device that stacks its output face up.
Suppose the preamble of a \.{DVI} file occupies bytes 0 to 99. Now if the
first page occupies bytes 100 to 999, say, and if the second
page occupies bytes 1000 to 1999, then the \\{bop} that starts in byte 1000
points to 100 and the \\{bop} that starts in byte 2000 points to 1000. (The
very first \\{bop}, i.e., the one that starts in byte 100, has a pointer of
$-1$.)

\fi

\M15. The \.{DVI} format is intended to be both compact and easily interpreted
by a machine. Compactness is achieved by making most of the information
implicit instead of explicit. When a \.{DVI}-reading program reads the
commands for a page, it keeps track of several quantities: (a)~The current
font \|f is an integer; this value is changed only
by \\{fnt} and \\{fnt\_num} commands. (b)~The current position on the page
is given by two numbers called the horizontal and vertical coordinates,
\|h and \|v. Both coordinates are zero at the upper left corner of the page;
moving to the right corresponds to increasing the horizontal coordinate, and
moving down corresponds to increasing the vertical coordinate. Thus, the
coordinates are essentially Cartesian, except that vertical directions are
flipped; the Cartesian version of $(\|h,\|v)$ would be $(\|h,-\|v)$.  (c)~The
current spacing amounts are given by four numbers \|w, \|x, \|y, and \|z,
where \|w and~\|x are used for horizontal spacing and where \|y and~\|z
are used for vertical spacing. (d)~There is a stack containing
$(\|h,\|v,\|w,\|x,\|y,\|z)$ values; the \.{DVI} commands \\{push} and \\{pop}
are used to
change the current level of operation. Note that the current font~\|f is
not pushed and popped; the stack contains only information about
positioning.

The values of \|h, \|v, \|w, \|x, \|y, and \|z are signed integers having up
to 32 bits, including the sign. Since they represent physical distances,
there is a small unit of measurement such that increasing \|h by~1 means
moving a certain tiny distance to the right. The actual unit of
measurement is variable, as explained below.

\fi

\M16. Here is a list of all the commands that may appear in a \.{DVI} file.
Each
command is specified by its symbolic name (e.g., \\{bop}), its opcode byte
(e.g., 139), and its parameters (if any). The parameters are followed
by a bracketed number telling how many bytes they occupy; for example,
`$\|p[4]$' means that parameter \|p is four bytes long.

\yskip\hang\\{set\_char\_0} 0. Typeset character number~0 from font~\|f
such that the reference point of the character is at $(\|h,\|v)$. Then
increase \|h by the width of that character. Note that a character may
have zero or negative width, so one cannot be sure that \|h will advance
after this command; but \|h usually does increase.

\yskip\hang\\{set\_char\_1} through \\{set\_char\_127} (opcodes 1 to 127).
Do the operations of \\{set\_char\_0}; but use the character whose number
matches the opcode, instead of character~0.

\yskip\hang\\{set1} 128 $\|c[1]$. Same as \\{set\_char\_0}, except that
character
number~\|c is typeset. \TeX82 uses this command for characters in the
range $128\L\|c<256$.

\yskip\hang\\{set2} 129 $\|c[2]$. Same as \\{set1}, except that \|c~is two
bytes long, so it is in the range $0\L\|c<65536$. \TeX82 never uses this
command, which is intended for processors that deal with oriental languages;
but \.{DVItype} will allow character codes greater than 255, assuming that
they all have the same width as the character whose code is $c \bmod 256$.

\yskip\hang\\{set3} 130 $\|c[3]$. Same as \\{set1}, except that \|c~is three
bytes long, so it can be as large as $2^{24}-1$.

\yskip\hang\\{set4} 131 $\|c[4]$. Same as \\{set1}, except that \|c~is four
bytes long, possibly even negative. Imagine that.

\yskip\hang\\{set\_rule} 132 $\|a[4]$ $\|b[4]$. Typeset a solid black rectangle
of height \|a and width \|b, with its bottom left corner at $(\|h,\|v)$. Then
set $\|h\K\|h+\|b$. If either $\|a\L0$ or $\|b\L0$, nothing should be typeset.
Note
that if $\|b<0$, the value of \|h will decrease even though nothing else
happens.
Programs that typeset from \.{DVI} files should be careful to make the rules
line up carefully with digitized characters, as explained in connection with
the \\{rule\_pixels} subroutine below.

\yskip\hang\\{put1} 133 $\|c[1]$. Typeset character number~\|c from font~\|f
such that the reference point of the character is at $(\|h,\|v)$. (The `put'
commands are exactly like the `set' commands, except that they simply put out a
character or a rule without moving the reference point afterwards.)

\yskip\hang\\{put2} 134 $\|c[2]$. Same as \\{set2}, except that \|h is not
changed.

\yskip\hang\\{put3} 135 $\|c[3]$. Same as \\{set3}, except that \|h is not
changed.

\yskip\hang\\{put4} 136 $\|c[4]$. Same as \\{set4}, except that \|h is not
changed.

\yskip\hang\\{put\_rule} 137 $\|a[4]$ $\|b[4]$. Same as \\{set\_rule}, except
that
\|h is not changed.

\yskip\hang\\{nop} 138. No operation, do nothing. Any number of \\{nop}'s
may occur between \.{DVI} commands, but a \\{nop} cannot be inserted between
a command and its parameters or between two parameters.

\yskip\hang\\{bop} 139 $c_0[4]$ $c_1[4]$ $\ldots$ $c_9[4]$ $p[4]$. Beginning
of a page: Set $(\|h,\|v,\|w,\|x,\|y,\|z)\K(0,0,0,0,0,0)$ and set the stack
empty. Set
the current font \|f to an undefined value.  The ten $c_i$ parameters can
be used to identify pages, if a user wants to print only part of a \.{DVI}
file; \TeX82 gives them the values of \.{\\count0} $\ldots$ \.{\\count9}
at the time \.{\\shipout} was invoked for this page.  The parameter \|p
points to the previous \\{bop} command in the file, where the first \\{bop}
has $p=-1$.

\yskip\hang\\{eop} 140.  End of page: Print what you have read since the
previous \\{bop}. At this point the stack should be empty. (The \.{DVI}-reading
programs that drive most output devices will have kept a buffer of the
material that appears on the page that has just ended. This material is
largely, but not entirely, in order by \|v coordinate and (for fixed \|v) by
\|h~coordinate; so it usually needs to be sorted into some order that is
appropriate for the device in question. \.{DVItype} does not do such sorting.)

\yskip\hang\\{push} 141. Push the current values of $(\|h,\|v,\|w,\|x,\|y,\|z)$
onto the
top of the stack; do not change any of these values. Note that \|f is
not pushed.

\yskip\hang\\{pop} 142. Pop the top six values off of the stack and assign
them to $(\|h,\|v,\|w,\|x,\|y,\|z)$. The number of pops should never exceed the
number
of pushes, since it would be highly embarrassing if the stack were empty
at the time of a \\{pop} command.

\yskip\hang\\{right1} 143 $\|b[1]$. Set $\|h\K\|h+\|b$, i.e., move right \|b
units.
The parameter is a signed number in two's complement notation, $-128\L\|b<128$;
if $\|b<0$, the reference point actually moves left.

\yskip\hang\\{right2} 144 $\|b[2]$. Same as \\{right1}, except that \|b is a
two-byte quantity in the range $-32768\L\|b<32768$.

\yskip\hang\\{right3} 145 $\|b[3]$. Same as \\{right1}, except that \|b is a
three-byte quantity in the range $\hbox{$-2^{23}$}\L\|b<\hbox{$2^{23}$}$.

\yskip\hang\\{right4} 146 $\|b[4]$. Same as \\{right1}, except that \|b is a
four-byte quantity in the range $\hbox{$-2^{31}$}\L\|b<\hbox{$2^{31}$}$.

\yskip\hang\\{w0} 147. Set $\|h\K\|h+\|w$; i.e., move right \|w units. With
luck,
this parameterless command will usually suffice, because the same kind of
motion
will occur several times in succession; the following commands explain how
\|w gets particular values.

\yskip\hang\\{w1} 148 $\|b[1]$. Set $\|w\K\|b$ and $\|h\K\|h+\|b$. The value of
\|b is a
signed quantity in two's complement notation, $-128\L\|b<128$. This command
changes the current \|w~spacing and moves right by \|b.

\yskip\hang\\{w2} 149 $\|b[2]$. Same as \\{w1}, but \|b is a two-byte-long
parameter, $-32768\L\|b<32768$.

\yskip\hang\\{w3} 150 $\|b[3]$. Same as \\{w1}, but \|b is a three-byte-long
parameter, $\hbox{$-2^{23}$}\L\|b<\hbox{$2^{23}$}$.

\yskip\hang\\{w4} 151 $\|b[4]$. Same as \\{w1}, but \|b is a four-byte-long
parameter, $\hbox{$-2^{31}$}\L\|b<\hbox{$2^{31}$}$.

\yskip\hang\\{x0} 152. Set $\|h\K\|h+\|x$; i.e., move right \|x units. The `%
\|x'
commands are like the `\|w' commands except that they involve \|x instead
of \|w.

\yskip\hang\\{x1} 153 $\|b[1]$. Set $\|x\K\|b$ and $\|h\K\|h+\|b$. The value of
\|b is a
signed quantity in two's complement notation, $-128\L\|b<128$. This command
changes the current \|x~spacing and moves right by \|b.

\yskip\hang\\{x2} 154 $\|b[2]$. Same as \\{x1}, but \|b is a two-byte-long
parameter, $-32768\L\|b<32768$.

\yskip\hang\\{x3} 155 $\|b[3]$. Same as \\{x1}, but \|b is a three-byte-long
parameter, $\hbox{$-2^{23}$}\L\|b<\hbox{$2^{23}$}$.

\yskip\hang\\{x4} 156 $\|b[4]$. Same as \\{x1}, but \|b is a four-byte-long
parameter, $\hbox{$-2^{31}$}\L\|b<\hbox{$2^{31}$}$.

\yskip\hang\\{down1} 157 $\|a[1]$. Set $\|v\K\|v+\|a$, i.e., move down \|a
units.
The parameter is a signed number in two's complement notation, $-128\L\|a<128$;
if $\|a<0$, the reference point actually moves up.

\yskip\hang\\{down2} 158 $\|a[2]$. Same as \\{down1}, except that \|a is a
two-byte quantity in the range $-32768\L\|a<32768$.

\yskip\hang\\{down3} 159 $\|a[3]$. Same as \\{down1}, except that \|a is a
three-byte quantity in the range $\hbox{$-2^{23}$}\L\|a<\hbox{$2^{23}$}$.

\yskip\hang\\{down4} 160 $\|a[4]$. Same as \\{down1}, except that \|a is a
four-byte quantity in the range $\hbox{$-2^{31}$}\L\|a<\hbox{$2^{31}$}$.

\yskip\hang\\{y0} 161. Set $\|v\K\|v+\|y$; i.e., move down \|y units. With
luck,
this parameterless command will usually suffice, because the same kind of
motion
will occur several times in succession; the following commands explain how
\|y gets particular values.

\yskip\hang\\{y1} 162 $\|a[1]$. Set $\|y\K\|a$ and $\|v\K\|v+\|a$. The value of
\|a is a
signed quantity in two's complement notation, $-128\L\|a<128$. This command
changes the current \|y~spacing and moves down by \|a.

\yskip\hang\\{y2} 163 $\|a[2]$. Same as \\{y1}, but \|a is a two-byte-long
parameter, $-32768\L\|a<32768$.

\yskip\hang\\{y3} 164 $\|a[3]$. Same as \\{y1}, but \|a is a three-byte-long
parameter, $\hbox{$-2^{23}$}\L\|a<\hbox{$2^{23}$}$.

\yskip\hang\\{y4} 165 $\|a[4]$. Same as \\{y1}, but \|a is a four-byte-long
parameter, $\hbox{$-2^{31}$}\L\|a<\hbox{$2^{31}$}$.

\yskip\hang\\{z0} 166. Set $\|v\K\|v+\|z$; i.e., move down \|z units. The `\|z'
commands
are like the `\|y' commands except that they involve \|z instead of \|y.

\yskip\hang\\{z1} 167 $\|a[1]$. Set $\|z\K\|a$ and $\|v\K\|v+\|a$. The value of
\|a is a
signed quantity in two's complement notation, $-128\L\|a<128$. This command
changes the current \|z~spacing and moves down by \|a.

\yskip\hang\\{z2} 168 $\|a[2]$. Same as \\{z1}, but \|a is a two-byte-long
parameter, $-32768\L\|a<32768$.

\yskip\hang\\{z3} 169 $\|a[3]$. Same as \\{z1}, but \|a is a three-byte-long
parameter, $\hbox{$-2^{23}$}\L\|a<\hbox{$2^{23}$}$.

\yskip\hang\\{z4} 170 $\|a[4]$. Same as \\{z1}, but \|a is a four-byte-long
parameter, $\hbox{$-2^{31}$}\L\|a<\hbox{$2^{31}$}$.

\yskip\hang\\{fnt\_num\_0} 171. Set $\|f\K0$. Font 0 must previously have been
defined by a \\{fnt\_def} instruction, as explained below.

\yskip\hang\\{fnt\_num\_1} through \\{fnt\_num\_63} (opcodes 172 to 234). Set
$\|f\K1$, \dots, $\|f\K63$, respectively.

\yskip\hang\\{fnt1} 235 $\|k[1]$. Set $\|f\K\|k$. \TeX82 uses this command for
font
numbers in the range $64\L\|k<256$.

\yskip\hang\\{fnt2} 236 $\|k[2]$. Same as \\{fnt1}, except that \|k~is two
bytes long, so it is in the range $0\L\|k<65536$. \TeX82 never generates this
command, but large font numbers may prove useful for specifications of
color or texture, or they may be used for special fonts that have fixed
numbers in some external coding scheme.

\yskip\hang\\{fnt3} 237 $\|k[3]$. Same as \\{fnt1}, except that \|k~is three
bytes long, so it can be as large as $2^{24}-1$.

\yskip\hang\\{fnt4} 238 $\|k[4]$. Same as \\{fnt1}, except that \|k~is four
bytes long; this is for the really big font numbers (and for the negative
ones).

\yskip\hang\\{xxx1} 239 $\|k[1]$ $\|x[\|k]$. This command is undefined in
general; it functions as a $(k+2)$-byte \\{nop} unless special \.{DVI}-reading
programs are being used. \TeX82 generates \\{xxx1} when a short enough
\.{\\special} appears, setting \|k to the number of bytes being sent. It
is recommended that \|x be a string having the form of a keyword followed
by possible parameters relevant to that keyword.

\yskip\hang\\{xxx2} 240 $\|k[2]$ $\|x[\|k]$. Like \\{xxx1}, but $0\L\|k<65536$.

\yskip\hang\\{xxx3} 241 $\|k[3]$ $\|x[\|k]$. Like \\{xxx1}, but $0\L\|k<%
\hbox{$2^{24}$}$.

\yskip\hang\\{xxx4} 242 $\|k[4]$ $\|x[\|k]$. Like \\{xxx1}, but \|k can be
ridiculously
large. \TeX82 uses \\{xxx4} when \\{xxx1} would be incorrect.

\yskip\hang\\{fnt\_def1} 243 $\|k[1]$ $\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $%
\|l[1]$ $\|n[\|a+\|l]$.
Define font \|k, where $0\L\|k<256$; font definitions will be explained
shortly.

\yskip\hang\\{fnt\_def2} 244 $\|k[2]$ $\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $%
\|l[1]$ $\|n[\|a+\|l]$.
Define font \|k, where $0\L\|k<65536$.

\yskip\hang\\{fnt\_def3} 245 $\|k[3]$ $\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $%
\|l[1]$ $\|n[\|a+\|l]$.
Define font \|k, where $0\L\|k<\hbox{$2^{24}$}$.

\yskip\hang\\{fnt\_def4} 246 $\|k[4]$ $\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $%
\|l[1]$ $\|n[\|a+\|l]$.
Define font \|k, where $\hbox{$-2^{31}$}\L\|k<\hbox{$2^{31}$}$.

\yskip\hang\\{pre} 247 $\|i[1]$ $\\{num}[4]$ $\\{den}[4]$ $\\{mag}[4]$ $\|k[1]$
$\|x[\|k]$.
Beginning of the preamble; this must come at the very beginning of the
file. Parameters \|i, \\{num}, \\{den}, \\{mag}, \|k, and \|x are explained
below.

\yskip\hang\\{post} 248. Beginning of the postamble, see below.

\yskip\hang\\{post\_post} 249. Ending of the postamble, see below.

\yskip\noindent Commands 250--255 are undefined at the present time.

\fi

\M17. \P\D \37$\\{set\_char\_0}=0$\C{typeset character 0 and move right}\par
\P\D \37$\\{set1}=128$\C{typeset a character and move right}\par
\P\D \37$\\{set\_rule}=132$\C{typeset a rule and move right}\par
\P\D \37$\\{put1}=133$\C{typeset a character}\par
\P\D \37$\\{put\_rule}=137$\C{typeset a rule}\par
\P\D \37$\\{nop}=138$\C{no operation}\par
\P\D \37$\\{bop}=139$\C{beginning of page}\par
\P\D \37$\\{eop}=140$\C{ending of page}\par
\P\D \37$\\{push}=141$\C{save the current positions}\par
\P\D \37$\\{pop}=142$\C{restore previous positions}\par
\P\D \37$\\{right1}=143$\C{move right}\par
\P\D \37$\\{w0}=147$\C{move right by \|w}\par
\P\D \37$\\{w1}=148$\C{move right and set \|w}\par
\P\D \37$\\{x0}=152$\C{move right by \|x}\par
\P\D \37$\\{x1}=153$\C{move right and set \|x}\par
\P\D \37$\\{down1}=157$\C{move down}\par
\P\D \37$\\{y0}=161$\C{move down by \|y}\par
\P\D \37$\\{y1}=162$\C{move down and set \|y}\par
\P\D \37$\\{z0}=166$\C{move down by \|z}\par
\P\D \37$\\{z1}=167$\C{move down and set \|z}\par
\P\D \37$\\{fnt\_num\_0}=171$\C{set current font to 0}\par
\P\D \37$\\{fnt1}=235$\C{set current font}\par
\P\D \37$\\{xxx1}=239$\C{extension to \.{DVI} primitives}\par
\P\D \37$\\{xxx4}=242$\C{potentially long extension to \.{DVI} primitives}\par
\P\D \37$\\{fnt\_def1}=243$\C{define the meaning of a font number}\par
\P\D \37$\\{pre}=247$\C{preamble}\par
\P\D \37$\\{post}=248$\C{postamble beginning}\par
\P\D \37$\\{post\_post}=249$\C{postamble ending}\par
\P\D \37$\\{undefined\_commands}\S250,\39251,\39252,\39253,\39254,\39255$\par
\fi

\M18. The preamble contains basic information about the file as a whole. As
stated above, there are six parameters:
$$\hbox{$\|i[1]$ $\\{num}[4]$ $\\{den}[4]$ $\\{mag}[4]$ $\|k[1]$ $\|x[\|k]$.}$$
The \|i byte identifies \.{DVI} format; currently this byte is always set
to~2. (Some day we will set $\|i=3$, when \.{DVI} format makes another
incompatible change---perhaps in 1992.)

The next two parameters, \\{num} and \\{den}, are positive integers that define
the units of measurement; they are the numerator and denominator of a
fraction by which all dimensions in the \.{DVI} file could be multiplied
in order to get lengths in units of $10^{-7}$ meters. (For example, there are
exactly 7227 \TeX\ points in 254 centimeters, and \TeX82 works with scaled
points where there are $2^{16}$ sp in a point, so \TeX82 sets $%
\\{num}=25400000$
and $\\{den}=7227\cdot2^{16}=473628672$.)

The \\{mag} parameter is what \TeX82 calls \.{\\mag}, i.e., 1000 times the
desired magnification. The actual fraction by which dimensions are
multiplied is therefore $mn/1000d$. Note that if a \TeX\ source document
does not call for any `\.{true}' dimensions, and if you change it only by
specifying a different \.{\\mag} setting, the \.{DVI} file that \TeX\
creates will be completely unchanged except for the value of \\{mag} in the
preamble and postamble. (Fancy \.{DVI}-reading programs allow users to
override the \\{mag}~setting when a \.{DVI} file is being printed.)

Finally, \|k and \|x allow the \.{DVI} writer to include a comment, which is
not
interpreted further. The length of comment \|x is \|k, where $0\L\|k<256$.

\Y\P\D \37$\\{id\_byte}=2$\C{identifies the kind of \.{DVI} files described
here}\par
\fi

\M19. Font definitions for a given font number \|k contain further parameters
$$\hbox{$\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $\|l[1]$ $\|n[\|a+\|l]$.}$$
The four-byte value \|c is the check sum that \TeX\ (or whatever program
generated the \.{DVI} file) found in the \.{TFM} file for this font;
\|c should match the check sum of the font found by programs that read
this \.{DVI} file.

Parameter \|s contains a fixed-point scale factor that is applied to the
character widths in font \|k; font dimensions in \.{TFM} files and other
font files are relative to this quantity, which is always positive and
less than $2^{27}$. It is given in the same units as the other dimensions
of the \.{DVI} file.  Parameter \|d is similar to \|s; it is the ``design
size,'' and it is given in \.{DVI} units that have not been corrected for
the magnification~\\{mag} found in the preamble.  Thus, font \|k is to be
used at $\\{mag}\cdot s/1000d$ times its normal size.

The remaining part of a font definition gives the external name of the font,
which is an ASCII string of length $\|a+\|l$. The number \|a is the length
of the ``area'' or directory, and \|l is the length of the font name itself;
the standard local system font area is supposed to be used when $\|a=0$.
The \|n field contains the area in its first \|a bytes.

Font definitions must appear before the first use of a particular font number.
Once font \|k is defined, it must not be defined again; however, we
shall see below that font definitions appear in the postamble as well as
in the pages, so in this sense each font number is defined exactly twice,
if at all. Like \\{nop} commands and \\{xxx} commands, font definitions can
appear before the first \\{bop}, or between an \\{eop} and a \\{bop}.

\fi

\M20. The last page in a \.{DVI} file is followed by `\\{post}'; this command
introduces the postamble, which summarizes important facts that \TeX\ has
accumulated about the file, making it possible to print subsets of the data
with reasonable efficiency. The postamble has the form
$$\vbox{\halign{\hbox{#\hfil}\cr
\\{post} $\|p[4]$ $\\{num}[4]$ $\\{den}[4]$ $\\{mag}[4]$ $\|l[4]$ $\|u[4]$ $%
\|s[2]$ $\|t[2]$\cr
$\langle\,$font definitions$\,\rangle$\cr
\\{post\_post} $\|q[4]$ $\|i[1]$ 223's$[{\G}4]$\cr}}$$
Here \|p is a pointer to the final \\{bop} in the file. The next three
parameters, \\{num}, \\{den}, and \\{mag}, are duplicates of the quantities
that
appeared in the preamble.

Parameters \|l and \|u give respectively the height-plus-depth of the tallest
page and the width of the widest page, in the same units as other dimensions
of the file. These numbers might be used by a \.{DVI}-reading program to
position individual ``pages'' on large sheets of film or paper; however,
the standard convention for output on normal size paper is to position each
page so that the upper left-hand corner is exactly one inch from the left
and the top. Experience has shown that it is unwise to design %
\.{DVI}-to-printer
software that attempts cleverly to center the output; a fixed position of
the upper left corner is easiest for users to understand and to work with.
Therefore \|l and~\|u are often ignored.

Parameter \|s is the maximum stack depth (i.e., the largest excess of
\\{push} commands over \\{pop} commands) needed to process this file. Then
comes \|t, the total number of pages (\\{bop} commands) present.

The postamble continues with font definitions, which are any number of
\\{fnt\_def} commands as described above, possibly interspersed with \\{nop}
commands. Each font number that is used in the \.{DVI} file must be defined
exactly twice: Once before it is first selected by a \\{fnt} command, and once
in the postamble.

\fi

\M21. The last part of the postamble, following the \\{post\_post} byte that
signifies the end of the font definitions, contains \|q, a pointer to the
\\{post} command that started the postamble.  An identification byte, \|i,
comes next; this currently equals~2, as in the preamble.

The \|i byte is followed by four or more bytes that are all equal to
the decimal number 223 (i.e., \O{337} in octal). \TeX\ puts out four to seven
of
these trailing bytes, until the total length of the file is a multiple of
four bytes, since this works out best on machines that pack four bytes per
word; but any number of 223's is allowed, as long as there are at least four
of them. In effect, 223 is a sort of signature that is added at the very end.

This curious way to finish off a \.{DVI} file makes it feasible for
\.{DVI}-reading programs to find the postamble first, on most computers,
even though \TeX\ wants to write the postamble last. Most operating
systems permit random access to individual words or bytes of a file, so
the \.{DVI} reader can start at the end and skip backwards over the 223's
until finding the identification byte. Then it can back up four bytes, read
\|q, and move to byte \|q of the file. This byte should, of course,
contain the value 248 (\\{post}); now the postamble can be read, so the
\.{DVI} reader discovers all the information needed for typesetting the
pages. Note that it is also possible to skip through the \.{DVI} file at
reasonably high speed to locate a particular page, if that proves
desirable. This saves a lot of time, since \.{DVI} files used in production
jobs tend to be large.

When \.{DVIDOC} "typesets" a character, it simply puts its ASCII code
into the document file in the proper place according to the rounding of
\|h and \|v to whole character positions.  It may, of course, obliterate
a character previously stored in the same position.  Especially if a
symbol font is being used, the ASCII code may print ultimately as an
entirely different character than the one the document designer originally
intended.  For \.{DVIDOC} to produce more than a rough approximation to
the intended document, fonts need to be chosen very carefully.

\fi

\N22.  Input from binary files.
We have seen that a \.{DVI} file is a sequence of 8-bit bytes. The bytes
appear physically in what is called a `\&{packed} \&{file} \&{of} $0\to255$'
in \PASCAL\ lingo.

Packing is system dependent, and many \PASCAL\ systems fail to implement
such files in a sensible way (at least, from the viewpoint of producing
good production software).  For example, some systems treat all
byte-oriented files as text, looking for end-of-line marks and such
things. Therefore some system-dependent code is often needed to deal with
binary files, even though most of the program in this section of
\.{DVIDOC} is written in standard \PASCAL.

One common way to solve the problem is to consider files of \\{integer}
numbers, and to convert an integer in the range $-2^{31}\L x<2^{31}$ to
a sequence of four bytes $(a,b,c,d)$ using the following code, which
avoids the controversial integer division of negative numbers:
$$\vbox{\halign{#\hfil\cr
 \&{if} $\|x\G0$ \&{then} $\|a\K\|x\mathbin{\&{div}}\O{100000000}$\cr
  \&{else}  \&{begin} $\|x\K(\|x+\O{10000000000})+\O{10000000000}$; $\|a\K\|x%
\mathbin{\&{div}}\O{100000000}+128$;\cr
\quad  \&{end} \cr
$\|x\K\|x\mathbin{\&{mod}}\O{100000000}$;\cr
$\|b\K\|x\mathbin{\&{div}}\O{200000}$; $\|x\K\|x\mathbin{\&{mod}}\O{200000}$;%
\cr
$\|c\K\|x\mathbin{\&{div}}\O{400}$; $\|d\K\|x\mathbin{\&{mod}}\O{400}$;\cr}}$$
The four bytes are then kept in a buffer and output one by one. (On 36-bit
computers, an additional division by 16 is necessary at the beginning.
Another way to separate an integer into four bytes is to use/abuse
\PASCAL's variant records, storing an integer and retrieving bytes that are
packed in the same place; {\sl caveat implementor!\/}) It is also desirable
in some cases to read a hundred or so integers at a time, maintaining a
larger buffer.

We shall stick to simple \PASCAL\ in this program, for reasons of clarity,
even if such simplicity is sometimes unrealistic.

\Y\P$\4\X9:Types in the outer block\X\mathrel{+}\S$\6
$\\{eight\_bits}=\\{integer}$;\C{unsigned one-byte quantity}\6
$\\{byte\_file}=$\1\5
\&{packed} \37\&{file} \1\&{of}\5
\\{char};\C{files that contain binary data}\2\2\par
\fi

\M23. The program deals with two binary file variables: \\{dvi\_file} is the
main
input file that we are translating into symbolic form, and \\{tfm\_file} is
the current font metric file from which character-width information is
being read.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{dvi\_file}: \37\\{byte\_file};\C{the stuff we are \.{DVI}typing}\6
\4\\{eof\_dvi\_file}: \37\\{boolean};\C{end of file on \.{DVI}file}\6
\4\\{tfm\_file}: \37\\{byte\_file};\C{a font metric file}\par
\fi

\M24. To prepare these files for input, we \\{reset} them. An extension of
\PASCAL\ is needed in the case of \\{tfm\_file}, since we want to associate
it with external files whose names are specified dynamically (i.e., not
known at compile time). The following code assumes that `$\\{reset}(\|f,\|s)$'
does this, when \|f is a file variable and \|s is a string variable that
specifies the file name. If $\\{eof}(\|f)$ is true immediately after
$\\{reset}(\|f,\|s)$ has acted, we assume that no file named \|s is accessible.

\Y\P\D \37$\\{read\_access\_mode}=4$\C{``read'' mode for \\{test\_access}}\par
\P\D \37$\\{write\_access\_mode}=2$\C{``write'' mode for \\{test\_access}}\par
\P\D \37$\\{no\_file\_path}=0$\C{no path searching should be done}\par
\P\D \37$\\{font\_file\_path}=3$\C{path specifier for \.{TFM} files}\par
\fi

\M25. We try to open the input file and append .dvi if it doesn't have this
extension already.

\Y\P$\4\X25:Open input file\X\S$\6
$\|i\K1$;\6
\&{while} $(\|i<\\{name\_length})\W(\\{base\_name}[\|i]\I\.{\'\ \'})$ \1\&{do}\5
$\\{incr}(\|i)$;\2\6
\&{if} $\|i<5$ \1\&{then}\6
\&{begin} \37$\\{base\_name}[\|i]\K\.{\'.\'}$;\5
$\\{base\_name}[\|i+1]\K\.{\'d\'}$;\5
$\\{base\_name}[\|i+2]\K\.{\'v\'}$;\5
$\\{base\_name}[\|i+3]\K\.{\'i\'}$;\5
$\\{base\_name}[\|i+4]\K\.{\'\ \'}$;\6
\&{end};\2\6
\&{if} $(\|i\G5)\W(\|i<\\{name\_length}-4)\W((\\{base\_name}[\|i-4]\I\.{\'.\'})%
\V(\\{base\_name}[\|i-3]\I\.{\'d\'})\V(\\{base\_name}[\|i-2]\I\.{\'v\'})\V(%
\\{base\_name}[\|i-1]\I\.{\'i\'}))$ \1\&{then}\6
\&{begin} \37$\\{base\_name}[\|i]\K\.{\'.\'}$;\5
$\\{base\_name}[\|i+1]\K\.{\'d\'}$;\5
$\\{base\_name}[\|i+2]\K\.{\'v\'}$;\5
$\\{base\_name}[\|i+3]\K\.{\'i\'}$;\5
$\\{base\_name}[\|i+4]\K\.{\'\ \'}$;\6
\&{end};\2\6
$\\{cur\_name}\K\\{base\_name}$;\6
\&{if} $\\{test\_access}(\\{read\_access\_mode},\39\\{no\_file\_path})$ \1%
\&{then}\6
\&{begin} \37\\{open\_dvi\_file};\6
\&{if} $\\{eof}(\\{dvi\_file})$ \1\&{then}\5
$\\{cannot\_start}(\.{\'Input\ file\ not\ found\'})$\2\6
\&{end}\6
\4\&{else} $\\{cannot\_start}(\.{\'Cannot\ open\ input\ file\'})$;\2\par
\U102.\fi

\M26. Procedure to open TFM file.

\Y\P\4\&{procedure}\1\  \37\\{open\_tfm\_file};\C{prepares to read packed bytes
in \\{tfm\_file}}\2\6
\&{begin} \37\&{if} $\\{test\_access}(\\{read\_access\_mode},\39\\{font\_file%
\_path})$ \1\&{then}\5
$\\{reset}(\\{tfm\_file},\39\\{real\_name\_of\_file})$\6
\4\&{else} \&{begin} \37$\\{error}(\.{\'TFM\ file\ not\ found\'})$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{end};\Y\par
\fi

\M27. If you looked carefully at the preceding code, you probably asked,
``What are \\{cur\_loc} and \\{cur\_name}?'' Good question. They're global
variables: \\{cur\_loc} is the number of the byte about to be read next from
\\{dvi\_file}, and \\{cur\_name} is a string variable that will be set to the
current font metric file name before \\{open\_tfm\_file} is called.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\_loc}: \37\\{integer};\C{where we are about to look, in \\{dvi\_file}}%
\6
\4$\\{base\_name},\39\\{cur\_name},\39\\{real\_name\_of\_file}$: \37\&{packed} %
\37\&{array} $[1\to\\{name\_length}]$ \1\&{of}\5
\\{char};\C{external name,   with no upper case letters}\2\par
\fi

\M28. It turns out to be convenient to read four bytes at a time, when we are
inputting from \.{TFM} files. The input goes into global variables
\\{b0}, \\{b1}, \\{b2}, and \\{b3}, with \\{b0} getting the first byte and %
\\{b3}
the fourth.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4$\\{b0},\39\\{b1},\39\\{b2},\39\\{b3}$: \37\\{eight\_bits};\C{four bytes
input at once}\par
\fi

\M29. The \\{read\_tfm\_word} procedure sets \\{b0} through \\{b3} to the next
four bytes in the current \.{TFM} file.
\Y\P\D \37$\\{get\_tfm\_byte}(\#)\S\\{read}(\\{tfm\_file},\39\\{byte})$;\5
$\#\K\\{ord}(\\{byte})$;\6
\&{if} $\#<0$ \1\&{then}\5
$\#\K\#+256$;\2\par
\Y\P\4\&{procedure}\1\  \37\\{read\_tfm\_word};\6
\4\&{var} \37\\{byte}: \37\\{char};\2\6
\&{begin} \37$\\{get\_tfm\_byte}(\\{b0})$;\5
$\\{get\_tfm\_byte}(\\{b1})$;\5
$\\{get\_tfm\_byte}(\\{b2})$;\5
$\\{get\_tfm\_byte}(\\{b3})$;\6
\&{end};\par
\fi

\M30. Finally we come to the routines that are used for random reading.
The driver program below needs two such routines: \\{dvi\_length} should
compute the total number of bytes in \\{dvi\_file}, possibly also
causing $\\{eof}(\\{dvi\_file})$ to be true; and $\\{move\_to\_byte}(\|n)$
should position \\{dvi\_file} so that the next \\{get\_byte} will read byte %
\|n,
starting with $\|n=0$ for the first byte in the file.

Such routines are, of course, highly system dependent. They are implemented
here in terms of two assumed system routines called \\{set\_pos} and \\{cur%
\_pos}.
The call $\\{set\_pos}(\|f,\|n)$ moves to item \|n in file \|f, unless \|n is
negative or larger than the total number of items in \|f; in the latter
case, $\\{set\_pos}(\|f,\|n)$ moves to the end of file \|f.
The call $\\{cur\_pos}(\|f)$ gives the total number of items in \|f, if
$\\{eof}(\|f)$ is true; we use \\{cur\_pos} only in such a situation.

\Y\P\4\&{function}\1\  \37\\{dvi\_length}: \37\\{integer};\2\6
\&{begin} \37$\\{set\_pos}(\\{dvi\_file},\39-1)$;\5
$\\{dvi\_length}\K\\{cur\_pos}(\\{dvi\_file})$;\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{move\_to\_byte}(\|n:\\{integer})$;\2\6
\&{begin} \37$\\{set\_pos}(\\{dvi\_file},\39\|n)$;\5
$\\{cur\_loc}\K\|n$;\6
\&{end};\par
\fi

\N31.  Reading the font information.
\.{DVI} file format does not include information about character widths, since
that would tend to make the files a lot longer. But a program that reads
a \.{DVI} file is supposed to know the widths of the characters that appear
in \\{set\_char} commands. Therefore \.{DVIDOC} looks at the font metric
(\.{TFM}) files for the fonts that are involved.

The character-width data appears also in other files (e.g., in \.{GF} files
that specify bit patterns for digitized characters);
thus, it is usually possible for \.{DVI} reading programs to get by with
accessing only one file per font. \.{DVItype} has a comparatively easy
task in this regard, since it needs only a few words of information from
each font; other \.{DVI}-to-printer programs may have to go to some pains to
deal with complications that arise when a large number of large font files
all need to be accessed simultaneously.

\fi

\M32. For purposes of this program, we need to know only two things about a
given character \|c in a given font \|f: (1)~Is \|c a legal character
in~\|f? (2)~If so, what is the width of \|c? We also need to know the
symbolic name of each font, so it can be printed out, and we need to know
the approximate size of inter-word spaces in each font.

The answers to these questions appear implicitly in the following data
structures. The current number of known fonts is \\{nf}. Each known font has
an internal number \|f, where $0\L\|f<\\{nf}$; the external number of this
font,
i.e., its font identification number in the \.{DVI} file, is
$\\{font\_num}[\|f]$, and the external name of this font is the string that
occupies positions $\\{font\_name}[\|f]$ through $\\{font\_name}[\|f+1]-1$ of
the array
\\{names}. The latter array consists of \\{ASCII\_code} characters, and
$\\{font\_name}[\\{nf}]$ is its first unoccupied position.  A horizontal motion
in the range $-4\ast\\{font\_space}[\|f]<\|h<\\{font\_space}[\|f]$
will be treated as a `kern' that is not
indicated in the printouts that \.{DVIDOC} produces between brackets. The
legal characters run from $\\{font\_bc}[\|f]$ to $\\{font\_ec}[\|f]$,
inclusive; more
precisely, a given character \|c is valid in font \|f if and only if
$\\{font\_bc}[\|f]\L\|c\L\\{font\_ec}[\|f]$ and $\\{char\_width}(\|f)(\|c)\I%
\\{invalid\_width}$.
Finally, $\\{char\_width}(\|f)(\|c)=\\{width}[\\{width\_base}[\|f]+\|c]$, and %
\\{width\_ptr} is the
first unused position of the \\{width} array.

\Y\P\D \37$\\{char\_width\_end}(\#)\S\#$ ] \par
\P\D $\\{char\_width}(\#)\S\\{width}$ [ $\\{width\_base}[\#]+\\{char\_width%
\_end}$\par
\P\D \37$\\{invalid\_width}\S\O{17777777777}$\par
\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{font\_num}: \37\&{array} $[0\to\\{max\_fonts}]$ \1\&{of}\5
\\{integer};\C{external font numbers}\2\6
\4\\{font\_name}: \37\&{array} $[0\to\\{max\_fonts}]$ \1\&{of}\5
$0\to\\{name\_size}$;\C{starting positions   of external font names}\2\6
\4\\{names}: \37\&{array} $[0\to\\{name\_size}]$ \1\&{of}\5
\\{ASCII\_code};\C{characters of names}\2\6
\4\\{font\_check\_sum}: \37\&{array} $[0\to\\{max\_fonts}]$ \1\&{of}\5
\\{integer};\C{check sums}\2\6
\4\\{font\_scaled\_size}: \37\&{array} $[0\to\\{max\_fonts}]$ \1\&{of}\5
\\{integer};\C{scale factors}\2\6
\4\\{font\_design\_size}: \37\&{array} $[0\to\\{max\_fonts}]$ \1\&{of}\5
\\{integer};\C{design sizes}\2\6
\4\\{font\_space}: \37\&{array} $[0\to\\{max\_fonts}]$ \1\&{of}\5
\\{integer};\C{boundary between ``small''   and ``large'' spaces}\2\6
\4\\{font\_bc}: \37\&{array} $[0\to\\{max\_fonts}]$ \1\&{of}\5
\\{integer};\C{beginning characters in fonts}\2\6
\4\\{font\_ec}: \37\&{array} $[0\to\\{max\_fonts}]$ \1\&{of}\5
\\{integer};\C{ending characters in fonts}\2\6
\4\\{width\_base}: \37\&{array} $[0\to\\{max\_fonts}]$ \1\&{of}\5
\\{integer};\C{index into \\{width} table}\2\6
\4\\{width}: \37\&{array} $[0\to\\{max\_widths}]$ \1\&{of}\5
\\{integer};\C{character widths, in \.{DVI} units}\2\6
\4\\{nf}: \37$0\to\\{max\_fonts}$;\C{the number of known fonts}\6
\4\\{width\_ptr}: \37$0\to\\{max\_widths}$;\C{the number of known character
widths}\par
\fi

\M33. \P$\X12:Set initial values\X\mathrel{+}\S$\6
$\\{nf}\K0$;\5
$\\{width\_ptr}\K0$;\5
$\\{font\_name}[0]\K0$;\5
$\\{font\_space}[0]\K0$;\par
\fi

\M34. It is, of course, a simple matter to print the name of a given font.

\Y\P\4\&{procedure}\1\  \37$\\{print\_font}(\|f:\\{integer})$;\C{\|f is an
internal font number}\6
\4\&{var} \37\|k: \37$0\to\\{name\_size}$;\C{index into \\{names}}\2\6
\&{begin} \37\&{if} $\|f=\\{nf}$ \1\&{then}\5
$\\{print}(\.{\'UNDEFINED!\'})$\6
\4\&{else} \&{begin} \37\&{for} $\|k\K\\{font\_name}[\|f]\mathrel{\&{to}}%
\\{font\_name}[\|f+1]-1$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{names}[\|k]])$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M35. An auxiliary array \\{in\_width} is used to hold the widths as they are
input. The global variable \\{tfm\_check\_sum} is set to the check sum that
appears in the current \.{TFM} file.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{in\_width}: \37\&{array} $[0\to255]$ \1\&{of}\5
\\{integer};\C{\.{TFM} width data in \.{DVI} units}\2\6
\4\\{tfm\_check\_sum}: \37\\{integer};\C{check sum found in \\{tfm\_file}}\par
\fi

\M36. Here is a procedure that absorbs the necessary information from a
\.{TFM} file, assuming that the file has just been successfully reset
so that we are ready to read its first byte. (A complete description of
\.{TFM} file format appears in the documentation of \.{TFtoPL} and will
not be repeated here.) The procedure does not check the \.{TFM} file
for validity, nor does it give explicit information about what is
wrong with a \.{TFM} file that proves to be invalid; \.{DVI}-reading
programs need not do this, since \.{TFM} files are almost always valid,
and since the \.{TFtoPL} utility program has been specifically designed
to diagnose \.{TFM} errors. The procedure simply returns \\{false} if it
detects anything amiss in the \.{TFM} data.

There is a parameter, \|z, which represents the scaling factor being
used to compute the font dimensions; it must be in the range $0<z<2^{27}$.

\Y\P\4\&{function}\1\  \37$\\{in\_TFM}(\|z:\\{integer})$: \37\\{boolean};%
\C{input \.{TFM} data or return \\{false}}\6
\4\&{label} \37$9997,\39$\C{go here when the format is bad}\6
$9998,\39$\C{go here when the information cannot be loaded}\6
9999;\C{go here to exit}\6
\4\&{var} \37\|k: \37\\{integer};\C{index for loops}\6
\\{lh}: \37\\{integer};\C{length of the header data, in four-byte words}\6
\\{nw}: \37\\{integer};\C{number of words in the width table}\6
\\{wp}: \37$0\to\\{max\_widths}$;\C{new value of \\{width\_ptr} after
successful input}\6
$\\{alpha},\39\\{beta}$: \37\\{integer};\C{quantities used in the scaling
computation}\2\6
\&{begin} \37\X37:Read past the header data; \&{goto} 9997 if there is a
problem\X;\6
\X38:Store character-width indices at the end of the \\{width} table\X;\6
\X39:Read and convert the width values, setting up the \\{in\_width} table\X;\6
\X42:Move the widths from \\{in\_width} to \\{width}, and append \\{pixel%
\_width} values\X;\6
$\\{width\_ptr}\K\\{wp}$;\5
$\\{in\_TFM}\K\\{true}$;\5
\&{goto} \379999;\6
\49997: \37$\\{print\_ln}(\.{\'---not\ loaded,\ TFM\ file\ is\ bad\'})$;\6
\49998: \37$\\{in\_TFM}\K\\{false}$;\6
\49999: \37\&{end};\par
\fi

\M37. \P$\X37:Read past the header data; \&{goto} 9997 if there is a problem\X%
\S$\6
\\{read\_tfm\_word};\5
$\\{lh}\K\\{b2}\ast256+\\{b3}$;\5
\\{read\_tfm\_word};\5
$\\{font\_bc}[\\{nf}]\K\\{b0}\ast256+\\{b1}$;\5
$\\{font\_ec}[\\{nf}]\K\\{b2}\ast256+\\{b3}$;\6
\&{if} $\\{font\_ec}[\\{nf}]<\\{font\_bc}[\\{nf}]$ \1\&{then}\5
$\\{font\_bc}[\\{nf}]\K\\{font\_ec}[\\{nf}]+1$;\2\6
\&{if} $\\{width\_ptr}+\\{font\_ec}[\\{nf}]-\\{font\_bc}[\\{nf}]+1>\\{max%
\_widths}$ \1\&{then}\6
\&{begin} \37$\\{print\_ln}(\.{\'---not\ loaded,\ DVIDOC\ needs\ larger\ width\
table\'})$;\5
\&{goto} \379998;\6
\&{end};\2\6
$\\{wp}\K\\{width\_ptr}+\\{font\_ec}[\\{nf}]-\\{font\_bc}[\\{nf}]+1$;\5
\\{read\_tfm\_word};\5
$\\{nw}\K\\{b0}\ast256+\\{b1}$;\6
\&{if} $(\\{nw}=0)\V(\\{nw}>256)$ \1\&{then}\5
\&{goto} \379997;\2\6
\&{for} $\|k\K1\mathrel{\&{to}}3+\\{lh}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{eof}(\\{tfm\_file})$ \1\&{then}\5
\&{goto} \379997;\2\6
\\{read\_tfm\_word};\6
\&{if} $\|k=4$ \1\&{then}\6
\&{if} $\\{b0}<128$ \1\&{then}\5
$\\{tfm\_check\_sum}\K((\\{b0}\ast256+\\{b1})\ast256+\\{b2})\ast256+\\{b3}$\6
\4\&{else} $\\{tfm\_check\_sum}\K(((\\{b0}-256)\ast256+\\{b1})\ast256+\\{b2})%
\ast256+\\{b3}$;\2\2\6
\&{end};\2\par
\U36.\fi

\M38. \P$\X38:Store character-width indices at the end of the \\{width} table\X%
\S$\6
\&{if} $\\{wp}>0$ \1\&{then}\6
\&{for} $\|k\K\\{width\_ptr}\mathrel{\&{to}}\\{wp}-1$ \1\&{do}\6
\&{begin} \37\\{read\_tfm\_word};\6
\&{if} $\\{b0}>\\{nw}$ \1\&{then}\5
\&{goto} \379997;\2\6
$\\{width}[\|k]\K\\{b0}$;\6
\&{end};\2\2\par
\U36.\fi

\M39. The most important part of \\{in\_TFM} is the width computation, which
involves multiplying the relative widths in the \.{TFM} file by the
scaling factor in the \.{DVI} file. This fixed-point multiplication
must be done with precisely the same accuracy by all \.{DVI}-reading programs,
in order to validate the assumptions made by \.{DVI}-writing programs
like \TeX82.

Let us therefore summarize what needs to be done. Each width in a \.{TFM}
file appears as a four-byte quantity called a \\{fix\_word}.  A \\{fix\_word}
whose respective bytes are $(a,b,c,d)$ represents the number
$$x=\left\{\vcenter{\halign{$#$,\hfil\qquad&if $#$\hfil\cr
b\cdot2^{-4}+c\cdot2^{-12}+d\cdot2^{-20}&a=0;\cr
-16+b\cdot2^{-4}+c\cdot2^{-12}+d\cdot2^{-20}&a=255.\cr}}\right.$$
(No other choices of $a$ are allowed, since the magnitude of a \.{TFM}
dimension must be less than 16.)  We want to multiply this quantity by the
integer~\|z, which is known to be less than $2^{27}$. Let $\alpha=16z$.
If $\|z<2^{23}$, the individual multiplications $b\cdot z$, $c\cdot z$,
$d\cdot z$ cannot overflow; otherwise we will divide \|z by 2, 4, 8, or
16, to obtain a multiplier less than $2^{23}$, and we can compensate for
this later. If \|z has thereby been replaced by $\|z^\prime=\|z/2^e$, let
$\beta=2^{4-e}$; we shall compute
$$\lfloor(b+c\cdot2^{-8}+d\cdot2^{-16})\,z^\prime/\beta\rfloor$$ if $a=0$,
or the same quantity minus $\alpha$ if $a=255$.  This calculation must be
done exactly, for the reasons stated above; the following program does the
job in a system-independent way, assuming that arithmetic is exact on
numbers less than $2^{31}$ in magnitude.

\Y\P$\4\X39:Read and convert the width values, setting up the \\{in\_width}
table\X\S$\6
\X40:Replace \|z by $\|z^\prime$ and compute $\alpha,\beta$\X;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{nw}-1$ \1\&{do}\6
\&{begin} \37\\{read\_tfm\_word};\5
$\\{in\_width}[\|k]\K(((((\\{b3}\ast\|z)\mathbin{\&{div}}\O{400})+(\\{b2}\ast%
\|z))\mathbin{\&{div}}\O{400})+(\\{b1}\ast\|z))\mathbin{\&{div}}\\{beta}$;\6
\&{if} $\\{b0}>0$ \1\&{then}\6
\&{if} $\\{b0}<255$ \1\&{then}\5
\&{goto} \379997\6
\4\&{else} $\\{in\_width}[\|k]\K\\{in\_width}[\|k]-\\{alpha}$;\2\2\6
\&{end}\2\par
\U36.\fi

\M40. \P$\X40:Replace \|z by $\|z^\prime$ and compute $\alpha,\beta$\X\S$\6
\&{begin} \37$\\{alpha}\K16\ast\|z$;\5
$\\{beta}\K16$;\6
\&{while} $\|z\G\O{40000000}$ \1\&{do}\6
\&{begin} \37$\|z\K\|z\mathbin{\&{div}}2$;\5
$\\{beta}\K\\{beta}\mathbin{\&{div}}2$;\6
\&{end};\2\6
\&{end}\par
\U39.\fi

\M41. A \.{DVI}-reading program usually works with font files instead of
\.{TFM} files, so \.{DVIDOC} is atypical in that respect. Font files
should, however, contain exactly the same character width data that is
found in the corresponding \.{TFM}s; check sums are used to help
ensure this. In addition, font files usually also contain the widths of
characters in pixels, since the device-independent character widths of
\.{TFM} files are generally not perfect multiples of pixels.

The \\{pixel\_width} array contains this information; when $\\{width}[\|k]$ is
the
device-independent width of some character in \.{DVI} units, $\\{pixel\_width}[%
\|k]$
is the corresponding width of that character in an actual font.
The macro \\{char\_pixel\_width} is set up to be analogous to \\{char\_width}.

\Y\P\D $\\{char\_pixel\_width}(\#)\S\\{pixel\_width}$ [ $\\{width\_base}[\#]+%
\\{char\_width\_end}$\par
\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{pixel\_width}: \37\&{array} $[0\to\\{max\_widths}]$ \1\&{of}\5
\\{integer};\C{actual character widths,   in pixels}\2\6
\4\\{horiz\_conv}: \37\\{real};\C{converts \.{DVI} units to horizontal pixels}\6
\4\\{vert\_conv}: \37\\{real};\C{converts \.{DVI} units to vertical pixels}\6
\4\\{true\_horiz\_conv}: \37\\{real};\C{converts unmagnified \.{DVI} units to
pixels}\6
\4\\{true\_vert\_conv}: \37\\{real};\C{converts unmagnified \.{DVI} units to
pixels}\6
\4$\\{numerator},\39\\{denominator}$: \37\\{integer};\C{stated conversion
ratio}\6
\4\\{mag}: \37\\{integer};\C{magnification factor times 1000}\par
\fi

\M42. The following code computes pixel widths by simply rounding the \.{TFM}
widths to the nearest integer number of pixels, based on the conversion factor
\\{horiz\_conv} that converts \.{DVI} units to pixels. However, such a simple
formula will not be valid for all fonts, and it will often give results that
are off by $\pm1$ when a low-resolution font has been carefully
hand-fitted. For example, a font designer often wants to make the letter `m'
a pixel wider or narrower in order to make the font appear more consistent.
\.{DVI}-to-printer programs should therefore input the correct pixel width
information from font files whenever there is a chance that it may differ.
A warning message may also be desirable in the case that at least one character
is found whose pixel width differs from $\\{conv}\ast\\{width}$ by more than a
full pixel.

\Y\P\D \37$\\{horiz\_pixel\_round}(\#)\S\\{round}(\\{horiz\_conv}\ast(\#))$\par
\P\D \37$\\{vert\_pixel\_round}(\#)\S\\{round}(\\{vert\_conv}\ast(\#))$\par
\Y\P$\4\X42:Move the widths from \\{in\_width} to \\{width}, and append %
\\{pixel\_width} values\X\S$\6
$\\{width\_base}[\\{nf}]\K\\{width\_ptr}-\\{font\_bc}[\\{nf}]$;\6
\&{if} $\\{wp}>0$ \1\&{then}\6
\&{for} $\|k\K\\{width\_ptr}\mathrel{\&{to}}\\{wp}-1$ \1\&{do}\6
\&{begin} \37$\\{width}[\|k]\K\\{in\_width}[\\{width}[\|k]]$;\5
$\\{pixel\_width}[\|k]\K\\{horiz\_pixel\_round}(\\{width}[\|k])$;\6
\&{end}\2\2\par
\U36.\fi

\N43.  Optional modes of output.
\.{DVIDOC} output will vary depending on some
options that the user must specify: The typeout can be confined to a
restricted subset of the pages by specifying the desired starting page and
the maximum number of pages.

The starting page is specified by giving a sequence of 1 to 10 numbers or
asterisks separated by dots. For example, the specification `\.{1.*.-5}'
can be used to refer to a page output by \TeX\ when $\.{\\count0}=1$
and $\.{\\count2}=-5$. (Recall that \\{bop} commands in a \.{DVI} file
are followed by ten `count' values.) An asterisk matches any number,
so the `\.*' in `\.{1.*.-5}' means that \.{\\count1} is ignored when
specifying the first page. If several pages match the given specification,
\.{DVIDOC} will begin with the earliest such page in the file. The
default specification `\.*' (which matches all pages) therefore denotes
the page at the beginning of the file.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{max\_pages}: \37\\{integer};\C{at most this many $\\{bop}\to\\{eop}$ pages
will be printed}\6
\4\\{horiz\_resolution}: \37\\{real};\C{pixels per inch}\6
\4\\{vert\_resolution}: \37\\{real};\C{pixels per inch}\6
\4\\{new\_mag}: \37\\{integer};\C{if positive, overrides the postamble's
magnification}\par
\fi

\M44. The starting page specification is recorded in two global arrays called
\\{start\_count} and \\{start\_there}. For example, `\.{1.*.-5}' is represented
by $\\{start\_there}[0]=\\{true}$, $\\{start\_count}[0]=1$, $\\{start%
\_there}[1]=\\{false}$,
$\\{start\_there}[2]=\\{true}$, $\\{start\_count}[2]=-5$.
We also set $\\{start\_vals}=2$, to indicate that count 2 was the last one
mentioned. The other values of \\{start\_count} and \\{start\_there} are not
important, in this example.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{start\_count}: \37\&{array} $[0\to9]$ \1\&{of}\5
\\{integer};\C{count values to select starting page}\2\6
\4\\{start\_there}: \37\&{array} $[0\to9]$ \1\&{of}\5
\\{boolean};\C{is the \\{start\_count} value relevant?}\2\6
\4\\{start\_vals}: \37$0\to9$;\C{the last count considered significant}\6
\4\\{count}: \37\&{array} $[0\to9]$ \1\&{of}\5
\\{integer};\C{the count values on the current page}\2\par
\fi

\M45. \P$\X12:Set initial values\X\mathrel{+}\S$\6
$\\{max\_pages}\K1000000$;\5
$\\{start\_vals}\K0$;\5
$\\{start\_there}[0]\K\\{false}$;\par
\fi

\M46. Here is a simple subroutine that tests if the current page might be the
starting page.

\Y\P\4\&{function}\1\  \37\\{start\_match}: \37\\{boolean};\C{does \\{count}
match the starting spec?}\6
\4\&{var} \37\|k: \37$0\to9$;\C{loop index}\6
\\{match}: \37\\{boolean};\C{does everything match so far?}\2\6
\&{begin} \37$\\{match}\K\\{true}$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{start\_vals}$ \1\&{do}\6
\&{if} $\\{start\_there}[\|k]\W(\\{start\_count}[\|k]\I\\{count}[\|k])$ \1%
\&{then}\5
$\\{match}\K\\{false}$;\2\2\6
$\\{start\_match}\K\\{match}$;\6
\&{end};\par
\fi

\M47. The \\{copy\_ln} copies characters from the command line argument in
\\{cur\_name}.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{buffer}: \37\&{array} $[0\to\\{terminal\_line\_length}]$ \1\&{of}\5
\\{ASCII\_code};\2\par
\fi

\M48. The count starts at 2 to skip the -x flag characters. We subtract
3 because \\{buffer} starts at 0.

\Y\P\4\&{procedure}\1\  \37\\{copy\_ln};\C{copies a line from the terminal}\6
\4\&{var} \37\|k: \37$0\to\\{terminal\_line\_length}$;\2\6
\&{begin} \37$\|k\K2$;\6
\&{while} $(\|k<\\{name\_length})\W(\\{cur\_name}[\|k]\I\.{\'\ \'})$ \1\&{do}\6
\&{begin} \37$\\{buffer}[\|k-3]\K\\{xord}[\\{cur\_name}[\|k]]$;\5
$\\{incr}(\|k)$\6
\&{end};\2\6
$\\{buffer}[\|k-3]\K\\{xord}[\.{\'\ \'}]$;\6
\&{end};\par
\fi

\M49. The global variable \\{buf\_ptr} is used while scanning each line of
input;
it points to the first unread character in \\{buffer}.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{buf\_ptr}: \37$0\to\\{terminal\_line\_length}$;\C{the number of characters
read}\par
\fi

\M50. Here is a routine that scans a (possibly signed) integer and computes
the decimal value. If no decimal integer starts at \\{buf\_ptr}, the
value 0 is returned. The integer should be less than $2^{31}$ in
absolute value.

\Y\P\4\&{function}\1\  \37\\{get\_integer}: \37\\{integer};\6
\4\&{var} \37\|x: \37\\{integer};\C{accumulates the value}\6
\\{negative}: \37\\{boolean};\C{should the value be negated?}\2\6
\&{begin} \37\&{if} $\\{buffer}[\\{buf\_ptr}]=\.{"-"}$ \1\&{then}\6
\&{begin} \37$\\{negative}\K\\{true}$;\5
$\\{incr}(\\{buf\_ptr})$;\6
\&{end}\6
\4\&{else} $\\{negative}\K\\{false}$;\2\6
$\|x\K0$;\6
\&{while} $(\\{buffer}[\\{buf\_ptr}]\G\.{"0"})\W(\\{buffer}[\\{buf\_ptr}]\L%
\.{"9"})$ \1\&{do}\6
\&{begin} \37$\|x\K10\ast\|x+\\{buffer}[\\{buf\_ptr}]-\.{"0"}$;\5
$\\{incr}(\\{buf\_ptr})$;\6
\&{end};\2\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{get\_integer}\K-\|x$\ \&{else} $\\{get\_integer}\K\|x$;\2\6
\&{end};\par
\fi

\M51. The selected options are put into global variables by the \\{options}
procedure, which is called just as \.{DVIDOC} begins.

\Y\P\4\&{procedure}\1\  \37\\{options};\6
\4\&{var} \37$\|j,\39\|k$: \37\\{integer};\C{loop variable}\2\6
\&{begin} \37$\\{log\_errors}\K\\{false}$;\5
$\\{start\_vals}\K0$;\5
$\\{start\_there}[0]\K\\{false}$;\5
$\\{max\_pages}\K1000000$;\5
$\\{horiz\_resolution}\K13.76582$;\C{cmtt10 chars per inch}\6
$\\{vert\_resolution}\K6.0225$;\C{72.27pt/12pt}\6
$\\{new\_mag}\K0$;\5
$\\{base\_name}[1]\K\.{\'\ \'}$;\5
$\|j\K1$;\6
\&{while} $\|j<\\{argc}$ \1\&{do}\6
\&{begin} \37$\\{argv}(\|j,\39\\{cur\_name})$;\6
\&{if} $\\{cur\_name}[1]=\.{\'-\'}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cur\_name}[2]=\.{\'e\'}$ \1\&{then}\5
$\\{log\_errors}\K\\{true}$\6
\4\&{else} \&{if} $\\{cur\_name}[2]=\.{\'s\'}$ \1\&{then}\6
\&{begin} \37\X52:Determine the desired \\{start\_count} values\X\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_name}[2]=\.{\'m\'}$ \1\&{then}\6
\&{begin} \37\X53:Determine the desired \\{max\_pages}\X\6
\&{end}\6
\4\&{else} $\\{cannot\_start}(\.{\'Usage:\ dvidoc\ [-e]\ [-s<start\ page\
spec>]\ [-m<maxpages>]\ <dvi-file>\'})$\2\2\2\6
\&{end}\6
\4\&{else} \&{if} $\\{base\_name}[1]=\.{\'\ \'}$ \1\&{then}\5
$\\{argv}(\|j,\39\\{base\_name})$\6
\4\&{else} $\\{cannot\_start}(\.{\'Only\ one\ input\ file\ please\'})$;\2\2\6
$\\{incr}(\|j)$\6
\&{end};\2\6
\&{if} $\\{base\_name}[1]=\.{\'\ \'}$ \1\&{then}\5
$\\{cannot\_start}(\.{\'No\ input\ file\ specified\'})$;\2\6
\&{end};\par
\fi

\M52. \P$\X52:Determine the desired \\{start\_count} values\X\S$\6
\\{copy\_ln};\5
$\\{buf\_ptr}\K0$;\5
$\|k\K0$;\6
\&{if} $\\{buffer}[0]\I\.{"\ "}$ \1\&{then}\6
\1\&{repeat} \37\&{if} $\\{buffer}[\\{buf\_ptr}]=\.{"*"}$ \1\&{then}\6
\&{begin} \37$\\{start\_there}[\|k]\K\\{false}$;\5
$\\{incr}(\\{buf\_ptr})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{start\_there}[\|k]\K\\{true}$;\5
$\\{start\_count}[\|k]\K\\{get\_integer}$;\6
\&{end};\2\6
\&{if} $(\|k<9)\W(\\{buffer}[\\{buf\_ptr}]=\.{"."})$ \1\&{then}\6
\&{begin} \37$\\{incr}(\|k)$;\5
$\\{incr}(\\{buf\_ptr})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{buffer}[\\{buf\_ptr}]=\.{"\ "}$ \1\&{then}\5
$\\{start\_vals}\K\|k$\6
\4\&{else} $\\{cannot\_start}(\.{\'1.*.-5\ specifies\ first\ page\ with\ %
\\count0=1,\ \\count2=-5.\'})$\2\2\6
\4\&{until}\5
$\\{start\_vals}=\|k$\2\2\par
\U51.\fi

\M53. \P$\X53:Determine the desired \\{max\_pages}\X\S$\6
\\{copy\_ln};\5
$\\{buf\_ptr}\K0$;\6
\&{if} $\\{buffer}[0]\I\.{"\ "}$ \1\&{then}\6
\&{begin} \37$\\{max\_pages}\K\\{get\_integer}$;\6
\&{if} $\\{max\_pages}\L0$ \1\&{then}\5
$\\{cannot\_start}(\.{\'Maxpages\ should\ be\ a\ positive\ number.\'})$\2\6
\&{end}\2\par
\U51.\fi

\N54.  Defining fonts.
\.{DVIDOC} reads the postamble first and loads
all of the fonts defined there; then it processes the pages. In this
case, a \\{fnt\_def} command should match a previous definition if and only
if the \\{fnt\_def} being processed is not in the postamble.

A global variable \\{in\_postamble} is provided to tell whether we are
processing the postamble or not.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{in\_postamble}: \37\\{boolean};\C{are we reading the postamble?}\par
\fi

\M55. \P$\X12:Set initial values\X\mathrel{+}\S$\6
$\\{in\_postamble}\K\\{false}$;\par
\fi

\M56. The following subroutine does the necessary things when a \\{fnt\_def}
command is being processed.

\Y\P\4\&{procedure}\1\  \37$\\{define\_font}(\|e:\\{integer})$;\C{\|e is an
external font number}\6
\4\&{var} \37\|f: \37$0\to\\{max\_fonts}$;\5
\|p: \37\\{integer};\C{length of the area/directory spec}\6
\|n: \37\\{integer};\C{length of the font name proper}\6
$\|c,\39\|q,\39\|d$: \37\\{integer};\C{check sum, scaled size, and design size}%
\6
\|r: \37$0\to\\{name\_length}$;\C{index into \\{cur\_name}}\6
$\|j,\39\|k$: \37$0\to\\{name\_size}$;\C{indices into \\{names}}\6
\\{mismatch}: \37\\{boolean};\C{do names disagree?}\2\6
\&{begin} \37\&{if} $\\{nf}=\\{max\_fonts}$ \1\&{then}\5
$\\{abort}(\.{\'DVIDOC\ capacity\ exceeded\ (max\ fonts=\'},\39\\{max%
\_fonts}:1,\39\.{\')!\'})$;\2\6
$\\{font\_num}[\\{nf}]\K\|e$;\5
$\|f\K0$;\6
\&{while} $\\{font\_num}[\|f]\I\|e$ \1\&{do}\5
$\\{incr}(\|f)$;\2\6
\X58:Read the font parameters into position for font \\{nf}, and print the font
name\X;\6
\&{if} $\\{in\_postamble}$ \1\&{then}\6
\&{begin} \37\&{if} $\|f<\\{nf}$ \1\&{then}\5
$\\{print\_ln}(\.{\'---this\ font\ was\ already\ defined!\'})$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\|f=\\{nf}$ \1\&{then}\5
$\\{print\_ln}(\.{\'---this\ font\ wasn\'}\.{\'t\ loaded\ before!\'})$;\2\6
\&{end};\2\6
\&{if} $\|f=\\{nf}$ \1\&{then}\5
\X59:Load the new font, unless there are problems\X\6
\4\&{else} \X57:Check that the current font definition matches the old one\X;\2%
\6
\&{end};\par
\fi

\M57. \P$\X57:Check that the current font definition matches the old one\X\S$\6
\&{begin} \37\&{if} $\\{font\_check\_sum}[\|f]\I\|c$ \1\&{then}\5
$\\{print\_ln}(\.{\'---check\ sum\ doesn\'}\.{\'t\ match\ previous\ definition!%
\'})$;\2\6
\&{if} $\\{font\_scaled\_size}[\|f]\I\|q$ \1\&{then}\5
$\\{print\_ln}(\.{\'---scaled\ size\ doesn\'}\.{\'t\ match\ previous\
definition!\'})$;\2\6
\&{if} $\\{font\_design\_size}[\|f]\I\|d$ \1\&{then}\5
$\\{print\_ln}(\.{\'---design\ size\ doesn\'}\.{\'t\ match\ previous\
definition!\'})$;\2\6
$\|j\K\\{font\_name}[\|f]$;\5
$\|k\K\\{font\_name}[\\{nf}]$;\5
$\\{mismatch}\K\\{false}$;\6
\&{while} $\|j<\\{font\_name}[\|f+1]$ \1\&{do}\6
\&{begin} \37\&{if} $\\{names}[\|j]\I\\{names}[\|k]$ \1\&{then}\5
$\\{mismatch}\K\\{true}$;\2\6
$\\{incr}(\|j)$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
\&{if} $\|k\I\\{font\_name}[\\{nf}+1]$ \1\&{then}\5
$\\{mismatch}\K\\{true}$;\2\6
\&{if} $\\{mismatch}$ \1\&{then}\5
$\\{print\_ln}(\.{\'---font\ name\ doesn\'}\.{\'t\ match\ previous\ definition!%
\'})$;\2\6
$\\{print\_ln}(\.{\'\ \'})$\6
\&{end}\par
\U56.\fi

\M58. \P$\X58:Read the font parameters into position for font \\{nf}, and print
the font name\X\S$\6
$\|c\K\\{signed\_quad}$;\5
$\\{font\_check\_sum}[\\{nf}]\K\|c$;\6
$\|q\K\\{signed\_quad}$;\5
$\\{font\_scaled\_size}[\\{nf}]\K\|q$;\6
$\|d\K\\{signed\_quad}$;\5
$\\{font\_design\_size}[\\{nf}]\K\|d$;\6
$\|p\K\\{get\_byte}$;\5
$\|n\K\\{get\_byte}$;\6
\&{if} $\\{font\_name}[\\{nf}]+\|n+\|p>\\{name\_size}$ \1\&{then}\5
$\\{abort}(\.{\'DVIDOC\ capacity\ exceeded\ (name\ size=\'},\39\\{name%
\_size}:1,\39\.{\')!\'})$;\2\6
$\\{font\_name}[\\{nf}+1]\K\\{font\_name}[\\{nf}]+\|n+\|p$;\5
$\\{print}(\.{\'Font\ \'},\39\|e:1,\39\.{\':\ \'})$;\6
\&{if} $\|n+\|p=0$ \1\&{then}\5
$\\{print}(\.{\'null\ font\ name!\'})$\6
\4\&{else} \&{for} $\|k\K\\{font\_name}[\\{nf}]\mathrel{\&{to}}\\{font\_name}[%
\\{nf}+1]-1$ \1\&{do}\5
$\\{names}[\|k]\K\\{get\_byte}$;\2\2\6
$\\{incr}(\\{nf})$;\5
$\\{print\_font}(\\{nf}-1)$;\5
$\\{decr}(\\{nf})$\par
\U56.\fi

\M59. \P$\X59:Load the new font, unless there are problems\X\S$\6
\&{begin} \37\X63:Move font name into the \\{cur\_name} string\X;\6
\\{open\_tfm\_file};\6
\&{if} $\\{eof}(\\{tfm\_file})$ \1\&{then}\5
$\\{print}(\.{\'---not\ loaded,\ TFM\ file\ can\'}\.{\'t\ be\ opened!\'})$\6
\4\&{else} \&{begin} \37\&{if} $(\|q\L0)\V(\|q\G\O{1000000000})$ \1\&{then}\5
$\\{print}(\.{\'---not\ loaded,\ bad\ scale\ (\'},\39\|q:1,\39\.{\')!\'})$\6
\4\&{else} \&{if} $(\|d\L0)\V(\|d\G\O{1000000000})$ \1\&{then}\5
$\\{print}(\.{\'---not\ loaded,\ bad\ design\ size\ (\'},\39\|d:1,\39\.{\')!%
\'})$\6
\4\&{else} \&{if} $\\{in\_TFM}(\|q)$ \1\&{then}\5
\X60:Finish loading the new font info\X;\2\2\2\6
\&{end};\2\6
$\\{print\_ln}(\.{\'\ \'})$;\6
\&{end}\par
\U56.\fi

\M60. \P$\X60:Finish loading the new font info\X\S$\6
\&{begin} \37$\\{font\_space}[\\{nf}]\K\|q\mathbin{\&{div}}6$;\C{this is a
3-unit ``thin space''}\6
\&{if} $(\|c\I0)\W(\\{tfm\_check\_sum}\I0)\W(\|c\I\\{tfm\_check\_sum})$ \1%
\&{then}\6
\&{begin} \37$\\{print\_ln}(\.{\'---beware:\ check\ sums\ do\ not\ agree!\'})$;%
\5
$\\{print\_ln}(\.{\'\ \ \ (\'},\39\|c:1,\39\.{\'\ vs.\ \'},\39\\{tfm\_check%
\_sum}:1,\39\.{\')\'})$;\5
$\\{print}(\.{\'\ \ \ \'})$;\6
\&{end};\2\6
$\\{print}(\.{\'---loaded\ at\ size\ \'},\39\|q:1,\39\.{\'\ DVI\ units\'})$;\5
$\|d\K\\{round}((100.0\ast\\{horiz\_conv}\ast\|q)/(\\{true\_horiz\_conv}\ast%
\|d))$;\6
\&{if} $\|d\I100$ \1\&{then}\6
\&{begin} \37$\\{print\_ln}(\.{\'\ \'})$;\5
$\\{print}(\.{\'\ (this\ font\ is\ magnified\ \'},\39\|d:1,\39\.{\'\%)\'})$;\6
\&{end};\2\6
$\\{incr}(\\{nf})$;\C{now the new font is officially present}\6
$\\{font\_space}[\\{nf}]\K0$;\C{for \\{out\_space} and \\{out\_vmove}}\6
\&{end}\par
\U59.\fi

\M61. If $\|p=0$, i.e., if no font directory has been specified, \.{DVIDOC}
is supposed to use the default font directory, which is a
system-dependent place where the standard fonts are kept.
The string variable \\{default\_directory} contains the name of this area.

\Y\P\D \37$\\{default\_directory\_name}\S\.{\'TeXfonts:\'}$\C{change this to
the correct name}\par
\P\D \37$\\{default\_directory\_name\_length}=9$\C{change this to the correct
length}\par
\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{default\_directory}: \37\&{packed} \37\&{array} $[1\to\\{default%
\_directory\_name\_length}]$ \1\&{of}\5
\\{char};\2\par
\fi

\M62. \P$\X12:Set initial values\X\mathrel{+}\S$\6
$\\{default\_directory}\K\\{default\_directory\_name}$;\par
\fi

\M63. The string \\{cur\_name} is supposed to be set to the external name of
the
\.{TFM} file for the current font. This usually means that we need to,
at most sites, append the
suffix ``.tfm''.

\Y\P$\4\X63:Move font name into the \\{cur\_name} string\X\S$\6
\&{for} $\|k\K1\mathrel{\&{to}}\\{name\_length}$ \1\&{do}\5
$\\{cur\_name}[\|k]\K\.{\'\ \'}$;\2\6
$\|r\K0$;\6
\&{for} $\|k\K\\{font\_name}[\\{nf}]\mathrel{\&{to}}\\{font\_name}[\\{nf}+1]-1$
\1\&{do}\6
\&{begin} \37$\\{incr}(\|r)$;\6
\&{if} $\|r+4>\\{name\_length}$ \1\&{then}\5
$\\{abort}(\.{\'DVIDOC\ capacity\ exceeded\ (max\ font\ name\ length=\'},\39%
\\{name\_length}:1,\39\.{\')!\'})$;\2\6
$\\{cur\_name}[\|r]\K\\{xchr}[\\{names}[\|k]]$;\6
\&{end};\2\6
$\\{cur\_name}[\|r+1]\K\.{\'.\'}$;\5
$\\{cur\_name}[\|r+2]\K\.{\'t\'}$;\5
$\\{cur\_name}[\|r+3]\K\.{\'f\'}$;\5
$\\{cur\_name}[\|r+4]\K\.{\'m\'}$\par
\U59.\fi

\N64.  Low level output routines.
Characters set by the \.{DVI} file are placed in \\{page\_buffer}, a two
dimensional array of characters with one element for each print
position on the page.  The \\{page\_buffer} is cleared at the beginning
of each page and printed at the end of each page.
\\{doc\_file}, the file to which the document is destined, is an ordinary text
file.

To optimize the initialization and printing of \\{page\_buffer}, a high
water mark line number, \\{page\_hwm}, is kept to indicate the last line
that contains any printable characters, and for each line a high water
mark character number, \\{line\_hwm}, is kept to indicate the location of
the last printable character in the line.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\|i: \37$1\to\\{name\_length}$;\6
\4\\{log\_errors}: \37\\{boolean};\6
\4\\{err\_file}: \37\\{text\_file};\6
\4\\{page\_buffer}: \37\&{packed} \37\&{array} $[1\to\\{page\_width\_max},\391%
\to\\{page\_length\_max}]$ \1\&{of}\5
\\{ASCII\_code};\C{storage for a document page}\2\6
\4\\{line\_hwm}: \37\&{array} $[1\to\\{page\_length\_max}]$ \1\&{of}\5
$0\to\\{page\_width\_max}$;\C{high water marks for each line}\2\6
\4\\{page\_hwm}: \37$0\to\\{page\_length\_max}$;\C{high water mark for page}\par
\fi

\M65. \\{err\_file} needs to be opened. Create \\{err\_file} with a suffix of
.err.

\Y\P$\4\X65:Create error message file\X\S$\6
\&{if} $\\{log\_errors}$ \1\&{then}\6
\&{begin} \37$\\{cur\_name}\K\\{base\_name}$;\5
$\|i\K1$;\6
\&{while} $(\|i\L\\{name\_length})\W(\\{cur\_name}[\|i]\I\.{\'\ \'})$ \1\&{do}\5
$\\{incr}(\|i)$;\2\6
$\\{cur\_name}[\|i-3]\K\.{\'e\'}$;\5
$\\{cur\_name}[\|i-2]\K\.{\'r\'}$;\5
$\\{cur\_name}[\|i-1]\K\.{\'r\'}$;\6
\&{if} $\\{test\_access}(\\{write\_access\_mode},\39\\{no\_file\_path})$ \1%
\&{then}\5
$\\{rewrite}(\\{err\_file},\39\\{cur\_name})$\6
\4\&{else} $\\{cannot\_start}(\.{\'Cannot\ create\ error\ file\'})$\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{cur\_name}\K\.{\'/dev/null\'}$;\6
\&{if} $\\{test\_access}(\\{write\_access\_mode},\39\\{no\_file\_path})$ \1%
\&{then}\5
$\\{rewrite}(\\{err\_file},\39\\{cur\_name})$\6
\4\&{else} $\\{cannot\_start}(\.{\'Somebody\ stole\ /dev/null!\'})$\2\6
\&{end};\2\par
\U102.\fi

\M66. The \\{flush\_page} procedure will print the \\{page\_buffer}.

\Y\P\4\&{procedure}\1\  \37\\{flush\_page};\6
\4\&{var} \37\|i: \37$0\to\\{page\_width\_max}$;\5
\|j: \37$0\to\\{page\_length\_max}$;\2\6
\&{begin} \37\&{for} $\|j\K1\mathrel{\&{to}}\\{page\_hwm}$ \1\&{do}\6
\&{begin} \37\&{for} $\|i\K1\mathrel{\&{to}}\\{line\_hwm}[\|j]$ \1\&{do}\5
$\\{write}(\\{doc\_file},\39\\{xchr}[\\{page\_buffer}[\|i,\39\|j]])$;\2\6
$\\{write\_ln}(\\{doc\_file})$\6
\&{end};\2\6
$\\{write}(\\{doc\_file},\39\\{chr}(12))$\C{end the page with a form feed}\6
\&{end};\par
\fi

\M67. The \\{empty\_page} procedure will empty the \\{page\_buffer} data
structure.

\Y\P\4\&{procedure}\1\  \37\\{empty\_page};\2\6
\&{begin} \37$\\{page\_hwm}\K0$\6
\&{end};\par
\fi

\M68. And the \\{out\_char} procedure puts something into it.  The usual
printable
ASCII characters will be put into the buffer as is.  Non-printable characters,
including the blank, will be put into the buffer as question mark chracters.

\Y\P\4\&{procedure}\1\  \37$\\{out\_char}(\|p,\39\\{hh},\39\\{vv}:%
\\{integer})$;\6
\4\&{var} \37\|i: \37$1\to\\{page\_width\_max}$;\5
\|j: \37$1\to\\{page\_length\_max}$;\C{\\{hh} and \\{vv} range from zero up
while \|i and \|j range from one up.}\6
\|k: \37\\{integer};\5
\|c: \37\\{ASCII\_code};\2\6
\&{begin} \37\&{if} $(\|p>\.{"\ "})\W(\|p\L\.{"\~"})$ \1\&{then}\5
$\|c\K\|p$\6
\4\&{else} $\|c\K\\{xord}[\.{\'?\'}]$;\2\6
\&{if} $(\\{hh}>\\{page\_width\_max}-1)\V(\\{vv}>\\{page\_length\_max}-1)$ \1%
\&{then}\6
\&{begin} \37$\\{print\_ln}(\.{\'\ \'})$;\5
$\\{print}(\.{\'Character\ "\'},\39\\{xchr}[\|c],\39\.{\'"\ set\ at\ column\ %
\'},\39\\{hh}+1:1)$;\5
$\\{print\_ln}(\.{\'\ and\ row\ \'},\39\\{vv}+1:1,\39\.{\',\'})$;\5
$\\{print}(\.{\'outside\ the\ range\ of\ DVIDOC\ (\'})$;\5
$\\{print}(\\{page\_width\_max}:1,\39\.{\',\'},\39\\{page\_length\_max}:1,\39%
\.{\').\'})$;\5
$\\{print\_ln}(\.{\'\ \'})$\6
\&{end}\6
\4\&{else} \&{begin} \37$\|i\K\\{hh}+1$;\5
$\|j\K\\{vv}+1$;\6
\&{if} $\|j>\\{page\_hwm}$ \1\&{then}\6
\&{begin} \37\C{initialize any as yet untouched lines}\6
\&{for} $\|k\K\\{page\_hwm}+1\mathrel{\&{to}}\|j$ \1\&{do}\5
$\\{line\_hwm}[\|k]\K0$;\2\6
$\\{page\_hwm}\K\|j$\6
\&{end};\2\6
\&{if} $\|i>\\{line\_hwm}[\|j]$ \1\&{then}\6
\&{begin} \37\C{initialize any as yet untouched characters}\6
\&{for} $\|k\K\\{line\_hwm}[\|j]+1\mathrel{\&{to}}\|i$ \1\&{do}\5
$\\{page\_buffer}[\|k,\39\|j]\K\\{xord}[\.{\'\ \'}]$;\2\6
$\\{line\_hwm}[\|j]\K\|i$\6
\&{end};\2\6
$\\{page\_buffer}[\|i,\39\|j]\K\|c$\C{put the character in its place}\6
\&{end}\2\6
\&{end};\par
\fi

\N69.  Translation to symbolic form.
The main work of \.{DVIDOC} is accomplished by the \\{do\_page} procedure,
which produces the output for an entire page, assuming that the \\{bop}
command for that page has already been processed. This procedure is
essentially an interpretive routine that reads and acts on the \.{DVI}
commands.

\fi

\M70. The definition of \.{DVI} files refers to six registers,
$(h,v,w,x,y,z)$, which hold integer values in \.{DVI} units.  In practice,
we also need registers \\{hh} and \\{vv}, the pixel analogs of $h$ and $v$,
since it is not always true that $\\{hh}=\\{horiz\_pixel\_round}(\|h)$ or
$\\{vv}=\\{vert\_pixel\_round}(\|v)$.

The stack of $(h,v,w,x,y,z)$ values is represented by eight arrays
called \\{hstack}, \dots, \\{zstack}, \\{hhstack}, and \\{vvstack}.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4$\|h,\39\|v,\39\|w,\39\|x,\39\|y,\39\|z,\39\\{hh},\39\\{vv}$: \37\\{integer};%
\C{current state values}\6
\4$\\{hstack},\39\\{vstack},\39\\{wstack},\39\\{xstack},\39\\{ystack},\39%
\\{zstack}$: \37\&{array} $[0\to\\{stack\_size}]$ \1\&{of}\5
\\{integer};\C{pushed down values in \.{DVI} units}\2\6
\4$\\{hhstack},\39\\{vvstack}$: \37\&{array} $[0\to\\{stack\_size}]$ \1\&{of}\5
\\{integer};\C{pushed down values in pixels}\2\par
\fi

\M71. Three characteristics of the pages (their \\{max\_v}, \\{max\_h}, and
\\{max\_s}) are specified in the postamble, and a warning message
is printed if these limits are exceeded. Actually \\{max\_v} is set to
the maximum height plus depth of a page, and \\{max\_h} to the maximum width,
for purposes of page layout. Since characters can legally be set outside
of the page boundaries, it is not an error when \\{max\_v} or \\{max\_h} is
exceeded. But \\{max\_s} should not be exceeded.

The postamble also specifies the total number of pages; \.{DVIDOC}
checks to see if this total is accurate.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{max\_v}: \37\\{integer};\C{the value of $\\{abs}(\|v)$ should probably not
exceed this}\6
\4\\{max\_h}: \37\\{integer};\C{the value of $\\{abs}(\|h)$ should probably not
exceed this}\6
\4\\{max\_s}: \37\\{integer};\C{the stack depth should not exceed this}\6
\4$\\{max\_v\_so\_far},\39\\{max\_h\_so\_far},\39\\{max\_s\_so\_far}$: \37%
\\{integer};\C{the record high levels}\6
\4\\{total\_pages}: \37\\{integer};\C{the stated total number of pages}\6
\4\\{page\_count}: \37\\{integer};\C{the total number of pages seen so far}\par
\fi

\M72. \P$\X12:Set initial values\X\mathrel{+}\S$\6
$\\{max\_v}\K\O{17777777777}-99$;\5
$\\{max\_h}\K\O{17777777777}-99$;\5
$\\{max\_s}\K\\{stack\_size}+1$;\6
$\\{max\_v\_so\_far}\K0$;\5
$\\{max\_h\_so\_far}\K0$;\5
$\\{max\_s\_so\_far}\K0$;\5
$\\{page\_count}\K0$;\par
\fi

\M73. Before we get into the details of \\{do\_page}, it is convenient to
consider a simpler routine that computes the first parameter of each
opcode.

\Y\P\D \37$\\{four\_cases}(\#)\S\#,\39\#+1,\39\#+2,\39\#+3$\par
\P\D \37$\\{eight\_cases}(\#)\S\\{four\_cases}(\#),\39\\{four\_cases}(\#+4)$\par
\P\D \37$\\{sixteen\_cases}(\#)\S\\{eight\_cases}(\#),\39\\{eight\_cases}(%
\#+8)$\par
\P\D \37$\\{thirty\_two\_cases}(\#)\S\\{sixteen\_cases}(\#),\39\\{sixteen%
\_cases}(\#+16)$\par
\P\D \37$\\{sixty\_four\_cases}(\#)\S\\{thirty\_two\_cases}(\#),\39\\{thirty%
\_two\_cases}(\#+32)$\par
\Y\P\4\&{function}\1\  \37$\\{first\_par}(\|o:\\{eight\_bits})$: \37%
\\{integer};\2\6
\&{begin} \37\&{case} $\|o$ \1\&{of}\6
\4$\\{sixty\_four\_cases}(\\{set\_char\_0}),\39\\{sixty\_four\_cases}(\\{set%
\_char\_0}+64)$: \37$\\{first\_par}\K\|o-\\{set\_char\_0}$;\6
\4$\\{set1},\39\\{put1},\39\\{fnt1},\39\\{xxx1},\39\\{fnt\_def1}$: \37$\\{first%
\_par}\K\\{get\_byte}$;\6
\4$\\{set1}+1,\39\\{put1}+1,\39\\{fnt1}+1,\39\\{xxx1}+1,\39\\{fnt\_def1}+1$: %
\37$\\{first\_par}\K\\{get\_two\_bytes}$;\6
\4$\\{set1}+2,\39\\{put1}+2,\39\\{fnt1}+2,\39\\{xxx1}+2,\39\\{fnt\_def1}+2$: %
\37$\\{first\_par}\K\\{get\_three\_bytes}$;\6
\4$\\{right1},\39\\{w1},\39\\{x1},\39\\{down1},\39\\{y1},\39\\{z1}$: \37$%
\\{first\_par}\K\\{signed\_byte}$;\6
\4$\\{right1}+1,\39\\{w1}+1,\39\\{x1}+1,\39\\{down1}+1,\39\\{y1}+1,\39%
\\{z1}+1$: \37$\\{first\_par}\K\\{signed\_pair}$;\6
\4$\\{right1}+2,\39\\{w1}+2,\39\\{x1}+2,\39\\{down1}+2,\39\\{y1}+2,\39%
\\{z1}+2$: \37$\\{first\_par}\K\\{signed\_trio}$;\6
\4$\\{set1}+3,\39\\{set\_rule},\39\\{put1}+3,\39\\{put\_rule},\39\\{right1}+3,%
\39\\{w1}+3,\39\\{x1}+3,\39\\{down1}+3,\39\\{y1}+3,\39\\{z1}+3,\39\\{fnt1}+3,%
\39\\{xxx1}+3,\39\\{fnt\_def1}+3$: \37$\\{first\_par}\K\\{signed\_quad}$;\6
\4$\\{nop},\39\\{bop},\39\\{eop},\39\\{push},\39\\{pop},\39\\{pre},\39\\{post},%
\39\\{post\_post},\39\\{undefined\_commands}$: \37$\\{first\_par}\K0$;\6
\4\\{w0}: \37$\\{first\_par}\K\|w$;\6
\4\\{x0}: \37$\\{first\_par}\K\|x$;\6
\4\\{y0}: \37$\\{first\_par}\K\|y$;\6
\4\\{z0}: \37$\\{first\_par}\K\|z$;\6
\4$\\{sixty\_four\_cases}(\\{fnt\_num\_0})$: \37$\\{first\_par}\K\|o-\\{fnt%
\_num\_0}$;\2\6
\&{end};\6
\&{end};\par
\fi

\M74. Here are two other subroutines that we need: They compute the number of
pixels in the height or width of a rule. Characters and rules will line up
properly if the sizes are computed precisely as specified here.  (Since
\\{horiz\_conv} and \\{vert\_conv}
are computed with some floating-point roundoff error, in a
machine-dependent way, format designers who are tailoring something for a
particular resolution should not plan their measurements to come out to an
exact integer number of pixels; they should compute things so that the
rule dimensions are a little less than an integer number of pixels, e.g.,
4.99 instead of 5.00.)

\Y\P\4\&{function}\1\  \37$\\{horiz\_rule\_pixels}(\|x:\\{integer})$: \37%
\\{integer};\C{computes $\lceil\\{horiz\_conv}\cdot x\rceil$}\6
\4\&{var} \37\|n: \37\\{integer};\2\6
\&{begin} \37$\|n\K\\{trunc}(\\{horiz\_conv}\ast\|x)$;\6
\&{if} $\|n<\\{horiz\_conv}\ast\|x$ \1\&{then}\5
$\\{horiz\_rule\_pixels}\K\|n+1$\ \&{else} $\\{horiz\_rule\_pixels}\K\|n$;\2\6
\&{end};\6
\4\&{function}\1\  \37$\\{vert\_rule\_pixels}(\|x:\\{integer})$: \37%
\\{integer};\C{computes $\lceil\\{vert\_conv}\cdot x\rceil$}\6
\4\&{var} \37\|n: \37\\{integer};\2\6
\&{begin} \37$\|n\K\\{trunc}(\\{vert\_conv}\ast\|x)$;\6
\&{if} $\|n<\\{vert\_conv}\ast\|x$ \1\&{then}\5
$\\{vert\_rule\_pixels}\K\|n+1$\ \&{else} $\\{vert\_rule\_pixels}\K\|n$;\2\6
\&{end};\par
\fi

\M75. Strictly speaking, the \\{do\_page} procedure is really a function with
side effects, not a `\&{procedure}'\thinspace; it returns the value \\{false}
if \.{DVIDOC} should be aborted because of some unusual happening. The
subroutine is organized as a typical interpreter, with a multiway branch
on the command code followed by \&{goto}  statements leading to routines that
finish up the activities common to different commands. We will use the
following labels:

\Y\P\D \37$\\{fin\_set}=41$\C{label for commands that set or put a character}%
\par
\P\D \37$\\{fin\_rule}=42$\C{label for commands that set or put a rule}\par
\P\D \37$\\{move\_right}=43$\C{label for commands that change \|h}\par
\P\D \37$\\{move\_down}=44$\C{label for commands that change \|v}\par
\P\D \37$\\{show\_state}=45$\C{label for commands that change \|s}\par
\P\D \37$\\{change\_font}=46$\C{label for commands that change \\{cur\_font}}%
\par
\fi

\M76. Some \PASCAL\ compilers severely restrict the length of procedure bodies,
so we shall split \\{do\_page} into two parts, one of which is
called \\{special\_cases}. The different parts communicate with each other
via the global variables mentioned above, together with the following ones:

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\|s: \37\\{integer};\C{current stack size}\6
\4\\{ss}: \37\\{integer};\C{stack size to print}\6
\4\\{cur\_font}: \37\\{integer};\C{current internal font number}\par
\fi

\M77. Here is the overall setup.

\Y\P\hbox{\4}\X80:Declare the function called \\{special\_cases}\X\6
\4\&{function}\1\  \37\\{do\_page}: \37\\{boolean};\6
\4\&{label} \37$\\{fin\_set},\39\\{fin\_rule},\39\\{move\_right},\39\\{show%
\_state},\39\\{done},\399998,\399999$;\6
\4\&{var} \37\|o: \37\\{eight\_bits};\C{operation code of the current command}\6
$\|p,\39\|q$: \37\\{integer};\C{parameters of the current command}\6
\|a: \37\\{integer};\C{byte number of the current command}\6
$\|i,\39\|j$: \37\\{integer};\C{for loop indices for setting rules}\6
\\{hhh}: \37\\{integer};\C{\|h, rounded to the nearest pixel}\2\6
\&{begin} \37\\{empty\_page};\5
$\\{cur\_font}\K\\{nf}$;\C{set current font undefined}\6
$\|s\K0$;\5
$\|h\K0$;\5
$\|v\K0$;\5
$\|w\K0$;\5
$\|x\K0$;\5
$\|y\K0$;\5
$\|z\K0$;\5
$\\{hh}\K0$;\5
$\\{vv}\K0$;\C{initialize the state variables}\6
\&{while} $\\{true}$ \1\&{do}\5
\X78:Translate the next command in the \.{DVI} file; \&{goto} 9999 with $\\{do%
\_page}=\\{true}$ if it was \\{eop}; \&{goto} 9998 if premature termination is
needed\X;\2\6
\49998: \37$\\{print\_ln}(\.{\'!\'})$;\5
$\\{do\_page}\K\\{false}$;\6
\49999: \37\&{end};\par
\fi

\M78.

\Y\P$\4\X78:Translate the next command in the \.{DVI} file; \&{goto} 9999 with
$\\{do\_page}=\\{true}$ if it was \\{eop}; \&{goto} 9998 if premature
termination is needed\X\S$\6
\&{begin} \37$\|a\K\\{cur\_loc}$;\5
$\|o\K\\{get\_byte}$;\5
$\|p\K\\{first\_par}(\|o)$;\6
\&{if} $\\{eof}(\\{dvi\_file})$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'the\ file\ ended\ prematurely\'})$;\2\6
\X79:Start translation of command \|o and \&{goto}  the appropriate label to
finish the job\X;\6
\4\\{fin\_set}: \37\X87:Finish a command that either sets or puts a character,
then \&{goto} \\{move\_right} or \\{done}\X;\6
\4\\{fin\_rule}: \37\X88:Finish a command that either sets or puts a rule, then
\&{goto} \\{move\_right} or \\{done}\X;\6
\4\\{move\_right}: \37\X89:Finish a command that sets $\|h\K\|h+\|q$, then %
\&{goto} \\{done}\X;\6
\4\\{show\_state}: \37;\6
\4\\{done}: \37;\6
\&{end}\par
\U77.\fi

\M79. The multiway switch in \\{first\_par}, above, was organized by the length
of each command; the one in \\{do\_page} is organized by the semantics.

\Y\P$\4\X79:Start translation of command \|o and \&{goto}  the appropriate
label to finish the job\X\S$\6
\&{if} $\|o<\\{set\_char\_0}+128$ \1\&{then}\5
\X86:Translate a \\{set\_char} command\X\6
\4\&{else} \&{case} $\|o$ \1\&{of}\6
\4$\\{four\_cases}(\\{set1})$: \37\&{begin} \37$\\{out\_char}(\|p,\39\\{hh},\39%
\\{vv})$;\5
\&{goto} \37\\{fin\_set};\6
\&{end};\6
\4\\{set\_rule}: \37\&{begin} \37\&{goto} \37\\{fin\_rule};\6
\&{end};\6
\4\\{put\_rule}: \37\&{begin} \37\&{goto} \37\\{fin\_rule};\6
\&{end};\6
\hbox{\4}\X81:Cases for commands \\{nop}, \\{bop}, \dots, \\{pop}\X\6
\hbox{\4}\X82:Cases for horizontal motion\X\6
\4\&{othercases} \37\&{if} $\\{special\_cases}(\|o,\39\|p,\39\|a)$ \1\&{then}\5
\&{goto} \37\\{done}\ \&{else} \&{goto} \379998\2\2\6
\&{endcases}\2\par
\U78.\fi

\M80. \P$\X80:Declare the function called \\{special\_cases}\X\S$\6
\4\&{function}\1\  \37$\\{special\_cases}(\|o:\\{eight\_bits};\,\35\|p,\39\|a:%
\\{integer})$: \37\\{boolean};\6
\4\&{label} \37$\\{change\_font},\39\\{move\_down},\39\\{done},\399998$;\6
\4\&{var} \37\|q: \37\\{integer};\C{parameter of the current command}\6
\|k: \37\\{integer};\C{loop index}\6
\\{bad\_char}: \37\\{boolean};\C{has a non-ASCII character code appeared in
this \\{xxx}?}\6
\\{pure}: \37\\{boolean};\C{is the command error-free?}\6
\\{vvv}: \37\\{integer};\C{\|v, rounded to the nearest pixel}\2\6
\&{begin} \37$\\{pure}\K\\{true}$;\6
\&{case} $\|o$ \1\&{of}\6
\4$\\{four\_cases}(\\{put1})$: \37\&{begin} \37\&{goto} \37\\{done};\6
\&{end};\6
\hbox{\4}\X83:Cases for vertical motion\X\6
\hbox{\4}\X84:Cases for fonts\X\6
\4$\\{four\_cases}(\\{xxx1})$: \37\X85:Translate an \\{xxx} command and %
\&{goto} \\{done}\X;\6
\4\\{pre}: \37\&{begin} \37$\\{error}(\.{\'preamble\ command\ within\ a\ page!%
\'})$;\5
\&{goto} \379998;\6
\&{end};\6
\4$\\{post},\39\\{post\_post}$: \37\&{begin} \37$\\{error}(\.{\'postamble\
command\ within\ a\ page!\'})$;\5
\&{goto} \379998;\6
\&{end};\6
\4\&{othercases} \37\&{begin} \37$\\{error}(\.{\'undefined\ command\ \'},\39%
\|o:1,\39\.{\'!\'})$;\5
\&{goto} \37\\{done};\6
\&{end}\2\6
\&{endcases};\6
\4\\{move\_down}: \37\X90:Finish a command that sets $\|v\K\|v+\|p$, then %
\&{goto} \\{done}\X;\6
\4\\{change\_font}: \37\X91:Finish a command that changes the current font,
then \&{goto} \\{done}\X;\6
\49998: \37$\\{pure}\K\\{false}$;\6
\4\\{done}: \37$\\{special\_cases}\K\\{pure}$;\6
\&{end};\par
\U77.\fi

\M81. \P$\X81:Cases for commands \\{nop}, \\{bop}, \dots, \\{pop}\X\S$\6
\4\\{nop}: \37\&{begin} \37\&{goto} \37\\{done};\6
\&{end};\6
\4\\{bop}: \37\&{begin} \37$\\{error}(\.{\'bop\ occurred\ before\ eop!\'})$;\5
\&{goto} \379998;\6
\&{end};\6
\4\\{eop}: \37\&{begin} \37\&{if} $\|s\I0$ \1\&{then}\5
$\\{error}(\.{\'stack\ not\ empty\ at\ end\ of\ page\ (level\ \'},\39\|s:1,\39%
\.{\')!\'})$;\2\6
$\\{do\_page}\K\\{true}$;\5
\\{flush\_page};\5
\&{goto} \379999;\6
\&{end};\6
\4\\{push}: \37\&{begin} \37\&{if} $\|s=\\{max\_s\_so\_far}$ \1\&{then}\6
\&{begin} \37$\\{max\_s\_so\_far}\K\|s+1$;\6
\&{if} $\|s=\\{max\_s}$ \1\&{then}\5
$\\{error}(\.{\'deeper\ than\ claimed\ in\ postamble!\'})$;\2\6
\&{if} $\|s=\\{stack\_size}$ \1\&{then}\6
\&{begin} \37$\\{error}(\.{\'DVIDOC\ capacity\ exceeded\ (stack\ size=\'},\39%
\\{stack\_size}:1,\39\.{\')\'})$;\5
\&{goto} \379998;\6
\&{end};\2\6
\&{end};\2\6
$\\{hstack}[\|s]\K\|h$;\5
$\\{vstack}[\|s]\K\|v$;\5
$\\{wstack}[\|s]\K\|w$;\5
$\\{xstack}[\|s]\K\|x$;\5
$\\{ystack}[\|s]\K\|y$;\5
$\\{zstack}[\|s]\K\|z$;\5
$\\{hhstack}[\|s]\K\\{hh}$;\5
$\\{vvstack}[\|s]\K\\{vv}$;\5
$\\{incr}(\|s)$;\5
$\\{ss}\K\|s-1$;\5
\&{goto} \37\\{show\_state};\6
\&{end};\6
\4\\{pop}: \37\&{begin} \37\&{if} $\|s=0$ \1\&{then}\5
$\\{error}(\.{\'Pop\ illegal\ at\ level\ zero!\'})$\6
\4\&{else} \&{begin} \37$\\{decr}(\|s)$;\5
$\\{hh}\K\\{hhstack}[\|s]$;\5
$\\{vv}\K\\{vvstack}[\|s]$;\5
$\|h\K\\{hstack}[\|s]$;\5
$\|v\K\\{vstack}[\|s]$;\5
$\|w\K\\{wstack}[\|s]$;\5
$\|x\K\\{xstack}[\|s]$;\5
$\|y\K\\{ystack}[\|s]$;\5
$\|z\K\\{zstack}[\|s]$;\6
\&{end};\2\6
$\\{ss}\K\|s$;\5
\&{goto} \37\\{show\_state};\6
\&{end};\par
\U79.\fi

\M82. Rounding to the nearest pixel is best done in the manner shown here, so
as
to be inoffensive to the eye: When the horizontal motion is small, like a
kern, \\{hh} changes by rounding the kern; but when the motion is large, \\{hh}
changes by rounding the true position \|h so that accumulated rounding errors
disappear.


\Y\P\D \37$\\{out\_space}\S$\1\6
\&{if} $\\{abs}(\|p)\G\\{font\_space}[\\{cur\_font}]$ \1\&{then}\6
\&{begin} \37$\\{hh}\K\\{horiz\_pixel\_round}(\|h+\|p)$;\6
\&{end}\6
\4\&{else} $\\{hh}\K\\{hh}+\\{horiz\_pixel\_round}(\|p)$;\2\2\6
$\|q\K\|p$;\5
\&{goto} \37\\{move\_right}\par
\Y\P$\4\X82:Cases for horizontal motion\X\S$\6
\4$\\{four\_cases}(\\{right1})$: \37\&{begin} \37\\{out\_space};\6
\&{end};\6
\4$\\{w0},\39\\{four\_cases}(\\{w1})$: \37\&{begin} \37$\|w\K\|p$;\5
\\{out\_space};\6
\&{end};\6
\4$\\{x0},\39\\{four\_cases}(\\{x1})$: \37\&{begin} \37$\|x\K\|p$;\5
\\{out\_space};\6
\&{end};\par
\U79.\fi

\M83. Vertical motion is done similarly, but with the threshold between
``small'' and ``large'' increased by a factor of five. The idea is to make
fractions like ``$1\over2$'' round consistently, but to absorb accumulated
rounding errors in the baseline-skip moves.

\Y\P\D \37$\\{out\_vmove}\S$\1\6
\&{if} $\\{abs}(\|p)\G5\ast\\{font\_space}[\\{cur\_font}]$ \1\&{then}\5
$\\{vv}\K\\{vert\_pixel\_round}(\|v+\|p)$\6
\4\&{else} $\\{vv}\K\\{vv}+\\{vert\_pixel\_round}(\|p)$;\2\2\6
\&{goto} \37\\{move\_down}\par
\Y\P$\4\X83:Cases for vertical motion\X\S$\6
\4$\\{four\_cases}(\\{down1})$: \37\&{begin} \37\\{out\_vmove};\6
\&{end};\6
\4$\\{y0},\39\\{four\_cases}(\\{y1})$: \37\&{begin} \37$\|y\K\|p$;\5
\\{out\_vmove};\6
\&{end};\6
\4$\\{z0},\39\\{four\_cases}(\\{z1})$: \37\&{begin} \37$\|z\K\|p$;\5
\\{out\_vmove};\6
\&{end};\par
\U80.\fi

\M84. \P$\X84:Cases for fonts\X\S$\6
\4$\\{sixty\_four\_cases}(\\{fnt\_num\_0})$: \37\&{begin} \37\&{goto} \37%
\\{change\_font};\6
\&{end};\6
\4$\\{four\_cases}(\\{fnt1})$: \37\&{begin} \37\&{goto} \37\\{change\_font};\6
\&{end};\6
\4$\\{four\_cases}(\\{fnt\_def1})$: \37\&{begin} \37$\\{define\_font}(\|p)$;\5
\&{goto} \37\\{done};\6
\&{end};\par
\U80.\fi

\M85. \P$\X85:Translate an \\{xxx} command and \&{goto} \\{done}\X\S$\6
\&{begin} \37$\\{print}(\.{\'xxx\'}\.{\'\'})$;\5
$\\{bad\_char}\K\\{false}$;\6
\&{for} $\|k\K1\mathrel{\&{to}}\|p$ \1\&{do}\6
\&{begin} \37$\|q\K\\{get\_byte}$;\6
\&{if} $(\|q<\.{"\ "})\V(\|q>\.{"\~"})$ \1\&{then}\5
$\\{bad\_char}\K\\{true}$;\2\6
$\\{print}(\\{xchr}[\|q])$;\6
\&{end};\2\6
$\\{print}(\.{\'\'}\.{\'\'})$;\6
\&{if} $\\{bad\_char}$ \1\&{then}\5
$\\{error}(\.{\'non-ASCII\ character\ in\ xxx\ command!\'})$;\2\6
\&{goto} \37\\{done};\6
\&{end}\par
\U80.\fi

\M86. \P$\X86:Translate a \\{set\_char} command\X\S$\6
\&{begin} \37$\\{out\_char}(\|p,\39\\{hh},\39\\{vv})$\6
\&{end}\par
\U79.\fi

\M87. \P$\X87:Finish a command that either sets or puts a character, then %
\&{goto} \\{move\_right} or \\{done}\X\S$\6
\&{if} $\|p<0$ \1\&{then}\5
$\|p\K255-((-1-\|p)\mathbin{\&{mod}}256)$\6
\4\&{else} \&{if} $\|p\G256$ \1\&{then}\5
$\|p\K\|p\mathbin{\&{mod}}256$;\C{width computation for oriental fonts}\2\2\6
\&{if} $(\|p<\\{font\_bc}[\\{cur\_font}])\V(\|p>\\{font\_ec}[\\{cur\_font}])$ %
\1\&{then}\5
$\|q\K\\{invalid\_width}$\6
\4\&{else} $\|q\K\\{char\_width}(\\{cur\_font})(\|p)$;\2\6
\&{if} $\|q=\\{invalid\_width}$ \1\&{then}\6
\&{begin} \37$\\{error}(\.{\'character\ \'},\39\|p:1,\39\.{\'\ invalid\ in\
font\ \'})$;\5
$\\{print\_font}(\\{cur\_font})$;\6
\&{if} $\\{cur\_font}\I\\{nf}$ \1\&{then}\5
$\\{print}(\.{\'!\'})$;\C{font \\{nf} has `\.!' in its name}\2\6
\&{end};\2\6
\&{if} $\|o\G\\{put1}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\|q=\\{invalid\_width}$ \1\&{then}\5
$\|q\K0$\6
\4\&{else} $\\{hh}\K\\{hh}+\\{char\_pixel\_width}(\\{cur\_font})(\|p)$;\2\6
\&{goto} \37\\{move\_right}\par
\U78.\fi

\M88. \P$\X88:Finish a command that either sets or puts a rule, then \&{goto} %
\\{move\_right} or \\{done}\X\S$\6
$\|q\K\\{signed\_quad}$;\6
\&{if} $(\|p>0)\W(\|q>0)$ \1\&{then}\6
\&{for} $\|i\K\\{hh}\mathrel{\&{to}}\\{hh}+\\{horiz\_rule\_pixels}(\|q)-1$ \1%
\&{do}\6
\&{for} $\|j\K\\{vv}\mathrel{\&{downto}}\\{vv}-\\{vert\_rule\_pixels}(\|p)+1$ %
\1\&{do}\5
$\\{out\_char}(\\{xord}[\.{\'-\'}],\39\|i,\39\|j)$;\2\2\2\6
\&{if} $\|o=\\{put\_rule}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{hh}\K\\{hh}+\\{horiz\_rule\_pixels}(\|q)$;\5
\&{goto} \37\\{move\_right}\par
\U78.\fi

\M89. Since \.{DVIDOC} is intended to diagnose strange errors, it checks
carefully to make sure that \|h and \|v do not get out of range.
Normal \.{DVI}-reading programs need not do this.

\Y\P\D \37$\\{infinity}\S\O{17777777777}$\C{$\infty$ (approximately)}\par
\P\D \37$\\{max\_drift}=2$\C{we insist that abs$(\\{hh}-\\{pixel\_round}(\|h))%
\L\\{max\_drift}$}\par
\Y\P$\4\X89:Finish a command that sets $\|h\K\|h+\|q$, then \&{goto} \\{done}\X%
\S$\6
\&{if} $(\|h>0)\W(\|q>0)$ \1\&{then}\6
\&{if} $\|h>\\{infinity}-\|q$ \1\&{then}\6
\&{begin} \37$\\{error}(\.{\'arithmetic\ overflow!\ parameter\ changed\ from\ %
\'},\39\|q:1,\39\.{\'\ to\ \'},\39\\{infinity}-\|h:1)$;\5
$\|q\K\\{infinity}-\|h$;\6
\&{end};\2\2\6
\&{if} $(\|h<0)\W(\|q<0)$ \1\&{then}\6
\&{if} $-\|h>\|q+\\{infinity}$ \1\&{then}\6
\&{begin} \37$\\{error}(\.{\'arithmetic\ overflow!\ parameter\ changed\ from\ %
\'},\39\|q:1,\39\.{\'\ to\ \'},\39(-\|h)-\\{infinity}:1)$;\5
$\|q\K(-\|h)-\\{infinity}$;\6
\&{end};\2\2\6
$\\{hhh}\K\\{horiz\_pixel\_round}(\|h+\|q)$;\6
\&{if} $\\{abs}(\\{hhh}-\\{hh})>\\{max\_drift}$ \1\&{then}\6
\&{if} $\\{hhh}>\\{hh}$ \1\&{then}\5
$\\{hh}\K\\{hhh}-\\{max\_drift}$\6
\4\&{else} $\\{hh}\K\\{hhh}+\\{max\_drift}$;\2\2\6
$\|h\K\|h+\|q$;\6
\&{if} $\\{abs}(\|h)>\\{max\_h\_so\_far}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{abs}(\|h)>\\{max\_h}+99$ \1\&{then}\6
\&{begin} \37$\\{error}(\.{\'warning:\ |h|>\'},\39\\{max\_h}:1,\39\.{\'!\'})$;\5
$\\{max\_h}\K\\{abs}(\|h)$;\6
\&{end};\2\6
$\\{max\_h\_so\_far}\K\\{abs}(\|h)$;\6
\&{end};\2\6
\&{goto} \37\\{done}\par
\U78.\fi

\M90. \P$\X90:Finish a command that sets $\|v\K\|v+\|p$, then \&{goto} \\{done}%
\X\S$\6
\&{if} $(\|v>0)\W(\|p>0)$ \1\&{then}\6
\&{if} $\|v>\\{infinity}-\|p$ \1\&{then}\6
\&{begin} \37$\\{error}(\.{\'arithmetic\ overflow!\ parameter\ changed\ from\ %
\'},\39\|p:1,\39\.{\'\ to\ \'},\39\\{infinity}-\|v:1)$;\5
$\|p\K\\{infinity}-\|v$;\6
\&{end};\2\2\6
\&{if} $(\|v<0)\W(\|p<0)$ \1\&{then}\6
\&{if} $-\|v>\|p+\\{infinity}$ \1\&{then}\6
\&{begin} \37$\\{error}(\.{\'arithmetic\ overflow!\ parameter\ changed\ from\ %
\'},\39\|p:1,\39\.{\'\ to\ \'},\39(-\|v)-\\{infinity}:1)$;\5
$\|p\K(-\|v)-\\{infinity}$;\6
\&{end};\2\2\6
$\\{vvv}\K\\{vert\_pixel\_round}(\|v+\|p)$;\6
\&{if} $\\{abs}(\\{vvv}-\\{vv})>\\{max\_drift}$ \1\&{then}\6
\&{if} $\\{vvv}>\\{vv}$ \1\&{then}\5
$\\{vv}\K\\{vvv}-\\{max\_drift}$\6
\4\&{else} $\\{vv}\K\\{vvv}+\\{max\_drift}$;\2\2\6
$\|v\K\|v+\|p$;\6
\&{if} $\\{abs}(\|v)>\\{max\_v\_so\_far}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{abs}(\|v)>\\{max\_v}+99$ \1\&{then}\6
\&{begin} \37$\\{error}(\.{\'warning:\ |v|>\'},\39\\{max\_v}:1,\39\.{\'!\'})$;\5
$\\{max\_v}\K\\{abs}(\|v)$;\6
\&{end};\2\6
$\\{max\_v\_so\_far}\K\\{abs}(\|v)$;\6
\&{end};\2\6
\&{goto} \37\\{done}\par
\U80.\fi

\M91. \P$\X91:Finish a command that changes the current font, then \&{goto} %
\\{done}\X\S$\6
$\\{font\_num}[\\{nf}]\K\|p$;\5
$\\{cur\_font}\K0$;\6
\&{while} $\\{font\_num}[\\{cur\_font}]\I\|p$ \1\&{do}\5
$\\{incr}(\\{cur\_font})$;\2\6
\&{goto} \37\\{done}\par
\U80.\fi

\N92.  Skipping pages.
\fi

\M93. Global variables called \\{old\_backpointer} and \\{new\_backpointer}
are used to check whether the back pointers are properly set up.
Another one tells whether we have already found the starting page.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{old\_backpointer}: \37\\{integer};\C{the previous \\{bop} command
location}\6
\4\\{new\_backpointer}: \37\\{integer};\C{the current \\{bop} command location}%
\6
\4\\{started}: \37\\{boolean};\C{has the starting page been found?}\par
\fi

\M94. \P$\X12:Set initial values\X\mathrel{+}\S$\6
$\\{old\_backpointer}\K-1$;\5
$\\{started}\K\\{false}$;\par
\fi

\M95. \P$\X95:Pass a \\{bop} command, setting up the \\{count} array\X\S$\6
$\\{new\_backpointer}\K\\{cur\_loc}-1$;\5
$\\{incr}(\\{page\_count})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}9$ \1\&{do}\5
$\\{count}[\|k]\K\\{signed\_quad}$;\2\6
\&{if} $\\{signed\_quad}\I\\{old\_backpointer}$ \1\&{then}\5
$\\{print\_ln}(\.{\'backpointer\ in\ byte\ \'},\39\\{cur\_loc}-4:1,\39\.{\'\
should\ be\ \'},\39\\{old\_backpointer}:1,\39\.{\'!\'})$;\2\6
$\\{old\_backpointer}\K\\{new\_backpointer}$\par
\U106.\fi

\N96.  Using the backpointers.
First comes a routine that illustrates how to find the postamble quickly.

\Y\P$\4\X96:Find the postamble, working back from the end\X\S$\6
$\|n\K\\{dvi\_length}$;\6
\&{if} $\|n<53$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'only\ \'},\39\|n:1,\39\.{\'\ bytes\ long\'})$;\2\6
$\|m\K\|n-4$;\6
\1\&{repeat} \37\&{if} $\|m=0$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'all\ 223s\'})$;\2\6
$\\{move\_to\_byte}(\|m)$;\5
$\|k\K\\{get\_byte}$;\5
$\\{decr}(\|m)$;\6
\4\&{until}\5
$\|k\I223$;\2\6
\&{if} $\|k\I\\{id\_byte}$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'ID\ byte\ is\ \'},\39\|k:1)$;\2\6
$\\{move\_to\_byte}(\|m-3)$;\5
$\|q\K\\{signed\_quad}$;\6
\&{if} $(\|q<0)\V(\|q>\|m-33)$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'post\ pointer\ \'},\39\|q:1,\39\.{\'\ at\ byte\ \'},\39%
\|m-3:1)$;\2\6
$\\{move\_to\_byte}(\|q)$;\5
$\|k\K\\{get\_byte}$;\6
\&{if} $\|k\I\\{post}$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'byte\ \'},\39\|q:1,\39\.{\'\ is\ not\ post\'})$;\2\6
$\\{post\_loc}\K\|q$;\5
$\\{first\_backpointer}\K\\{signed\_quad}$\par
\U102.\fi

\M97. Note that the last steps of the above code save the locations of the
the \\{post} byte and the final \\{bop}.  We had better declare these global
variables, together with another one that we will need shortly.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{post\_loc}: \37\\{integer};\C{byte location where the postamble begins}\6
\4\\{first\_backpointer}: \37\\{integer};\C{the pointer following \\{post}}\6
\4\\{start\_loc}: \37\\{integer};\C{byte location of the first page to process}%
\par
\fi

\M98. The next little routine shows how the backpointers can be followed
to move through a \.{DVI} file in reverse order. Ordinarily a \.{DVI}-reading
program would do this only if it wants to print the pages backwards or
if it wants to find a specified starting page that is not necessarily the
first page in the file; otherwise it would of course be simpler and faster
just to read the whole file from the beginning.

\Y\P$\4\X98:Count the pages and move to the starting page\X\S$\6
$\|q\K\\{post\_loc}$;\5
$\|p\K\\{first\_backpointer}$;\5
$\\{start\_loc}\K-1$;\6
\&{if} $\|p\G0$ \1\&{then}\6
\1\&{repeat} \37\C{now \|q points to a \\{post} or \\{bop} command; $\|p\G0$ is
prev pointer}\6
\&{if} $\|p>\|q-46$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'page\ link\ \'},\39\|p:1,\39\.{\'\ after\ byte\ \'},\39%
\|q:1)$;\2\6
$\|q\K\|p$;\5
$\\{move\_to\_byte}(\|q)$;\5
$\|k\K\\{get\_byte}$;\6
\&{if} $\|k=\\{bop}$ \1\&{then}\5
$\\{incr}(\\{page\_count})$\6
\4\&{else} $\\{bad\_dvi}(\.{\'byte\ \'},\39\|q:1,\39\.{\'\ is\ not\ bop\'})$;\2%
\6
\&{for} $\|k\K0\mathrel{\&{to}}9$ \1\&{do}\5
$\\{count}[\|k]\K\\{signed\_quad}$;\2\6
\&{if} $\\{start\_match}$ \1\&{then}\5
$\\{start\_loc}\K\|q$;\2\6
$\|p\K\\{signed\_quad}$;\6
\4\&{until}\5
$\|p<0$;\2\2\6
\&{if} $\\{start\_loc}<0$ \1\&{then}\5
$\\{abort}(\.{\'starting\ page\ number\ could\ not\ be\ found!\'})$;\2\6
$\\{move\_to\_byte}(\\{start\_loc}+1)$;\5
$\\{old\_backpointer}\K\\{start\_loc}$;\6
\&{for} $\|k\K0\mathrel{\&{to}}9$ \1\&{do}\5
$\\{count}[\|k]\K\\{signed\_quad}$;\2\6
$\|p\K\\{signed\_quad}$;\5
$\\{started}\K\\{true}$\par
\U102.\fi

\N99.  Reading the postamble.
Now imagine that we are reading the \.{DVI} file and positioned just
four bytes after the \\{post} command. That, in fact, is the situation,
when the following part of \.{DVIDOC} is called upon to read, translate,
and check the rest of the postamble.

\Y\P\4\&{procedure}\1\  \37\\{read\_postamble};\6
\4\&{var} \37\|k: \37\\{integer};\C{loop index}\6
$\|p,\39\|q,\39\|m$: \37\\{integer};\C{general purpose registers}\2\6
\&{begin} \37$\\{post\_loc}\K\\{cur\_loc}-5$;\6
\&{if} $\\{signed\_quad}\I\\{numerator}$ \1\&{then}\5
$\\{print\_ln}(\.{\'numerator\ doesn\'}\.{\'t\ match\ the\ preamble!\'})$;\2\6
\&{if} $\\{signed\_quad}\I\\{denominator}$ \1\&{then}\5
$\\{print\_ln}(\.{\'denominator\ doesn\'}\.{\'t\ match\ the\ preamble!\'})$;\2\6
\&{if} $\\{signed\_quad}\I\\{mag}$ \1\&{then}\6
\&{if} $\\{new\_mag}=0$ \1\&{then}\5
$\\{print\_ln}(\.{\'magnification\ doesn\'}\.{\'t\ match\ the\ preamble!\'})$;%
\2\2\6
$\\{max\_v}\K\\{signed\_quad}$;\5
$\\{max\_h}\K\\{signed\_quad}$;\6
$\\{max\_s}\K\\{get\_two\_bytes}$;\5
$\\{total\_pages}\K\\{get\_two\_bytes}$;\6
\X101:Process the font definitions of the postamble\X;\6
\X100:Make sure that the end of the file is well-formed\X;\6
\&{end};\par
\fi

\M100. When we get to the present code, the \\{post\_post} command has
just been read.

\Y\P$\4\X100:Make sure that the end of the file is well-formed\X\S$\6
$\|q\K\\{signed\_quad}$;\6
\&{if} $\|q\I\\{post\_loc}$ \1\&{then}\5
$\\{print\_ln}(\.{\'bad\ postamble\ pointer\ in\ byte\ \'},\39\\{cur\_loc}-4:1,%
\39\.{\'!\'})$;\2\6
$\|m\K\\{get\_byte}$;\6
\&{if} $\|m\I\\{id\_byte}$ \1\&{then}\5
$\\{print\_ln}(\.{\'identification\ in\ byte\ \'},\39\\{cur\_loc}-1:1,\39\.{\'\
should\ be\ \'},\39\\{id\_byte}:1,\39\.{\'!\'})$;\2\6
$\|k\K\\{cur\_loc}$;\5
$\|m\K223$;\6
\&{while} $(\|m=223)\W\R\\{eof}(\\{dvi\_file})$ \1\&{do}\5
$\|m\K\\{get\_byte}$;\2\6
\&{if} $\R\\{eof}(\\{dvi\_file})$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'signature\ in\ byte\ \'},\39\\{cur\_loc}-1:1,\39\.{\'\
should\ be\ 223\'})$\6
\4\&{else} \&{if} $\\{cur\_loc}<\|k+4$ \1\&{then}\5
$\\{print\_ln}(\.{\'not\ enough\ signature\ bytes\ at\ end\ of\ file\ (\'},\39%
\\{cur\_loc}-\|k:1,\39\.{\')\'})$;\2\2\par
\U99.\fi

\M101. \P$\X101:Process the font definitions of the postamble\X\S$\6
\1\&{repeat} \37$\|k\K\\{get\_byte}$;\6
\&{if} $(\|k\G\\{fnt\_def1})\W(\|k<\\{fnt\_def1}+4)$ \1\&{then}\6
\&{begin} \37$\|p\K\\{first\_par}(\|k)$;\5
$\\{define\_font}(\|p)$;\5
$\\{print\_ln}(\.{\'\ \'})$;\5
$\|k\K\\{nop}$;\6
\&{end};\2\6
\4\&{until}\5
$\|k\I\\{nop}$;\2\6
\&{if} $\|k\I\\{post\_post}$ \1\&{then}\5
$\\{print\_ln}(\.{\'byte\ \'},\39\\{cur\_loc}-1:1,\39\.{\'\ is\ not\ postpost!%
\'})$\2\par
\U99.\fi

\N102.  The main program.
Now we are ready to put it all together. This is where \.{DVIDOC} starts,
and where it ends.
We use the UNIX facilty to pass in command line arguments here.

\Y\P\&{begin} \37\\{initialize};\C{get all variables initialized}\6
\\{options};\C{set up all the options}\6
\X25:Open input file\X\X65:Create error message file\X\X104:Process the
preamble\X;\6
\X96:Find the postamble, working back from the end\X;\6
$\\{in\_postamble}\K\\{true}$;\5
\\{read\_postamble};\5
$\\{in\_postamble}\K\\{false}$;\5
\X98:Count the pages and move to the starting page\X;\6
\&{if} $\R\\{in\_postamble}$ \1\&{then}\5
\X106:Translate up to \\{max\_pages} pages\X;\2\6
\4\\{final\_end}: \37\&{end}.\par
\fi

\M103. The main program needs a few global variables in order to do its work.

\Y\P$\4\X11:Globals in the outer block\X\mathrel{+}\S$\6
\4$\|k,\39\|m,\39\|n,\39\|p,\39\|q$: \37\\{integer};\C{general purpose
registers}\par
\fi

\M104. A \.{DVI}-reading program that reads the postamble first need not look
at the
preamble; but \.{DVIDOC} looks at the preamble in order to do error
checking, and to display the introductory comment.

\Y\P$\4\X104:Process the preamble\X\S$\6
$\|p\K\\{get\_byte}$;\C{fetch the first byte}\6
\&{if} $\|p\I\\{pre}$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'First\ byte\ isn\'}\.{\'t\ start\ of\ preamble!\'})$;\2\6
$\|p\K\\{get\_byte}$;\C{fetch the identification byte}\6
\&{if} $\|p\I\\{id\_byte}$ \1\&{then}\5
$\\{print\_ln}(\.{\'identification\ in\ byte\ 1\ should\ be\ \'},\39\\{id%
\_byte}:1,\39\.{\'!\'})$;\2\6
\X105:Compute the conversion factor\X;\6
$\|p\K\\{get\_byte}$;\C{fetch the length of the introductory comment}\6
$\\{print}(\.{\'\'}\.{\'\'})$;\6
\&{while} $\|p>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\|p)$;\5
$\\{print}(\\{xchr}[\\{get\_byte}])$;\6
\&{end};\2\6
$\\{print\_ln}(\.{\'\'}\.{\'\'})$\par
\U102.\fi

\M105. The conversion factors \\{horiz\_conv} and
\\{vert\_conv} are figured as follows: There are exactly
$\|n/\|d$ \.{DVI} units per decimicron, and 254000 decimicrons per inch,
and \\{horiz\_resolution} or \\{vert\_resolution} characters per inch. Then we
have to adjust this
by the stated amount of magnification.

\Y\P$\4\X105:Compute the conversion factor\X\S$\6
$\\{numerator}\K\\{signed\_quad}$;\5
$\\{denominator}\K\\{signed\_quad}$;\6
\&{if} $\\{numerator}\L0$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'numerator\ is\ \'},\39\\{numerator}:1)$;\2\6
\&{if} $\\{denominator}\L0$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'denominator\ is\ \'},\39\\{denominator}:1)$;\2\6
$\\{horiz\_conv}\K(\\{numerator}/254000.0)\ast(\\{horiz\_resolution}/%
\\{denominator})$;\5
$\\{vert\_conv}\K(\\{numerator}/254000.0)\ast(\\{vert\_resolution}/%
\\{denominator})$;\5
$\\{mag}\K\\{signed\_quad}$;\6
\&{if} $\\{new\_mag}>0$ \1\&{then}\5
$\\{mag}\K\\{new\_mag}$\6
\4\&{else} \&{if} $\\{mag}\L0$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'magnification\ is\ \'},\39\\{mag}:1)$;\2\2\6
$\\{true\_horiz\_conv}\K\\{horiz\_conv}$;\5
$\\{horiz\_conv}\K\\{true\_horiz\_conv}\ast(\\{mag}/1000.0)$;\5
$\\{true\_vert\_conv}\K\\{vert\_conv}$;\5
$\\{vert\_conv}\K\\{true\_vert\_conv}\ast(\\{mag}/1000.0)$;\par
\U104.\fi

\M106. The code shown here uses a convention that has proved to be useful:
If the starting page was specified as, e.g., `\.{1.*.-5}', then
all page numbers in the file are displayed by showing the values of
counts 0, 1, and~2, separated by dots. Such numbers can, for example,
be displayed on the console of a printer when it is working on that
page.

\Y\P$\4\X106:Translate up to \\{max\_pages} pages\X\S$\6
\&{begin} \37\&{while} $\\{max\_pages}>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\\{max\_pages})$;\5
$\\{print}(\.{\'Page\ \'})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{start\_vals}$ \1\&{do}\6
\&{begin} \37$\\{print}(\\{count}[\|k]:1)$;\6
\&{if} $\|k<\\{start\_vals}$ \1\&{then}\5
$\\{print}(\.{\'.\'})$\6
\4\&{else} $\\{print\_ln}(\.{\'\ \'})$;\2\6
\&{end};\2\6
\&{if} $\R\\{do\_page}$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'page\ ended\ unexpectedly\'})$;\2\6
\1\&{repeat} \37$\|k\K\\{get\_byte}$;\6
\&{if} $(\|k\G\\{fnt\_def1})\W(\|k<\\{fnt\_def1}+4)$ \1\&{then}\6
\&{begin} \37$\|p\K\\{first\_par}(\|k)$;\5
$\\{define\_font}(\|p)$;\5
$\|k\K\\{nop}$;\6
\&{end};\2\6
\4\&{until}\5
$\|k\I\\{nop}$;\2\6
\&{if} $\|k=\\{post}$ \1\&{then}\6
\&{begin} \37$\\{in\_postamble}\K\\{true}$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{if} $\|k\I\\{bop}$ \1\&{then}\5
$\\{bad\_dvi}(\.{\'byte\ \'},\39\\{cur\_loc}-1:1,\39\.{\'\ is\ not\ bop\'})$;\2%
\6
\X95:Pass a \\{bop} command, setting up the \\{count} array\X;\6
\&{end};\2\6
\4\\{done}: \37\&{end}\par
\U102.\fi

\N107.  System-dependent changes.
This section should be replaced, if necessary, by changes to the program
that are necessary to make \.{DVIDOC} work at a particular installation.
It is usually best to design your change file so that all changes to
previous sections preserve the section numbering; then everybody's version
will be consistent with the printed program. More extensive changes,
which introduce new sections, can be inserted here; then only the index
itself will get a new section number.

\fi

\N108.  Index.
Pointers to error messages appear here together with the section numbers
where each ident\-i\-fier is used.
\fi


\inx
\:\|{a}, \[77], \[80].
\:\\{abort}, \[7], 56, 58, 63, 98.
\:\\{abs}, 71, 82, 83, 89, 90.
\:\.{all 223s}, 96.
\:\\{alpha}, \[36], 39, 40.
\:\\{argc}, 51.
\:\\{argv}, 51.
\:\.{arithmetic overflow...}, 89, 90.
\:\\{ASCII\_code}, \[9], 11, 32, 47, 64, 68.
\:\.{backpointer...should be p}, 95.
\:\.{bad design size}, 59.
\:\.{Bad DVI file}, 7.
\:\.{bad postamble pointer}, 100.
\:\.{bad scale}, 59.
\:\\{bad\_char}, \[80], 85.
\:\\{bad\_dvi}, \[7], 78, 96, 98, 100, 104, 105, 106.
\:\\{banner}, \[1].
\:\\{base\_name}, 25, \[27], 51, 65.
\:\\{beta}, \[36], 39, 40.
\:\.{beware: check sums do not agree}, 60.
\:\\{boolean}, 23, 36, 44, 46, 50, 54, 56, 64, 77, 80, 93.
\:\\{bop}, 14, 16, \[17], 19, 20, 43, 69, 73, 81, 93, 97, 98, 106.
\:\.{bop occurred before eop}, 81.
\:\\{buf\_ptr}, \[49], 50, 52, 53.
\:\\{buffer}, \[47], 48, 49, 50, 52, 53.
\:\\{byte}, \[29].
\:\.{byte n is not bop}, 98, 106.
\:\.{byte n is not post}, 96.
\:\.{byte n is not postpost}, 101.
\:\\{byte\_file}, \[22], 23.
\:\\{b0}, \[28], 29, 37, 38, 39.
\:\\{b1}, \[28], 29, 37, 39.
\:\\{b2}, \[28], 29, 37, 39.
\:\\{b3}, \[28], 29, 37, 39.
\:\|{c}, \[56].
\:\\{cannot\_start}, \[8], 25, 51, 52, 53, 65.
\:\\{change\_font}, \[75], 80, 84.
\:\\{char}, 10, 22, 27, 29, 61.
\:\\{char\_pixel\_width}, \[41], 87.
\:\\{char\_width}, \[32], 41, 87.
\:\\{char\_width\_end}, \[32], 41.
\:\.{character $c$ invalid...}, 87.
\:{check sum}, 19.
\:\.{check sum doesn't match}, 57.
\:\.{check sums do not agree}, 60.
\:{Chinese characters}, 16, 87.
\:\\{chr}, 10, 11, 13, 66.
\:\\{conv}, 42.
\:\\{copy\_ln}, 47, \[48], 52, 53.
\:\\{count}, \[44], 46, 95, 98, 106.
\:\\{cur\_font}, 75, \[76], 77, 82, 83, 87, 91.
\:\\{cur\_loc}, \[27], 30, 78, 95, 99, 100, 101, 106.
\:\\{cur\_name}, 25, 27, 47, 48, 51, 56, 63, 65.
\:\\{cur\_pos}, 30.
\:\|{d}, \[56].
\:\\{decr}, \[6], 58, 81, 96, 104, 106.
\:\.{deeper than claimed...}, 81.
\:\\{default\_directory}, \[61], 62.
\:\\{default\_directory\_name}, \[61], 62.
\:\\{default\_directory\_name\_length}, \[61].
\:\\{define\_font}, \[56], 84, 101, 106.
\:\\{den}, 16, \[18], 20.
\:\\{denominator}, \[41], 99, 105.
\:\.{denominator doesn't match}, 99.
\:\.{denominator is wrong}, 105.
\:\.{design size doesn't match}, 57.
\:\\{do\_nothing}, \[6].
\:\\{do\_page}, 69, 73, 75, 76, \[77], 79, 81, 106.
\:\\{doc\_file}, \[3], 64, 66.
\:\\{done}, \[4], 8, 26, 77, 78, 79, 80, 81, 84, 85, 87, 88, 89, 90, 91, 106.
\:\\{down1}, 16, \[17], 73, 83.
\:\\{down2}, 16.
\:\\{down3}, 16.
\:\\{down4}, 16.
\:\.{DVI {\rm files}}, 14.
\:\\{dvi\_file}, \[3], \[23], 25, 27, 30, 78, 100.
\:\\{dvi\_length}, \[30], 96.
\:\\{DVIDOC}, \[3].
\:\.{DVIDOC capacity exceeded...}, 56, 58, 63.
\:\.{DVIDOC needs larger...}, 37.
\:\|{e}, \[56].
\:\\{eight\_bits}, \[22], 28, 73, 77, 80.
\:\\{eight\_cases}, \[73].
\:\&{else}, 2.
\:\\{empty\_page}, \[67], 77.
\:\&{end}, 2.
\:\&{endcases}, \[2].
\:\\{eof}, \[3], 24, 25, 30, 37, 59, 78, 100.
\:\\{eof\_dvi\_file}, 3, \[23].
\:\\{eop}, 14, 16, \[17], 19, 43, 73, 81.
\:\\{err\_file}, \[3], \[64], 65.
\:\\{error}, \[3], 26, 80, 81, 85, 87, 89, 90.
\:\|{f}, \[34], \[56].
\:\\{false}, 36, 44, 45, 46, 50, 51, 52, 55, 57, 75, 77, 80, 85, 94, 102.
\:\\{fin\_rule}, \[75], 77, 78, 79.
\:\\{fin\_set}, \[75], 77, 78, 79.
\:\\{final\_end}, \[4], 7, 102.
\:\.{First byte isn't...}, 104.
\:\\{first\_backpointer}, 96, \[97], 98.
\:\\{first\_par}, \[73], 78, 79, 101, 106.
\:\\{first\_text\_char}, \[10], 13.
\:\\{fix\_word}, 39.
\:\\{flush\_page}, \[66], 81.
\:\\{fnt\_def1}, 16, \[17], 73, 84, 101, 106.
\:\\{fnt\_def2}, 16.
\:\\{fnt\_def3}, 16.
\:\\{fnt\_def4}, 16.
\:\\{fnt\_num\_0}, 16, \[17], 73, 84.
\:\\{fnt\_num\_1}, 16.
\:\\{fnt\_num\_63}, 16.
\:\\{fnt1}, 16, \[17], 73, 84.
\:\\{fnt2}, 16.
\:\\{fnt3}, 16.
\:\\{fnt4}, 16.
\:\.{font name doesn't match}, 57.
\:\\{font\_bc}, \[32], 37, 42, 87.
\:\\{font\_check\_sum}, \[32], 57, 58.
\:\\{font\_design\_size}, \[32], 57, 58.
\:\\{font\_ec}, \[32], 37, 87.
\:\\{font\_file\_path}, \[24], 26.
\:\\{font\_name}, \[32], 33, 34, 57, 58, 63.
\:\\{font\_num}, \[32], 56, 91.
\:\\{font\_scaled\_size}, \[32], 57, 58.
\:\\{font\_space}, \[32], 33, 60, 82, 83.
\:\\{four\_cases}, \[73], 79, 80, 82, 83, 84.
\:{Fuchs, David Raymond}, 14, 21.
\:\\{get\_byte}, 30, 58, 73, 78, 85, 96, 98, 100, 101, 104, 106.
\:\\{get\_integer}, \[50], 52, 53.
\:\\{get\_tfm\_byte}, \[29].
\:\\{get\_three\_bytes}, 73.
\:\\{get\_two\_bytes}, 73, 99.
\:\|{h}, \[70].
\:\\{hh}, 68, \[70], 77, 79, 81, 82, 86, 87, 88, 89.
\:\\{hhh}, \[77], 89.
\:\\{hhstack}, \[70], 81.
\:\\{horiz\_conv}, \[41], 42, 60, 74, 105.
\:\\{horiz\_pixel\_round}, \[42], 70, 82, 89.
\:\\{horiz\_resolution}, \[43], 51, 105.
\:\\{horiz\_rule\_pixels}, \[74], 88.
\:\\{hstack}, \[70], 81.
\:\|{i}, \[3], \[18], \[64], \[66], \[68].
\:\.{ID byte is wrong}, 96.
\:\\{id\_byte}, \[18], 96, 100, 104.
\:\.{identification...should be n}, 100, 104.
\:\\{in\_postamble}, \[54], 55, 56, 102, 106.
\:\\{in\_TFM}, \[36], 39, 59.
\:\\{in\_width}, \[35], 39, 42.
\:\\{incr}, \[6], 25, 48, 50, 51, 52, 56, 57, 58, 60, 63, 65, 81, 91, 95, 98.
\:\\{infinity}, \[89], 90.
\:\\{initialize}, \[3], 102.
\:\\{input}, 3.
\:\\{integer}, 3, 22, 27, 30, 32, 34, 35, 36, 41, 43, 44, 50, 51, 56, 68, 70,
71, 73, 74, 76, 77, 80, 93, 97, 99, 103.
\:\\{invalid\_width}, \[32], 87.
\:\|{j}, \[51], \[56].
\:{Japanese characters}, 16, 87.
\:\\{jump\_out}, \[7].
\:\|{k}, \[18], \[34], \[36], \[46], \[48], \[56], \[80], \[99], \[103].
\:\\{last\_text\_char}, \[10], 13.
\:\\{lh}, \[36], 37.
\:\\{line\_hwm}, \[64], 66, 68.
\:\\{log\_errors}, 51, \[64], 65.
\:\|{m}, \[99], \[103].
\:\\{mag}, 16, \[18], 19, 20, \[41], 99, 105.
\:\.{magnification doesn't match}, 99.
\:\.{magnification is wrong}, 105.
\:\\{match}, \[46].
\:\\{max\_drift}, \[89], 90.
\:\\{max\_fonts}, \[5], 32, 56.
\:\\{max\_h}, \[71], 72, 89, 99.
\:\\{max\_h\_so\_far}, \[71], 72, 89.
\:\\{max\_pages}, \[43], 45, 51, 53, 106.
\:\\{max\_s}, \[71], 72, 81, 99.
\:\\{max\_s\_so\_far}, \[71], 72, 81.
\:\\{max\_v}, \[71], 72, 90, 99.
\:\\{max\_v\_so\_far}, \[71], 72, 90.
\:\\{max\_widths}, \[5], 32, 36, 37, 41.
\:\\{message}, 7, 8.
\:\\{mismatch}, \[56], 57.
\:\\{move\_down}, \[75], 80, 83.
\:\\{move\_right}, \[75], 77, 78, 82, 87, 88.
\:\\{move\_to\_byte}, \[30], 96, 98.
\:\|{n}, \[56], \[74], \[103].
\:\\{name\_length}, \[5], 25, 27, 48, 56, 63, 64, 65.
\:\\{name\_size}, \[5], 32, 34, 56, 58.
\:\\{names}, \[32], 34, 56, 57, 58, 63.
\:\\{negative}, \[50].
\:\\{new\_backpointer}, \[93], 95.
\:\\{new\_mag}, \[43], 51, 99, 105.
\:\\{nf}, \[32], 33, 34, 37, 42, 56, 57, 58, 60, 63, 77, 87, 91.
\:\\{no\_file\_path}, \[24], 25, 65.
\:\.{non-ASCII character...}, 85.
\:\\{nop}, 14, 16, \[17], 19, 20, 73, 81, 101, 106.
\:\.{not enough signature bytes...}, 100.
\:\.{null font name}, 58.
\:\\{num}, 16, \[18], 20.
\:\\{numerator}, \[41], 99, 105.
\:\.{numerator doesn't match}, 99.
\:\.{numerator is wrong}, 105.
\:\\{nw}, \[36], 37, 38, 39.
\:\|{o}, \[77], \[80].
\:\\{old\_backpointer}, \[93], 94, 95, 98.
\:\.{only n bytes long}, 96.
\:\\{open\_dvi\_file}, 25.
\:\\{open\_tfm\_file}, \[26], 27, 59.
\:\\{options}, \[51], 102.
\:\\{ord}, 11, 29.
\:{oriental characters}, 16, 87.
\:\&{othercases}, \[2].
\:\\{others}, 2.
\:\\{out\_char}, \[68], 79, 86, 88.
\:\\{out\_space}, 60, \[82].
\:\\{out\_vmove}, 60, \[83].
\:\\{output}, 3.
\:\.{outside the range of DVIDOC}, 68.
\:\|{p}, \[56], \[77], \[80], \[99], \[103].
\:\.{page ended unexpectedly}, 106.
\:\.{page link wrong...}, 98.
\:\\{page\_buffer}, \[64], 66, 67, 68.
\:\\{page\_count}, \[71], 72, 95, 98.
\:\\{page\_hwm}, \[64], 66, 67, 68.
\:\\{page\_length\_max}, \[5], 64, 66, 68.
\:\\{page\_width\_max}, \[5], 64, 66, 68.
\:\\{pixel\_round}, 89.
\:\\{pixel\_width}, \[41], 42.
\:\\{pop}, 15, 16, \[17], 20, 73, 81.
\:\\{post}, 14, 16, \[17], 20, 21, 73, 80, 96, 97, 98, 99, 106.
\:\.{post pointer is wrong}, 96.
\:\\{post\_loc}, 96, \[97], 98, 99, 100.
\:\\{post\_post}, 16, \[17], 20, 21, 73, 80, 100, 101.
\:\.{postamble command within a page}, 80.
\:\.{Postamble starts at byte n}, 99.
\:\\{pre}, 14, 16, \[17], 73, 80, 104.
\:\.{preamble command within a page}, 80.
\:\\{print}, \[3], 34, 58, 59, 60, 68, 85, 87, 104, 106.
\:\\{print\_font}, \[34], 58, 87.
\:\\{print\_ln}, \[3], 36, 37, 56, 57, 59, 60, 68, 77, 95, 99, 100, 101, 104,
106.
\:\\{pure}, \[80].
\:\\{push}, 5, 15, 16, \[17], 20, 73, 81.
\:\.{push deeper than claimed...}, 81.
\:\\{put\_rule}, 16, \[17], 73, 79, 88.
\:\\{put1}, 16, \[17], 73, 80, 87.
\:\\{put2}, 16.
\:\\{put3}, 16.
\:\\{put4}, 16.
\:\|{q}, \[56], \[77], \[80], \[99], \[103].
\:\|{r}, \[56].
\:\\{read}, 29.
\:\\{read\_access\_mode}, \[24], 25, 26.
\:\\{read\_postamble}, \[99], 102.
\:\\{read\_tfm\_word}, \[29], 37, 38, 39.
\:\\{real}, 41, 43.
\:\\{real\_name\_of\_file}, 26, 27.
\:\\{reset}, 24, 26.
\:\\{rewrite}, 65.
\:\\{right1}, 16, \[17], 73, 82.
\:\\{right2}, 16.
\:\\{right3}, 16.
\:\\{right4}, 16.
\:\\{round}, 42, 60.
\:\\{rule\_pixels}, 16.
\:\|{s}, \[76].
\:\.{scaled size doesn't match}, 57.
\:\\{set\_char\_0}, 16, \[17], 73, 79.
\:\\{set\_char\_1}, 16.
\:\\{set\_char\_127}, 16.
\:\\{set\_pos}, 30.
\:\\{set\_rule}, 14, 16, \[17], 73, 79.
\:\\{setpaths}, 3.
\:\\{set1}, 16, \[17], 73, 79.
\:\\{set2}, 16.
\:\\{set3}, 16.
\:\\{set4}, 16.
\:\\{show\_state}, \[75], 77, 78, 81.
\:\.{signature...should be...}, 100.
\:\\{signed\_byte}, 73.
\:\\{signed\_pair}, 73.
\:\\{signed\_quad}, 58, 73, 88, 95, 96, 98, 99, 100, 105.
\:\\{signed\_trio}, 73.
\:\\{sixteen\_cases}, \[73].
\:\\{sixty\_four\_cases}, \[73], 84.
\:{sp}, 18.
\:\\{special\_cases}, 76, 79, \[80].
\:\\{ss}, \[76], 81.
\:\.{stack not empty...}, 81.
\:\\{stack\_size}, \[5], 70, 72, 81.
\:\\{start\_count}, \[44], 46, 52.
\:\\{start\_loc}, \[97], 98.
\:\\{start\_match}, \[46], 98.
\:\\{start\_there}, \[44], 45, 46, 51, 52.
\:\\{start\_vals}, \[44], 45, 46, 51, 52, 106.
\:\\{started}, \[93], 94, 98.
\:{system dependencies}, \[2], 7, 8, 10, 22, 24, 25, 29, 30, 42, 47, 48, 51,
61, 63, 102, 107.
\:\\{terminal\_line\_length}, \[5], 47, 48, 49.
\:\\{test\_access}, 24, 25, 26, 65.
\:\\{text\_char}, \[10], 11.
\:\\{text\_file}, \[10], 64.
\:\.{TFM {\rm files}}, 31.
\:\.{TFM file can\'t be opened}, 59.
\:\.{TFM file is bad}, 36.
\:\\{tfm\_check\_sum}, \[35], 37, 60.
\:\\{tfm\_file}, \[23], 24, 26, 29, 35, 37, 59.
\:\.{the file ended prematurely}, 78.
\:\\{thirty\_two\_cases}, \[73].
\:\.{this font is magnified}, 60.
\:\.{this font was already defined}, 56.
\:\.{this font wasn't loaded before}, 56.
\:\\{total\_pages}, \[71], 99.
\:\\{true}, 36, 44, 46, 50, 51, 52, 57, 77, 80, 81, 85, 98, 102, 106.
\:\\{true\_horiz\_conv}, \[41], 60, 105.
\:\\{true\_vert\_conv}, \[41], 105.
\:\\{trunc}, 74.
\:\.{UNDEFINED}, 34.
\:\.{undefined command}, 80.
\:\\{undefined\_commands}, \[17], 73.
\:\|{v}, \[70].
\:\\{vert\_conv}, \[41], 42, 74, 105.
\:\\{vert\_pixel\_round}, \[42], 70, 83, 90.
\:\\{vert\_resolution}, \[43], 51, 105.
\:\\{vert\_rule\_pixels}, \[74], 88.
\:\\{vstack}, \[70], 81.
\:\\{vv}, 68, \[70], 77, 79, 81, 83, 86, 88, 90.
\:\\{vvstack}, \[70], 81.
\:\\{vvv}, \[80], 90.
\:\|{w}, \[70].
\:\.{warning: |h|...}, 89.
\:\.{warning: |v|...}, 90.
\:\\{width}, \[32], 38, 41, 42.
\:\\{width\_base}, \[32], 41, 42.
\:\\{width\_ptr}, \[32], 33, 36, 37, 38, 42.
\:\\{wp}, \[36], 37, 38, 42.
\:\\{write}, 3, 66.
\:\\{write\_access\_mode}, \[24], 65.
\:\\{write\_ln}, 3, 66.
\:\\{wstack}, \[70], 81.
\:\\{w0}, 16, \[17], 73, 82.
\:\\{w1}, 16, \[17], 73, 82.
\:\\{w2}, 16.
\:\\{w3}, 16.
\:\\{w4}, 16.
\:\|{x}, \[18], \[50], \[70].
\:\\{xchr}, \[11], 12, 13, 34, 63, 66, 68, 85, 104.
\:\\{xord}, \[11], 13, 48, 68, 88.
\:\\{xstack}, \[70], 81.
\:\\{xxx1}, 16, \[17], 73, 80.
\:\\{xxx2}, 16.
\:\\{xxx3}, 16.
\:\\{xxx4}, 16, \[17].
\:\\{x0}, 16, \[17], 73, 82.
\:\\{x1}, 16, \[17], 73, 82.
\:\\{x2}, 16.
\:\\{x3}, 16.
\:\\{x4}, 16.
\:\|{y}, \[70].
\:\\{ystack}, \[70], 81.
\:\\{y0}, 16, \[17], 73, 83.
\:\\{y1}, 16, \[17], 73, 83.
\:\\{y2}, 16.
\:\\{y3}, 16.
\:\\{y4}, 16.
\:\|{z}, \[36], \[70].
\:\\{zstack}, \[70], 81.
\:\\{z0}, 16, \[17], 73, 83.
\:\\{z1}, 16, \[17], 73, 83.
\:\\{z2}, 16.
\:\\{z3}, 16.
\:\\{z4}, 16.
\fin
\:\X81:Cases for commands \\{nop}, \\{bop}, \dots, \\{pop}\X
\U79.
\:\X84:Cases for fonts\X
\U80.
\:\X82:Cases for horizontal motion\X
\U79.
\:\X83:Cases for vertical motion\X
\U80.
\:\X57:Check that the current font definition matches the old one\X
\U56.
\:\X105:Compute the conversion factor\X
\U104.
\:\X5:Constants in the outer block\X
\U3.
\:\X98:Count the pages and move to the starting page\X
\U102.
\:\X65:Create error message file\X
\U102.
\:\X80:Declare the function called \\{special\_cases}\X
\U77.
\:\X53:Determine the desired \\{max\_pages}\X
\U51.
\:\X52:Determine the desired \\{start\_count} values\X
\U51.
\:\X96:Find the postamble, working back from the end\X
\U102.
\:\X91:Finish a command that changes the current font, then \&{goto} \\{done}\X
\U80.
\:\X87:Finish a command that either sets or puts a character, then \&{goto} %
\\{move\_right} or \\{done}\X
\U78.
\:\X88:Finish a command that either sets or puts a rule, then \&{goto} \\{move%
\_right} or \\{done}\X
\U78.
\:\X89:Finish a command that sets $\|h\K\|h+\|q$, then \&{goto} \\{done}\X
\U78.
\:\X90:Finish a command that sets $\|v\K\|v+\|p$, then \&{goto} \\{done}\X
\U80.
\:\X60:Finish loading the new font info\X
\U59.
\:\X11, 23, 27, 28, 32, 35, 41, 43, 44, 47, 49, 54, 61, 64, 70, 71, 76, 93, 97,
103:Globals in the outer block\X
\U3.
\:\X4:Labels in the outer block\X
\U3.
\:\X59:Load the new font, unless there are problems\X
\U56.
\:\X100:Make sure that the end of the file is well-formed\X
\U99.
\:\X63:Move font name into the \\{cur\_name} string\X
\U59.
\:\X42:Move the widths from \\{in\_width} to \\{width}, and append \\{pixel%
\_width} values\X
\U36.
\:\X25:Open input file\X
\U102.
\:\X95:Pass a \\{bop} command, setting up the \\{count} array\X
\U106.
\:\X101:Process the font definitions of the postamble\X
\U99.
\:\X104:Process the preamble\X
\U102.
\:\X39:Read and convert the width values, setting up the \\{in\_width} table\X
\U36.
\:\X37:Read past the header data; \&{goto} 9997 if there is a problem\X
\U36.
\:\X58:Read the font parameters into position for font \\{nf}, and print the
font name\X
\U56.
\:\X40:Replace \|z by $\|z^\prime$ and compute $\alpha,\beta$\X
\U39.
\:\X12, 13, 33, 45, 55, 62, 72, 94:Set initial values\X
\U3.
\:\X79:Start translation of command \|o and \&{goto}  the appropriate label to
finish the job\X
\U78.
\:\X38:Store character-width indices at the end of the \\{width} table\X
\U36.
\:\X86:Translate a \\{set\_char} command\X
\U79.
\:\X85:Translate an \\{xxx} command and \&{goto} \\{done}\X
\U80.
\:\X78:Translate the next command in the \.{DVI} file; \&{goto} 9999 with $%
\\{do\_page}=\\{true}$ if it was \\{eop}; \&{goto} 9998 if premature
termination is needed\X
\U77.
\:\X106:Translate up to \\{max\_pages} pages\X
\U102.
\:\X9, 10, 22:Types in the outer block\X
\U3.
\con
