\input webmac
% This is DVICOPY.WEB in text format, as of February 13, 1991.
% Copyright (C) 1990,91 Peter Breitenlohner (peb@dm0mpi11.bitnet)
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 1, or (at your option)
% any later version.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%
% Version 0.9 was finished May 21, 1990.
% Version 1.0 pixel rounding for real devices (August 6, 1990).
% Version 1.1 major rearrangements for DVIprint (October 7, 1990).
% Version 1.2 fixed some bugs, introduced page selection (February 13, 1991).

% 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}
\font\tenlogo=logo10 % font used for the METAFONT logo
\font\ninelogo=logo9 % font used for the METAFONT logo
\let\logo=\tenlogo
\def\MF{{\logo META}\-{\logo FONT}}
\mathchardef\RA="3221 % right arrow

\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{DVI\lowercase{copy}}
\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 DVIcopy} processor}
  \vskip 5pt
  \centerline{Copyright (C) 1990,91 Peter Breitenlohner}
  \centerline{Distributed under terms of GNU General Public License}
  \vskip 15pt
  \centerline{(Version 1.2, February 1991)}
  \vfill}
\def\botofcontents{\vfill
  \centerline{\hsize 5in\baselineskip9pt
    \vbox{\ninerm \let\logo=\ninelogo \noindent
    This program was developed at the
    Max-Planck-Institut f\"ur Physik
    (Werner-Heisenberg-Institut), Munich, Germany.
    `\TeX' is a trademark of the American Mathematical Society.
    `\MF' is a trademark of Addison-Wesley
    Publishing Company.}}}
\pageno=\contentspagenumber \advance\pageno by 1


\N1.  Introduction.
The \.{DVIcopy} utility program copies (selected pages of) binary
device-independent (``\.{DVI}'') files that are produced by document
compilers such as \TeX, and replaces all references to characters from
virtual fonts by the typesetting instructions specified for them in
binary virtual-font (``\.{VF}'') files.
This program has two chief purposes: (1)~It can be used as preprocessor
for existing \.{DVI}-related software in cases where this software is
unable to handle virtual fonts or (given suitable \.{VF} files) where
this software cannot handle fonts with more than 128~characters;
and (2)~it serves as an example of a program that reads \.{DVI} and
\.{VF} files correctly, for system programmers who are developing
\.{DVI}-related software.

Goal number (1) is important since quite a few existing programs have
to be adapted to the extened capabilities of Version~3 of \TeX\ which
will require some time. Moreover some existing programs are `as is' and
the source code is, unfortunately, not available.
Goal number (2) needs perhaps a bit more explanation. Programs for
typesetting need to be especially careful about how they do arithmetic; if
rounding errors accumulate, margins won't be straight, vertical rules
won't line up, and so on (see the documentaion of \.{DVItype} for more
details). This program is written as if it were a \.{DVI}-driver for a
hypothetical typesetting device \\{out\_file}, the output file receiving
the copy of the input \\{dvi\_file}. In addition all code related to
\\{out\_file} is concentrated in two chapters at the end of this program
and quite independent of the rest of the code concerned with the
decoding of \.{DVI} and \.{VF} files and with font substitutions. Thus
it should be relatively easy to replace the device dependent code of
this program by the corresponding code required for a real typesetting
device. Having this in mind \.{DVItype}'s pixel rounding algorithms are
included as conditional code not used by \.{DVIcopy}.

The \\{banner} and \\{preamble\_comment} strings defined here should be
changed whenever \.{DVIcopy} gets modified.

\Y\P\D \37$\\{banner}\S\.{\'This\ is\ DVIcopy,\ Version\ 1.2\'}$\C{printed when
the program starts}\par
\P\D \37$\\{title}\S\.{\'DVIcopy\'}$\C{the name of this program, used in some
messages}\par
\P\D \37$\\{copyright}\S\.{\'Copyright\ (C)\ 1990,91\ Peter\ Breitenlohner\'}$%
\Y\par
\P\D \37$\\{preamble\_comment}\S\.{\'DVIcopy\ 1.2\ output\ from\ \'}$\par
\P\D \37$\\{comm\_length}=24$\C{length of \\{preamble\_comment}}\par
\P\D \37$\\{from\_length}=6$\C{length of its \.{\'\ from\ \'} part}\par
\fi

\M2. This program is written in standard \PASCAL, except where it is necessary
to use extensions; for example, \.{DVIcopy} 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 is to
determine the length of a binary file. Such extensions are not necessary
for reading \.{DVI} files; since \.{DVIcopy} is (a model for) a
production program it should, however, be made as efficient as possible
for a particular system. If \.{DVIcopy} is being used with
\PASCAL s for which random file positioning is not efficiently available,
the following definition should be changed from \\{true} to \\{false}; in such
cases, \.{DVIcopy} will not include the optional feature that reads the
postamble first.

\Y\P\D \37$\\{random\_reading}\S\\{true}$\C{should we skip around in the file?}%
\par
\fi

\M3. The program begins with a fairly normal header, made up of pieces that
will mostly be filled in later. The \.{DVI} input comes from file
\\{dvi\_file}, the \.{DVI} output goes to file \\{out\_file}, and messages
go to \PASCAL's standard \\{output} file.
The \.{TFM} and \.{VF} files are defined later since their external
names are determined dynamically.

If it is necessary to abort the job because of a fatal error, the program
calls the `\\{jump\_out}' procedure, which goes to the label \\{final\_end}.

\Y\P\D \37$\\{final\_end}=9999$\C{go here to wrap it up}\par
\Y\P\hbox{\4}\X9:Compiler directives\X\6
\4\&{program}\1\  \37$\\{DVI\_copy}(\\{dvi\_file},\39\\{out\_file},\39%
\\{output})$;\6
\4\&{label} \37\\{final\_end};\6
\4\&{const} \37\X5:Constants in the outer block\X\6
\4\&{type} \37\X7:Types in the outer block\X\6
\4\&{var} \37\X17:Globals in the outer block\X\6
\X23:Error handling procedures\X\6
\4\&{procedure}\1\  \37\\{initialize};\C{this procedure gets things started
properly}\6
\4\&{var} \37\X16:Local variables for initialization\X\2\6
\&{begin} \37$\\{print\_ln}(\\{banner})$;\6
$\\{print\_ln}(\\{copyright})$;\5
$\\{print\_ln}(\.{\'Distributed\ under\ terms\ of\ GNU\ General\ Public\
License\'})$;\6
\X18:Set initial values\X\6
\&{end};\par
\fi

\M4. The definition of \\{max\_font\_type} should be adapted to the number of
font types used by the program; the first two values have a fixed meaning:
$\\{new\_font\_type}=0$ indicates that a font has been defined but has
not yet been used, and $\\{vf\_font\_type}=1$ indicates a virtual font;
font type values $\G\\{out\_font\_type}=2$ indicate real fonts and different
font types could be used to distinguish various kinds of font files
(\.{GF} or \.{PK} or \.{PXL}).

\Y\P\D \37$\\{new\_font\_type}=0$\C{this font has been defined but has not yet
been used}\par
\P\D \37$\\{vf\_font\_type}=1$\C{this font is a virtual font}\par
\P\D \37$\\{out\_font\_type}=2$\C{this font is a real font}\Y\par
\P\D \37$\\{max\_font\_type}=2$\par
\fi

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

\Y\P\D \37$\\{max\_select}=10$\C{maximum number of page selection ranges}\par
\Y\P$\4\X5:Constants in the outer block\X\S$\6
$\\{max\_fonts}=100$;\C{maximum number of distinct fonts}\6
$\\{max\_chars}=10000$;\C{maximum number of different characters among all
fonts}\6
$\\{max\_widths}=3000$;\C{maximum number of different characters widths}\6
$\\{max\_packets}=5000$;\C{maximum number of different characters packets;
must be less than 65536}\6
$\\{max\_bytes}=30000$;\C{maximum number of bytes for characters packets}\6
$\\{max\_recursion}=10$;\C{\.{VF} files shouldn't recurse beyond this level}\6
$\\{stack\_size}=100$;\C{\.{DVI} files shouldn't \\{push} beyond this depth}\6
$\\{terminal\_line\_length}=150$;\C{maximum number of characters input in a
single   line of input from the terminal}\6
$\\{name\_length}=50$;\C{a file name shouldn't be longer than this}\par
\U3.\fi

\M6. As mentioned above, \.{DVIcopy} has two chief purposes: (1)~It produces
a copy of the input \.{DVI} file with all references to characters from
virtual fonts replaced by their expansion as specified in the character
packets of \.{VF} files; and (2)~it serves as an example of a program
that reads \.{DVI} and \.{VF} files correctly, for system programmers
who are developing \.{DVI}-related software.

In fact, a very large section of code (starting with the second half of
this first chapter `Introduction' and ending with the fourteenth chapter
`The main program') is used in identical form in \.{DVIcopy} and in
\.{DVIprint}, a prototype \.{DVI}-driver for certain types of laser
printers. This has been made possible mostly by using several \.{WEB}
coding tricks, such as not to make the resulting \PASCAL\ program
inefficient in any way.

Parts of the program that are needed in \.{DVIprint} but not in
\.{DVIcopy} are delimited by the codewords `$ \&{device} \ldots  \&{ecived} $';
these are mostly the pixel rounding algorithms used to convert the
\.{DVI} units of a \.{DVI} file to the raster units of a real output
device and have been copied more or less verbatim from \.{DVItype}.

\Y\P\D \37$\\{device}\S\B$\C{change this to `$\\{device}\equiv\null$' when
output   for a real device is produced}\par
\P\D \37$\\{ecived}\S\hbox{}\T$\C{change this to `$\\{ecived}\equiv\null$' when
output   for a real device is produced}\par
\P\F \37$\\{device}\S\\{begin}$\par
\P\F \37$\\{ecived}\S\\{end}$\par
\fi

\M7. On some systems it is necessary to use various integer subrange types
in order to make \.{\title} efficient; this is true in particular for
frequently used variables such as loop indices. Consider an integer
variable \|x with values in the range $0\to255$: on most small systems
\|x should be a one or two byte integer whereas on most large systems
\|x should be a four byte integer.
Clearly the author of a program knows best which range of values is
required for each variable; thus \.{\title} never uses \PASCAL's \\{integer}
type. All integer variables are declared as one of the integer subrange
types defined below as \.{WEB} macros or \PASCAL\ types; these definitions
can be used without system-dependent changes, provided the signed 32~bit
integers are a subset of the standard type \\{integer}, and the compiler
automatically uses the optimal representation for integer subranges
(both conditions need not be satisfied for a particular system).

The complementary problem of storing large arrays of integer type
variables as compactly as possible is addressed differently; here
\.{\title} uses a \PASCAL\  \&{type} ~declaration for each kind of array
element.

Note that the primary purpose of these definitions is optimizations, not
range checking. All places where optimization for a particular system is
highly desirable have been listed in the index under ``optimization.''

\Y\P\D \37$\\{int\_32}\S\\{integer}$\C{signed 32~bit integers}\par
\Y\P$\4\X7:Types in the outer block\X\S$\6
$\\{int\_31}=0\to\H{7FFFFFFF}$;\C{unsigned 31~bit integer}\6
$\\{int\_24u}=0\to\H{FFFFFF}$;\C{unsigned 24~bit integer}\6
$\\{int\_24}=-\H{800000}\to\H{7FFFFF}$;\C{signed 24~bit integer}\6
$\\{int\_23}=0\to\H{7FFFFF}$;\C{unsigned 23~bit integer}\6
$\\{int\_16u}=0\to\H{FFFF}$;\C{unsigned 16~bit integer}\6
$\\{int\_16}=-\H{8000}\to\H{7FFF}$;\C{signed 16~bit integer}\6
$\\{int\_15}=0\to\H{7FFF}$;\C{unsigned 15~bit integer}\6
$\\{int\_8u}=0\to\H{FF}$;\C{unsigned 8~bit integer}\6
$\\{int\_8}=-\H{80}\to\H{7F}$;\C{signed 8~bit integer}\6
$\\{int\_7}=0\to\H{7F}$;\C{unsigned 7~bit integer}\par
\As14, 15, 27, 29, 31, 36, 71, 77, 80, 84, 117, 120, 154, 156, 183\ETs209.
\U3.\fi

\M8. Some of this code is optional for use when debugging only;
such material is enclosed between the delimiters  \&{debug}  and $  \&{gubed}
$.
Other parts, delimited by  \&{stat}  and $  \&{tats} $, are optionally included
if statistics about \.{\title}'s memory usage are desired.

\Y\P\D \37$\\{debug}\S\B$\C{change this to `$\\{debug}\equiv\null$' when
debugging}\par
\P\D \37$\\{gubed}\S\hbox{}\T$\C{change this to `$\\{gubed}\equiv\null$' when
debugging}\par
\P\F \37$\\{debug}\S\\{begin}$\par
\P\F \37$\\{gubed}\S\\{end}$\Y\par
\P\D \37$\\{stat}\S\B$\C{change this to `$\\{stat}\equiv\null$'   when
gathering usage statistics}\par
\P\D \37$\\{tats}\S\hbox{}\T$\C{change this to `$\\{tats}\equiv\null$'   when
gathering usage statistics}\par
\P\F \37$\\{stat}\S\\{begin}$\par
\P\F \37$\\{tats}\S\\{end}$\par
\fi

\M9. The \PASCAL\ compiler used to develop this program has ``compiler
directives'' that can appear in comments whose first character is a dollar
sign.
In production versions of \.{\title} these directives tell the compiler that
it is safe to avoid range checks and to leave out the extra code it inserts
for the \PASCAL\ debugger's benefit, although interrupts will occur if
there is arithmetic overflow.

\Y\P$\4\X9:Compiler directives\X\S$\6
$\B\J\$\|C-,\39\|A+,\39\|D-\T$\C{no range check, catch arithmetic overflow, no
debug overhead}\6
\&{debug} \37$\B\J\$\|C+,\39\|D+\T$\ \&{gubed}\C{but turn everything on when
debugging}\par
\U3.\fi

\M10. Labels are given symbolic names by the following definitions. We insert
the label `\\{exit}:' just before the `\ignorespaces  \&{end} \unskip' of a
procedure in which we have used the `\&{return}' statement defined below;
the label `\\{restart}' is occasionally used at the very beginning of a
procedure; and the label `\\{reswitch}' is occasionally used just prior to
a \&{case} statement in which some cases change the conditions and we wish to
branch to the newly applicable case.
Loops that are set up with the \&{loop} construction defined below are
commonly exited by going to `\\{done}' or to `\\{found}' or to `\\{not%
\_found}',
and they are sometimes repeated by going to `\\{continue}'.

\Y\P\D \37$\\{exit}=10$\C{go here to leave a procedure}\par
\P\D \37$\\{restart}=20$\C{go here to start a procedure again}\par
\P\D \37$\\{reswitch}=21$\C{go here to start a case statement again}\par
\P\D \37$\\{continue}=22$\C{go here to resume a loop}\par
\P\D \37$\\{done}=30$\C{go here to exit a loop}\par
\P\D \37$\\{found}=31$\C{go here when you've found it}\par
\P\D \37$\\{not\_found}=32$\C{go here when you've found something else}\par
\fi

\M11. The term \\{print} is used instead of \\{write} when this program writes
on
\\{output}, so that all such output could easily be redirected if desired;
the term \\{d\_print} is used for conditional output if we are debugging.

\Y\P\D \37$\\{print}(\#)\S\\{write}(\\{output},\39\#)$\par
\P\D \37$\\{print\_ln}(\#)\S\\{write\_ln}(\\{output},\39\#)$\par
\P\D \37$\\{new\_line}\S\\{write\_ln}(\\{output})$\C{start new line}\par
\P\D \37$\\{print\_nl}(\#)\S$\C{print information starting on a new line}\6
\&{begin} \37\\{new\_line};\5
$\\{print}(\#)$;\6
\&{end}\Y\par
\P\D \37$\\{d\_print}(\#)\S$\1\6
\&{debug} \37$\\{print}(\#)$\ \&{gubed}\2\par
\P\D \37$\\{d\_print\_ln}(\#)\S$\1\6
\&{debug} \37$\\{print\_ln}(\#)$\ \&{gubed}\2\par
\fi

\M12. 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$\\{Incr\_Decr}(\#)\S\#$\par
\P\D \37$\\{Incr}(\#)\S\#\K\#+\\{Incr\_Decr}$\C{increase a variable}\par
\P\D \37$\\{Decr}(\#)\S\#\K\#-\\{Incr\_Decr}$\C{decrease a variable}\par
\P\D \37$\\{loop}\S$\ \&{while} $\\{true}$ \1\&{do}\ \C{repeat over and over
until a \&{goto}  happens}\par
\P\D \37$\\{do\_nothing}\S$\C{empty statement}\par
\P\D \37$\\{return}\S$\1\5
\&{goto} \37\\{exit}\C{terminate a procedure call}\2\par
\P\F \37$\\{return}\S\\{nil}$\par
\P\F \37$\\{loop}\S\\{xclause}$\par
\fi

\M13. We assume that   \&{case}  statements may include a default case that
applies
if no matching label is found. Thus, we shall use constructions like
$$\vbox{\halign{#\hfil\cr
 \&{case} $\|x$ \&{of}\cr
1: $\langle\,$code for $x=1\,\rangle$;\cr
3: $\langle\,$code for $x=3\,\rangle$;\cr
 \&{othercases}  $\langle\,$code for $\|x\I1$ and $\|x\I3$$\,\rangle$\cr
  \&{endcases} \cr}}$$
since most \PASCAL\ compilers have plugged this hole in the language by
incorporating some sort of default mechanism. For example, the compiler
used to develop \.{WEB} and \TeX\ allows `\\{others}:' as a default label,
and other \PASCAL s allow syntaxes like `\ignorespaces \&{else} \unskip' or
`\&{otherwise}' or `\\{otherwise}:', etc. The definitions of  \&{othercases}
and   \&{endcases}  should be changed to agree with local conventions. (Of
course, if no default mechanism is available, the   \&{case}  statements of
this program must be extended by listing all remaining cases.
Donald~E. Knuth, the author of the \.{WEB} system program \.{TANGLE},
would have taken the trouble to modify \.{TANGLE} so that such extensions
were done automatically, if he had not wanted to encourage \PASCAL\
compiler writers to make this important change in \PASCAL, where it belongs.)

\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

\N14.  The character set.
Like all programs written with the  \.{WEB} system, \.{\title} 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} and \.{VF} files use ASCII code for
file names and certain other strings.

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

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

\M15. 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 \.{\title}.
So we shall assume that the \PASCAL\ system being used for \.{\title}
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\X7: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

\M16. \P$\X16:Local variables for initialization\X\S$\6
\4\|i: \37\\{int\_16};\C{loop index for initializations}\par
\A39.
\U3.\fi

\M17. The \.{\title} 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\X17: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
\As21, 32, 37, 46, 49, 62, 65, 72, 78, 81, 82, 85, 91, 93, 97, 102, 109, 118,
121, 123, 125, 126, 128, 134, 137, 142, 146, 157, 158, 173, 176, 181, 184, 187,
210, 221, 234\ETs245.
\U3.\fi

\M18. 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\X18: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
\As19, 22, 38, 73, 79, 83, 86, 94, 119, 122, 124, 129, 138, 147, 159, 174, 182,
185, 211, 235\ETs246.
\U3.\fi

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

\Y\P$\4\X18: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

\N20.  Reporting errors to the user.
The \.{\title} processor does not verify that every single bit read from
one of its binary input files is meaningful and consistent; there are
other programs, e.g., \.{DVItype}, \.{TFtoPL}, and \.{VFtoPL}, specially
designed for that purpose.

On the other hand, \.{\title} is designed to avoid unpredictable results
due to undetected arithmetic overflow, or due to violation of integer
subranges or array bounds under {\it all\/} circumstances. Thus a fair
amount of checking is done when reading and analyzing the input data,
even in cases where such checking reduces the efficiency of the program
to some extent.

\fi

\M21. A global variable called \\{history} will contain one of four values
at the end of every run: \\{spotless} means that no unusual messages were
printed; \\{harmless\_message} means that a message of possible interest
was printed but no serious errors were detected; \\{error\_message} means that
at least one error was found; \\{fatal\_message} means that the program
terminated abnormally. The value of \\{history} does not influence the
behavior of the program; it is simply computed for the convenience
of systems that might want to use such information.

\Y\P\D \37$\\{spotless}=0$\C{\\{history} value for normal jobs}\par
\P\D \37$\\{harmless\_message}=1$\C{\\{history} value when non-serious info was
printed}\par
\P\D \37$\\{error\_message}=2$\C{\\{history} value when an error was noted}\par
\P\D \37$\\{fatal\_message}=3$\C{\\{history} value when we had to stop
prematurely}\Y\par
\P\D \37$\\{mark\_harmless}\S\hbox{}$\ \&{if} $\\{history}=\\{spotless}$ \1%
\&{then}\5
$\\{history}\K\\{harmless\_message}$\2\par
\P\D \37$\\{mark\_error}\S\\{history}\K\\{error\_message}$\par
\P\D \37$\\{mark\_fatal}\S\\{history}\K\\{fatal\_message}$\par
\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{history}: \37$\\{spotless}\to\\{fatal\_message}$;\C{how bad was this run?}%
\par
\fi

\M22. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{history}\K\\{spotless}$;\par
\fi

\M23. If an input (\.{DVI}, \.{TFM}, \.{VF}, or other) file is badly malformed,
the whole process must be aborted; \.{\title} will give up, after issuing
an error message about what caused the error. These messages will, however,
in most cases just indicate which input file caused the error. One of the
programs \.{DVItype}, \.{TFtoPL} or \.{VFtoVP} should then be used to
diagnose the error in full detail.

Such errors might be discovered inside of subroutines inside of subroutines,
so a procedure called \\{jump\_out} has been introduced. This procedure, which
transfers control to the label \\{final\_end} at the end of the program,
contains the only non-local \&{goto}  statement in \.{\title}.
Some \PASCAL\ compilers do not implement non-local \&{goto}  statements. In
such cases the \&{goto} \\{final\_end} in \\{jump\_out} should simply be
replaced
by a call on some system procedure that quietly terminates the program.

\Y\P\D \37$\\{abort}(\#)\S$\1\6
\&{begin} \37$\\{print\_ln}(\.{\'\ \'},\39\#,\39\.{\'.\'})$;\5
\\{jump\_out};\6
\&{end}\2\par
\Y\P$\4\X23:Error handling procedures\X\S$\6
\X48:Basic printing procedures\X\6
\4\&{procedure}\1\  \37\\{close\_files\_and\_terminate};\5
\\{forward};\7
\4\&{procedure}\1\  \37\\{jump\_out};\2\6
\&{begin} \37\\{mark\_fatal};\5
\\{close\_files\_and\_terminate};\5
\&{goto} \37\\{final\_end};\6
\&{end};\par
\As24, 25, 95\ETs110.
\U3.\fi

\M24. Sometimes the program's behavior is far different from what it should
be, and \.{\title} prints an error message that is really for the
\.{\title} maintenance person, not the user. In such cases the program
says \\{confusion} ( indication of where we are) .

\Y\P$\4\X23:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{confusion}(\|p:\\{pckt\_pointer})$;\2\6
\&{begin} \37$\\{print}(\.{\'\ !This\ can\'}\.{\'t\ happen\ (\'})$;\5
$\\{print\_packet}(\|p)$;\5
$\\{print\_ln}(\.{\').\'})$;\5
\\{jump\_out};\6
\&{end};\par
\fi

\M25. An overflow stop occurs if \.{\title}'s tables aren't large enough.

\Y\P$\4\X23:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{overflow}(\|p:\\{pckt\_pointer};\,\35\|n:\\{int%
\_16u})$;\2\6
\&{begin} \37$\\{print}(\.{\'\ !Sorry,\ \'},\39\\{title},\39\.{\'\ capacity\
exceeded\ [\'})$;\5
$\\{print\_packet}(\|p)$;\5
$\\{print\_ln}(\.{\'=\'},\39\|n:1,\39\.{\'].\'})$;\5
\\{jump\_out};\6
\&{end};\par
\fi

\N26.  Binary data and binary files.
A detailed description of the \.{DVI} file format can be found in the
documentation of \TeX, \.{DVItype}, or \.{GFtoDVI}; here we just define
symbolic names for some of the \.{DVI} command bytes.

\Y\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}\Y\par
\P\D \37$\\{dvi\_id}=2$\C{identifies \.{DVI} files}\par
\fi

\M27. A \.{DVI}, \.{VF}, or \.{TFM} 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. One, two, three, or four consecutive bytes are often
interpreted as (signed or unsigned) integers.
We might as well define the corresponding data types.

\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{signed\_byte}=-\H{80}\to\H{7F}$;\C{signed one-byte quantity}\6
$\\{eight\_bits}=0\to\H{FF}$;\C{unsigned one-byte quantity}\6
$\\{signed\_pair}=-\H{8000}\to\H{7FFF}$;\C{signed two-byte quantity}\6
$\\{sixteen\_bits}=0\to\H{FFFF}$;\C{unsigned two-byte quantity}\6
$\\{signed\_trio}=-\H{800000}\to\H{7FFFFF}$;\C{signed three-byte quantity}\6
$\\{twentyfour\_bits}=0\to\H{FFFFFF}$;\C{unsigned three-byte quantity}\6
$\\{signed\_quad}=\\{int\_32}$;\C{signed four-byte quantity}\par
\fi

\M28. 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
\.{\title} 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.

\fi

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

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

\M30. For some operating systems it may be convenient or even necessary to
close the input files.

\Y\P\D \37$\\{close\_in}(\#)\S\\{do\_nothing}$\C{close an input file}\par
\fi

\M31. Character packets extracted from \.{VF} files will be stored in a large
array \\{byte\_mem}. Other packets of bytes, e.g., character packets
extracted from a \.{GF} or \.{PK} or \.{PXL} file could be stored in the
same way. A `\\{pckt\_pointer}' variable, which signifies a packet,
is an index into another array \\{pckt\_start}. The actual sequence of bytes
in the packet pointed to by \|p appears in positions $\\{pckt\_start}[\|p]$ to
$\\{pckt\_start}[\|p+1]-1$, inclusive, in \\{byte\_mem}.

Packets will also be used to store sequences of \\{ASCII\_code}s; in this
respect the \\{byte\_mem} array is very similar to \TeX's string pool and
part of the following code has, in fact, been copied more or less
verbatim from \TeX.

In other respects the packets resemble the identifiers used by
\.{TANGLE} and \.{WEAVE} (also stored in an array called \\{byte\_mem})
since there is, in general, at most one packet with a given contents;
thus part of the code below has been adapted from the corresponding code
in these programs.

Some \PASCAL\ compilers won't pack integers into a single byte unless the
integers lie in the range $-128\to127$. To accommodate such systems we
access the array \\{byte\_mem} only via macros that can easily be redefined.

\Y\P\D \37$\\{bi}(\#)\S\#$\C{convert from \\{eight\_bits} to \\{packed\_byte}}%
\par
\P\D \37$\\{bo}(\#)\S\#$\C{convert from \\{packed\_byte} to \\{eight\_bits}}\par
\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{packed\_byte}=\\{eight\_bits}$;\C{elements of \\{byte\_mem} array}\6
$\\{byte\_pointer}=0\to\\{max\_bytes}$;\C{an index into \\{byte\_mem}}\6
$\\{pckt\_pointer}=0\to\\{max\_packets}$;\C{an index into \\{pckt\_start}}\par
\fi

\M32. The global variable \\{byte\_ptr} points to the first unused location in
\\{byte\_mem} and \\{pckt\_ptr} points to the first unused location in
\\{pckt\_start}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{byte\_mem}: \37\&{packed} \37\&{array} $[\\{byte\_pointer}]$ \1\&{of}\5
\\{packed\_byte};\C{bytes of packets}\2\6
\4\\{pckt\_start}: \37\&{array} $[\\{pckt\_pointer}]$ \1\&{of}\5
\\{byte\_pointer};\C{directory into \\{byte\_mem}}\2\6
\4\\{byte\_ptr}: \37\\{byte\_pointer};\6
\4\\{pckt\_ptr}: \37\\{pckt\_pointer};\par
\fi

\M33. Several of the elementary operations with packets are performed using
\.{WEB} macros instead of \PASCAL\ procedures, because many of the
operations are done quite frequently and we want to avoid the
overhead of procedure calls. For example, here is
a simple macro that computes the length of a packet.

\Y\P\D \37$\\{pckt\_length}(\#)\S(\\{pckt\_start}[\#+1]-\\{pckt\_start}[\#])$%
\C{the number of bytes   in packet number \#}\par
\fi

\M34. Packets are created by appending bytes to \\{byte\_mem}.
The \\{append\_byte} macro, defined here, does not check to see if the
value of \\{byte\_ptr} has gotten too high; this test is supposed to be
made before \\{append\_byte} is used. There is also a \\{flush\_byte}
macro, which erases the last byte appended.

To test if there is room to append \|l more bytes to \\{byte\_mem},
we shall write $\\{pckt\_room}(\|l)$, which aborts \.{\title} and gives an
apologetic error message if there isn't enough room.

\Y\P\D \37$\\{append\_byte}(\#)\S$\C{put byte \# at the end of \\{byte\_mem}}\6
\&{begin} \37$\\{byte\_mem}[\\{byte\_ptr}]\K\\{bi}(\#)$;\5
$\\{incr}(\\{byte\_ptr})$;\6
\&{end}\par
\P\D \37$\\{flush\_byte}\S\\{decr}(\\{byte\_ptr})$\C{forget the last byte in %
\\{byte\_mem}}\par
\P\D \37$\\{pckt\_room}(\#)\S$\C{make sure that \\{byte\_mem} hasn't
overflowed}\6
\&{if} $\\{max\_bytes}-\\{byte\_ptr}<\#$ \1\&{then}\5
$\\{overflow}(\\{str\_bytes},\39\\{max\_bytes})$\2\par
\P\D \37$\\{append\_one}(\#)\S$\1\6
\&{begin} \37$\\{pckt\_room}(1)$;\5
$\\{append\_byte}(\#)$;\6
\&{end}\2\par
\fi

\M35. The length of the current packet is called \\{cur\_pckt\_length}:

\Y\P\D \37$\\{cur\_pckt\_length}\S(\\{byte\_ptr}-\\{pckt\_start}[\\{pckt%
\_ptr}])$\par
\fi

\M36. Once a sequence of bytes has been appended to \\{byte\_mem}, it
officially becomes a packet when the \\{make\_packet} function is called.
This function returns as its value the identification number of either
an existing packet with the same contents or, if no such packet exists,
of the new packet. Thus two packets have the same contents if and only
if they have the same identification number. In order to locate the
packet with a given contents, or to find out that no such packet exists,
we need a hash table. The hash table is kept by the method of simple
chaining, where the heads of the individual lists appear in the \\{p\_hash}
array. If \|h is a hash code, the hash table list starts at $\\{p\_hash}[\|h]$
and proceeds through \\{p\_link} pointers.

\Y\P\D \37$\\{hash\_size}=353$\C{should be prime, must be $>256$}\par
\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{hash\_code}=0\to\\{hash\_size}$;\par
\fi

\M37. \P$\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{p\_link}: \37\&{array} $[\\{pckt\_pointer}]$ \1\&{of}\5
\\{pckt\_pointer};\C{hash table}\2\6
\4\\{p\_hash}: \37\&{array} $[\\{hash\_code}]$ \1\&{of}\5
\\{pckt\_pointer};\2\par
\fi

\M38. Initially \\{byte\_mem} and all the hash lists are empty; \\{empty%
\_packet}
is the empty packet.

\Y\P\D \37$\\{empty\_packet}=0$\C{the empty packet}\par
\P\D \37$\\{invalid\_packet}\S\\{max\_packets}$\C{used when there is no packet}%
\par
\Y\P$\4\X18:Set initial values\X\mathrel{+}\S$\6
$\\{pckt\_ptr}\K1$;\5
$\\{byte\_ptr}\K1$;\5
$\\{pckt\_start}[0]\K1$;\5
$\\{pckt\_start}[1]\K1$;\6
\&{for} $\|h\K0\mathrel{\&{to}}\\{hash\_size}-1$ \1\&{do}\5
$\\{p\_hash}[\|h]\K0$;\2\par
\fi

\M39. \P$\X16:Local variables for initialization\X\mathrel{+}\S$\6
\4\|h: \37\\{hash\_code};\C{index into hash-head arrays}\par
\fi

\M40. Here now is the \\{make\_packet} function used to create packets (and
strings).

\Y\P\4\&{function}\1\  \37\\{make\_packet}: \37\\{pckt\_pointer};\6
\4\&{label} \37\\{found};\6
\4\&{var} \37$\|i,\39\|k$: \37\\{byte\_pointer};\C{indices into \\{byte\_mem}}\6
\|h: \37\\{hash\_code};\C{hash code}\6
$\|s,\39\|l$: \37\\{byte\_pointer};\C{start and length of the given packet}\6
\|p: \37\\{pckt\_pointer};\C{where the packet is being sought}\2\6
\&{begin} \37$\|s\K\\{pckt\_start}[\\{pckt\_ptr}]$;\5
$\|l\K\\{byte\_ptr}-\|s$;\C{compute start and length}\6
\&{if} $\|l=0$ \1\&{then}\5
$\|p\K\\{empty\_packet}$\6
\4\&{else} \&{begin} \37\X41:Compute the packet hash code \|h\X;\6
\X42:Compute the packet location \|p\X;\6
\&{if} $\\{pckt\_ptr}=\\{max\_packets}$ \1\&{then}\5
$\\{overflow}(\\{str\_packets},\39\\{max\_packets})$;\2\6
$\\{incr}(\\{pckt\_ptr})$;\5
$\\{pckt\_start}[\\{pckt\_ptr}]\K\\{byte\_ptr}$;\6
\&{end};\2\6
\4\\{found}: \37$\\{make\_packet}\K\|p$;\6
\&{end};\par
\fi

\M41. A simple hash code is used: If the sequence of bytes is
$b_1b_2\ldots b_n$, its hash value will be
$$(2^{n-1}b_1+2^{n-2}b_2+\cdots+b_n)\,\bmod\,\\{hash\_size}.$$

\Y\P$\4\X41:Compute the packet hash code \|h\X\S$\6
$\|h\K\\{bo}(\\{byte\_mem}[\|s])$;\5
$\|i\K\|s+1$;\6
\&{while} $\|i<\\{byte\_ptr}$ \1\&{do}\6
\&{begin} \37$\|h\K(\|h+\|h+\\{bo}(\\{byte\_mem}[\|i]))\mathbin{\&{mod}}\\{hash%
\_size}$;\5
$\\{incr}(\|i)$;\6
\&{end}\2\par
\U40.\fi

\M42. If the packet is new, it will be placed in position $\|p=\\{pckt\_ptr}$,
otherwise \|p will point to its existing location.

\Y\P$\4\X42:Compute the packet location \|p\X\S$\6
$\|p\K\\{p\_hash}[\|h]$;\6
\&{while} $\|p\I0$ \1\&{do}\6
\&{begin} \37\&{if} $\\{pckt\_length}(\|p)=\|l$ \1\&{then}\5
\X43:Compare packet \|p with current packet, \&{goto} \\{found} if equal\X;\2\6
$\|p\K\\{p\_link}[\|p]$;\6
\&{end};\2\6
$\|p\K\\{pckt\_ptr}$;\C{the current packet is new}\6
$\\{p\_link}[\|p]\K\\{p\_hash}[\|h]$;\5
$\\{p\_hash}[\|h]\K\|p$\C{insert \|p at beginning of hash list}\par
\U40.\fi

\M43. \P$\X43:Compare packet \|p with current packet, \&{goto} \\{found} if
equal\X\S$\6
\&{begin} \37$\|i\K\|s$;\5
$\|k\K\\{pckt\_start}[\|p]$;\6
\&{while} $(\|i<\\{byte\_ptr})\W(\\{byte\_mem}[\|i]=\\{byte\_mem}[\|k])$ \1%
\&{do}\6
\&{begin} \37$\\{incr}(\|i)$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
\&{if} $\|i=\\{byte\_ptr}$ \1\&{then}\C{all bytes agree}\6
\&{begin} \37$\\{byte\_ptr}\K\\{pckt\_start}[\\{pckt\_ptr}]$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
\&{end}\par
\U42.\fi

\M44. Some packets are initialized with predefined strings of \\{ASCII\_code}s;
a few macros permit us to do the initialization with a compact program.
Since this initialization is done when \\{byte\_mem} is still empty, and
since \\{byte\_mem} is supposed to be large enough for all the predefined
strings, \\{pckt\_room} is used only if we are debugging.

\Y\P\D \37$\\{pid0}(\#)\S\#\K\\{make\_packet}$\par
\P\D \37$\\{pid1}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-1]\K\\{bi}(\#)$;\5
\\{pid0}\par
\P\D \37$\\{pid2}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-2]\K\\{bi}(\#)$;\5
\\{pid1}\par
\P\D \37$\\{pid3}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-3]\K\\{bi}(\#)$;\5
\\{pid2}\par
\P\D \37$\\{pid4}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-4]\K\\{bi}(\#)$;\5
\\{pid3}\par
\P\D \37$\\{pid5}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-5]\K\\{bi}(\#)$;\5
\\{pid4}\par
\P\D \37$\\{pid6}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-6]\K\\{bi}(\#)$;\5
\\{pid5}\par
\P\D \37$\\{pid7}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-7]\K\\{bi}(\#)$;\5
\\{pid6}\par
\P\D \37$\\{pid8}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-8]\K\\{bi}(\#)$;\5
\\{pid7}\par
\P\D \37$\\{pid9}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-9]\K\\{bi}(\#)$;\5
\\{pid8}\par
\P\D \37$\\{pid10}(\#)\S\\{byte\_mem}[\\{byte\_ptr}-10]\K\\{bi}(\#)$;\5
\\{pid9}\Y\par
\P\D \37$\\{pid\_init}(\#)\S$\1\6
\&{debug} \37$\\{pckt\_room}(\#)$;\ \&{gubed}\2\6
$\\{Incr}(\\{byte\_ptr})(\#)$\Y\par
\P\D \37$\\{id1}\S\\{pid\_init}(1)$;\5
\\{pid1}\par
\P\D \37$\\{id2}\S\\{pid\_init}(2)$;\5
\\{pid2}\par
\P\D \37$\\{id3}\S\\{pid\_init}(3)$;\5
\\{pid3}\par
\P\D \37$\\{id4}\S\\{pid\_init}(4)$;\5
\\{pid4}\par
\P\D \37$\\{id5}\S\\{pid\_init}(5)$;\5
\\{pid5}\par
\P\D \37$\\{id6}\S\\{pid\_init}(6)$;\5
\\{pid6}\par
\P\D \37$\\{id7}\S\\{pid\_init}(7)$;\5
\\{pid7}\par
\P\D \37$\\{id8}\S\\{pid\_init}(8)$;\5
\\{pid8}\par
\P\D \37$\\{id9}\S\\{pid\_init}(9)$;\5
\\{pid9}\par
\P\D \37$\\{id10}\S\\{pid\_init}(10)$;\5
\\{pid10}\par
\fi

\M45. Here we initialize some strings used as argument of the \\{overflow} and
\\{confusion} procedures.

\Y\P$\4\X45:Initialize predefined strings\X\S$\6
$\\{id5}(\.{"f"})(\.{"o"})(\.{"n"})(\.{"t"})(\.{"s"})(\\{str\_fonts})$;\5
$\\{id5}(\.{"c"})(\.{"h"})(\.{"a"})(\.{"r"})(\.{"s"})(\\{str\_chars})$;\5
$\\{id6}(\.{"w"})(\.{"i"})(\.{"d"})(\.{"t"})(\.{"h"})(\.{"s"})(\\{str%
\_widths})$;\5
$\\{id7}(\.{"p"})(\.{"a"})(\.{"c"})(\.{"k"})(\.{"e"})(\.{"t"})(\.{"s"})(\\{str%
\_packets})$;\5
$\\{id5}(\.{"b"})(\.{"y"})(\.{"t"})(\.{"e"})(\.{"s"})(\\{str\_bytes})$;\5
$\\{id9}(\.{"r"})(\.{"e"})(\.{"c"})(\.{"u"})(\.{"r"})(\.{"s"})(\.{"i"})(%
\.{"o"})(\.{"n"})(\\{str\_recursion})$;\5
$\\{id5}(\.{"s"})(\.{"t"})(\.{"a"})(\.{"c"})(\.{"k"})(\\{str\_stack})$;\5
$\\{id10}(\.{"n"})(\.{"a"})(\.{"m"})(\.{"e"})(\.{"l"})(\.{"e"})(\.{"n"})(%
\.{"g"})(\.{"t"})(\.{"h"})(\\{str\_name\_length})$;\par
\As92, 135\ETs193.
\U231.\fi

\M46. \P$\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4$\\{str\_fonts},\39\\{str\_chars},\39\\{str\_widths},\39\\{str\_packets},\39%
\\{str\_bytes},\39\\{str\_recursion},\39\\{str\_stack},\39\\{str\_name%
\_length}$: \37\\{pckt\_pointer};\par
\fi

\M47. Some packets, e.g., the preamble comments of \.{DVI} and \.{VF} files,
are needed only temporarily. In such cases \\{new\_packet} is used to
create a packet (which might duplicate an existing packet) and
\\{flush\_packet} is used to discard it; the calls to \\{new\_packet} and
\\{flush\_packet} must occur in balanced pairs, without any intervening
calls to \\{make\_packet}.

\Y\P\4\&{function}\1\  \37\\{new\_packet}: \37\\{pckt\_pointer};\2\6
\&{begin} \37\&{if} $\\{pckt\_ptr}=\\{max\_packets}$ \1\&{then}\5
$\\{overflow}(\\{str\_packets},\39\\{max\_packets})$;\2\6
$\\{new\_packet}\K\\{pckt\_ptr}$;\5
$\\{incr}(\\{pckt\_ptr})$;\5
$\\{pckt\_start}[\\{pckt\_ptr}]\K\\{byte\_ptr}$;\6
\&{end};\7
\4\&{procedure}\1\  \37\\{flush\_packet};\2\6
\&{begin} \37$\\{decr}(\\{pckt\_ptr})$;\5
$\\{byte\_ptr}\K\\{pckt\_start}[\\{pckt\_ptr}]$;\6
\&{end};\par
\fi

\M48. The \\{print\_packet} procedure prints the contents of a packet; such a
packets should, of course, consists of a sequence of \\{ASCII\_code}s.

\Y\P$\4\X48:Basic printing procedures\X\S$\6
\4\&{procedure}\1\  \37$\\{print\_packet}(\|p:\\{pckt\_pointer})$;\6
\4\&{var} \37\|k: \37\\{byte\_pointer};\2\6
\&{begin} \37\&{for} $\|k\K\\{pckt\_start}[\|p]\mathrel{\&{to}}\\{pckt\_start}[%
\|p+1]-1$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{bo}(\\{byte\_mem}[\|k])])$;\2\6
\&{end};\par
\As60\ET61.
\U23.\fi

\M49. When we interpret a packet we will use two (global or local) variables:
\\{cur\_loc} will point to the byte to be used next, and \\{cur\_limit} will
point to the start of the next packet. The macro \\{pckt\_extract} will be
used to extract one byte; it should, however, never be used with
$\\{cur\_loc}\G\\{cur\_limit}$.

\Y\P\D \37$\\{pckt\_extract}(\#)\S$\1\6
\&{debug} \37\&{if} $\\{cur\_loc}\G\\{cur\_limit}$ \1\&{then}\5
$\\{confusion}(\\{str\_packets})$\ \&{else} \2\6
\&{gubed}\2\6
\&{begin} \37$\#\K\\{bo}(\\{byte\_mem}[\\{cur\_loc}])$;\5
$\\{incr}(\\{cur\_loc})$;\ \&{end}\par
\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\_pckt}: \37\\{pckt\_pointer};\C{the current packet}\6
\4\\{cur\_loc}: \37\\{byte\_pointer};\C{current location in a packet}\6
\4\\{cur\_limit}: \37\\{byte\_pointer};\C{start of next packet}\par
\fi

\M50. We will need routines to extract one, two, three, or four bytes from
\\{byte\_mem}, from the \.{DVI} file, or from a \.{VF} file and assemble
them into (signed or unsigned) integers and these routines should be
optimized for efficiency. Here we define \.{WEB} macros to be used for
the body of these routines; thus the changes for system dependent
optimization have to be applied only once.

In addition we demonstrates how these macros can be used to define
functions that extract one, two, three, or four bytes from a character
packet and assemble them into signed or unsigned integers (assuming that
\\{cur\_loc} and \\{cur\_limit} are initialized suitably).

\Y\P\D \37$\\{begin\_byte}(\#)\S$\1\6
\4\&{var} \37\|a: \37\\{eight\_bits};\2\6
\&{begin} \37$\#(\|a)$\par
\P\D \37$\\{comp\_sbyte}(\#)\S$\1\6
\&{if} $\|a<128$ \1\&{then}\5
$\#\K\|a$\ \&{else} $\#\K\|a-256$\2\2\par
\P\D \37$\\{comp\_ubyte}(\#)\S\#\K\|a$\par
\P\F \37$\\{begin\_byte}\S\\{begin}$\par
\Y\P\4\&{function}\1\  \37\\{pckt\_sbyte}: \37\\{int\_8};\C{returns the next
byte, signed}\2\6
\&{begin\_byte} \37$(\\{pckt\_extract})$;\5
$\\{comp\_sbyte}(\\{pckt\_sbyte})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{pckt\_ubyte}: \37\\{int\_8u};\C{returns the next byte,
unsigned}\2\6
\&{begin\_byte} \37$(\\{pckt\_extract})$;\5
$\\{comp\_ubyte}(\\{pckt\_ubyte})$;\6
\&{end};\par
\fi

\M51. \P\D \37$\\{begin\_pair}(\#)\S$\1\6
\4\&{var} \37$\|a,\39\|b$: \37\\{eight\_bits};\2\6
\&{begin} \37$\#(\|a)$;\5
$\#(\|b)$\par
\P\D \37$\\{comp\_spair}(\#)\S$\1\6
\&{if} $\|a<128$ \1\&{then}\5
$\#\K\|a\ast256+\|b$\ \&{else} $\#\K(\|a-256)\ast256+\|b$\2\2\par
\P\D \37$\\{comp\_upair}(\#)\S\#\K\|a\ast256+\|b$\par
\P\F \37$\\{begin\_pair}\S\\{begin}$\par
\Y\P\4\&{function}\1\  \37\\{pckt\_spair}: \37\\{int\_16};\C{returns the next
two bytes, signed}\2\6
\&{begin\_pair} \37$(\\{pckt\_extract})$;\5
$\\{comp\_spair}(\\{pckt\_spair})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{pckt\_upair}: \37\\{int\_16u};\C{returns the next two
bytes, unsigned}\2\6
\&{begin\_pair} \37$(\\{pckt\_extract})$;\5
$\\{comp\_upair}(\\{pckt\_upair})$;\6
\&{end};\par
\fi

\M52. \P\D \37$\\{begin\_trio}(\#)\S$\1\6
\4\&{var} \37$\|a,\39\|b,\39\|c$: \37\\{eight\_bits};\2\6
\&{begin} \37$\#(\|a)$;\5
$\#(\|b)$;\5
$\#(\|c)$\par
\P\D \37$\\{comp\_strio}(\#)\S$\1\6
\&{if} $\|a<128$ \1\&{then}\5
$\#\K(\|a\ast256+\|b)\ast256+\|c$\ \&{else} $\#\K((\|a-256)\ast256+\|b)\ast256+%
\|c$\2\2\par
\P\D \37$\\{comp\_utrio}(\#)\S\#\K(\|a\ast256+\|b)\ast256+\|c$\par
\P\F \37$\\{begin\_trio}\S\\{begin}$\par
\Y\P\4\&{function}\1\  \37\\{pckt\_strio}: \37\\{int\_24};\C{returns the next
three bytes, signed}\2\6
\&{begin\_trio} \37$(\\{pckt\_extract})$;\5
$\\{comp\_strio}(\\{pckt\_strio})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{pckt\_utrio}: \37\\{int\_24u};\C{returns the next
three bytes, unsigned}\2\6
\&{begin\_trio} \37$(\\{pckt\_extract})$;\5
$\\{comp\_utrio}(\\{pckt\_utrio})$;\6
\&{end};\par
\fi

\M53. \P\D \37$\\{begin\_quad}(\#)\S$\1\6
\4\&{var} \37$\|a,\39\|b,\39\|c,\39\|d$: \37\\{eight\_bits};\2\6
\&{begin} \37$\#(\|a)$;\5
$\#(\|b)$;\5
$\#(\|c)$;\5
$\#(\|d)$\par
\P\D \37$\\{comp\_squad}(\#)\S$\1\6
\&{if} $\|a<128$ \1\&{then}\5
$\#\K((\|a\ast256+\|b)\ast256+\|c)\ast256+\|d$\6
\4\&{else} $\#\K(((\|a-256)\ast256+\|b)\ast256+\|c)\ast256+\|d$\2\2\par
\P\F \37$\\{begin\_quad}\S\\{begin}$\par
\Y\P\4\&{function}\1\  \37\\{pckt\_squad}: \37\\{int\_32};\C{returns the next
four bytes, signed}\2\6
\&{begin\_quad} \37$(\\{pckt\_extract})$;\5
$\\{comp\_squad}(\\{pckt\_squad})$;\6
\&{end};\par
\fi

\M54. A similar set of routines is needed for the inverse task of
decomposing a \.{DVI} command into a sequence of bytes to be appended
to \\{byte\_mem} or, in the case of \.{DVIcopy}, to be written to the
output file. Again we define \.{WEB} macros to be used for the body
of these routines; thus the changes for system dependent optimization
have to be applied only once.

First, the \\{pckt\_one} outputs one byte, negative values are represented
in two's complement notation.

\Y\P\D $\\{begin\_one}\S$ \6
\&{begin} \37\par
\P\D \37$\\{comp\_one}(\#)\S$\1\6
\&{if} $\|x<0$ \1\&{then}\5
$\\{Incr}(\|x)(256)$;\2\2\6
$\#(\|x)$\par
\P\F \37$\\{begin\_one}\S\\{begin}$\par
\Y\P\&{device} \37\&{procedure}\1\  \37$\\{pckt\_one}(\|x:\\{int\_32})$;%
\C{output one byte}\2\6
\&{begin\_one} \37;\5
$\\{pckt\_room}(1)$;\5
$\\{comp\_one}(\\{append\_byte})$;\6
\&{end};\6
\&{ecived}\par
\fi

\M55. The \\{pckt\_two} outputs two bytes, negative values are represented in
two's complement notation.

\Y\P\D $\\{begin\_two}\S$ \6
\&{begin} \37\par
\P\D \37$\\{comp\_two}(\#)\S$\1\6
\&{if} $\|x<0$ \1\&{then}\5
$\\{Incr}(\|x)(\H{10000})$;\2\2\6
$\#(\|x\mathbin{\&{div}}\H{100})$;\5
$\#(\|x\mathbin{\&{mod}}\H{100})$\par
\P\F \37$\\{begin\_two}\S\\{begin}$\par
\Y\P\&{device} \37\&{procedure}\1\  \37$\\{pckt\_two}(\|x:\\{int\_32})$;%
\C{output two byte}\2\6
\&{begin\_two} \37;\5
$\\{pckt\_room}(2)$;\5
$\\{comp\_two}(\\{append\_byte})$;\6
\&{end};\6
\&{ecived}\par
\fi

\M56. The \\{pckt\_four} procedure outputs four bytes in two's complement
notation, without risking arithmetic overflow.

\Y\P\D $\\{begin\_four}\S$ \6
\&{begin} \37\par
\P\D \37$\\{comp\_four}(\#)\S$\1\6
\&{if} $\|x\G0$ \1\&{then}\5
$\#(\|x\mathbin{\&{div}}\H{1000000})$\6
\4\&{else} \&{begin} \37$\\{Incr}(\|x)(\H{40000000})$;\5
$\\{Incr}(\|x)(\H{40000000})$;\5
$\#((\|x\mathbin{\&{div}}\H{1000000})+128)$;\6
\&{end};\2\2\6
$\|x\K\|x\mathbin{\&{mod}}\H{1000000}$;\5
$\#(\|x\mathbin{\&{div}}\H{10000})$;\5
$\|x\K\|x\mathbin{\&{mod}}\H{10000}$;\5
$\#(\|x\mathbin{\&{div}}\H{100})$;\5
$\#(\|x\mathbin{\&{mod}}\H{100})$\par
\P\F \37$\\{begin\_four}\S\\{begin}$\par
\Y\P\4\&{procedure}\1\  \37$\\{pckt\_four}(\|x:\\{int\_32})$;\C{output four
bytes}\2\6
\&{begin\_four} \37;\5
$\\{pckt\_room}(4)$;\5
$\\{comp\_four}(\\{append\_byte})$;\6
\&{end};\par
\fi

\M57. Next, the \\{pckt\_char} procedure outputs a \\{set\_char} or \\{set}
command
or, if $\\{upd}=\\{false}$, a \\{put} command.

\Y\P\D \37$\\{begin\_char}\S$\1\6
\4\&{var} \37\|o: \37\\{eight\_bits};\C{\\{set1} or \\{put1}}\2\6
\&{begin} \37\par
\P\D \37$\\{comp\_char}(\#)\S$\1\6
\&{if} $(\R\\{upd})\V(\\{res}>127)\V(\\{ext}\I0)$ \1\&{then}\6
\&{begin} \37$\|o\K\\{dvi\_char\_cmd}[\\{upd}]$;\C{\\{set1} or \\{put1}}\6
\&{if} $\\{ext}<0$ \1\&{then}\5
$\\{Incr}(\\{ext})(\H{1000000})$;\2\6
\&{if} $\\{ext}=0$ \1\&{then}\5
$\#(\|o)$\ \&{else} \2\6
\&{begin} \37\&{if} $\\{ext}<\H{100}$ \1\&{then}\5
$\#(\|o+1)$\ \&{else} \2\6
\&{begin} \37\&{if} $\\{ext}<\H{10000}$ \1\&{then}\5
$\#(\|o+2)$\ \&{else} \2\6
\&{begin} \37$\#(\|o+3)$;\5
$\#(\\{ext}\mathbin{\&{div}}\H{10000})$;\5
$\\{ext}\K\\{ext}\mathbin{\&{mod}}\H{10000}$;\6
\&{end};\5
$\#(\\{ext}\mathbin{\&{div}}\H{100})$;\5
$\\{ext}\K\\{ext}\mathbin{\&{mod}}\H{100}$;\6
\&{end};\5
$\#(\\{ext})$;\6
\&{end};\6
\&{end};\2\2\6
$\#(\\{res})$\par
\P\F \37$\\{begin\_char}\S\\{begin}$\par
\Y\P\4\&{procedure}\1\  \37$\\{pckt\_char}(\\{upd}:\\{boolean};\,\35\\{ext}:%
\\{int\_32};\,\35\\{res}:\\{eight\_bits})$;\C{output \\{set} or \\{put}}\2\6
\&{begin\_char} \37;\5
$\\{pckt\_room}(5)$;\5
$\\{comp\_char}(\\{append\_byte})$;\6
\&{end};\par
\fi

\M58. Then, the \\{pckt\_unsigned} procedure outputs a \\{fnt} or \\{xxx}
command with its first parameter (normally unsigned); a \\{fnt} command
is converted into \\{fnt\_num} whenever this is possible.

\Y\P\D $\\{begin\_unsigned}\S$ \6
\&{begin} \37\par
\P\D \37$\\{comp\_unsigned}(\#)\S$\1\6
\&{if} $(\|x<\H{100})\W(\|x\G0)$ \1\&{then}\6
\&{if} $(\|o=\\{fnt1})\W(\|x<64)$ \1\&{then}\5
$\\{Incr}(\|x)(\\{fnt\_num\_0})$\ \&{else} $\#(\|o)$\2\6
\4\&{else} \&{begin} \37\&{if} $(\|x<\H{10000})\W(\|x\G0)$ \1\&{then}\5
$\#(\|o+1)$\ \&{else} \2\6
\&{begin} \37\&{if} $(\|x<\H{1000000})\W(\|x\G0)$ \1\&{then}\5
$\#(\|o+2)$\ \&{else} \2\6
\&{begin} \37$\#(\|o+3)$;\6
\&{if} $\|x\G0$ \1\&{then}\5
$\#(\|x\mathbin{\&{div}}\H{1000000})$\6
\4\&{else} \&{begin} \37$\\{Incr}(\|x)(\H{40000000})$;\5
$\\{Incr}(\|x)(\H{40000000})$;\5
$\#((\|x\mathbin{\&{div}}\H{1000000})+128)$;\6
\&{end};\2\6
$\|x\K\|x\mathbin{\&{mod}}\H{1000000}$;\6
\&{end};\5
$\#(\|x\mathbin{\&{div}}\H{10000})$;\5
$\|x\K\|x\mathbin{\&{mod}}\H{10000}$;\6
\&{end};\5
$\#(\|x\mathbin{\&{div}}\H{100})$;\5
$\|x\K\|x\mathbin{\&{mod}}\H{100}$;\6
\&{end};\2\2\6
$\#(\|x)$\par
\P\F \37$\\{begin\_unsigned}\S\\{begin}$\par
\Y\P\4\&{procedure}\1\  \37$\\{pckt\_unsigned}(\|o:\\{eight\_bits};\,\35\|x:%
\\{int\_32})$;\C{output \\{fnt\_num}, \\{fnt}, or \\{xxx}}\2\6
\&{begin\_unsigned} \37;\5
$\\{pckt\_room}(5)$;\5
$\\{comp\_unsigned}(\\{append\_byte})$;\6
\&{end};\par
\fi

\M59. Finally, the \\{pckt\_signed} procedure outputs a movement (\\{right}, %
\|w,
\|x, \\{down}, \|y, or \|z) command with its (signed) parameter.

\Y\P\D \37$\\{begin\_signed}\S$\1\6
\4\&{var} \37\\{xx}: \37\\{int\_31};\C{`absolute value' of \|x}\2\6
\&{begin} \37\par
\P\D \37$\\{comp\_signed}(\#)\S$\1\6
\&{if} $\|x\G0$ \1\&{then}\5
$\\{xx}\K\|x$\ \&{else} $\\{xx}\K-(\|x+1)$;\2\2\6
\&{if} $\\{xx}<\H{80}$ \1\&{then}\6
\&{begin} \37$\#(\|o)$;\ \&{if} $\|x<0$ \1\&{then}\5
$\\{Incr}(\|x)(\H{100})$;\ \2\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{xx}<\H{8000}$ \1\&{then}\6
\&{begin} \37$\#(\|o+1)$;\ \&{if} $\|x<0$ \1\&{then}\5
$\\{Incr}(\|x)(\H{10000})$;\ \2\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{xx}<\H{800000}$ \1\&{then}\6
\&{begin} \37$\#(\|o+2)$;\ \&{if} $\|x<0$ \1\&{then}\5
$\\{Incr}(\|x)(\H{1000000})$;\ \2\6
\&{end}\6
\4\&{else} \&{begin} \37$\#(\|o+3)$;\6
\&{if} $\|x\G0$ \1\&{then}\5
$\#(\|x\mathbin{\&{div}}\H{1000000})$\6
\4\&{else} \&{begin} \37$\|x\K\H{7FFFFFFF}-\\{xx}$;\5
$\#((\|x\mathbin{\&{div}}\H{1000000})+128)$;\ \&{end};\2\6
$\|x\K\|x\mathbin{\&{mod}}\H{1000000}$;\6
\&{end};\2\6
$\#(\|x\mathbin{\&{div}}\H{10000})$;\5
$\|x\K\|x\mathbin{\&{mod}}\H{10000}$;\6
\&{end};\2\6
$\#(\|x\mathbin{\&{div}}\H{100})$;\5
$\|x\K\|x\mathbin{\&{mod}}\H{100}$;\6
\&{end};\2\6
$\#(\|x)$\par
\P\F \37$\\{begin\_signed}\S\\{begin}$\par
\Y\P\4\&{procedure}\1\  \37$\\{pckt\_signed}(\|o:\\{eight\_bits};\,\35\|x:%
\\{int\_32})$;\C{output \\{right}, \|w, \|x, \\{down}, \|y, or \|z}\2\6
\&{begin\_signed} \37;\5
$\\{pckt\_room}(5)$;\5
$\\{comp\_signed}(\\{append\_byte})$;\6
\&{end};\par
\fi

\M60. The \\{hex\_packet} procedure prints the contents of a packet in
hexadecimal form.

\Y\P$\4\X48:Basic printing procedures\X\mathrel{+}\S$\6
\&{debug} \37\&{procedure}\1\  \37$\\{hex\_packet}(\|p:\\{pckt\_pointer})$;%
\C{prints a packet in hex}\6
\4\&{var} \37$\|j,\39\|k,\39\|l$: \37\\{byte\_pointer};\C{indices into \\{byte%
\_mem}}\6
\|d: \37\\{int\_8u};\2\6
\&{begin} \37$\|j\K\\{pckt\_start}[\|p]-1$;\5
$\|k\K\\{pckt\_start}[\|p+1]-1$;\5
$\\{print\_ln}(\.{\'\ packet=\'},\39\|p:1,\39\.{\'\ start=\'},\39\|j+1:1,\39\.{%
\'\ length=\'},\39\|k-\|j:1)$;\6
\&{for} $\|l\K\|j+1\mathrel{\&{to}}\|k$ \1\&{do}\6
\&{begin} \37$\|d\K(\\{bo}(\\{byte\_mem}[\|l]))\mathbin{\&{div}}16$;\6
\&{if} $\|d<10$ \1\&{then}\5
$\\{print}(\\{xchr}[\|d+\.{"0"}])$\ \&{else} $\\{print}(\\{xchr}[\|d-10+%
\.{"A"}])$;\2\6
$\|d\K(\\{bo}(\\{byte\_mem}[\|l]))\mathbin{\&{mod}}16$;\6
\&{if} $\|d<10$ \1\&{then}\5
$\\{print}(\\{xchr}[\|d+\.{"0"}])$\ \&{else} $\\{print}(\\{xchr}[\|d-10+%
\.{"A"}])$;\2\6
\&{if} $(\|l=\|k)\V(((\|l-\|j)\mathbin{\&{mod}}16)=0)$ \1\&{then}\5
\\{new\_line}\6
\4\&{else} \&{if} $((\|l-\|j)\mathbin{\&{mod}}4)=0$ \1\&{then}\5
$\\{print}(\.{\'\ \ \'})$\6
\4\&{else} $\\{print}(\.{\'\ \'})$;\2\2\6
\&{end};\2\6
\&{end};\6
\&{gubed}\par
\fi

\N61.  File names.
The structure of file names is different for different systems; therefore
this part of the program will, in most cases, require system dependent
modifications. Here we assume that a file name consists of three parts:
an area or directory specifying where the file can be found, a name
proper and an extension; \.{\title} assumes that these three parts appear
in order stated above but this need not be true in all cases.

The font names extracted from \.{DVI} and \.{VF} files consist of an area
part and a name proper; these are stored as packets consisting of the
length of the area part followed by the area and the name proper.
When we print an external font name we simple print the area and the name
contained in the `file name packet' without delimiter between them.
This may need to be modified for some systems.

\Y\P$\4\X48:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_font}(\|f:\\{font\_number})$;\6
\4\&{var} \37\|p: \37\\{pckt\_pointer};\C{the font name packet}\6
\|k: \37\\{byte\_pointer};\C{index into \\{byte\_mem}}\6
\|m: \37\\{int\_31};\C{font magnification}\2\6
\&{begin} \37$\\{print}(\.{\'\ =\ \'})$;\5
$\|p\K\\{font\_name}(\|f)$;\6
\&{for} $\|k\K\\{pckt\_start}[\|p]+1\mathrel{\&{to}}\\{pckt\_start}[\|p+1]-1$ %
\1\&{do}\5
$\\{print}(\\{xchr}[\\{bo}(\\{byte\_mem}[\|k])])$;\2\6
$\|m\K\\{round}((\\{font\_scaled}(\|f)/\\{font\_design}(\|f))\ast\\{out%
\_mag})$;\6
\&{if} $\|m\I1000$ \1\&{then}\5
$\\{print}(\.{\'\ scaled\ \'},\39\|m:1)$;\2\6
\&{end};\par
\fi

\M62. Before a font file can be opened for input we must build a string
with its external name.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\_name}: \37\&{packed} \37\&{array} $[1\to\\{name\_length}]$ \1\&{of}\5
\\{char};\C{external name,   with no lower case letters}\2\6
\4\\{cur\_name\_length}: \37\\{int\_15};\C{this many characters are actually
relevant in   \\{cur\_name}}\par
\fi

\M63. For \.{TFM} and \.{VF} files we just append the apropriate extension
to the file name packet; in addition a system dependent area part
(usually different for \.{TFM} and \.{VF} files) is prepended if
the file name packet contains no area part.

\Y\P\D \37$\\{append\_to\_name}(\#)\S$\1\6
\&{if} $\\{cur\_name\_length}<\\{name\_length}$ \1\&{then}\6
\&{begin} \37$\\{incr}(\\{cur\_name\_length})$;\5
$\\{cur\_name}[\\{cur\_name\_length}]\K\#$;\6
\&{end}\6
\4\&{else} $\\{overflow}(\\{str\_name\_length},\39\\{name\_length})$\2\2\par
\P\D \37$\\{make\_font\_name\_end}(\#)\S\\{append\_to\_name}(\#[\|l])$;\5
\\{make\_name}\par
\P\D \37$\\{make\_font\_name}(\#)\S\\{cur\_name\_length}\K0$;\6
\&{for} $\|l\K1\mathrel{\&{to}}\#$ \1\&{do}\5
\\{make\_font\_name\_end}\2\par
\fi

\M64. For files with character raster data (e.g., \.{GF} or \.{PK} files) the
the extension and\slash or area part will in most cases depend on the
resolution of the output device (corrected for font magnification).
If the special character \\{res\_char} occurs in the extension and\slash or
default area, a character string representing the device resolution will
be substituted.

\Y\P\D \37$\\{res\_char}\S\.{\'?\'}$\C{character to be replaced by font
resolution}\par
\P\D \37$\\{res\_ASCII}=\.{"?"}$\C{$\\{xord}[\\{res\_char}]$}\Y\par
\P\D \37$\\{append\_res\_to\_name}(\#)\S$\1\6
\&{begin} \37$\|c\K\#$;\6
\&{device} \37\&{if} $\|c=\\{res\_char}$ \1\&{then}\6
\&{for} $\\{ll}\K\\{n\_res\_digits}\mathrel{\&{downto}}1$ \1\&{do}\5
$\\{append\_to\_name}(\\{res\_digits}[\\{ll}])$\2\6
\4\&{else} \2\6
\&{ecived}\6
$\\{append\_to\_name}(\|c)$;\6
\&{end}\2\par
\P\D \37$\\{make\_font\_res\_end}(\#)\S\\{append\_res\_to\_name}(\#[\|l])$;\5
\\{make\_name}\par
\P\D \37$\\{make\_font\_res}(\#)\S\\{make\_res}$;\5
$\\{cur\_name\_length}\K0$;\6
\&{for} $\|l\K1\mathrel{\&{to}}\#$ \1\&{do}\5
\\{make\_font\_res\_end}\2\par
\fi

\M65. \P$\X17:Globals in the outer block\X\mathrel{+}\S$\6
\&{device} \37\\{f\_res}: \37\\{int\_16u};\C{font resolution}\6
\4\\{res\_digits}: \37\&{array} $[1\to5]$ \1\&{of}\5
\\{char};\2\6
\4\\{n\_res\_digits}: \37\\{int\_7};\C{number of significant characters in %
\\{res\_digits}}\6
\&{ecived}\par
\fi

\M66. The \\{make\_res} procedure creates a sequence of characters representing
to the font resolution \\{f\_res}.

\Y\P\&{device} \37\&{procedure}\1\  \37\\{make\_res};\6
\4\&{var} \37\|r: \37\\{int\_16u};\2\6
\&{begin} \37$\\{n\_res\_digits}\K0$;\5
$\|r\K\\{f\_res}$;\6
\1\&{repeat} \37$\\{incr}(\\{n\_res\_digits})$;\5
$\\{res\_digits}[\\{n\_res\_digits}]\K\\{xchr}[\.{"0"}+(\|r\mathbin{%
\&{mod}}10)]$;\5
$\|r\K\|r\mathbin{\&{div}}10$;\6
\4\&{until}\5
$\|r=0$;\2\6
\&{end};\6
\&{ecived}\par
\fi

\M67. The \\{make\_name} procedure used to build the external file name. The
global variable \\{cur\_name\_length} contains the length of a default area
which has been copied to \\{cur\_name} before \\{make\_name} is called.

\Y\P\4\&{procedure}\1\  \37$\\{make\_name}(\|e:\\{pckt\_pointer})$;\6
\4\&{var} \37\|b: \37\\{eight\_bits};\C{a byte extracted from \\{byte\_mem}}\6
\|n: \37\\{pckt\_pointer};\C{file name packet}\6
$\\{cur\_loc},\39\\{cur\_limit}$: \37\\{byte\_pointer};\C{indices into \\{byte%
\_mem}}\2\6
\&{device} \37\\{ll}: \37\\{int\_15};\C{loop index}\6
\&{ecived}\6
\4\|c: \37\\{char};\C{a character to be appended to \\{cur\_name}}\6
\&{begin} \37$\|n\K\\{font\_name}(\\{cur\_fnt})$;\5
$\\{cur\_loc}\K\\{pckt\_start}[\|n]$;\5
$\\{cur\_limit}\K\\{pckt\_start}[\|n+1]$;\5
$\\{pckt\_extract}(\|b)$;\C{length of area part}\6
\&{if} $\|b>0$ \1\&{then}\5
$\\{cur\_name\_length}\K0$;\2\6
\&{while} $\\{cur\_loc}<\\{cur\_limit}$ \1\&{do}\6
\&{begin} \37$\\{pckt\_extract}(\|b)$;\6
\&{if} $(\|b\G\.{"a"})\W(\|b\L\.{"z"})$ \1\&{then}\5
$\\{Decr}(\|b)(\.{"a"}-\.{"A"})$;\C{convert to upper case}\2\6
$\\{append\_to\_name}(\\{xchr}[\|b])$;\6
\&{end};\2\6
$\\{cur\_loc}\K\\{pckt\_start}[\|e]$;\5
$\\{cur\_limit}\K\\{pckt\_start}[\|e+1]$;\6
\&{while} $\\{cur\_loc}<\\{cur\_limit}$ \1\&{do}\6
\&{begin} \37$\\{pckt\_extract}(\|b)$;\5
$\\{append\_res\_to\_name}(\\{xchr}[\|b])$;\6
\&{end};\2\6
\&{while} $\\{cur\_name\_length}<\\{name\_length}$ \1\&{do}\6
\&{begin} \37$\\{incr}(\\{cur\_name\_length})$;\5
$\\{cur\_name}[\\{cur\_name\_length}]\K\.{\'\ \'}$;\6
\&{end};\2\6
\&{end};\par
\fi

\N68.  Defining fonts.
A detailed description of the \.{TFM} file format can be found in the
documentation of \TeX, \MF, or \.{TFtoPL}.

\fi

\M69. \.{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 \.{\title} 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 \.{VF} files
or in \.{GF} and \.{PK} 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. For \.{VF} reading
programs there is, however, a problem: (1)~when reading the character
packets from a \.{VF} file the \.{TFM} width for its local fonts should
be known in order to analyze and optimize the packets (e.g., determine
if a packet must indeed be enclosed with \\{push} and \\{pop} as implied by
the \.{VF} format); and (2)~ in order to avoid infinite recursion such
programs must not try to read a \.{VF} file for a font before a
character from that font is actually used. Thus \.{\title} reads the
\.{TFM} file whenever a new font is encountered and delays the decision
whether this is a virtual font or not.

\fi

\M70. First of all we need to know for each font~\|f such things as its
external name, design and scaled size, and the approximate size of
inter-word spaces. In addition we need to know the range $\\{bc}\to\\{ec}$ of
valid characters for this font, and for each character~\|c in~\|f  we
need to know if this character exists and if so what is the width of~\|c.
Depending on the font type of~\|f we may want to know a few other things
about character~\|c in~\|f such as the character packet from a \.{VF}
file or the raster data from a \.{PK} file.

In \.{\title} we want to be able to handle the full range
$\hbox{$-2^{31}$}\L\|c<\hbox{$2^{31}$}$ of character codes; each character code
is decomposed into a character residue $0\L\\{res}<256$ and character
extension $\hbox{$-2^{23}$}\L\\{ext}<\hbox{$2^{23}$}$ such that $\|c=256\ast%
\\{ext}+\\{res}$.
At present \.{VFtoVP}, \.{VPtoVF}, and the standard version of \TeX\ use
only characters in the range $0\L\|c<256$ (i.e., $\\{ext}=0$), there are,
however, extensions of \TeX\ which use characters with $\\{ext}\I0$.
In any case characters with $\\{ext}\I0$ will be used rather infrequently
and we want to handle this possibility without too much overhead.

Some of the data for each character~\|c depend only on its residue:
first of all its width and escapement; others, such as \.{VF} packets or
raster data will also depend on its extension. The later will be stored
as packets in \\{byte\_mem}, and the packets for characters with the same
residue but different extension will be chained.

Thus we have to maintain several variables for each character
residue~$\\{bc}\L\\{res}\L\\{ec}$ from each font~\|f; we store each type of
variable
in a large array such that the array index $\\{font\_chars}(\|f)+\\{res}$
points to
the value for characters with residue \\{res} from font~\|f.

\fi

\M71. Quite often a particular width value is shared by several characters in
a font or even by characters from different fonts; the later will
probably occur in particular for virtual fonts and the local fonts used
by them. Thus the array \\{widths} is used to store all different \.{TFM}
width values of all legal characters in all fonts; a variable of type
\\{width\_pointer} is an index into \\{widths} or is zero if a characters does
not exist. If the output is for a real typesetting device the \\{pix\_widths}
array contains the same width values converted to (horizontal) pixels.

In order to locate a given width value we use again a hash
table with simple chaining; this time the heads of the individual lists
appear in the \\{w\_hash} array and the lists proceed through \\{w\_link}
pointers.

\Y\P\D \37$\\{min\_pix\_value}\S-\H{8000}$\C{smallest allowed pixel value}\par
\P\D \37$\\{max\_pix\_value}\S\H{7FFF}$\C{largest allowed pixel value; this
range may not   suffice for high resolution output devices}\par
\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{width\_pointer}=0\to\\{max\_widths}$;\C{an index into \\{widths}}\6
\&{device} \37$\\{pix\_value}=\\{min\_pix\_value}\to\\{max\_pix\_value}$;\C{a
pixel coordinate or displacement}\6
\&{ecived}\par
\fi

\M72. \P$\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{widths}: \37\&{array} $[\\{width\_pointer}]$ \1\&{of}\5
\\{int\_32};\C{the different width values}\2\6
\&{device} \37\\{pix\_widths}: \37\&{array} $[\\{width\_pointer}]$ \1\&{of}\5
\\{pix\_value};\C{the widths in pixels}\2\6
\&{ecived}\6
\4\\{w\_link}: \37\&{array} $[\\{width\_pointer}]$ \1\&{of}\5
\\{width\_pointer};\C{hash table}\2\6
\4\\{w\_hash}: \37\&{array} $[\\{hash\_code}]$ \1\&{of}\5
\\{width\_pointer};\2\6
\4\\{n\_widths}: \37\\{width\_pointer};\C{first unoccupied position in %
\\{widths}}\par
\fi

\M73. Initially the \\{widths} array and all the hash lists are empty, except
for one entry: the width value zero; in addition we set $\\{widths}[0]\K0$.

\Y\P\D \37$\\{invalid\_width}=0$\C{width pointer for invalid characters}\par
\P\D \37$\\{zero\_width}=1$\C{a width pointer to the value zero}\par
\Y\P$\4\X18:Set initial values\X\mathrel{+}\S$\6
$\\{w\_hash}[0]\K1$;\5
$\\{w\_link}[1]\K0$;\5
$\\{widths}[0]\K0$;\5
$\\{widths}[1]\K0$;\5
$\\{n\_widths}\K2$;\6
\&{device} \37$\\{pix\_widths}[0]\K0$;\5
$\\{pix\_widths}[1]\K0$;\ \&{ecived}\6
\&{for} $\|h\K1\mathrel{\&{to}}\\{hash\_size}-1$ \1\&{do}\5
$\\{w\_hash}[\|h]\K0$;\2\par
\fi

\M74. The \\{make\_width} function returns an index into \\{widths} and, if
necessary, adds a new width value; thus two characters will have the
same \\{width\_pointer} if and only if their widths agree.

\Y\P\D \37$\\{h\_pixel\_round}(\#)\S\\{round}(\\{h\_conv}\ast(\#))$\par
\P\D \37$\\{v\_pixel\_round}(\#)\S\\{round}(\\{v\_conv}\ast(\#))$\par
\Y\P\4\&{function}\1\  \37$\\{make\_width}(\|w:\\{int\_32})$: \37\\{width%
\_pointer};\6
\4\&{label} \37\\{found};\6
\4\&{var} \37\|h: \37\\{hash\_code};\C{hash code}\6
\|p: \37\\{width\_pointer};\C{where the identifier is being sought}\6
\|x: \37\\{int\_16};\C{intermediate value}\2\6
\&{begin} \37$\\{widths}[\\{n\_widths}]\K\|w$;\5
\X75:Compute the width hash code \|h\X;\6
\X76:Compute the width location \|p, \&{goto}  found unless the value is new\X;%
\6
\&{if} $\\{n\_widths}=\\{max\_widths}$ \1\&{then}\5
$\\{overflow}(\\{str\_widths},\39\\{max\_widths})$;\2\6
$\\{incr}(\\{n\_widths})$;\6
\&{device} \37$\\{pix\_widths}[\|p]\K\\{h\_pixel\_round}(\|w)$;\ \&{ecived}\6
\4\\{found}: \37$\\{make\_width}\K\|p$;\6
\&{end};\par
\fi

\M75. A simple hash code is used: If the width value consists of the four
bytes $b_0b_1b_2b_3$, its hash value will be
$$(8*b_0+4*b_1+2*b_2+b_3)\,\bmod\,\\{hash\_size}.$$

\Y\P$\4\X75:Compute the width hash code \|h\X\S$\6
\&{if} $\|w\G0$ \1\&{then}\5
$\|x\K\|w\mathbin{\&{div}}\H{1000000}$\6
\4\&{else} \&{begin} \37$\|w\K\|w+\H{40000000}$;\5
$\|w\K\|w+\H{40000000}$;\5
$\|x\K(\|w\mathbin{\&{div}}\H{1000000})+\H{80}$;\6
\&{end};\2\6
$\|w\K\|w\mathbin{\&{mod}}\H{1000000}$;\5
$\|x\K\|x+\|x+(\|w\mathbin{\&{div}}\H{10000})$;\5
$\|w\K\|w\mathbin{\&{mod}}\H{10000}$;\5
$\|x\K\|x+\|x+(\|w\mathbin{\&{div}}\H{100})$;\5
$\|h\K(\|x+\|x+(\|w\mathbin{\&{mod}}\H{100}))\mathbin{\&{mod}}\\{hash\_size}$%
\par
\U74.\fi

\M76. If the width is new, it has been placed into position $\|p=\\{n%
\_widths}$,
otherwise \|p will point to its existing location.

\Y\P$\4\X76:Compute the width location \|p, \&{goto}  found unless the value is
new\X\S$\6
$\|p\K\\{w\_hash}[\|h]$;\6
\&{while} $\|p\I0$ \1\&{do}\6
\&{begin} \37\&{if} $\\{widths}[\|p]=\\{widths}[\\{n\_widths}]$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
$\|p\K\\{w\_link}[\|p]$;\6
\&{end};\2\6
$\|p\K\\{n\_widths}$;\C{the current width is new}\6
$\\{w\_link}[\|p]\K\\{w\_hash}[\|h]$;\5
$\\{w\_hash}[\|h]\K\|p$\C{insert \|p at beginning of hash list}\par
\U74.\fi

\M77. The \\{char\_widths} array is used to store the \\{width\_pointer}s for
all
different characters among all fonts. For a real typesetting device the
\\{char\_pixels} array is used to store the horizontal character escapements:
Initially we use the \\{pix\_widths} values, but these will be replaced by
the character escapements specified in a \.{PK} or \.{GF} file;
these values may differ by a small amount.

The \\{char\_packets} array is used to store the \\{pckt\_pointer}s for all
different characters among all fonts; they can point to character
packets from \.{VF} files or, e.g., raster packets from \.{PK} files.

\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{char\_offset}=-255\to\\{max\_chars}$;\C{\\{char\_pointer} offset for a
font}\6
$\\{char\_pointer}=0\to\\{max\_chars}$;\C{index into \\{char\_widths} or
similar arrays}\par
\fi

\M78. \P$\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{char\_widths}: \37\&{array} $[\\{char\_pointer}]$ \1\&{of}\5
\\{width\_pointer};\C{width pointers}\2\6
\&{device} \37\\{char\_pixels}: \37\&{array} $[\\{char\_pointer}]$ \1\&{of}\5
\\{pix\_value};\C{character escapements}\2\6
\&{ecived}\6
\4\\{char\_packets}: \37\&{array} $[\\{char\_pointer}]$ \1\&{of}\5
\\{pckt\_pointer};\C{packet pointers}\2\6
\4\\{n\_chars}: \37\\{char\_pointer};\C{first unused position in \\{char%
\_widths}}\par
\fi

\M79. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{n\_chars}\K0$;\par
\fi

\M80. The current number of known fonts is \\{nf}; each known font has an
internal number \|f, where $0\L\|f<\\{nf}$. For the moment we need for each
known font: \\{font\_check}, \\{font\_scaled}, \\{font\_design}, \\{font%
\_space},
\\{font\_name}, \\{font\_bc}, \\{font\_ec}, \\{font\_chars}, and \\{font%
\_type}.
Here \\{font\_scaled}, \\{font\_design}, and \\{font\_space} are measured in
\.{DVI} units and \\{font\_chars} is of type \\{char\_offset}:
the width pointer for character~\|c of the font is stored in
$\\{char\_widths}[\\{char\_offset}+\|c]$ (for $\\{font\_bc}\L\|c\L\\{font%
\_ec}$).
Lateron we will need additional information depending on the font type:
\.{VF} or real (\.{GF}, \.{PK}, or \.{PXL}).

\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{f\_type}=\\{new\_font\_type}\to\\{max\_font\_type}$;\C{type of a font}\6
$\\{font\_number}=0\to\\{max\_fonts}$;\par
\fi

\M81. \P$\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{nf}: \37\\{font\_number};\par
\fi

\M82. These data are stored in several arrays and we use \.{WEB} macros
to access the various fields. Thus it would be simple to store the
data in an array of record structures and adapt the \.{WEB} macros
accordingly.

We will say, e.g., $\\{font\_name}(\|f)$ for the name field of font~\|f, and
$\\{font\_width}(\|f)(\|c)$ for the width pointer of character~\|c in font~\|f
and $\\{font\_packet}(\|f)(\|c)$ for its character packet (this character
exists provided $\\{font\_bc}(\|f)\L\|c\L\\{font\_ec}(\|f)$ and
$\\{font\_width}(\|f)(\|c)\I\\{invalid\_width}$). The actual width of
character~\|c in
font~\|f is stored in $\\{widths}[\\{font\_width}(\|f)(\|c)]$; the horizontal
escapement is given by $\\{font\_pixel}(\|f)(\|c)$.

\Y\P\D \37$\\{font\_check}(\#)\S\\{fnt\_check}[\#]$\C{checksum}\par
\P\D \37$\\{font\_scaled}(\#)\S\\{fnt\_scaled}[\#]$\C{scaled or `at' size}\par
\P\D \37$\\{font\_design}(\#)\S\\{fnt\_design}[\#]$\C{design size}\par
\P\D \37$\\{font\_space}(\#)\S\\{fnt\_space}[\#]$\C{boundary between ``small''
and ``large''   spaces}\par
\P\D \37$\\{font\_name}(\#)\S\\{fnt\_name}[\#]$\C{area plus name packet}\par
\P\D \37$\\{font\_bc}(\#)\S\\{fnt\_bc}[\#]$\C{first character}\par
\P\D \37$\\{font\_ec}(\#)\S\\{fnt\_ec}[\#]$\C{last character}\par
\P\D \37$\\{font\_chars}(\#)\S\\{fnt\_chars}[\#]$\C{character info offset}\par
\P\D \37$\\{font\_type}(\#)\S\\{fnt\_type}[\#]$\C{type of this font}\par
\P\D \37$\\{font\_font}(\#)\S\\{fnt\_font}[\#]$\C{use depends on \\{font%
\_type}}\Y\par
\P\D \37$\\{font\_width\_end}(\#)\S\#$ ] \par
\P\D $\\{font\_width}(\#)\S\\{char\_widths}$ [ $\\{font\_chars}(\#)+\\{font%
\_width\_end}$\par
\P\D $\\{font\_pixel}(\#)\S\\{char\_pixels}$ [ $\\{font\_chars}(\#)+\\{font%
\_width\_end}$\par
\P\D $\\{font\_packet}(\#)\S\\{char\_packets}$ [ $\\{font\_chars}(\#)+\\{font%
\_width\_end}$\par
\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{fnt\_check}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{int\_32};\C{checksum}\2\6
\4\\{fnt\_scaled}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{int\_31};\C{scaled size}\2\6
\4\\{fnt\_design}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{int\_31};\C{design size}\2\6
\&{device} \37\\{fnt\_space}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{int\_32};\C{boundary between ``small''   and ``large'' spaces}\2\6
\&{ecived}\6
\4\\{fnt\_name}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{pckt\_pointer};\C{pointer to area plus   name packet}\2\6
\4\\{fnt\_bc}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{eight\_bits};\C{first character}\2\6
\4\\{fnt\_ec}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{eight\_bits};\C{last character}\2\6
\4\\{fnt\_chars}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{char\_offset};\C{character info offset}\2\6
\4\\{fnt\_type}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{f\_type};\C{type of font}\2\6
\4\\{fnt\_font}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{font\_number};\C{use depends on \\{font\_type}}\2\par
\fi

\M83. \P\D \37$\\{invalid\_font}\S\\{max\_fonts}$\C{used when there is no valid
font}\par
\Y\P$\4\X18:Set initial values\X\mathrel{+}\S$\6
\&{device} \37$\\{font\_space}(\\{invalid\_font})\K0$;\ \&{ecived}\6
$\\{nf}\K0$;\par
\fi

\M84. A \.{VF}, or \.{GF}, or \.{PK} file may contain information for
several characters with the same residue but with different extension;
all except the first of the corresponding packets in \\{byte\_mem} will
contain a pointer to the previous one and $\\{font\_packet}(\|f)(\\{res})$
identifies the last such packet.

A character packet in \\{byte\_mem} starts with a flag byte
$$\hbox{$\\{flag}=\H{40}\ast\\{ext\_flag}+\H{20}\ast\\{chain\_flag}+\\{type%
\_flag}$}$$
with $0\L\\{ext\_flag}\L3$, $0\L\\{chain\_flag}\L1$, $0\L\\{type\_flag}\L%
\H{1F}$,
followed by \\{ext\_flag} bytes with the character extension for this
packet and, if $\\{chain\_flag}=1$, by a two byte packet pointer to the
previous packet for the same font and character residue. The actual
character packet follows after these header bytes and the
interpretation of the \\{type\_flag} depends on whether this is a \.{VF}
packet or a packet for raster data.

The empty packet is interpreted as a special case of a packet with
$\\{flag}=0$.

\Y\P\D \37$\\{ext\_flag}=\H{40}$\par
\P\D \37$\\{chain\_flag}=\H{20}$\par
\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{type\_flag}=0\to\\{chain\_flag}-1$;\C{the range of values for the \\{type%
\_flag}}\par
\fi

\M85. The global variable \\{cur\_fnt} is the internal font number of the
currently selected font, or equals \\{invalid\_font} if no font has
been selected; \\{cur\_res} and \\{cur\_ext} are the residue and extension
part of the current character code. The type of a character packet
located by the \\{find\_packet} function defined below is \\{cur\_type}.
While building a character packet for a character, \\{pckt\_ext} and
\\{pckt\_res} are the extension and residue of this character; \\{pckt\_dup}
indicates whether a packet for this extension exists already.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\_fnt}: \37\\{font\_number};\C{the currently selected font}\6
\4\\{cur\_ext}: \37\\{int\_24};\C{the current character extension}\6
\4\\{cur\_res}: \37\\{int\_8u};\C{the current character residue}\6
\4\\{cur\_type}: \37\\{type\_flag};\C{type of the current character packet}\6
\4\\{pckt\_ext}: \37\\{int\_24};\C{character extension for the current
character packet}\6
\4\\{pckt\_res}: \37\\{int\_8u};\C{character residue for the current character
packet}\6
\4\\{pckt\_dup}: \37\\{boolean};\C{is there a previous packet for the same
extension?}\6
\4\\{pckt\_prev}: \37\\{pckt\_pointer};\C{a previous packet for the same
extension}\6
\4$\\{pckt\_m\_msg},\39\\{pckt\_s\_msg},\39\\{pckt\_d\_msg}$: \37\\{int\_7};%
\C{counts for various character   packet error messages}\par
\fi

\M86. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{cur\_fnt}\K\\{invalid\_font}$;\5
$\\{pckt\_m\_msg}\K0$;\5
$\\{pckt\_s\_msg}\K0$;\5
$\\{pckt\_d\_msg}\K0$;\par
\fi

\M87. The \\{find\_packet} functions is used to locate the character packet for
the character with residue~\\{cur\_res} and extension~\\{cur\_ext} from
font~\\{cur\_fnt} and returns \\{false} if no packet exists for any extension;
otherwise the result is \\{true} and the global variables \\{cur\_packet},
\\{cur\_type}, \\{cur\_loc}, and \\{cur\_limit} are initialized. In case none
of
the character packets has the correct extension, the last one in the
chain (the one defined first) is used instead and \\{cur\_ext} is changed
accordingly.

\Y\P\4\&{function}\1\  \37\\{find\_packet}: \37\\{boolean};\6
\4\&{label} \37$\\{found},\39\\{exit}$;\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pckt\_pointer};\C{current and next packet}\6
\|f: \37\\{eight\_bits};\C{a flag byte}\6
\|e: \37\\{int\_24};\C{extension for a packet}\2\6
\&{begin} \37\X88:Locate a character packet and \&{goto} \\{found} if found\X;\6
\&{if} $\\{font\_packet}(\\{cur\_fnt})(\\{cur\_res})=\\{invalid\_packet}$ \1%
\&{then}\6
\&{begin} \37\&{if} $\\{pckt\_m\_msg}<10$ \1\&{then}\C{stop telling after first
10 times}\6
\&{begin} \37$\\{print\_ln}(\.{\'---missing\ character\ packet\ for\ character\
\'},\39\\{cur\_res}:1,\39\.{\'\ font\ \'},\39\\{cur\_fnt}:1)$;\5
$\\{incr}(\\{pckt\_m\_msg})$;\5
\\{mark\_error};\6
\&{if} $\\{pckt\_m\_msg}=10$ \1\&{then}\5
$\\{print\_ln}(\.{\'---further\ messages\ suppressed.\'})$;\2\6
\&{end};\2\6
$\\{find\_packet}\K\\{false}$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\\{pckt\_s\_msg}<10$ \1\&{then}\C{stop telling after first 10 times}\6
\&{begin} \37$\\{print\_ln}(\.{\'---substituted\ character\ packet\ with\
extension\ \'},\39\|e:1,\39\.{\'\ instead\ of\ \'},\39\\{cur\_ext}:1,\39\.{\'\
for\ character\ \'},\39\\{cur\_res}:1,\39\.{\'\ font\ \'},\39\\{cur\_fnt}:1)$;\5
$\\{incr}(\\{pckt\_s\_msg})$;\5
\\{mark\_error};\6
\&{if} $\\{pckt\_s\_msg}=10$ \1\&{then}\5
$\\{print\_ln}(\.{\'---further\ messages\ suppressed.\'})$;\2\6
\&{end};\2\6
$\\{cur\_ext}\K\|e$;\6
\4\\{found}: \37$\\{cur\_pckt}\K\|p$;\5
$\\{cur\_type}\K\|f$;\5
$\\{find\_packet}\K\\{true}$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M88. \P$\X88:Locate a character packet and \&{goto} \\{found} if found\X\S$\6
$\|q\K\\{font\_packet}(\\{cur\_fnt})(\\{cur\_res})$;\6
\&{while} $\|q\I\\{invalid\_packet}$ \1\&{do}\6
\&{begin} \37$\|p\K\|q$;\5
$\|q\K\\{invalid\_packet}$;\5
$\\{cur\_loc}\K\\{pckt\_start}[\|p]$;\5
$\\{cur\_limit}\K\\{pckt\_start}[\|p+1]$;\6
\&{if} $\|p=\\{empty\_packet}$ \1\&{then}\6
\&{begin} \37$\|e\K0$;\5
$\|f\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{pckt\_extract}(\|f)$;\6
\&{case} $(\|f\mathbin{\&{div}}\\{ext\_flag})$ \1\&{of}\6
\40: \37$\|e\K0$;\6
\41: \37$\|e\K\\{pckt\_ubyte}$;\6
\42: \37$\|e\K\\{pckt\_upair}$;\6
\43: \37$\|e\K\\{pckt\_strio}$;\2\6
\&{end};\C{there are no other cases}\6
\&{if} $(\|f\mathbin{\&{mod}}\\{ext\_flag})\G\\{chain\_flag}$ \1\&{then}\5
$\|q\K\\{pckt\_upair}$;\2\6
$\|f\K\|f\mathbin{\&{mod}}\\{chain\_flag}$;\6
\&{end};\2\6
\&{if} $\|e=\\{cur\_ext}$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
\&{end}\2\par
\Us87\ET89.\fi

\M89. The \\{start\_packet} procedure is used to create the header bytes of a
character packet for the character with residue~\\{cur\_res} and
extension~\\{cur\_ext} from font~\\{cur\_fnt}; if a previous such a packet
exists, we try to build an exact duplicate, i.e., use the chain field of
that previous packet.

\Y\P\4\&{procedure}\1\  \37$\\{start\_packet}(\|t:\\{type\_flag})$;\6
\4\&{label} \37$\\{found},\39\\{not\_found}$;\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pckt\_pointer};\C{current and next packet}\6
\|f: \37\\{int\_8u};\C{a flag byte}\6
\|e: \37\\{int\_32};\C{extension for a packet}\6
\\{cur\_loc}: \37\\{byte\_pointer};\C{current location in a packet}\6
\\{cur\_limit}: \37\\{byte\_pointer};\C{start of next packet}\2\6
\&{begin} \37\X88:Locate a character packet and \&{goto} \\{found} if found\X;\6
$\|q\K\\{font\_packet}(\\{cur\_fnt})(\\{cur\_res})$;\5
$\\{pckt\_dup}\K\\{false}$;\5
\&{goto} \37\\{not\_found};\6
\4\\{found}: \37$\\{pckt\_dup}\K\\{true}$;\5
$\\{pckt\_prev}\K\|p$;\6
\4\\{not\_found}: \37$\\{pckt\_ext}\K\\{cur\_ext}$;\5
$\\{pckt\_res}\K\\{cur\_res}$;\5
$\\{pckt\_room}(6)$;\6
\&{debug} \37\&{if} $\\{byte\_ptr}\I\\{pckt\_start}[\\{pckt\_ptr}]$ \1\&{then}\5
$\\{confusion}(\\{str\_packets})$;\2\6
\&{gubed}\6
\&{if} $\|q=\\{invalid\_packet}$ \1\&{then}\5
$\|f\K\|t$\ \&{else} $\|f\K\|t+\\{chain\_flag}$;\2\6
$\|e\K\\{cur\_ext}$;\6
\&{if} $\|e<0$ \1\&{then}\5
$\\{Incr}(\|e)(\H{1000000})$;\2\6
\&{if} $\|e=0$ \1\&{then}\5
$\\{append\_byte}(\|f)$\ \&{else} \2\6
\&{begin} \37\&{if} $\|e<\H{100}$ \1\&{then}\5
$\\{append\_byte}(\|f+\\{ext\_flag})$\ \&{else} \2\6
\&{begin} \37\&{if} $\|e<\H{10000}$ \1\&{then}\5
$\\{append\_byte}(\|f+\\{ext\_flag}+\\{ext\_flag})$\ \&{else} \2\6
\&{begin} \37$\\{append\_byte}(\|f+\\{ext\_flag}+\\{ext\_flag}+\\{ext\_flag})$;%
\5
$\\{append\_byte}(\|e\mathbin{\&{div}}\H{10000})$;\5
$\|e\K\|e\mathbin{\&{mod}}\H{10000}$;\6
\&{end};\5
$\\{append\_byte}(\|e\mathbin{\&{div}}\H{100})$;\5
$\|e\K\|e\mathbin{\&{mod}}\H{100}$;\6
\&{end};\5
$\\{append\_byte}(\|e)$;\6
\&{end};\6
\&{if} $\|q\I\\{invalid\_packet}$ \1\&{then}\6
\&{begin} \37$\\{append\_byte}(\|q\mathbin{\&{div}}\H{100})$;\5
$\\{append\_byte}(\|q\mathbin{\&{mod}}\H{100})$;\6
\&{end};\2\6
\&{end};\par
\fi

\M90. The \\{build\_packet} procedure is used to finish a character packet.
If a previous packet for the same character extension exists, the new
one is discarded; if the two packets are identical, as it occasionally
occurs for raster files, this is done without an error message.

\Y\P\4\&{procedure}\1\  \37\\{build\_packet};\6
\4\&{var} \37$\|k,\39\|l$: \37\\{byte\_pointer};\C{indices into \\{byte\_mem}}%
\2\6
\&{begin} \37\&{if} $\\{pckt\_dup}$ \1\&{then}\6
\&{begin} \37$\|k\K\\{pckt\_start}[\\{pckt\_prev}+1]$;\5
$\|l\K\\{pckt\_start}[\\{pckt\_ptr}]$;\6
\&{if} $(\\{byte\_ptr}-\|l)\I(\|k-\\{pckt\_start}[\\{pckt\_prev}])$ \1\&{then}\5
$\\{pckt\_dup}\K\\{false}$;\2\6
\&{while} $\\{pckt\_dup}\W(\\{byte\_ptr}>\|l)$ \1\&{do}\6
\&{begin} \37\\{flush\_byte};\5
$\\{decr}(\|k)$;\6
\&{if} $\\{byte\_mem}[\\{byte\_ptr}]\I\\{byte\_mem}[\|k]$ \1\&{then}\5
$\\{pckt\_dup}\K\\{false}$;\2\6
\&{end};\2\6
\&{if} $(\R\\{pckt\_dup})\W(\\{pckt\_d\_msg}<10)$ \1\&{then}\C{stop telling
after first 10 times}\6
\&{begin} \37$\\{print}(\.{\'---duplicate\ packet\ for\ character\ \'},\39%
\\{pckt\_res}:1)$;\6
\&{if} $\\{pckt\_ext}\I0$ \1\&{then}\5
$\\{print}(\.{\'.\'},\39\\{pckt\_ext}:1)$;\2\6
$\\{print\_ln}(\.{\'\ font\ \'},\39\\{cur\_fnt}:1)$;\5
$\\{incr}(\\{pckt\_d\_msg})$;\5
\\{mark\_error};\6
\&{if} $\\{pckt\_d\_msg}=10$ \1\&{then}\5
$\\{print\_ln}(\.{\'---further\ messages\ suppressed.\'})$;\2\6
\&{end};\2\6
$\\{byte\_ptr}\K\|l$;\6
\&{end}\6
\4\&{else} $\\{font\_packet}(\\{cur\_fnt})(\\{pckt\_res})\K\\{make\_packet}$;\2%
\6
\&{end};\par
\fi

\M91. In order to read \.{TFM} files the program uses the binary file
variable \\{tfm\_file}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{tfm\_file}: \37\\{byte\_file};\C{a \.{TFM} file}\6
\4\\{tfm\_ext}: \37\\{pckt\_pointer};\C{extension for \.{TFM} files}\par
\fi

\M92. \P$\X45:Initialize predefined strings\X\mathrel{+}\S$\6
$\\{id4}(\.{"."})(\.{"T"})(\.{"F"})(\.{"M"})(\\{tfm\_ext})$;\C{file name
extension for \.{TFM} files}\par
\fi

\M93. If no font directory has been specified, \.{\title} is supposed to use
the default \.{TFM} directory, which is a system-dependent place where
the \.{TFM} files for standard fonts are kept.
The string variable \\{TFM\_default\_area} contains the name of this area.

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

\M94. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{TFM\_default\_area}\K\\{TFM\_default\_area\_name}$;\par
\fi

\M95. If a \.{TFM} file is badly malformed, we say \\{bad\_font}; for a \.{TFM}
file the \\{bad\_tfm} procedure is used to give an error message which
refers the user to \.{TFtoPL} and \.{PLtoTF}, and terminates \.{\title}.

\Y\P$\4\X23:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{bad\_tfm};\2\6
\&{begin} \37$\\{print}(\.{\'Bad\ TFM\ file\'})$;\5
$\\{print\_font}(\\{cur\_fnt})$;\5
$\\{print\_ln}(\.{\'!\'})$;\5
$\\{abort}(\.{\'Use\ TFtoPL/PLtoTF\ to\ diagnose\ and\ correct\ the\ problem%
\'})$;\6
\&{end};\7
\4\&{procedure}\1\  \37\\{bad\_font};\2\6
\&{begin} \37\\{new\_line};\6
\&{case} $\\{font\_type}(\\{cur\_fnt})$ \1\&{of}\6
\4\\{new\_font\_type}: \37\\{bad\_tfm};\6
\X136:Cases for \\{bad\_font}\X\2\6
\&{end};\C{there are no other cases}\6
\&{end};\par
\fi

\M96. To prepare \\{tfm\_file} for input we \\{reset} it.

\Y\P$\4\X96:TFM: Open \\{tfm\_file}\X\S$\6
$\\{make\_font\_name}(\\{TFM\_default\_area\_name\_length})(\\{TFM\_default%
\_area})(\\{tfm\_ext})$;\5
$\\{reset}(\\{tfm\_file},\39\\{cur\_name})$;\6
\&{if} $\\{eof}(\\{tfm\_file})$ \1\&{then}\5
$\\{abort}(\.{\'---not\ loaded,\ TFM\ file\ can\'}\.{\'t\ be\ opened!\'})$\2\par
\U101.\fi

\M97. 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
\\{tfm\_b0}, \\{tfm\_b1}, \\{tfm\_b2}, and \\{tfm\_b3}, with \\{tfm\_b0}
getting the
first byte and \\{tfm\_b3} the fourth.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4$\\{tfm\_b0},\39\\{tfm\_b1},\39\\{tfm\_b2},\39\\{tfm\_b3}$: \37\\{eight%
\_bits};\C{four bytes input at once}\par
\fi

\M98. Reading a \.{TFM} file should be done as efficient as possible for a
particular system; on many systems this means that a large number of
bytes from \\{tfm\_file} is read into a buffer and will then be extracted
from that buffer. In order to simplify such system dependent changes
we use the \.{WEB} macro \\{tfm\_byte} to extract the next \.{TFM} byte;
this macro and $\\{eof}(\\{tfm\_file})$ are used only in the \\{read\_tfm%
\_word}
procedure which sets \\{tfm\_b0} through \\{tfm\_b3} to the next four bytes
in the current \.{TFM} file. Here we give simple minded definitions in
terms of standard \PASCAL.

\Y\P\D \37$\\{tfm\_byte}(\#)\S\\{read}(\\{tfm\_file},\39\#)$\C{read next %
\.{TFM} byte}\par
\Y\P\4\&{procedure}\1\  \37\\{read\_tfm\_word};\2\6
\&{begin} \37$\\{tfm\_byte}(\\{tfm\_b0})$;\5
$\\{tfm\_byte}(\\{tfm\_b1})$;\5
$\\{tfm\_byte}(\\{tfm\_b2})$;\5
$\\{tfm\_byte}(\\{tfm\_b3})$;\6
\&{if} $\\{eof}(\\{tfm\_file})$ \1\&{then}\5
\\{bad\_font};\2\6
\&{end};\par
\fi

\M99. Here are three procedures used to check the consistency of font files:
First, the \\{check\_check\_sum} procedure compares two check sum values: a
warning is given if they differ and are both non-zero; if the second
value is not zero it may replace the first one.
Next, the \\{check\_design\_size} procedure compares two design size
values: a warning is given if they differ by more than a small amount.
Finally, the \\{check\_width} function compares the character width value
for character \\{cur\_res} read from a \.{VF} or raster file for font
\\{cur\_fnt} with the value previously read from the \.{TFM} file and
returns the width pointer for that value; a warning is given if the two
values differ.

\Y\P\4\&{procedure}\1\  \37$\\{check\_check\_sum}(\|c:\\{int\_32};\,\35\|u:%
\\{boolean})$;\C{compare $\\{font\_check}(\\{cur\_fnt})$ with \|c}\2\6
\&{begin} \37\&{if} $(\|c\I\\{font\_check}(\\{cur\_fnt}))\W(\|c\I0)$ \1\&{then}%
\6
\&{begin} \37\&{if} $\\{font\_check}(\\{cur\_fnt})\I0$ \1\&{then}\6
\&{begin} \37\\{new\_line};\5
$\\{print\_ln}(\.{\'---beware:\ check\ sums\ do\ not\ agree!\ \ \ (\'},\39%
\|c:1,\39\.{\'\ vs.\ \'},\39\\{font\_check}(\\{cur\_fnt}):1,\39\.{\')\'})$;\5
\\{mark\_error};\6
\&{end};\2\6
\&{if} $\|u$ \1\&{then}\5
$\\{font\_check}(\\{cur\_fnt})\K\|c$;\2\6
\&{end};\2\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{check\_design\_size}(\|d:\\{int\_32})$;\C{compare $%
\\{font\_design}(\\{cur\_fnt})$ with \|d}\2\6
\&{begin} \37\&{if} $\\{abs}(\|d-\\{font\_design}(\\{cur\_fnt}))>2$ \1\&{then}\6
\&{begin} \37\\{new\_line};\5
$\\{print\_ln}(\.{\'---beware:\ design\ sizes\ do\ not\ agree!\ \ \ (\'},\39%
\|d:1,\39\.{\'\ vs.\ \'},\39\\{font\_design}(\\{cur\_fnt}):1,\39\.{\')\'})$;\5
\\{mark\_error};\6
\&{end};\2\6
\&{end};\7
\4\&{function}\1\  \37$\\{check\_width}(\|w:\\{int\_32})$: \37\\{width%
\_pointer};\C{compare $\\{widths}[\\{font\_width}(\\{cur\_fnt})(\\{cur\_res})]$
with \|w}\6
\4\&{var} \37\\{wp}: \37\\{width\_pointer};\C{pointer to \.{TFM} width value}\2%
\6
\&{begin} \37\&{if} $(\\{cur\_res}\G\\{font\_bc}(\\{cur\_fnt}))\W(\\{cur\_res}%
\L\\{font\_ec}(\\{cur\_fnt}))$ \1\&{then}\5
$\\{wp}\K\\{font\_width}(\\{cur\_fnt})(\\{cur\_res})$\6
\4\&{else} $\\{wp}\K\\{invalid\_width}$;\2\6
\&{if} $\\{wp}=\\{invalid\_width}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{\'Bad\ char\ \'},\39\\{cur\_res}:1)$;\6
\&{if} $\\{cur\_ext}\I0$ \1\&{then}\5
$\\{print}(\.{\'.\'},\39\\{cur\_ext}:1)$;\2\6
$\\{print}(\.{\'\ font\ \'},\39\\{cur\_fnt}:1)$;\5
$\\{print\_font}(\\{cur\_fnt})$;\5
$\\{abort}(\.{\'\ (compare\ TFM\ file)\'})$;\6
\&{end};\2\6
\&{if} $\|w\I\\{widths}[\\{wp}]$ \1\&{then}\6
\&{begin} \37\\{new\_line};\5
$\\{print\_ln}(\.{\'---beware:\ char\ widths\ do\ not\ agree!\ \ \ (\'},\39%
\|w:1,\39\.{\'\ vs.\ \'},\39\\{widths}[\\{wp}]:1,\39\.{\')\'})$;\5
\\{mark\_error};\6
\&{end};\2\6
$\\{check\_width}\K\\{wp}$;\6
\&{end};\par
\fi

\M100. When processing a font definition we put the data extracted from the
\.{DVI} or \.{VF} file into the fields of $\\{font\_data}[\\{nf}]$ and call
\\{make\_font} to obtain the internal font number for this font.
The \\{make\_font} function determines if this font is already defined and,
if this is not the case, reads the \.{TFM} file.

\Y\P\4\&{function}\1\  \37\\{make\_font}: \37\\{font\_number};\6
\4\&{var} \37\|l: \37\\{int\_16};\C{loop index}\6
\|p: \37\\{char\_pointer};\C{index into \\{char\_widths}}\6
\|q: \37\\{width\_pointer};\C{index into \\{widths}}\6
$\\{bc},\39\\{ec}$: \37\\{int\_15};\C{first and last character in this font}\6
\\{lh}: \37\\{int\_15};\C{length of header in four byte words}\6
\\{nw}: \37\\{int\_15};\C{number of words in width table}\6
\|w: \37\\{int\_32};\C{a four byte integer}\6
\\{save\_fnt}: \37\\{font\_number};\C{used to save \\{cur\_fnt}}\6
\X105:Variables for scaling computation\X\2\6
\&{begin} \37$\\{save\_fnt}\K\\{cur\_fnt}$;\C{save}\6
$\\{cur\_fnt}\K0$;\6
\&{while} $(\\{font\_name}(\\{cur\_fnt})\I\\{font\_name}(\\{nf}))\V\30(\\{font%
\_scaled}(\\{cur\_fnt})\I\\{font\_scaled}(\\{nf}))$ \1\&{do}\5
$\\{incr}(\\{cur\_fnt})$;\2\6
$\\{d\_print}(\.{\'\ =>\ \'},\39\\{cur\_fnt}:1)$;\5
$\\{print\_font}(\\{cur\_fnt})$;\6
\&{if} $\\{cur\_fnt}<\\{nf}$ \1\&{then}\6
\&{begin} \37$\\{check\_check\_sum}(\\{font\_check}(\\{nf}),\39\\{true})$;\5
$\\{check\_design\_size}(\\{font\_design}(\\{nf}))$;\5
$\\{d\_print}(\.{\'\ loaded\ previously\'})$;\6
\&{end}\6
\4\&{else} \X101:Define a new font\X;\2\6
\\{new\_line};\5
$\\{make\_font}\K\\{cur\_fnt}$;\5
$\\{cur\_fnt}\K\\{save\_fnt}$;\C{restore}\6
\&{end};\par
\fi

\M101. \P$\X101:Define a new font\X\S$\6
\&{begin} \37\&{if} $\\{nf}=\\{max\_fonts}$ \1\&{then}\5
$\\{overflow}(\\{str\_fonts},\39\\{max\_fonts})$;\2\6
$\\{font\_type}(\\{cur\_fnt})\K\\{new\_font\_type}$;\5
$\\{font\_font}(\\{cur\_fnt})\K\\{invalid\_font}$;\5
\X96:TFM: Open \\{tfm\_file}\X;\6
\X103:TFM: Read past the header data\X;\6
\X104:TFM: Store character-width indices\X;\6
\X107:TFM: Read and convert the width values\X;\6
\X108:TFM: Convert character-width indices to character-width pointers\X;\6
$\\{close\_in}(\\{tfm\_file})$;\5
$\\{d\_print}(\.{\'\ loaded\ at\ \'},\39\\{font\_scaled}(\\{cur\_fnt}):1,\39\.{%
\'\ DVI\ units\'})$;\5
$\\{incr}(\\{nf})$;\6
\&{end}\par
\U100.\fi

\M102. \P$\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{tfm\_conv}: \37\\{real};\C{\.{DVI} units per absolute \.{TFM} unit}\par
\fi

\M103. We will use the following \.{WEB} macros to construct integers from
two or four of the four bytes read by \\{read\_tfm\_word}.

\Y\P\D \37$\\{tfm\_b01}(\#)\S$\C{$\\{tfm\_b0}\to\\{tfm\_b1}$ as non-negative
integer}\6
\&{if} $\\{tfm\_b0}>127$ \1\&{then}\5
\\{bad\_font}\6
\4\&{else} $\#\K\\{tfm\_b0}\ast256+\\{tfm\_b1}$\2\par
\P\D \37$\\{tfm\_b23}(\#)\S$\C{$\\{tfm\_b2}\to\\{tfm\_b3}$ as non-negative
integer}\6
\&{if} $\\{tfm\_b2}>127$ \1\&{then}\5
\\{bad\_font}\6
\4\&{else} $\#\K\\{tfm\_b2}\ast256+\\{tfm\_b3}$\2\par
\P\D \37$\\{tfm\_squad}(\#)\S$\C{$\\{tfm\_b0}\to\\{tfm\_b3}$ as signed integer}%
\6
\&{if} $\\{tfm\_b0}<128$ \1\&{then}\5
$\#\K((\\{tfm\_b0}\ast256+\\{tfm\_b1})\ast256+\\{tfm\_b2})\ast256+\\{tfm\_b3}$\6
\4\&{else} $\#\K(((\\{tfm\_b0}-256)\ast256+\\{tfm\_b1})\ast256+\\{tfm\_b2})%
\ast256+\\{tfm\_b3}$\2\par
\P\D \37$\\{tfm\_uquad}\S$\C{$\\{tfm\_b0}\to\\{tfm\_b3}$ as unsigned integer}\6
$(((\\{tfm\_b0}\ast256+\\{tfm\_b1})\ast256+\\{tfm\_b2})\ast256+\\{tfm\_b3})$\par
\Y\P$\4\X103:TFM: Read past the header data\X\S$\6
\\{read\_tfm\_word};\5
$\\{tfm\_b23}(\\{lh})$;\5
\\{read\_tfm\_word};\5
$\\{tfm\_b01}(\\{bc})$;\5
$\\{tfm\_b23}(\\{ec})$;\6
\&{if} $\\{ec}<\\{bc}$ \1\&{then}\6
\&{begin} \37$\\{bc}\K1$;\5
$\\{ec}\K0$;\6
\&{end}\6
\4\&{else} \&{if} $\\{ec}>255$ \1\&{then}\5
\\{bad\_font};\2\2\6
\\{read\_tfm\_word};\5
$\\{tfm\_b01}(\\{nw})$;\6
\&{if} $(\\{nw}=0)\V(\\{nw}>256)$ \1\&{then}\5
\\{bad\_font};\2\6
\&{for} $\|l\K-2\mathrel{\&{to}}\\{lh}$ \1\&{do}\6
\&{begin} \37\\{read\_tfm\_word};\6
\&{if} $\|l=1$ \1\&{then}\6
\&{begin} \37$\\{tfm\_squad}(\|w)$;\5
$\\{check\_check\_sum}(\|w,\39\\{true})$;\6
\&{end}\6
\4\&{else} \&{if} $\|l=2$ \1\&{then}\6
\&{begin} \37\&{if} $\\{tfm\_b0}>127$ \1\&{then}\5
\\{bad\_font};\2\6
$\\{check\_design\_size}(\\{round}(\\{tfm\_conv}\ast\\{tfm\_uquad}))$;\6
\&{end};\2\2\6
\&{end}\2\par
\U101.\fi

\M104. The width indices for the characters are stored in positions \\{n%
\_chars}
through $\\{n\_chars}-\\{bc}+\\{ec}$ of the \\{char\_widths} array; if
characters on
either end of the range $\\{bc}\to\\{ec}$ do not exist, they are ignored and
the
range is adjusted accordingly.

\Y\P$\4\X104:TFM: Store character-width indices\X\S$\6
\\{read\_tfm\_word};\6
\&{while} $(\\{tfm\_b0}=0)\W(\\{bc}\L\\{ec})$ \1\&{do}\6
\&{begin} \37$\\{incr}(\\{bc})$;\5
\\{read\_tfm\_word};\6
\&{end};\2\6
$\\{font\_bc}(\\{cur\_fnt})\K\\{bc}$;\5
$\\{font\_chars}(\\{cur\_fnt})\K\\{n\_chars}-\\{bc}$;\6
\&{if} $\\{ec}\G\\{max\_chars}-\\{font\_chars}(\\{cur\_fnt})$ \1\&{then}\5
$\\{overflow}(\\{str\_chars},\39\\{max\_chars})$;\2\6
\&{for} $\|l\K\\{bc}\mathrel{\&{to}}\\{ec}$ \1\&{do}\6
\&{begin} \37$\\{char\_widths}[\\{n\_chars}]\K\\{tfm\_b0}$;\5
$\\{incr}(\\{n\_chars})$;\5
\\{read\_tfm\_word};\6
\&{end};\2\6
\&{while} $(\\{char\_widths}[\\{n\_chars}-1]=0)\W(\\{ec}\G\\{bc})$ \1\&{do}\6
\&{begin} \37$\\{decr}(\\{n\_chars})$;\5
$\\{decr}(\\{ec})$;\6
\&{end};\2\6
$\\{font\_ec}(\\{cur\_fnt})\K\\{ec}$\par
\U101.\fi

\M105. The most important part of \\{make\_font} is the width computation,
which
involves multiplying the relative widths in the \.{TFM} file by the
scaling factor in the \.{DVI} file. A similar computation is used for
dimensions read from \.{VF} files. 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}$.
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=2^{4+e}z^\prime$ 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. We
use \.{WEB} macros for various versions of this computation.

\Y\P\D \37$\\{tfm\_fix3u}\S$\C{convert $\\{tfm\_b1}\to\\{tfm\_b3}$ to an
unsigned scaled dimension}\6
$(((((\\{tfm\_b3}\ast\|z)\mathbin{\&{div}}\O{400})+(\\{tfm\_b2}\ast\|z))%
\mathbin{\&{div}}\O{400})+(\\{tfm\_b1}\ast\|z))\mathbin{\&{div}}\\{beta}$\Y\par
\P\D \37$\\{tfm\_fix4}(\#)\S$\C{convert $\\{tfm\_b0}\to\\{tfm\_b3}$ to a scaled
dimension}\6
$\#\K\\{tfm\_fix3u}$;\6
\&{if} $\\{tfm\_b0}>0$ \1\&{then}\6
\&{if} $\\{tfm\_b0}=255$ \1\&{then}\5
$\\{Decr}(\#)(\\{alpha})$\6
\4\&{else} \\{bad\_font}\2\2\par
\P\D \37$\\{tfm\_fix3}(\#)\S$\C{convert $\\{tfm\_b1}\to\\{tfm\_b3}$ to a scaled
dimension}\6
$\#\K\\{tfm\_fix3u}$;\ \&{if} $\\{tfm\_b1}>127$ \1\&{then}\5
$\\{Decr}(\#)(\\{alpha})$\2\par
\P\D \37$\\{tfm\_fix2}\S$\C{convert $\\{tfm\_b2}\to\\{tfm\_b3}$ to a scaled
dimension}\6
\&{if} $\\{tfm\_b2}>127$ \1\&{then}\5
$\\{tfm\_b1}\K255$\6
\4\&{else} $\\{tfm\_b1}\K0$;\2\6
\\{tfm\_fix3}\par
\P\D \37$\\{tfm\_fix1}\S$\C{convert \\{tfm\_b3} to a scaled dimension}\6
\&{if} $\\{tfm\_b3}>127$ \1\&{then}\5
$\\{tfm\_b1}\K255$\6
\4\&{else} $\\{tfm\_b1}\K0$;\2\6
$\\{tfm\_b2}\K\\{tfm\_b1}$;\5
\\{tfm\_fix3}\par
\Y\P$\4\X105:Variables for scaling computation\X\S$\6
\4\|z: \37\\{int\_32};\C{multiplier}\6
\4\\{alpha}: \37\\{int\_32};\C{correction for negative values}\6
\4\\{beta}: \37\\{int\_15};\C{divisor}\par
\Us100\ET142.\fi

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

\M107. The first width value, which indicates that a character does not exist
and which must vanish, is converted to \\{invalid\_width}; the other width
values are scaled by $\\{font\_scaled}(\\{cur\_fnt})$ and converted to width
pointers by \\{make\_width}. The resulting width pointers are stored
temporarily in the \\{char\_widths} array, following the with indices.

\Y\P$\4\X107:TFM: Read and convert the width values\X\S$\6
\&{if} $\\{nw}-1>\\{max\_chars}-\\{n\_chars}$ \1\&{then}\5
$\\{overflow}(\\{str\_chars},\39\\{max\_chars})$;\2\6
\&{if} $(\\{tfm\_b0}\I0)\V(\\{tfm\_b1}\I0)\V(\\{tfm\_b2}\I0)\V(\\{tfm\_b3}\I0)$
\1\&{then}\5
\\{bad\_font}\6
\4\&{else} $\\{char\_widths}[\\{n\_chars}]\K\\{invalid\_width}$;\2\6
$\|z\K\\{font\_scaled}(\\{cur\_fnt})$;\6
\&{device} \37$\\{font\_space}(\\{cur\_fnt})\K\|z\mathbin{\&{div}}6$;\C{this is
a 3-unit ``thin space''}\6
\&{ecived}\5
\X106:Replace \|z by $\|z^\prime$ and compute $\alpha,\beta$\X;\6
\&{for} $\|p\K\\{n\_chars}+1\mathrel{\&{to}}\\{n\_chars}+\\{nw}-1$ \1\&{do}\6
\&{begin} \37\\{read\_tfm\_word};\5
$\\{tfm\_fix4}(\|w)$;\5
$\\{char\_widths}[\|p]\K\\{make\_width}(\|w)$;\6
\&{end}\2\par
\U101.\fi

\M108. We simply translate the width indices into width pointers. In addition
we initialize the character packets with the invalid packet.

\Y\P$\4\X108:TFM: Convert character-width indices to character-width pointers\X%
\S$\6
\&{for} $\|p\K\\{font\_chars}(\\{cur\_fnt})+\\{bc}\mathrel{\&{to}}\\{n%
\_chars}-1$ \1\&{do}\6
\&{begin} \37$\|q\K\\{char\_widths}[\\{n\_chars}+\\{char\_widths}[\|p]]$;\5
$\\{char\_widths}[\|p]\K\|q$;\6
\&{device} \37$\\{char\_pixels}[\|p]\K\\{pix\_widths}[\|q]$;\ \&{ecived}\6
$\\{char\_packets}[\|p]\K\\{invalid\_packet}$;\6
\&{end}\2\par
\U101.\fi

\N109.  Low-level DVI input routines.
The program uses the binary file variable \\{dvi\_file} for its main input
file; \\{dvi\_loc} is the number of the byte about to be read next from
\\{dvi\_file}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{dvi\_file}: \37\\{byte\_file};\C{the stuff we are \.{\title}ing}\6
\4\\{dvi\_loc}: \37\\{int\_32};\C{where we are about to look, in \\{dvi\_file}}%
\par
\fi

\M110. If the \.{DVI} file is badly malformed, we say \\{bad\_dvi}; this
procedure gives an error message which refers the user to \.{DVItype},
and terminates \.{\title}.

\Y\P$\4\X23:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{bad\_dvi};\2\6
\&{begin} \37\\{new\_line};\5
$\\{print\_ln}(\.{\'Bad\ DVI\ file:\ loc=\'},\39\\{dvi\_loc}:1,\39\.{\'!\'})$;\5
$\\{print}(\.{\'\ Use\ DVItype\ with\ output\ level\'})$;\6
\&{if} $\\{random\_reading}$ \1\&{then}\5
$\\{print}(\.{\'=4\'})$\ \&{else} $\\{print}(\.{\'<4\'})$;\2\6
$\\{abort}(\.{\'to\ diagnose\ the\ problem\'})$;\6
\&{end};\par
\fi

\M111. To prepare \\{dvi\_file} for input, we \\{reset} it.

\Y\P$\4\X111:Open input file(s)\X\S$\6
$\\{reset}(\\{dvi\_file})$;\C{prepares to read packed bytes from \\{dvi\_file}}%
\6
$\\{dvi\_loc}\K0$;\par
\U231.\fi

\M112. Reading the \.{DVI} file should be done as efficient as possible for a
particular system; on many systems this means that a large number of
bytes from \\{dvi\_file} is read into a buffer and will then be extracted
from that buffer. In order to simplify such system dependent changes
we use a pair of \.{WEB} macros: \\{dvi\_byte} extracts the next \.{DVI}
byte and \\{dvi\_eof} is \\{true} if we have reached the end of the \.{DVI}
file. Here we give simple minded definitions for these macros in terms
of standard \PASCAL.

\Y\P\D \37$\\{dvi\_eof}\S\\{eof}(\\{dvi\_file})$\C{has the \.{DVI} file been
exhausted?}\par
\P\D \37$\\{dvi\_byte}(\#)\S$\1\6
\&{if} $\\{dvi\_eof}$ \1\&{then}\5
\\{bad\_dvi}\6
\4\&{else} $\\{read}(\\{dvi\_file},\39\#)$\C{obtain next \.{DVI} byte}\2\2\par
\fi

\M113. Next we come to the routines that are used only if \\{random\_reading}
is
\\{true}. 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 $\\{dvi\_move}(\|n)$ should
position
\\{dvi\_file} so that the next \\{dvi\_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\\{int\_32};\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$\\{dvi\_move}(\|n:\\{int\_32})$;\2\6
\&{begin} \37$\\{set\_pos}(\\{dvi\_file},\39\|n)$;\5
$\\{dvi\_loc}\K\|n$;\6
\&{end};\par
\fi

\M114. We need seven simple functions to read the next byte or bytes
from \\{dvi\_file}.

\Y\P\4\&{function}\1\  \37\\{dvi\_sbyte}: \37\\{int\_8};\C{returns the next
byte, signed}\2\6
\&{begin\_byte} \37$(\\{dvi\_byte})$;\5
$\\{incr}(\\{dvi\_loc})$;\5
$\\{comp\_sbyte}(\\{dvi\_sbyte})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{dvi\_ubyte}: \37\\{int\_8u};\C{returns the next byte,
unsigned}\2\6
\&{begin\_byte} \37$(\\{dvi\_byte})$;\5
$\\{incr}(\\{dvi\_loc})$;\5
$\\{comp\_ubyte}(\\{dvi\_ubyte})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{dvi\_spair}: \37\\{int\_16};\C{returns the next two
bytes, signed}\2\6
\&{begin\_pair} \37$(\\{dvi\_byte})$;\5
$\\{Incr}(\\{dvi\_loc})(2)$;\5
$\\{comp\_spair}(\\{dvi\_spair})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{dvi\_upair}: \37\\{int\_16u};\C{returns the next two
bytes, unsigned}\2\6
\&{begin\_pair} \37$(\\{dvi\_byte})$;\5
$\\{Incr}(\\{dvi\_loc})(2)$;\5
$\\{comp\_upair}(\\{dvi\_upair})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{dvi\_strio}: \37\\{int\_24};\C{returns the next three
bytes, signed}\2\6
\&{begin\_trio} \37$(\\{dvi\_byte})$;\5
$\\{Incr}(\\{dvi\_loc})(3)$;\5
$\\{comp\_strio}(\\{dvi\_strio})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{dvi\_utrio}: \37\\{int\_24u};\C{returns the next three
bytes, unsigned}\2\6
\&{begin\_trio} \37$(\\{dvi\_byte})$;\5
$\\{Incr}(\\{dvi\_loc})(3)$;\5
$\\{comp\_utrio}(\\{dvi\_utrio})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{dvi\_squad}: \37\\{int\_32};\C{returns the next four
bytes, signed}\2\6
\&{begin\_quad} \37$(\\{dvi\_byte})$;\5
$\\{Incr}(\\{dvi\_loc})(4)$;\5
$\\{comp\_squad}(\\{dvi\_squad})$;\6
\&{end};\par
\fi

\M115. Three other functions are used in cases where a four byte integer
(which is always signed) must have a non-negative value, a positive
value, or is a pointer which must be either positive or $=-1$.

\Y\P\4\&{function}\1\  \37\\{dvi\_uquad}: \37\\{int\_31};\C{result must be
non-negative}\6
\4\&{var} \37\|x: \37\\{int\_32};\2\6
\&{begin} \37$\|x\K\\{dvi\_squad}$;\6
\&{if} $\|x<0$ \1\&{then}\5
\\{bad\_dvi}\6
\4\&{else} $\\{dvi\_uquad}\K\|x$;\2\6
\&{end};\7
\4\&{function}\1\  \37\\{dvi\_pquad}: \37\\{int\_31};\C{result must be
positive}\6
\4\&{var} \37\|x: \37\\{int\_32};\2\6
\&{begin} \37$\|x\K\\{dvi\_squad}$;\6
\&{if} $\|x\L0$ \1\&{then}\5
\\{bad\_dvi}\6
\4\&{else} $\\{dvi\_pquad}\K\|x$;\2\6
\&{end};\7
\4\&{function}\1\  \37\\{dvi\_pointer}: \37\\{int\_32};\C{result must be
positive or $=-1$}\6
\4\&{var} \37\|x: \37\\{int\_32};\2\6
\&{begin} \37$\|x\K\\{dvi\_squad}$;\6
\&{if} $(\|x\L0)\W(\|x\I-1)$ \1\&{then}\5
\\{bad\_dvi}\6
\4\&{else} $\\{dvi\_pointer}\K\|x$;\2\6
\&{end};\par
\fi

\M116. Given the structure of the \.{DVI} commands it is fairly obvious
that their interpretation consists of two steps: First zero to four
bytes are read in order to obtain the value of the first parameter
(e.g., zero bytes for \\{set\_char\_0}, four bytes for \\{set4}); then,
depending on the command class, a specific action is performed (e.g.,
typeset a character but don't move the reference point for $\\{put1}\to%
\\{put4}$).

The \.{DVItype} program uses large case statements for both steps;
unfortunately some \PASCAL\ compilers fail to implement large case
statements efficiently -- in particular those as the one used in the
\\{first\_par} function of \.{DVItype}. Here we use a pair of look up tables:
\\{dvi\_par} determines how to obtain the value of the first parameter, and
\\{dvi\_cl} determines the command class.

A slight complication arises from the fact that we want to decompose the
character code of each character to be typset into a residue
$0\L\\{char\_res}<256$ and extension: $\\{char\_code}=\\{char\_res}+256\ast%
\\{char\_ext}$;
the \.{TFM} widths as well as the pixel widths for a given resolution
are the same for all characters in a font with the same residue.

\Y\P\D \37$\\{two\_cases}(\#)\S\#,\39\#+1$\par
\P\D \37$\\{three\_cases}(\#)\S\#,\39\#+1,\39\#+2$\par
\P\D \37$\\{five\_cases}(\#)\S\#,\39\#+1,\39\#+2,\39\#+3,\39\#+4$\par
\fi

\M117. First we define the values used as array elements of \\{dvi\_par}; we
distinguish between pure numbers and dimensions because dimensions read
from a \.{VF} file must be scaled.

\Y\P\D \37$\\{char\_par}=0$\C{character for \\{set} and \\{put}}\par
\P\D \37$\\{no\_par}=1$\C{no parameter}\par
\P\D \37$\\{dim1\_par}=2$\C{one-byte signed dimension}\par
\P\D \37$\\{num1\_par}=3$\C{one-byte unsigned number}\par
\P\D \37$\\{dim2\_par}=4$\C{two-byte signed dimension}\par
\P\D \37$\\{num2\_par}=5$\C{two-byte unsigned number}\par
\P\D \37$\\{dim3\_par}=6$\C{three-byte signed dimension}\par
\P\D \37$\\{num3\_par}=7$\C{three-byte unsigned number}\par
\P\D \37$\\{dim4\_par}=8$\C{four-byte signed dimension}\par
\P\D \37$\\{num4\_par}=9$\C{four-byte signed number}\par
\P\D \37$\\{numu\_par}=10$\C{four-byte non-negative number}\par
\P\D \37$\\{rule\_par}=11$\C{dimensions for \\{set\_rule} and \\{put\_rule}}\par
\P\D \37$\\{fnt\_par}=12$\C{font for \\{fnt\_num} commands}\par
\P\D \37$\\{max\_par}=12$\C{largest possible value}\par
\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{cmd\_par}=\\{char\_par}\to\\{max\_par}$;\par
\fi

\M118. Here we declare the array \\{dvi\_par}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{dvi\_par}: \37\&{packed} \37\&{array} $[\\{eight\_bits}]$ \1\&{of}\5
\\{cmd\_par};\2\par
\fi

\M119. And here we initialize it.

\Y\P$\4\X18:Set initial values\X\mathrel{+}\S$\6
\&{for} $\|i\K0\mathrel{\&{to}}\\{put1}+3$ \1\&{do}\5
$\\{dvi\_par}[\|i]\K\\{char\_par}$;\2\6
\&{for} $\|i\K\\{nop}\mathrel{\&{to}}255$ \1\&{do}\5
$\\{dvi\_par}[\|i]\K\\{no\_par}$;\2\6
$\\{dvi\_par}[\\{set\_rule}]\K\\{rule\_par}$;\5
$\\{dvi\_par}[\\{put\_rule}]\K\\{rule\_par}$;\6
$\\{dvi\_par}[\\{right1}]\K\\{dim1\_par}$;\5
$\\{dvi\_par}[\\{right1}+1]\K\\{dim2\_par}$;\5
$\\{dvi\_par}[\\{right1}+2]\K\\{dim3\_par}$;\5
$\\{dvi\_par}[\\{right1}+3]\K\\{dim4\_par}$;\6
\&{for} $\|i\K\\{fnt\_num\_0}\mathrel{\&{to}}\\{fnt\_num\_0}+63$ \1\&{do}\5
$\\{dvi\_par}[\|i]\K\\{fnt\_par}$;\2\6
$\\{dvi\_par}[\\{fnt1}]\K\\{num1\_par}$;\5
$\\{dvi\_par}[\\{fnt1}+1]\K\\{num2\_par}$;\5
$\\{dvi\_par}[\\{fnt1}+2]\K\\{num3\_par}$;\5
$\\{dvi\_par}[\\{fnt1}+3]\K\\{num4\_par}$;\6
$\\{dvi\_par}[\\{xxx1}]\K\\{num1\_par}$;\5
$\\{dvi\_par}[\\{xxx1}+1]\K\\{num2\_par}$;\5
$\\{dvi\_par}[\\{xxx1}+2]\K\\{num3\_par}$;\5
$\\{dvi\_par}[\\{xxx1}+3]\K\\{numu\_par}$;\6
\&{for} $\|i\K0\mathrel{\&{to}}3$ \1\&{do}\6
\&{begin} \37$\\{dvi\_par}[\|i+\\{w1}]\K\\{dvi\_par}[\|i+\\{right1}]$;\5
$\\{dvi\_par}[\|i+\\{x1}]\K\\{dvi\_par}[\|i+\\{right1}]$;\5
$\\{dvi\_par}[\|i+\\{down1}]\K\\{dvi\_par}[\|i+\\{right1}]$;\5
$\\{dvi\_par}[\|i+\\{y1}]\K\\{dvi\_par}[\|i+\\{right1}]$;\5
$\\{dvi\_par}[\|i+\\{z1}]\K\\{dvi\_par}[\|i+\\{right1}]$;\5
$\\{dvi\_par}[\|i+\\{fnt\_def1}]\K\\{dvi\_par}[\|i+\\{fnt1}]$;\6
\&{end};\2\par
\fi

\M120. Next we define the values used as array elements of \\{dvi\_cl};
several \.{DVI} commands (e.g., \\{nop}, \\{bop}, \\{eop}, \\{pre}, \\{post})
will
allways be treated separately and are therfore assigned to the invalid
class here.

\Y\P\D \37$\\{char\_cl}=0$\par
\P\D \37$\\{rule\_cl}=\\{char\_cl}+1$\par
\P\D \37$\\{xxx\_cl}=\\{char\_cl}+2$\par
\P\D \37$\\{push\_cl}=3$\par
\P\D \37$\\{pop\_cl}=4$\par
\P\D \37$\\{w0\_cl}=5$\par
\P\D \37$\\{x0\_cl}=\\{w0\_cl}+1$\par
\P\D \37$\\{right\_cl}=\\{w0\_cl}+2$\par
\P\D \37$\\{w\_cl}=\\{w0\_cl}+3$\par
\P\D \37$\\{x\_cl}=\\{w0\_cl}+4$\par
\P\D \37$\\{y0\_cl}=10$\par
\P\D \37$\\{z0\_cl}=\\{y0\_cl}+1$\par
\P\D \37$\\{down\_cl}=\\{y0\_cl}+2$\par
\P\D \37$\\{y\_cl}=\\{y0\_cl}+3$\par
\P\D \37$\\{z\_cl}=\\{y0\_cl}+4$\par
\P\D \37$\\{fnt\_cl}=15$\par
\P\D \37$\\{fnt\_def\_cl}=16$\par
\P\D \37$\\{invalid\_cl}=17$\par
\P\D \37$\\{max\_cl}=\\{invalid\_cl}$\C{largest possible value}\par
\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{cmd\_cl}=\\{char\_cl}\to\\{max\_cl}$;\par
\fi

\M121. Here we declare the array \\{dvi\_cl}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{dvi\_cl}: \37\&{packed} \37\&{array} $[\\{eight\_bits}]$ \1\&{of}\5
\\{cmd\_cl};\2\par
\fi

\M122. And here we initialize it.

\Y\P$\4\X18:Set initial values\X\mathrel{+}\S$\6
\&{for} $\|i\K\\{set\_char\_0}\mathrel{\&{to}}\\{put1}+3$ \1\&{do}\5
$\\{dvi\_cl}[\|i]\K\\{char\_cl}$;\2\6
$\\{dvi\_cl}[\\{set\_rule}]\K\\{rule\_cl}$;\5
$\\{dvi\_cl}[\\{put\_rule}]\K\\{rule\_cl}$;\6
$\\{dvi\_cl}[\\{nop}]\K\\{invalid\_cl}$;\5
$\\{dvi\_cl}[\\{bop}]\K\\{invalid\_cl}$;\5
$\\{dvi\_cl}[\\{eop}]\K\\{invalid\_cl}$;\6
$\\{dvi\_cl}[\\{push}]\K\\{push\_cl}$;\5
$\\{dvi\_cl}[\\{pop}]\K\\{pop\_cl}$;\6
$\\{dvi\_cl}[\\{w0}]\K\\{w0\_cl}$;\5
$\\{dvi\_cl}[\\{x0}]\K\\{x0\_cl}$;\6
$\\{dvi\_cl}[\\{y0}]\K\\{y0\_cl}$;\5
$\\{dvi\_cl}[\\{z0}]\K\\{z0\_cl}$;\6
\&{for} $\|i\K0\mathrel{\&{to}}3$ \1\&{do}\6
\&{begin} \37$\\{dvi\_cl}[\|i+\\{right1}]\K\\{right\_cl}$;\5
$\\{dvi\_cl}[\|i+\\{w1}]\K\\{w\_cl}$;\5
$\\{dvi\_cl}[\|i+\\{x1}]\K\\{x\_cl}$;\6
$\\{dvi\_cl}[\|i+\\{down1}]\K\\{down\_cl}$;\5
$\\{dvi\_cl}[\|i+\\{y1}]\K\\{y\_cl}$;\5
$\\{dvi\_cl}[\|i+\\{z1}]\K\\{z\_cl}$;\6
$\\{dvi\_cl}[\|i+\\{xxx1}]\K\\{xxx\_cl}$;\5
$\\{dvi\_cl}[\|i+\\{fnt\_def1}]\K\\{fnt\_def\_cl}$;\6
\&{end};\2\6
\&{for} $\|i\K\\{fnt\_num\_0}\mathrel{\&{to}}\\{fnt1}+3$ \1\&{do}\5
$\\{dvi\_cl}[\|i]\K\\{fnt\_cl}$;\2\6
\&{for} $\|i\K\\{pre}\mathrel{\&{to}}255$ \1\&{do}\5
$\\{dvi\_cl}[\|i]\K\\{invalid\_cl}$;\2\par
\fi

\M123. A few small arrays are used to generate \.{DVI} commands.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{dvi\_char\_cmd}: \37\&{array} $[\\{boolean}]$ \1\&{of}\5
\\{eight\_bits};\C{\\{put1} and \\{set1}}\2\6
\4\\{dvi\_rule\_cmd}: \37\&{array} $[\\{boolean}]$ \1\&{of}\5
\\{eight\_bits};\C{\\{put\_rule} and \\{set\_rule}}\2\6
\4\\{dvi\_right\_cmd}: \37\&{array} $[\\{right\_cl}\to\\{x\_cl}]$ \1\&{of}\5
\\{eight\_bits};\C{\\{right1}, \\{w1}, and \\{x1}}\2\6
\4\\{dvi\_down\_cmd}: \37\&{array} $[\\{down\_cl}\to\\{z\_cl}]$ \1\&{of}\5
\\{eight\_bits};\C{\\{down1}, \\{y1}, and \\{z1}}\2\par
\fi

\M124. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{dvi\_char\_cmd}[\\{false}]\K\\{put1}$;\5
$\\{dvi\_char\_cmd}[\\{true}]\K\\{set1}$;\6
$\\{dvi\_rule\_cmd}[\\{false}]\K\\{put\_rule}$;\5
$\\{dvi\_rule\_cmd}[\\{true}]\K\\{set\_rule}$;\6
$\\{dvi\_right\_cmd}[\\{right\_cl}]\K\\{right1}$;\5
$\\{dvi\_right\_cmd}[\\{w\_cl}]\K\\{w1}$;\5
$\\{dvi\_right\_cmd}[\\{x\_cl}]\K\\{x1}$;\6
$\\{dvi\_down\_cmd}[\\{down\_cl}]\K\\{down1}$;\5
$\\{dvi\_down\_cmd}[\\{y\_cl}]\K\\{y1}$;\5
$\\{dvi\_down\_cmd}[\\{z\_cl}]\K\\{z1}$;\par
\fi

\M125. The global variables \\{cur\_cmd}, \\{cur\_parm} and \\{cur\_class} are
used
for the current \.{DVI} command, its first parameter (if any), and its
command class respectively.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\_cmd}: \37\\{eight\_bits};\C{current \.{DVI} command byte}\6
\4\\{cur\_parm}: \37\\{int\_32};\C{its first parameter (if any)}\6
\4\\{cur\_class}: \37\\{cmd\_cl};\C{its class}\par
\fi

\M126. When typesetting a character or rule, the boolean variable \\{cur\_upd}
is \\{true} for \\{set} commands, \\{false} for \\{put} commands.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\_wp}: \37\\{width\_pointer};\C{width pointer of the current character}%
\6
\4\\{cur\_upd}: \37\\{boolean};\C{is this a \\{set} or \\{set\_rule} command ?}%
\6
\4\\{cur\_v\_dimen}: \37\\{int\_32};\C{a vertical dimension}\6
\4\\{cur\_h\_dimen}: \37\\{int\_32};\C{a horizontal dimension}\par
\fi

\M127. The \\{dvi\_first\_par} procedure first reads \.{DVI} command bytes into
\\{cur\_cmd} until $\\{cur\_cmd}\I\\{nop}$; then \\{cur\_parm} is set to the
value of
the first parameter (if any) and \\{cur\_class} to the command class.

\Y\P\D \37$\\{set\_cur\_char}(\#)\S$\C{set up \\{cur\_res}, \\{cur\_ext}, and %
\\{cur\_upd}}\6
\&{begin} \37$\\{cur\_ext}\K0$;\6
\&{if} $\\{cur\_cmd}<\\{set1}$ \1\&{then}\6
\&{begin} \37$\\{cur\_res}\K\\{cur\_cmd}$;\5
$\\{cur\_upd}\K\\{true}$\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{cur\_res}\K\#$;\5
$\\{cur\_upd}\K(\\{cur\_cmd}<\\{put1})$;\5
$\\{Decr}(\\{cur\_cmd})(\\{dvi\_char\_cmd}[\\{cur\_upd}])$;\6
\&{while} $\\{cur\_cmd}>0$ \1\&{do}\6
\&{begin} \37\&{if} $\\{cur\_cmd}=3$ \1\&{then}\6
\&{if} $\\{cur\_res}>127$ \1\&{then}\5
$\\{cur\_ext}\K-1$;\2\2\6
$\\{cur\_ext}\K\\{cur\_ext}\ast256+\\{cur\_res}$;\5
$\\{cur\_res}\K\#$;\5
$\\{decr}(\\{cur\_cmd})$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\par
\Y\P\4\&{procedure}\1\  \37\\{dvi\_first\_par};\2\6
\&{begin} \37\1\&{repeat} \37$\\{cur\_cmd}\K\\{dvi\_ubyte}$;\6
\4\&{until}\5
$\\{cur\_cmd}\I\\{nop}$;\C{skip over \\{nop}s}\2\6
\&{case} $\\{dvi\_par}[\\{cur\_cmd}]$ \1\&{of}\6
\4\\{char\_par}: \37$\\{set\_cur\_char}(\\{dvi\_ubyte})$;\6
\4\\{no\_par}: \37\\{do\_nothing};\6
\4\\{dim1\_par}: \37$\\{cur\_parm}\K\\{dvi\_sbyte}$;\6
\4\\{num1\_par}: \37$\\{cur\_parm}\K\\{dvi\_ubyte}$;\6
\4\\{dim2\_par}: \37$\\{cur\_parm}\K\\{dvi\_spair}$;\6
\4\\{num2\_par}: \37$\\{cur\_parm}\K\\{dvi\_upair}$;\6
\4\\{dim3\_par}: \37$\\{cur\_parm}\K\\{dvi\_strio}$;\6
\4\\{num3\_par}: \37$\\{cur\_parm}\K\\{dvi\_utrio}$;\6
\4$\\{two\_cases}(\\{dim4\_par})$: \37$\\{cur\_parm}\K\\{dvi\_squad}$;\C{%
\\{dim4\_par} and \\{num4\_par}}\6
\4\\{numu\_par}: \37$\\{cur\_parm}\K\\{dvi\_uquad}$;\6
\4\\{rule\_par}: \37\&{begin} \37$\\{cur\_v\_dimen}\K\\{dvi\_squad}$;\5
$\\{cur\_h\_dimen}\K\\{dvi\_squad}$;\5
$\\{cur\_upd}\K(\\{cur\_cmd}=\\{set\_rule})$;\6
\&{end};\6
\4\\{fnt\_par}: \37$\\{cur\_parm}\K\\{cur\_cmd}-\\{fnt\_num\_0}$;\2\6
\&{end};\C{there are no other cases}\6
$\\{cur\_class}\K\\{dvi\_cl}[\\{cur\_cmd}]$;\6
\&{end};\par
\fi

\M128. The global variable \\{dvi\_nf} is used for the number of different
\.{DVI} fonts defined so far; their external font numbers (as extracted
from the \.{DVI} file) are stored in the array \\{dvi\_e\_fnts}, the
corresponding internal font numbers used internally by \.{\title} are
stored in the array \\{dvi\_i\_fnts}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{dvi\_e\_fnts}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{int\_32};\C{external font numbers}\2\6
\4\\{dvi\_i\_fnts}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{font\_number};\C{corresponding   internal font numbers}\2\6
\4\\{dvi\_nf}: \37\\{font\_number};\C{number of \.{DVI} fonts defined so far}%
\par
\fi

\M129. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{dvi\_nf}\K0$;\par
\fi

\M130. The \\{dvi\_font} procedure sets \\{cur\_fnt} to the internal font
number
corresponding to the external font number \\{cur\_parm} (or aborts the
program if such a font was never defined).

\Y\P\4\&{procedure}\1\  \37\\{dvi\_font};\C{computes \\{cur\_fnt} corresponding
to \\{cur\_parm}}\6
\4\&{var} \37\|f: \37\\{font\_number};\C{where the font is sought}\2\6
\&{begin} \37\X131:DVI: Locate font \\{cur\_parm}\X;\6
\&{if} $\|f=\\{dvi\_nf}$ \1\&{then}\5
\\{bad\_dvi};\2\6
$\\{cur\_fnt}\K\\{dvi\_i\_fnts}[\|f]$;\6
\&{end};\par
\fi

\M131. \P$\X131:DVI: Locate font \\{cur\_parm}\X\S$\6
$\|f\K0$;\5
$\\{dvi\_e\_fnts}[\\{dvi\_nf}]\K\\{cur\_parm}$;\6
\&{while} $\\{cur\_parm}\I\\{dvi\_e\_fnts}[\|f]$ \1\&{do}\5
$\\{incr}(\|f)$\2\par
\Us130\ET132.\fi

\M132. Finally the \\{dvi\_do\_font} procedure is called when one of the
command
$\\{fnt\_def1}\to\\{fnt\_def4}$ and its first parameter have been read from the
\.{DVI} file; the argument indicates whether this should be the second
definition of the font (\\{true}) or not (\\{false}).

\Y\P\4\&{procedure}\1\  \37$\\{dvi\_do\_font}(\\{second}:\\{boolean})$;\6
\4\&{var} \37\|f: \37\\{font\_number};\C{where the font is sought}\6
\|k: \37\\{int\_15};\C{general purpose variable}\2\6
\&{begin} \37$\\{print}(\.{\'DVI:\ font\ \'},\39\\{cur\_parm}:1)$;\5
\X131:DVI: Locate font \\{cur\_parm}\X;\6
\&{if} $(\|f=\\{dvi\_nf})=\\{second}$ \1\&{then}\5
\\{bad\_dvi};\2\6
$\\{font\_check}(\\{nf})\K\\{dvi\_squad}$;\5
$\\{font\_scaled}(\\{nf})\K\\{dvi\_pquad}$;\5
$\\{font\_design}(\\{nf})\K\\{dvi\_pquad}$;\5
$\|k\K\\{dvi\_ubyte}$;\5
$\\{pckt\_room}(1)$;\5
$\\{append\_byte}(\|k)$;\5
$\\{Incr}(\|k)(\\{dvi\_ubyte})$;\5
$\\{pckt\_room}(\|k)$;\6
\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{append\_byte}(\\{dvi\_ubyte})$;\5
$\\{decr}(\|k)$;\6
\&{end};\2\6
$\\{font\_name}(\\{nf})\K\\{make\_packet}$;\C{the font area plus name}\6
$\\{dvi\_i\_fnts}[\\{dvi\_nf}]\K\\{make\_font}$;\6
\&{if} $\R\\{second}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{dvi\_nf}=\\{max\_fonts}$ \1\&{then}\5
$\\{overflow}(\\{str\_fonts},\39\\{max\_fonts})$;\2\6
$\\{incr}(\\{dvi\_nf})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{dvi\_i\_fnts}[\|f]\I\\{dvi\_i\_fnts}[\\{dvi\_nf}]$ \1%
\&{then}\5
\\{bad\_dvi};\2\2\6
\&{end};\par
\fi

\N133.  Low-level VF input routines.
A detailed description of the \.{VF} file format can be found in the
documentation of \.{VFtoVP}; here we just define symbolic names for
some of the \.{VF} command bytes.

\Y\P\D \37$\\{long\_char}=242$\C{\.{VF} command for general character packet}\Y%
\par
\P\D \37$\\{vf\_id}=202$\C{identifies \.{VF} files}\par
\fi

\M134. The program uses the binary file variable \\{vf\_file} for input from
\.{VF} files; \\{vf\_loc} is the number of the byte about to be read next
from \\{vf\_file}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{vf\_file}: \37\\{byte\_file};\C{a \.{VF} file}\6
\4\\{vf\_loc}: \37\\{int\_32};\C{where we are about to look, in \\{vf\_file}}\6
\4\\{vf\_limit}: \37\\{int\_32};\C{value of \\{vf\_loc} at end of a character
packet}\6
\4\\{vf\_ext}: \37\\{pckt\_pointer};\C{extension for \.{VF} files}\6
\4\\{vf\_cur\_fnt}: \37\\{font\_number};\C{current font number in a \.{VF}
file}\par
\fi

\M135. \P$\X45:Initialize predefined strings\X\mathrel{+}\S$\6
$\\{id3}(\.{"."})(\.{"V"})(\.{"F"})(\\{vf\_ext})$;\C{file name extension for %
\.{VF} files}\par
\fi

\M136. If a \.{VF} file is badly malformed, we say \\{bad\_font}; this
procedure
gives an error message which refers the user to \.{VFtoVP} and \.{VPtoVF},
and terminates \.{\title}.

\Y\P$\4\X136:Cases for \\{bad\_font}\X\S$\6
\4\\{vf\_font\_type}: \37\&{begin} \37$\\{print}(\.{\'Bad\ VF\ file\'})$;\5
$\\{print\_font}(\\{cur\_fnt})$;\5
$\\{print\_ln}(\.{\'\ loc=\'},\39\\{vf\_loc}:1)$;\5
$\\{abort}(\.{\'Use\ VFtoVP/VPtoVF\ to\ diagnose\ and\ correct\ the\ problem%
\'})$;\6
\&{end};\par
\U95.\fi

\M137. If no font directory has been specified, \.{\title} is supposed to use
the default \.{VF} directory, which is a system-dependent place where
the \.{VF} files for standard fonts are kept.
The string variable \\{VF\_default\_area} contains the name of this area.

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

\M138. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{VF\_default\_area}\K\\{VF\_default\_area\_name}$;\par
\fi

\M139. To prepare \\{vf\_file} for input we \\{reset} it.

\Y\P$\4\X139:VF: Open \\{vf\_file} or \&{goto} \\{not\_found}\X\S$\6
$\\{make\_font\_name}(\\{VF\_default\_area\_name\_length})(\\{VF\_default%
\_area})(\\{vf\_ext})$;\5
$\\{reset}(\\{vf\_file},\39\\{cur\_name})$;\6
\&{if} $\\{eof}(\\{vf\_file})$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\\{vf\_loc}\K0$\par
\U151.\fi

\M140. Reading a \.{VF} file should be done as efficient as possible for a
particular system; on many systems this means that a large number of
bytes from \\{vf\_file} is read into a buffer and will then be extracted
from that buffer. In order to simplify such system dependent changes
we use a pair of \.{WEB} macros: \\{vf\_byte} extracts the next \.{VF}
byte and \\{vf\_eof} is \\{true} if we have reached the end of the \.{VF}
file. Here we give simple minded definitions for these macros in terms
of standard \PASCAL.

\Y\P\D \37$\\{vf\_eof}\S\\{eof}(\\{vf\_file})$\C{has the \.{VF} file been
exhausted?}\par
\P\D \37$\\{vf\_byte}(\#)\S$\1\6
\&{if} $\\{vf\_eof}$ \1\&{then}\5
\\{bad\_font}\6
\4\&{else} $\\{read}(\\{vf\_file},\39\#)$\C{obtain next \.{VF} byte}\2\2\par
\fi

\M141. We need several simple functions to read the next byte or bytes
from \\{vf\_file}.

\Y\P\4\&{function}\1\  \37\\{vf\_ubyte}: \37\\{int\_8u};\C{returns the next
byte, unsigned}\2\6
\&{begin\_byte} \37$(\\{vf\_byte})$;\5
$\\{incr}(\\{vf\_loc})$;\5
$\\{comp\_ubyte}(\\{vf\_ubyte})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_upair}: \37\\{int\_16u};\C{returns the next two
bytes, unsigned}\2\6
\&{begin\_pair} \37$(\\{vf\_byte})$;\5
$\\{Incr}(\\{vf\_loc})(2)$;\5
$\\{comp\_upair}(\\{vf\_upair})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_strio}: \37\\{int\_24};\C{returns the next three
bytes, signed}\2\6
\&{begin\_trio} \37$(\\{vf\_byte})$;\5
$\\{Incr}(\\{vf\_loc})(3)$;\5
$\\{comp\_strio}(\\{vf\_strio})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_utrio}: \37\\{int\_24u};\C{returns the next three
bytes, unsigned}\2\6
\&{begin\_trio} \37$(\\{vf\_byte})$;\5
$\\{Incr}(\\{vf\_loc})(3)$;\5
$\\{comp\_utrio}(\\{vf\_utrio})$;\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_squad}: \37\\{int\_32};\C{returns the next four
bytes, signed}\2\6
\&{begin\_quad} \37$(\\{vf\_byte})$;\5
$\\{Incr}(\\{vf\_loc})(4)$;\5
$\\{comp\_squad}(\\{vf\_squad})$;\6
\&{end};\par
\fi

\M142. All dimensions in a \.{VF} file, except the design sizes of a virtual
font and its local fonts, are \\{fix\_word}s that must be scaled in exactly
the same way as the character widths from a \.{TFM} file; we can use the
same code, but this time \|z, \\{alpha}, and \\{beta} are global variables.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\X105:Variables for scaling computation\X\par
\fi

\M143. We need five functions to read the next byte or bytes and convert a
\\{fix\_word} to a scaled dimension.

\Y\P\4\&{function}\1\  \37\\{vf\_fix1}: \37\\{int\_32};\C{returns the next byte
as scaled value}\6
\4\&{var} \37\|x: \37\\{int\_32};\C{accumulator}\2\6
\&{begin} \37$\\{vf\_byte}(\\{tfm\_b3})$;\5
$\\{incr}(\\{vf\_loc})$;\5
$\\{tfm\_fix1}(\|x)$;\5
$\\{vf\_fix1}\K\|x$;\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_fix2}: \37\\{int\_32};\C{returns the next two
bytes as scaled value}\6
\4\&{var} \37\|x: \37\\{int\_32};\C{accumulator}\2\6
\&{begin} \37$\\{vf\_byte}(\\{tfm\_b2})$;\5
$\\{vf\_byte}(\\{tfm\_b3})$;\5
$\\{Incr}(\\{vf\_loc})(2)$;\5
$\\{tfm\_fix2}(\|x)$;\5
$\\{vf\_fix2}\K\|x$;\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_fix3}: \37\\{int\_32};\C{returns the next three
bytes as scaled value}\6
\4\&{var} \37\|x: \37\\{int\_32};\C{accumulator}\2\6
\&{begin} \37$\\{vf\_byte}(\\{tfm\_b1})$;\5
$\\{vf\_byte}(\\{tfm\_b2})$;\5
$\\{vf\_byte}(\\{tfm\_b3})$;\5
$\\{Incr}(\\{vf\_loc})(3)$;\6
$\\{tfm\_fix3}(\|x)$;\5
$\\{vf\_fix3}\K\|x$;\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_fix3u}: \37\\{int\_32};\C{returns the next three
bytes as scaled value}\2\6
\&{begin} \37$\\{vf\_byte}(\\{tfm\_b1})$;\5
$\\{vf\_byte}(\\{tfm\_b2})$;\5
$\\{vf\_byte}(\\{tfm\_b3})$;\5
$\\{Incr}(\\{vf\_loc})(3)$;\6
$\\{vf\_fix3u}\K\\{tfm\_fix3u}$;\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_fix4}: \37\\{int\_32};\C{returns the next four
bytes as scaled value}\6
\4\&{var} \37\|x: \37\\{int\_32};\C{accumulator}\2\6
\&{begin} \37$\\{vf\_byte}(\\{tfm\_b0})$;\5
$\\{vf\_byte}(\\{tfm\_b1})$;\5
$\\{vf\_byte}(\\{tfm\_b2})$;\5
$\\{vf\_byte}(\\{tfm\_b3})$;\5
$\\{Incr}(\\{vf\_loc})(4)$;\6
$\\{tfm\_fix4}(\|x)$;\5
$\\{vf\_fix4}\K\|x$;\6
\&{end};\par
\fi

\M144. Three other functions are used in cases where the result must have a
non-negative value or a positive value.

\Y\P\4\&{function}\1\  \37\\{vf\_uquad}: \37\\{int\_31};\C{result must be
non-negative}\6
\4\&{var} \37\|x: \37\\{int\_32};\2\6
\&{begin} \37$\|x\K\\{vf\_squad}$;\6
\&{if} $\|x<0$ \1\&{then}\5
\\{bad\_font}\ \&{else} $\\{vf\_uquad}\K\|x$;\2\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_pquad}: \37\\{int\_31};\C{result must be positive}%
\6
\4\&{var} \37\|x: \37\\{int\_32};\2\6
\&{begin} \37$\|x\K\\{vf\_squad}$;\6
\&{if} $\|x\L0$ \1\&{then}\5
\\{bad\_font}\ \&{else} $\\{vf\_pquad}\K\|x$;\2\6
\&{end};\7
\4\&{function}\1\  \37\\{vf\_fixp}: \37\\{int\_31};\C{result must be positive}\6
\4\&{var} \37\|x: \37\\{int\_32};\C{accumulator}\2\6
\&{begin} \37$\\{vf\_byte}(\\{tfm\_b0})$;\5
$\\{vf\_byte}(\\{tfm\_b1})$;\5
$\\{vf\_byte}(\\{tfm\_b2})$;\5
$\\{vf\_byte}(\\{tfm\_b3})$;\5
$\\{Incr}(\\{vf\_loc})(4)$;\6
\&{if} $\\{tfm\_b0}>0$ \1\&{then}\5
\\{bad\_font};\2\6
$\\{vf\_fixp}\K\\{tfm\_fix3u}$;\6
\&{end};\par
\fi

\M145. The \\{vf\_first\_par} procedure first reads a \.{VF} command byte into
\\{cur\_cmd}; then \\{cur\_parm} is set to the value of the first parameter
(if any) and \\{cur\_class} to the command class.

\Y\P\D \37$\\{set\_cur\_wp\_end}(\#)\S$\1\6
\&{if} $\\{cur\_wp}=\\{invalid\_width}$ \1\&{then}\5
$\#$\2\2\par
\P\D \37$\\{set\_cur\_wp}(\#)\S$\C{set \\{cur\_wp} to the char's width pointer}%
\6
$\\{cur\_wp}\K\\{invalid\_width}$;\6
\&{if} $\#\I\\{invalid\_font}$ \1\&{then}\6
\&{if} $(\\{cur\_res}\G\\{font\_bc}(\#))\W(\\{cur\_res}\L\\{font\_ec}(\#))$ \1%
\&{then}\5
$\\{cur\_wp}\K\\{font\_width}(\#)(\\{cur\_res})$;\2\2\6
\\{set\_cur\_wp\_end}\par
\Y\P\4\&{procedure}\1\  \37\\{vf\_first\_par};\2\6
\&{begin} \37$\\{cur\_cmd}\K\\{vf\_ubyte}$;\6
\&{case} $\\{dvi\_par}[\\{cur\_cmd}]$ \1\&{of}\6
\4\\{char\_par}: \37\&{begin} \37$\\{set\_cur\_char}(\\{vf\_ubyte})$;\5
$\\{set\_cur\_wp}(\\{vf\_cur\_fnt})(\\{bad\_font})$;\6
\&{end};\6
\4\\{no\_par}: \37\\{do\_nothing};\6
\4\\{dim1\_par}: \37$\\{cur\_parm}\K\\{vf\_fix1}$;\6
\4\\{num1\_par}: \37$\\{cur\_parm}\K\\{vf\_ubyte}$;\6
\4\\{dim2\_par}: \37$\\{cur\_parm}\K\\{vf\_fix2}$;\6
\4\\{num2\_par}: \37$\\{cur\_parm}\K\\{vf\_upair}$;\6
\4\\{dim3\_par}: \37$\\{cur\_parm}\K\\{vf\_fix3}$;\6
\4\\{num3\_par}: \37$\\{cur\_parm}\K\\{vf\_utrio}$;\6
\4\\{dim4\_par}: \37$\\{cur\_parm}\K\\{vf\_fix4}$;\6
\4\\{num4\_par}: \37$\\{cur\_parm}\K\\{vf\_squad}$;\6
\4\\{numu\_par}: \37$\\{cur\_parm}\K\\{vf\_uquad}$;\6
\4\\{rule\_par}: \37\&{begin} \37$\\{cur\_v\_dimen}\K\\{vf\_fix4}$;\5
$\\{cur\_h\_dimen}\K\\{vf\_fix4}$;\5
$\\{cur\_upd}\K(\\{cur\_cmd}=\\{set\_rule})$;\6
\&{end};\6
\4\\{fnt\_par}: \37$\\{cur\_parm}\K\\{cur\_cmd}-\\{fnt\_num\_0}$;\2\6
\&{end};\C{there are no other cases}\6
$\\{cur\_class}\K\\{dvi\_cl}[\\{cur\_cmd}]$;\6
\&{end};\par
\fi

\M146. For a virtual font we set $\\{font\_type}(\|f)\K\\{vf\_font\_type}$; in
this case
$\\{font\_font}(\|f)$ is the default font for character packets from virtual
font~\|f.

The global variable \\{vf\_nf} is used for the number of different local
fonts defined in a \.{VF} file so far; their external font numbers (as
extracted from the \.{VF} file) are stored in the array \\{vf\_e\_fnts}, the
corresponding internal font numbers used internally by \.{\title} are
stored in the array \\{vf\_i\_fnts}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{vf\_e\_fnts}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{int\_32};\C{external font numbers}\2\6
\4\\{vf\_i\_fnts}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{font\_number};\C{corresponding   internal font numbers}\2\6
\4\\{vf\_nf}: \37\\{font\_number};\C{number of local fonts defined so far}\6
\4\\{lcl\_nf}: \37\\{font\_number};\C{largest \\{vf\_nf} value for any \.{VF}
file}\par
\fi

\M147. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{lcl\_nf}\K0$;\par
\fi

\M148. The \\{vf\_font} procedure sets \\{vf\_cur\_fnt} to the internal font
number
corresponding to the external font number \\{cur\_parm} (or aborts the
program if such a font was never defined).

\Y\P\4\&{procedure}\1\  \37\\{vf\_font};\C{computes \\{vf\_cur\_fnt}
corresponding to \\{cur\_parm}}\6
\4\&{var} \37\|f: \37\\{font\_number};\C{where the font is sought}\2\6
\&{begin} \37\X149:VF: Locate font \\{cur\_parm}\X;\6
\&{if} $\|f=\\{vf\_nf}$ \1\&{then}\5
\\{bad\_font};\2\6
$\\{vf\_cur\_fnt}\K\\{vf\_i\_fnts}[\|f]$;\6
\&{end};\par
\fi

\M149. \P$\X149:VF: Locate font \\{cur\_parm}\X\S$\6
$\|f\K0$;\5
$\\{vf\_e\_fnts}[\\{vf\_nf}]\K\\{cur\_parm}$;\6
\&{while} $\\{cur\_parm}\I\\{vf\_e\_fnts}[\|f]$ \1\&{do}\5
$\\{incr}(\|f)$\2\par
\Us148\ET150.\fi

\M150. Finally the \\{vf\_do\_font} procedure is called when one of the command
$\\{fnt\_def1}\to\\{fnt\_def4}$ and its first parameter have been read from the
\.{VF} file.

\Y\P\4\&{procedure}\1\  \37\\{vf\_do\_font};\6
\4\&{var} \37\|f: \37\\{font\_number};\C{where the font is sought}\6
\|k: \37\\{int\_15};\C{general purpose variable}\2\6
\&{begin} \37$\\{print}(\.{\'VF:\ font\ \'},\39\\{cur\_parm}:1)$;\6
\X149:VF: Locate font \\{cur\_parm}\X;\6
\&{if} $\|f\I\\{vf\_nf}$ \1\&{then}\5
\\{bad\_font};\2\6
$\\{font\_check}(\\{nf})\K\\{vf\_squad}$;\5
$\\{font\_scaled}(\\{nf})\K\\{vf\_fixp}$;\5
$\\{font\_design}(\\{nf})\K\\{round}(\\{tfm\_conv}\ast\\{vf\_pquad})$;\5
$\|k\K\\{vf\_ubyte}$;\5
$\\{pckt\_room}(1)$;\5
$\\{append\_byte}(\|k)$;\5
$\\{Incr}(\|k)(\\{vf\_ubyte})$;\5
$\\{pckt\_room}(\|k)$;\6
\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{append\_byte}(\\{vf\_ubyte})$;\5
$\\{decr}(\|k)$;\6
\&{end};\2\6
$\\{font\_name}(\\{nf})\K\\{make\_packet}$;\C{the font area plus name}\6
$\\{vf\_i\_fnts}[\\{vf\_nf}]\K\\{make\_font}$;\6
\&{if} $\\{vf\_nf}=\\{lcl\_nf}$ \1\&{then}\6
\&{if} $\\{lcl\_nf}=\\{max\_fonts}$ \1\&{then}\5
$\\{overflow}(\\{str\_fonts},\39\\{max\_fonts})$\6
\4\&{else} $\\{incr}(\\{lcl\_nf})$;\2\2\6
$\\{incr}(\\{vf\_nf})$;\6
\&{end};\par
\fi

\N151.  Reading VF files.
The \\{do\_vf} function attempts to read the \.{VF} file for a font and
returns \\{false} if the \.{VF} file could not be found; when the \.{VF}
file has been read, the font type is changed to \\{vf\_font\_type}.

\Y\P\4\&{function}\1\  \37\\{do\_vf}: \37\\{boolean};\C{read a \.{VF} file}\6
\4\&{label} \37$\\{reswitch},\39\\{done},\39\\{not\_found},\39\\{exit}$;\6
\4\&{var} \37\\{temp\_int}: \37\\{int\_32};\C{integer for temporary variables}\6
\\{temp\_byte}: \37\\{int\_8u};\C{byte for temporary variables}\6
\|k: \37\\{byte\_pointer};\C{index into \\{byte\_mem}}\6
\|l: \37\\{int\_15};\C{general purpose variable}\6
\\{save\_ext}: \37\\{int\_24};\C{used to save \\{cur\_ext}}\6
\\{save\_res}: \37\\{int\_8u};\C{used to save \\{cur\_res}}\6
\\{save\_wp}: \37\\{width\_pointer};\C{used to save \\{cur\_wp}}\6
\\{save\_upd}: \37\\{boolean};\C{used to save \\{cur\_upd}}\6
\\{vf\_wp}: \37\\{width\_pointer};\C{width pointer for the current character
packet}\6
\\{vf\_fnt}: \37\\{font\_number};\C{current font in the current character
packet}\6
\\{move\_zero}: \37\\{boolean};\C{\\{true} if rule 1 is used}\6
\\{last\_pop}: \37\\{boolean};\C{\\{true} if final \\{pop} has been
manufactured}\2\6
\&{begin} \37\X139:VF: Open \\{vf\_file} or \&{goto} \\{not\_found}\X;\6
$\\{save\_ext}\K\\{cur\_ext}$;\5
$\\{save\_res}\K\\{cur\_res}$;\5
$\\{save\_wp}\K\\{cur\_wp}$;\5
$\\{save\_upd}\K\\{cur\_upd}$;\C{save}\6
$\\{font\_type}(\\{cur\_fnt})\K\\{vf\_font\_type}$;\6
\X152:VF: Process the preamble\X;\6
\X153:VF: Process the font definitions\X;\6
\&{while} $\\{cur\_cmd}\L\\{long\_char}$ \1\&{do}\5
\X160:VF: Build a character packet\X;\2\6
\&{if} $\\{cur\_cmd}\I\\{post}$ \1\&{then}\5
\\{bad\_font};\2\6
\&{debug} \37$\\{print}(\.{\'VF\ file\ for\ font\ \'},\39\\{cur\_fnt}:1)$;\5
$\\{print\_font}(\\{cur\_fnt})$;\5
$\\{print\_ln}(\.{\'\ loaded.\'})$;\6
\&{gubed}\6
$\\{close\_in}(\\{vf\_file})$;\5
$\\{cur\_ext}\K\\{save\_ext}$;\5
$\\{cur\_res}\K\\{save\_res}$;\5
$\\{cur\_wp}\K\\{save\_wp}$;\5
$\\{cur\_upd}\K\\{save\_upd}$;\C{restore}\6
$\\{do\_vf}\K\\{true}$;\5
\&{return};\6
\4\\{not\_found}: \37$\\{do\_vf}\K\\{false}$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M152. \P$\X152:VF: Process the preamble\X\S$\6
\&{if} $\\{vf\_ubyte}\I\\{pre}$ \1\&{then}\5
\\{bad\_font};\2\6
\&{if} $\\{vf\_ubyte}\I\\{vf\_id}$ \1\&{then}\5
\\{bad\_font};\2\6
$\\{temp\_byte}\K\\{vf\_ubyte}$;\5
$\\{pckt\_room}(\\{temp\_byte})$;\6
\&{for} $\|l\K1\mathrel{\&{to}}\\{temp\_byte}$ \1\&{do}\5
$\\{append\_byte}(\\{vf\_ubyte})$;\2\6
$\\{print}(\.{\'VF\ file:\ \'}\.{\'\'})$;\5
$\\{print\_packet}(\\{new\_packet})$;\5
$\\{print}(\.{\'\'}\.{\',\'})$;\5
\\{flush\_packet};\6
$\\{check\_check\_sum}(\\{vf\_squad},\39\\{false})$;\5
$\\{check\_design\_size}(\\{round}(\\{tfm\_conv}\ast\\{vf\_pquad}))$;\6
$\|z\K\\{font\_scaled}(\\{cur\_fnt})$;\5
\X106:Replace \|z by $\|z^\prime$ and compute $\alpha,\beta$\X;\6
$\\{print\_nl}(\.{\'\ \ \ for\ font\ \'},\39\\{cur\_fnt}:1)$;\5
$\\{print\_font}(\\{cur\_fnt})$;\5
$\\{print\_ln}(\.{\'.\'})$\par
\U151.\fi

\M153. \P$\X153:VF: Process the font definitions\X\S$\6
$\\{vf\_i\_fnts}[0]\K\\{invalid\_font}$;\5
$\\{vf\_nf}\K0$;\6
$\\{cur\_cmd}\K\\{vf\_ubyte}$;\6
\&{while} $(\\{cur\_cmd}\G\\{fnt\_def1})\W(\\{cur\_cmd}\L\\{fnt\_def1}+3)$ \1%
\&{do}\6
\&{begin} \37\&{case} $\\{cur\_cmd}-\\{fnt\_def1}$ \1\&{of}\6
\40: \37$\\{cur\_parm}\K\\{vf\_ubyte}$;\6
\41: \37$\\{cur\_parm}\K\\{vf\_upair}$;\6
\42: \37$\\{cur\_parm}\K\\{vf\_utrio}$;\6
\43: \37$\\{cur\_parm}\K\\{vf\_squad}$;\2\6
\&{end};\C{there are no other cases}\6
\\{vf\_do\_font};\5
$\\{cur\_cmd}\K\\{vf\_ubyte}$;\6
\&{end};\2\6
$\\{font\_font}(\\{cur\_fnt})\K\\{vf\_i\_fnts}[0]$\par
\U151.\fi

\M154. The \.{VF} format specifies that the interpretation of each packet
begins with $\|w=\|x=\|y=\|z=0$; any \\{w0}, \\{x0}, \\{y0}, or \\{z0} command
using
these initial values will be ignored.

\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{vf\_state}=$\1\5
\&{array} $[0\to1,\390\to1]$ \1\&{of}\5
\\{boolean};\C{state of \|w, \|x, \|y, and \|z}\2\2\par
\fi

\M155. As implied by the \.{VF} format the \.{DVI} commands read from the
\.{VF} file are enclosed by \\{push} and \\{pop}; as we read \.{DVI}
commands and append them to \\{byte\_mem}, we perform a set of
transformations in order to simplify the resulting packet: Let \\{zero} be
any of the commands \\{put}, \\{put\_rule}, \\{fnt\_num}, \\{fnt}, or \\{xxx}
which
all leave the current position on the page unchanged, let \\{move} be any
of the horizontal or vertical movement commands $\\{right1}\to\\{z4}$, and let
\\{any} be any sequence of commands containing \\{push} and \\{pop} in
properly nested pairs; whenever possible we apply one of the following
transformation rules: $$\def\n#1:{\hbox to 3cm{\hfil#1:}}
\leqalignno{
\hbox{\\{push} \\{zero}}&\RA\hbox{\\{zero} \\{push}}&\n1:\cr
\hbox{\\{move} \\{pop}}&\RA\hbox{\\{pop}}&\n2:\cr
\hbox{\\{push} \\{pop}}&\RA{}&\n3:\cr
\hbox{\\{push} \\{set\_char} \\{pop}}&\RA\hbox{\\{put}}&\n4a:\cr
\hbox{\\{push} \\{set} \\{pop}}&\RA\hbox{\\{put}}&\n4b:\cr
\hbox{\\{push} \\{set\_rule} \\{pop}}&\RA\hbox{\\{put\_rule}}&\n4c:\cr
\hbox{\\{push} \\{push} \\{any} \\{pop}}&\RA\hbox{\\{push} \\{any} \\{pop} %
\\{push}}&\n5:\cr
\hbox{\\{push} \\{any} \\{pop} \\{pop}}&\RA\hbox{\\{any} \\{pop}}&\n6:\cr
}$$

\fi

\M156. In order to perform these transformations we need a stack which is
indexed by \\{vf\_ptr}, the number of \\{push} commands without corresponding
\\{pop} in the packet we are building; the \\{vf\_push\_loc} array contains
the locations in \\{byte\_mem} following such \\{push} commands.
In view of rule~5 consecutive \\{push} commands are never stored, the
\\{vf\_push\_num} array is used to count them.
The \\{vf\_last} array indicates the type of the last non-discardable item:
a character, a rule, or a group enclosed by \\{push} and \\{pop};
the \\{vf\_last\_end} array points to the ending locations and, if
$\\{vf\_last}\I\\{vf\_other}$, the \\{vf\_last\_loc} array points to the
starting
locations of these items.

\Y\P\D \37$\\{vf\_set}=0$\C{$\\{vf\_set}=\\{char\_cl}$, last item is a \\{set%
\_char} or \\{set}}\par
\P\D \37$\\{vf\_rule}=1$\C{$\\{vf\_rule}=\\{rule\_cl}$, last item is a \\{set%
\_rule}}\par
\P\D \37$\\{vf\_group}=2$\C{last item is a group enclosed by \\{push} and %
\\{pop}}\par
\P\D \37$\\{vf\_put}=3$\C{last item is a \\{put}}\par
\P\D \37$\\{vf\_other}=4$\C{last item (if any) is none of the above}\par
\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{vf\_type}=\\{vf\_set}\to\\{vf\_other}$;\par
\fi

\M157. \P$\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{vf\_move}: \37\&{array} $[\\{stack\_pointer}]$ \1\&{of}\5
\\{vf\_state};\C{state of \|w, \|x, \|y, and \|z}\2\6
\4\\{vf\_push\_loc}: \37\&{array} $[\\{stack\_pointer}]$ \1\&{of}\5
\\{byte\_pointer};\C{end of a \\{push}}\2\6
\4\\{vf\_last\_loc}: \37\&{array} $[\\{stack\_pointer}]$ \1\&{of}\5
\\{byte\_pointer};\C{start of an item}\2\6
\4\\{vf\_last\_end}: \37\&{array} $[\\{stack\_pointer}]$ \1\&{of}\5
\\{byte\_pointer};\C{end of an item}\2\6
\4\\{vf\_push\_num}: \37\&{array} $[\\{stack\_pointer}]$ \1\&{of}\5
\\{eight\_bits};\C{\\{push} count}\2\6
\4\\{vf\_last}: \37\&{array} $[\\{stack\_pointer}]$ \1\&{of}\5
\\{vf\_type};\C{type of last item}\2\6
\4\\{vf\_ptr}: \37\\{stack\_pointer};\C{current number of unfinished groups}\6
\4\\{stack\_used}: \37\\{stack\_pointer};\C{largest \\{vf\_ptr} or \\{stack%
\_ptr} value}\par
\fi

\M158. We use two small arrays to determine the item type of a character or a
rule.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{vf\_char\_type}: \37\&{array} $[\\{boolean}]$ \1\&{of}\5
\\{vf\_type};\2\6
\4\\{vf\_rule\_type}: \37\&{array} $[\\{boolean}]$ \1\&{of}\5
\\{vf\_type};\2\par
\fi

\M159. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{vf\_move}[0][0][0]\K\\{false}$;\5
$\\{vf\_move}[0][0][1]\K\\{false}$;\5
$\\{vf\_move}[0][1][0]\K\\{false}$;\5
$\\{vf\_move}[0][1][1]\K\\{false}$;\6
$\\{stack\_used}\K0$;\6
$\\{vf\_char\_type}[\\{false}]\K\\{vf\_put}$;\5
$\\{vf\_char\_type}[\\{true}]\K\\{vf\_set}$;\6
$\\{vf\_rule\_type}[\\{false}]\K\\{vf\_other}$;\5
$\\{vf\_rule\_type}[\\{true}]\K\\{vf\_rule}$;\par
\fi

\M160. Here we read the first bytes of a character packet from the \.{VF}
file and initialize the packet being built in \\{byte\_mem}; the start of
the whole packet is stored in $\\{vf\_push\_loc}[0]$. When the character
packet is finished, a type is be assigned to it: \\{vf\_simple} if the
packet ends with a character of the correct width, or \\{vf\_complex}
otherwise. Moreover, if such a packet for a character with
extension zero consists of just one character with extension zero and
the same residue, and if there is no previous packet, the whole packet
is replaced by the empty packet.

\Y\P\D \37$\\{vf\_simple}=0$\C{the packet ends with a character of the correct
width}\par
\P\D \37$\\{vf\_complex}=\\{vf\_simple}+1$\C{otherwise}\par
\Y\P$\4\X160:VF: Build a character packet\X\S$\6
\&{begin} \37\&{if} $\\{cur\_cmd}<\\{long\_char}$ \1\&{then}\6
\&{begin} \37$\\{vf\_limit}\K\\{cur\_cmd}$;\5
$\\{cur\_ext}\K0$;\5
$\\{cur\_res}\K\\{vf\_ubyte}$;\5
$\\{vf\_wp}\K\\{check\_width}(\\{vf\_fix3u})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{vf\_limit}\K\\{vf\_uquad}$;\5
$\\{cur\_ext}\K\\{vf\_strio}$;\5
$\\{cur\_res}\K\\{vf\_ubyte}$;\5
$\\{vf\_wp}\K\\{check\_width}(\\{vf\_fix4})$;\6
\&{end};\2\6
$\\{Incr}(\\{vf\_limit})(\\{vf\_loc})$;\5
$\\{vf\_push\_loc}[0]\K\\{byte\_ptr}$;\5
$\\{vf\_last\_end}[0]\K\\{byte\_ptr}$;\5
$\\{vf\_last}[0]\K\\{vf\_other}$;\5
$\\{vf\_ptr}\K0$;\6
$\\{start\_packet}(\\{vf\_complex})$;\5
\X161:VF: Append \.{DVI} commands to the character packet\X;\6
$\|k\K\\{pckt\_start}[\\{pckt\_ptr}]$;\6
\&{if} $\\{vf\_last}[0]=\\{vf\_put}$ \1\&{then}\6
\&{if} $\\{cur\_wp}=\\{vf\_wp}$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{byte\_mem}[\|k])$;\C{change \\{vf\_complex} into %
\\{vf\_simple}}\6
\&{if} $(\\{byte\_mem}[\|k]=\\{bi}(0))\W\30(\\{vf\_push\_loc}[0]=\\{vf\_last%
\_loc}[0])\W\30(\\{cur\_ext}=0)\W\30(\\{cur\_res}=\\{pckt\_res})$ \1\&{then}\5
$\\{byte\_ptr}\K\|k$;\2\6
\&{end};\2\2\6
\\{build\_packet};\5
$\\{cur\_cmd}\K\\{vf\_ubyte}$;\6
\&{end}\par
\U151.\fi

\M161. For every \.{DVI} command read from the \.{VF} file some action is
performed; in addition the initial \\{push} and the final \\{pop} are
manufactured here.

\Y\P$\4\X161:VF: Append \.{DVI} commands to the character packet\X\S$\6
$\\{vf\_cur\_fnt}\K\\{font\_font}(\\{cur\_fnt})$;\5
$\\{vf\_fnt}\K\\{vf\_cur\_fnt}$;\6
$\\{last\_pop}\K\\{false}$;\5
$\\{cur\_class}\K\\{push\_cl}$;\C{initial \\{push}}\6
\~ \1\&{loop}\6
\&{begin} \37\\{reswitch}: \37\&{case} $\\{cur\_class}$ \1\&{of}\6
\4$\\{three\_cases}(\\{char\_cl})$: \37\X164:VF: Do a \\{char}, \\{rule}, or %
\\{xxx}\X;\6
\4\\{push\_cl}: \37\X162:VF: Do a \\{push}\X;\6
\4\\{pop\_cl}: \37\X168:VF: Do a \\{pop}\X;\6
\4$\\{two\_cases}(\\{w0\_cl})$: \37\&{if} $\\{vf\_move}[\\{vf\_ptr}][0][\\{cur%
\_class}-\\{w0\_cl}]$ \1\&{then}\5
$\\{append\_one}(\\{cur\_cmd})$;\2\6
\4$\\{three\_cases}(\\{right\_cl})$: \37\&{begin} \37$\\{pckt\_signed}(\\{dvi%
\_right\_cmd}[\\{cur\_class}],\39\\{cur\_parm})$;\6
\&{if} $\\{cur\_class}\G\\{w\_cl}$ \1\&{then}\5
$\\{vf\_move}[\\{vf\_ptr}][0][\\{cur\_class}-\\{w\_cl}]\K\\{true}$;\2\6
\&{end};\6
\4$\\{two\_cases}(\\{y0\_cl})$: \37\&{if} $\\{vf\_move}[\\{vf\_ptr}][1][\\{cur%
\_class}-\\{y0\_cl}]$ \1\&{then}\5
$\\{append\_one}(\\{cur\_cmd})$;\2\6
\4$\\{three\_cases}(\\{down\_cl})$: \37\&{begin} \37$\\{pckt\_signed}(\\{dvi%
\_down\_cmd}[\\{cur\_class}],\39\\{cur\_parm})$;\6
\&{if} $\\{cur\_class}\G\\{y\_cl}$ \1\&{then}\5
$\\{vf\_move}[\\{vf\_ptr}][1][\\{cur\_class}-\\{y\_cl}]\K\\{true}$;\2\6
\&{end};\6
\4\\{fnt\_cl}: \37\\{vf\_font};\6
\4\\{fnt\_def\_cl}: \37\\{bad\_font};\6
\4\\{invalid\_cl}: \37\&{if} $\\{cur\_cmd}\I\\{nop}$ \1\&{then}\5
\\{bad\_font};\2\2\6
\&{end};\C{there are no other cases}\6
\&{if} $\\{vf\_loc}<\\{vf\_limit}$ \1\&{then}\5
\\{vf\_first\_par}\6
\4\&{else} \&{if} $\\{last\_pop}$ \1\&{then}\5
\&{goto} \37\\{done}\6
\4\&{else} \&{begin} \37$\\{cur\_class}\K\\{pop\_cl}$;\5
$\\{last\_pop}\K\\{true}$;\C{final \\{pop}}\6
\&{end};\2\2\6
\&{end};\2\6
\4\\{done}: \37\&{if} $(\\{vf\_ptr}\I0)\V(\\{vf\_loc}\I\\{vf\_limit})$ \1%
\&{then}\5
\\{bad\_font}\2\par
\U160.\fi

\M162. For a \\{push} we either increase \\{vf\_push\_num} or start a new level
and
append a \\{push}.

\Y\P\D \37$\\{incr\_stack}(\#)\S$\1\6
\&{if} $\#=\\{stack\_used}$ \1\&{then}\6
\&{if} $\\{stack\_used}=\\{stack\_size}$ \1\&{then}\5
$\\{overflow}(\\{str\_stack},\39\\{stack\_size})$\6
\4\&{else} $\\{incr}(\\{stack\_used})$;\2\2\2\6
$\\{incr}(\#)$\par
\Y\P$\4\X162:VF: Do a \\{push}\X\S$\6
\&{if} $(\\{vf\_ptr}>0)\W(\\{vf\_push\_loc}[\\{vf\_ptr}]=\\{byte\_ptr})$ \1%
\&{then}\6
\&{begin} \37\&{if} $\\{vf\_push\_num}[\\{vf\_ptr}]=255$ \1\&{then}\5
$\\{overflow}(\\{str\_stack},\39255)$;\2\6
$\\{incr}(\\{vf\_push\_num}[\\{vf\_ptr}])$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{incr\_stack}(\\{vf\_ptr})$;\5
\X163:VF: Start a new level\X;\6
$\\{vf\_push\_num}[\\{vf\_ptr}]\K0$;\6
\&{end}\2\par
\U161.\fi

\M163. \P$\X163:VF: Start a new level\X\S$\6
$\\{append\_one}(\\{push})$;\5
$\\{vf\_move}[\\{vf\_ptr}]\K\\{vf\_move}[\\{vf\_ptr}-1]$;\5
$\\{vf\_push\_loc}[\\{vf\_ptr}]\K\\{byte\_ptr}$;\5
$\\{vf\_last\_end}[\\{vf\_ptr}]\K\\{byte\_ptr}$;\5
$\\{vf\_last}[\\{vf\_ptr}]\K\\{vf\_other}$\par
\Us162\ET172.\fi

\M164. When a character, a rule, or an \\{xxx} is appended, transformation
rule~1 might be applicable.

\Y\P$\4\X164:VF: Do a \\{char}, \\{rule}, or \\{xxx}\X\S$\6
\&{begin} \37\&{if} $(\\{vf\_ptr}=0)\V(\\{byte\_ptr}>\\{vf\_push\_loc}[\\{vf%
\_ptr}])$ \1\&{then}\5
$\\{move\_zero}\K\\{false}$\6
\4\&{else} \&{case} $\\{cur\_class}$ \1\&{of}\6
\4\\{char\_cl}: \37$\\{move\_zero}\K(\R\\{cur\_upd})\V(\\{vf\_cur\_fnt}\I\\{vf%
\_fnt})$;\6
\4\\{rule\_cl}: \37$\\{move\_zero}\K\R\\{cur\_upd}$;\6
\4\\{xxx\_cl}: \37$\\{move\_zero}\K\\{true}$;\2\6
\&{end};\C{there are no other cases}\2\6
\&{if} $\\{move\_zero}$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{byte\_ptr})$;\5
$\\{decr}(\\{vf\_ptr})$;\6
\&{end};\2\6
\&{case} $\\{cur\_class}$ \1\&{of}\6
\4\\{char\_cl}: \37\X165:VF: Do a \\{fnt}, a \\{char}, or both\X;\6
\4\\{rule\_cl}: \37\X166:VF: Do a \\{rule}\X;\6
\4\\{xxx\_cl}: \37\X167:VF: Do an \\{xxx}\X;\2\6
\&{end};\C{there are no other cases}\6
$\\{vf\_last\_end}[\\{vf\_ptr}]\K\\{byte\_ptr}$;\6
\&{if} $\\{move\_zero}$ \1\&{then}\6
\&{begin} \37$\\{incr}(\\{vf\_ptr})$;\5
$\\{append\_one}(\\{push})$;\5
$\\{vf\_push\_loc}[\\{vf\_ptr}]\K\\{byte\_ptr}$;\5
$\\{vf\_last\_end}[\\{vf\_ptr}]\K\\{byte\_ptr}$;\6
\&{if} $\\{cur\_class}=\\{char\_cl}$ \1\&{then}\6
\&{if} $\\{cur\_upd}$ \1\&{then}\5
\&{goto} \37\\{reswitch};\2\2\6
\&{end};\2\6
\&{end}\par
\U161.\fi

\M165. A special situation arises if transformation rule~1 is applied to a
\\{fnt\_num} of \\{fnt} command, but not to the \\{set\_char} or \\{set}
command
following it; in this case \\{cur\_upd} and \\{move\_zero} are both \\{true}
and
the \\{set\_char} or \\{set} command will be appended later.

\Y\P$\4\X165:VF: Do a \\{fnt}, a \\{char}, or both\X\S$\6
\&{begin} \37\&{if} $\\{vf\_cur\_fnt}\I\\{vf\_fnt}$ \1\&{then}\6
\&{begin} \37$\\{vf\_last}[\\{vf\_ptr}]\K\\{vf\_other}$;\5
$\\{pckt\_unsigned}(\\{fnt1},\39\\{vf\_cur\_fnt})$;\5
$\\{vf\_fnt}\K\\{vf\_cur\_fnt}$;\6
\&{end};\2\6
\&{if} $(\R\\{move\_zero})\V(\R\\{cur\_upd})$ \1\&{then}\6
\&{begin} \37$\\{vf\_last}[\\{vf\_ptr}]\K\\{vf\_char\_type}[\\{cur\_upd}]$;\5
$\\{vf\_last\_loc}[\\{vf\_ptr}]\K\\{byte\_ptr}$;\5
$\\{pckt\_char}(\\{cur\_upd},\39\\{cur\_ext},\39\\{cur\_res})$;\6
\&{end};\2\6
\&{end}\par
\U164.\fi

\M166. \P$\X166:VF: Do a \\{rule}\X\S$\6
\&{begin} \37$\\{vf\_last}[\\{vf\_ptr}]\K\\{vf\_rule\_type}[\\{cur\_upd}]$;\5
$\\{vf\_last\_loc}[\\{vf\_ptr}]\K\\{byte\_ptr}$;\5
$\\{append\_one}(\\{dvi\_rule\_cmd}[\\{cur\_upd}])$;\5
$\\{pckt\_four}(\\{cur\_v\_dimen})$;\5
$\\{pckt\_four}(\\{cur\_h\_dimen})$;\6
\&{end}\par
\U164.\fi

\M167. \P$\X167:VF: Do an \\{xxx}\X\S$\6
\&{begin} \37$\\{vf\_last}[\\{vf\_ptr}]\K\\{vf\_other}$;\5
$\\{pckt\_unsigned}(\\{xxx1},\39\\{cur\_parm})$;\5
$\\{pckt\_room}(\\{cur\_parm})$;\6
\&{while} $\\{cur\_parm}>0$ \1\&{do}\6
\&{begin} \37$\\{append\_byte}(\\{vf\_ubyte})$;\5
$\\{decr}(\\{cur\_parm})$;\6
\&{end};\2\6
\&{end}\par
\U164.\fi

\M168. Transformation rules 2--6 are triggered by a \\{pop}, either read from
the \.{VF} file or manufactured at the end of the packet.

\Y\P$\4\X168:VF: Do a \\{pop}\X\S$\6
\&{begin} \37\&{if} $\\{vf\_ptr}<1$ \1\&{then}\5
\\{bad\_font};\2\6
$\\{byte\_ptr}\K\\{vf\_last\_end}[\\{vf\_ptr}]$;\C{this is rule 2}\6
\&{if} $\\{vf\_last}[\\{vf\_ptr}]\L\\{vf\_rule}$ \1\&{then}\6
\&{if} $\\{vf\_last\_loc}[\\{vf\_ptr}]=\\{vf\_push\_loc}[\\{vf\_ptr}]$ \1%
\&{then}\5
\X169:VF: Prepare for rule 4\X;\2\2\6
\&{if} $\\{byte\_ptr}=\\{vf\_push\_loc}[\\{vf\_ptr}]$ \1\&{then}\5
\X170:VF: Apply rule 3 or 4\X\6
\4\&{else} \&{begin} \37\&{if} $\\{vf\_last}[\\{vf\_ptr}]=\\{vf\_group}$ \1%
\&{then}\5
\X171:VF: Apply rule 6\X;\2\6
$\\{append\_one}(\\{pop})$;\5
$\\{decr}(\\{vf\_ptr})$;\5
$\\{vf\_last}[\\{vf\_ptr}]\K\\{vf\_group}$;\5
$\\{vf\_last\_loc}[\\{vf\_ptr}]\K\\{vf\_push\_loc}[\\{vf\_ptr}+1]-1$;\5
$\\{vf\_last\_end}[\\{vf\_ptr}]\K\\{byte\_ptr}$;\6
\&{if} $\\{vf\_push\_num}[\\{vf\_ptr}+1]>0$ \1\&{then}\5
\X172:VF: Apply rule 5\X;\2\6
\&{end};\2\6
\&{end}\par
\U161.\fi

\M169. In order to implement transformation rule~4, we cancel the \\{set%
\_char},
\\{set}, or \\{set\_rule}, append a \\{pop}, and insert a \\{put} or \\{put%
\_rule}
with the old parameters.

\Y\P$\4\X169:VF: Prepare for rule 4\X\S$\6
\&{begin} \37$\\{cur\_class}\K\\{vf\_last}[\\{vf\_ptr}]$;\5
$\\{cur\_upd}\K\\{false}$;\5
$\\{byte\_ptr}\K\\{vf\_push\_loc}[\\{vf\_ptr}]$;\6
\&{end}\par
\U168.\fi

\M170. \P$\X170:VF: Apply rule 3 or 4\X\S$\6
\&{begin} \37\&{if} $\\{vf\_push\_num}[\\{vf\_ptr}]>0$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{vf\_push\_num}[\\{vf\_ptr}])$;\5
$\\{vf\_move}[\\{vf\_ptr}]\K\\{vf\_move}[\\{vf\_ptr}-1]$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{decr}(\\{byte\_ptr})$;\5
$\\{decr}(\\{vf\_ptr})$;\6
\&{end};\2\6
\&{if} $\\{cur\_class}\I\\{pop\_cl}$ \1\&{then}\5
\&{goto} \37\\{reswitch};\C{this is rule 4}\2\6
\&{end}\par
\U168.\fi

\M171. \P$\X171:VF: Apply rule 6\X\S$\6
\&{begin} \37$\\{Decr}(\\{byte\_ptr})(2)$;\6
\&{for} $\|k\K\\{vf\_last\_loc}[\\{vf\_ptr}]+1\mathrel{\&{to}}\\{byte\_ptr}$ \1%
\&{do}\5
$\\{byte\_mem}[\|k-1]\K\\{byte\_mem}[\|k]$;\2\6
$\\{vf\_last}[\\{vf\_ptr}]\K\\{vf\_other}$;\5
$\\{vf\_last\_end}[\\{vf\_ptr}]\K\\{byte\_ptr}$;\6
\&{end}\par
\U168.\fi

\M172. \P$\X172:VF: Apply rule 5\X\S$\6
\&{begin} \37$\\{incr}(\\{vf\_ptr})$;\5
\X163:VF: Start a new level\X;\6
$\\{decr}(\\{vf\_push\_num}[\\{vf\_ptr}])$;\6
\&{end}\par
\U168.\fi

\M173. The \.{VF} format specifies that after a character packet invoked by a
\\{set\_char} or \\{set} command, ``\|h~is increased by the \.{TFM} width
(properly scaled)---just as if a simple character had been typeset'';
for \\{vf\_simple} packets this is achieved by changing the final \\{put}
command into \\{set\_char} or \\{set}, but for \\{vf\_complex} packets an
explicit movement must be done. This poses a problem for programs,
such as \.{DVIcopy}, which write a new \.{DVI} file with all references
to characters from virtual fonts replaced by their character packets:
The \.{DVItype} program specifies that the horizontal movements after a
\\{set\_char} or \\{set} command, after a \\{set\_rule} command, and after one
of the commands $\\{right1}\to\\{x4}$, are all treated differently when \.{DVI}
units are converted to pixels.

Thus we introduce a slight extension of \.{DVItype}'s pixel rounding
algorithm and hope that this extension will become part of the standard
\.{DVItype} program in the near future: If a \.{DVI} file contains a
\\{set\_rule} command for a rule with the negative height \\{width\_dimen},
then this rule shall be treated in exactly the same way as a ficticious
character whose width is the width of that rule; as value of \\{width\_dimen}
we choose $-2^{31}$, the smallest signed 32-bit integer.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{width\_dimen}: \37\\{int\_32};\C{vertical dimension of special rules}\par
\fi

\M174. When initializing \\{width\_dimen} we are careful to avoid arithmetic
overflow.

\Y\P$\4\X18:Set initial values\X\mathrel{+}\S$\6
$\\{width\_dimen}\K-\H{40000000}$;\5
$\\{Decr}(\\{width\_dimen})(\H{40000000})$;\par
\fi

\N175.  Terminal communication.
When \.{\title} begins, it engages the user in a brief dialog so that
various options may be specified. This part of \.{\title} requires
nonstandard \PASCAL\ constructions to handle the online interaction; so
it may be preferable in some cases to omit the dialog and simply to
stick to the default options. On other hand, the system-dependent
routines that are needed are not complicated, so it will not be terribly
difficult to introduce them; furthermore they are similar to those in
\.{DVItype}.

The \\{input\_ln} routine waits for the user to type a line at his or her
terminal; then it puts ASCII-code equivalents for the characters on that
line into the \\{byte\_mem} array as a temporary string. \PASCAL's
standard \\{input} file is used for terminal input, as \\{output} is used
for terminal output.

Since the terminal is being used for both input and output, some systems
need a special routine to make sure that the user can see a prompt message
before waiting for input based on that message. (Otherwise the message
may just be sitting in a hidden buffer somewhere, and the user will have
no idea what the program is waiting for.) We shall invoke a system-dependent
subroutine \\{update\_terminal} in order to avoid this problem.

\Y\P\D \37$\\{update\_terminal}\S\\{break}(\\{output})$\C{empty the terminal
output buffer}\Y\par
\P\D \37$\\{scan\_skip}\S$\C{skip blanks}\6
\&{while} $(\\{byte\_mem}[\\{scan\_ptr}]=\\{bi}(\.{"\ "}))\W(\\{scan\_ptr}<%
\\{byte\_ptr})$ \1\&{do}\5
$\\{incr}(\\{scan\_ptr})$\2\par
\P\D \37$\\{scan\_init}\S$\C{initialize \\{scan\_ptr}}\6
$\\{byte\_mem}[\\{byte\_ptr}]\K\\{bi}(\.{"\ "})$;\5
$\\{scan\_ptr}\K\\{pckt\_start}[\\{pckt\_ptr}-1]$;\5
\\{scan\_skip}\par
\Y\P$\4\X175:Action procedures for \\{dialog}\X\S$\6
\4\&{procedure}\1\  \37\\{input\_ln};\C{inputs a line from the terminal}\6
\4\&{var} \37\|k: \37$0\to\\{terminal\_line\_length}$;\2\6
\&{begin} \37$\\{print}(\.{\'Enter\ option:\ \'})$;\5
\\{update\_terminal};\5
$\\{reset}(\\{input})$;\6
\&{if} $\\{eoln}(\\{input})$ \1\&{then}\5
$\\{read\_ln}(\\{input})$;\2\6
$\|k\K0$;\5
$\\{pckt\_room}(\\{terminal\_line\_length})$;\6
\&{while} $(\|k<\\{terminal\_line\_length})\W\R\\{eoln}(\\{input})$ \1\&{do}\6
\&{begin} \37$\\{append\_byte}(\\{xord}[\\{input}\^])$;\5
$\\{incr}(\|k)$;\5
$\\{get}(\\{input})$;\6
\&{end};\2\6
\&{end};\par
\As177, 178\ETs191.
\U179.\fi

\M176. The global variable \\{scan\_ptr} is used while scanning the temporary
packet; it points to the next byte in \\{byte\_mem} to be examined.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{scan\_ptr}: \37\\{byte\_pointer};\C{pointer to next byte to be examined}%
\par
\fi

\M177. The \\{scan\_keyword} function is used to test for keywords in a
character
string stored as temporary packet in \\{byte\_mem}; the result is \\{true}
(and \\{scan\_ptr} is updated) if the characters starting at position
\\{scan\_ptr} are an abbreviation of a given keyword followed by at least
one blank.

\Y\P$\4\X175:Action procedures for \\{dialog}\X\mathrel{+}\S$\6
\4\&{function}\1\  \37$\\{scan\_keyword}(\|p:\\{pckt\_pointer};\,\35\|l:\\{int%
\_7})$: \37\\{boolean};\6
\4\&{var} \37$\|i,\39\|j,\39\|k$: \37\\{byte\_pointer};\C{indices into \\{byte%
\_mem}}\2\6
\&{begin} \37$\|i\K\\{pckt\_start}[\|p]$;\5
$\|j\K\\{pckt\_start}[\|p+1]$;\5
$\|k\K\\{scan\_ptr}$;\6
\&{while} $(\|i<\|j)\W((\\{byte\_mem}[\|k]=\\{byte\_mem}[\|i])\V(\\{byte\_mem}[%
\|k]=\\{byte\_mem}[\|i]-\.{"a"}+\.{"A"}))$ \1\&{do}\6
\&{begin} \37$\\{incr}(\|i)$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
\&{if} $(\\{byte\_mem}[\|k]=\\{bi}(\.{"\ "}))\W(\|i-\\{pckt\_start}[\|p]\G\|l)$
\1\&{then}\6
\&{begin} \37$\\{scan\_ptr}\K\|k$;\5
\\{scan\_skip};\5
$\\{scan\_keyword}\K\\{true}$;\6
\&{end}\6
\4\&{else} $\\{scan\_keyword}\K\\{false}$;\2\6
\&{end};\par
\fi

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

\Y\P$\4\X175:Action procedures for \\{dialog}\X\mathrel{+}\S$\6
\4\&{function}\1\  \37\\{scan\_int}: \37\\{int\_32};\6
\4\&{var} \37\|x: \37\\{int\_32};\C{accumulates the value}\6
\\{negative}: \37\\{boolean};\C{should the value be negated?}\2\6
\&{begin} \37\&{if} $\\{byte\_mem}[\\{scan\_ptr}]=\.{"-"}$ \1\&{then}\6
\&{begin} \37$\\{negative}\K\\{true}$;\5
$\\{incr}(\\{scan\_ptr})$;\6
\&{end}\6
\4\&{else} $\\{negative}\K\\{false}$;\2\6
$\|x\K0$;\6
\&{while} $(\\{byte\_mem}[\\{scan\_ptr}]\G\.{"0"})\W(\\{byte\_mem}[\\{scan%
\_ptr}]\L\.{"9"})$ \1\&{do}\6
\&{begin} \37$\|x\K10\ast\|x+\\{byte\_mem}[\\{scan\_ptr}]-\.{"0"}$;\5
$\\{incr}(\\{scan\_ptr})$;\6
\&{end};\2\6
\\{scan\_skip};\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{scan\_int}\K-\|x$\ \&{else} $\\{scan\_int}\K\|x$;\2\6
\&{end};\par
\fi

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

\Y\P\X175:Action procedures for \\{dialog}\X\6
\4\&{procedure}\1\  \37\\{dialog};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|p: \37\\{pckt\_pointer};\C{packet being created}\2\6
\&{begin} \37\X189:Initialize options\X\6
\~ \1\&{loop}\6
\&{begin} \37\\{input\_ln};\5
$\|p\K\\{new\_packet}$;\5
\\{scan\_init};\6
\&{if} $\\{scan\_ptr}=\\{byte\_ptr}$ \1\&{then}\6
\&{begin} \37\\{flush\_packet};\5
\&{return};\6
\&{end}\2\6
\X192:Cases for options\X\6
\4\&{else} \37\&{begin} \37$\\{print\_ln}(\.{\'Valid\ options\ are:\'})$;\5
\X190:Print valid options\X\6
\&{end};\5
\\{flush\_packet};\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\N180.  Subroutines for typesetting commands.
This is the central part of the whole \.{\title} program:
When a typesetting command from the \.{DVI} file or from a \.{VF} packet
has been decoded, one of the typesetting routines defined below is
invoked to execute the command; apart from the necessary book keeping,
these routines invoke device dependent code defined later.

\Y\P\X240:Declare typesetting procedures\X\par
\fi

\M181. These typesetting routines communicate with the rest of the program
through global variables.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{type\_setting}: \37\\{boolean};\C{\\{true} while typesetting a page}\6
\&{device} \37\\{h\_conv}: \37\\{real};\C{converts \.{DVI} units to horizontal
pixels}\6
\4\\{v\_conv}: \37\\{real};\C{converts \.{DVI} units to vertical pixels}\6
\4\\{h\_pixels}: \37\\{pix\_value};\C{a horizontal dimension in pixels}\6
\4\\{v\_pixels}: \37\\{pix\_value};\C{a vertical dimension in pixels}\6
\4\\{temp\_pix}: \37\\{pix\_value};\C{temporary value for pixel rounding}\6
\&{ecived}\par
\fi

\M182. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{type\_setting}\K\\{false}$;\par
\fi

\M183. A stack is used to keep track of the current horizonal and vertical
position, \|h and \|v, and the four registers \|w, \|x, \|y, and \|z;
the register pairs $(\|w,\|x)$ and $(\|y,\|z)$ are maintained as arrays.

\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{stack\_pointer}=0\to\\{stack\_size}$;\6
$\\{stack\_index}=1\to\\{stack\_size}$;\6
$\\{pair\_32}=$\1\5
\&{array} $[0\to1]$ \1\&{of}\5
\\{int\_32};\C{a pair of \\{int\_32} variables}\2\2\6
$\\{stack\_record}=$\1\5
\1\&{record} \37\\{h\_field}: \37\\{int\_32};\C{horizontal position \|h}\6
\4\\{v\_field}: \37\\{int\_32};\C{vertical position \|v}\6
\&{device} \37\\{hh\_field}: \37\\{pix\_value};\C{horizontal pixel position %
\\{hh}}\6
\4\\{vv\_field}: \37\\{pix\_value};\C{vertical pixel position \\{vv}}\6
\&{ecived}\6
\4\\{w\_x\_field}: \37\\{pair\_32};\C{\|w and \|x register for horizontal
movements}\6
\4\\{y\_z\_field}: \37\\{pair\_32};\C{\|y and \|z register for vertical
movements}\2\6
\&{end};\2\par
\fi

\M184. The current values are kept in \\{cur\_stack}; they are pushed onto and
popped from \\{stack}. We use \.{WEB} macros to access the current values.

\Y\P\D \37$\\{cur\_h}\S\\{cur\_stack}.\\{h\_field}$\C{the current \|h value}\par
\P\D \37$\\{cur\_v}\S\\{cur\_stack}.\\{v\_field}$\C{the current \|v value}\par
\P\D \37$\\{cur\_hh}\S\\{cur\_stack}.\\{hh\_field}$\C{the current \\{hh} value}%
\par
\P\D \37$\\{cur\_vv}\S\\{cur\_stack}.\\{vv\_field}$\C{the current \\{vv} value}%
\par
\P\D \37$\\{cur\_w\_x}\S\\{cur\_stack}.\\{w\_x\_field}$\C{the current \|w and %
\|x value}\par
\P\D \37$\\{cur\_y\_z}\S\\{cur\_stack}.\\{y\_z\_field}$\C{the current \|y and %
\|z value}\par
\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{stack}: \37\&{array} $[\\{stack\_index}]$ \1\&{of}\5
\\{stack\_record};\C{the pushed values}\2\6
\4\\{cur\_stack}: \37\\{stack\_record};\C{the current values}\6
\4\\{zero\_stack}: \37\\{stack\_record};\C{initial values}\6
\4\\{stack\_ptr}: \37\\{stack\_pointer};\C{last used position in \\{stack}}\par
\fi

\M185. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{zero\_stack}.\\{h\_field}\K0$;\5
$\\{zero\_stack}.\\{v\_field}\K0$;\6
\&{device} \37$\\{zero\_stack}.\\{hh\_field}\K0$;\5
$\\{zero\_stack}.\\{vv\_field}\K0$;\ \&{ecived}\6
\&{for} $\|i\K0\mathrel{\&{to}}1$ \1\&{do}\6
\&{begin} \37$\\{zero\_stack}.\\{w\_x\_field}[\|i]\K0$;\5
$\\{zero\_stack}.\\{y\_z\_field}[\|i]\K0$;\6
\&{end};\2\par
\fi

\M186. A sequence of consecutive rules, or consecutive characters in a
fixed-width
font whose width is not an integer number of pixels, can cause \\{hh} to drift
far away from a correctly rounded value. \.{\title} ensures that the
amount of drift will never exceed \\{max\_h\_drift} pixels; similarly \\{vv}
shall never drift away from the correctly rounded value by more than
\\{max\_v\_drift} pixels.

\Y\P\D \37$\\{max\_h\_drift}=2$\C{we insist that abs$(\\{hh}-\\{h\_pixel%
\_round}(\|h))\L\\{max\_drift}$}\par
\P\D \37$\\{max\_v\_drift}=2$\C{we insist that abs$(\\{vv}-\\{v\_pixel\_round}(%
\|v))\L\\{max\_drift}$}\par
\fi

\M187. The user may select up to \\{max\_select} ranges of consecutive pages to
be processed. Each 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. The number of pages is recorded in
\\{max\_pages}; a non positive value indicates that there is no limit.

\Y\P\D \37$\\{start\_count}\S\\{select\_count}[\\{cur\_select}]$\C{count values
to select   starting page}\par
\P\D \37$\\{start\_there}\S\\{select\_there}[\\{cur\_select}]$\C{is the %
\\{start\_count} value   relevant?}\par
\P\D \37$\\{start\_vals}\S\\{select\_vals}[\\{cur\_select}]$\C{the last count
considered   significant}\par
\P\D \37$\\{max\_pages}\S\\{select\_max}[\\{cur\_select}]$\C{at most this many
$\\{bop}\to\\{eop}$ pages   will be printed}\par
\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{select\_count}: \37\&{array} $[0\to\\{max\_select}-1,\390\to9]$ \1\&{of}\5
\\{int\_32};\2\6
\4\\{select\_there}: \37\&{array} $[0\to\\{max\_select}-1,\390\to9]$ \1\&{of}\5
\\{boolean};\2\6
\4\\{select\_vals}: \37\&{array} $[0\to\\{max\_select}-1]$ \1\&{of}\5
$0\to9$;\2\6
\4\\{select\_max}: \37\&{array} $[0\to\\{max\_select}-1]$ \1\&{of}\5
\\{int\_32};\2\6
\4\\{out\_mag}: \37\\{int\_32};\C{output maginfication}\6
\4\\{count}: \37\&{array} $[0\to9]$ \1\&{of}\5
\\{int\_32};\C{the count values on the current page}\2\6
\4\\{num\_select}: \37$0\to\\{max\_select}$;\C{number of page selection ranges
specified}\6
\4\\{cur\_select}: \37$0\to\\{max\_select}$;\C{current page selection range}\6
\4\\{selected}: \37\\{boolean};\C{has starting page been found?}\6
\4\\{all\_done}: \37\\{boolean};\C{have all selected pages been processed?}\6
\4$\\{str\_mag},\39\\{str\_select}$: \37\\{pckt\_pointer};\par
\fi

\M188. 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

\M189. \P$\X189:Initialize options\X\S$\6
$\\{out\_mag}\K0$;\5
$\\{cur\_select}\K0$;\5
$\\{max\_pages}\K0$;\5
$\\{selected}\K\\{true}$;\par
\U179.\fi

\M190. \P$\X190:Print valid options\X\S$\6
$\\{print\_ln}(\.{\'\ \ mag\ <mag>\'})$;\5
$\\{print\_ln}(\.{\'\ \ select\ <first\ page>\ [<num\ pages>]\'})$;\par
\U179.\fi

\M191. \P$\X175:Action procedures for \\{dialog}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{scan\_count};\C{scan a \\{start\_count} value}\2\6
\&{begin} \37\&{if} $\\{byte\_mem}[\\{scan\_ptr}]=\\{bi}(\.{"*"})$ \1\&{then}\6
\&{begin} \37$\\{start\_there}[\\{start\_vals}]\K\\{false}$;\5
$\\{incr}(\\{scan\_ptr})$;\5
\\{scan\_skip};\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{start\_there}[\\{start\_vals}]\K\\{true}$;\5
$\\{start\_count}[\\{start\_vals}]\K\\{scan\_int}$;\6
\&{if} $\\{cur\_select}=0$ \1\&{then}\5
$\\{selected}\K\\{false}$;\C{don't start at first page}\2\6
\&{end};\2\6
\&{end};\par
\fi

\M192. \P$\X192:Cases for options\X\S$\6
\4\&{else} \37\&{if} $\\{scan\_keyword}(\\{str\_mag},\393)$ \1\&{then}\5
$\\{out\_mag}\K\\{scan\_int}$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\\{str\_select},\393)$ \1\&{then}\6
\&{if} $\\{cur\_select}=\\{max\_select}$ \1\&{then}\5
$\\{print\_ln}(\.{\'Too\ many\ page\ selections\'})$\6
\4\&{else} \&{begin} \37$\\{start\_vals}\K0$;\5
\\{scan\_count};\6
\&{while} $(\\{start\_vals}<9)\W(\\{byte\_mem}[\\{scan\_ptr}]=\\{bi}(\.{"."}))$
\1\&{do}\6
\&{begin} \37$\\{incr}(\\{start\_vals})$;\5
$\\{incr}(\\{scan\_ptr})$;\5
\\{scan\_count};\6
\&{end};\2\6
$\\{max\_pages}\K\\{scan\_int}$;\5
$\\{incr}(\\{cur\_select})$;\6
\&{end}\2\2\2\par
\U179.\fi

\M193. \P$\X45:Initialize predefined strings\X\mathrel{+}\S$\6
$\\{id3}(\.{"m"})(\.{"a"})(\.{"g"})(\\{str\_mag})$;\5
$\\{id6}(\.{"s"})(\.{"e"})(\.{"l"})(\.{"e"})(\.{"c"})(\.{"t"})(\\{str%
\_select})$;\par
\fi

\M194. The routines defined below use sections named `Declare local variables
(if any) for \dots' or `Declare additional local variables for \dots';
the former may declare variables (including the keyword \&{var}), whereas
the later must at least contain the keyword \&{var}. In general, both may
start with the declaration of labels, constants, and\slash or types.

Let us start with the simple cases:
The \\{do\_pre} procedure is called when the preamble has been read from
the \.{DVI} file; the preamble comment has just been converted into a
temporary packet with the \\{new\_packet} procedure.

\Y\P\4\&{procedure}\1\  \37\\{do\_pre};\6
\X250:OUT: Declare local variables (if any) for \\{do\_pre}\X\2\6
\&{begin} \37$\\{all\_done}\K\\{false}$;\5
$\\{num\_select}\K\\{cur\_select}$;\5
$\\{cur\_select}\K0$;\6
\&{if} $\\{num\_select}=0$ \1\&{then}\5
$\\{max\_pages}\K0$;\2\6
\X251:OUT: Process the \\{pre}\X\6
\&{device} \37$\\{h\_conv}\K(\\{dvi\_num}/254000.0)\ast(\\{h\_resolution}/%
\\{dvi\_den})\ast(\\{out\_mag}/1000.0)$;\5
$\\{v\_conv}\K(\\{dvi\_num}/254000.0)\ast(\\{v\_resolution}/\\{dvi\_den})\ast(%
\\{out\_mag}/1000.0)$;\6
\&{ecived}\6
\&{end};\par
\fi

\M195. The \\{do\_bop} procedure is called when a \\{bop} has been read. This
routine determines whether a page shall be processed or skipped and sets
the variable \\{type\_setting} accordingly.

\Y\P\4\&{procedure}\1\  \37\\{do\_bop};\6
\X252:OUT: Declare additional local variables \\{do\_bop}\X\6
\4$\|i,\39\|j$: \37$0\to9$;\C{indices into \\{count}}\2\6
\&{begin} \37\X196:Determine whether this page should be processed or skipped%
\X;\6
$\\{print}(\.{\'DVI:\ \'})$;\6
\&{if} $\\{type\_setting}$ \1\&{then}\5
$\\{print}(\.{\'process\'})$\ \&{else} $\\{print}(\.{\'skipp\'})$;\2\6
$\\{print}(\.{\'ing\ page\ \'},\39\\{count}[0]:1)$;\5
$\|j\K9$;\6
\&{while} $(\|j>0)\W(\\{count}[\|j]=0)$ \1\&{do}\5
$\\{decr}(\|j)$;\2\6
\&{for} $\|i\K1\mathrel{\&{to}}\|j$ \1\&{do}\5
$\\{print}(\.{\'.\'},\39\\{count}[\|i]:1)$;\2\6
$\\{d\_print}(\.{\'\ at\ \'},\39\\{dvi\_loc}-45:1)$;\5
$\\{print\_ln}(\.{\'.\'})$;\6
\&{if} $\\{type\_setting}$ \1\&{then}\6
\&{begin} \37$\\{stack\_ptr}\K0$;\5
$\\{cur\_stack}\K\\{zero\_stack}$;\5
$\\{cur\_fnt}\K\\{invalid\_font}$;\6
\X253:OUT: Process a \\{bop}\X\6
\&{end};\2\6
\&{end};\par
\fi

\M196. \P$\X196:Determine whether this page should be processed or skipped\X\S$%
\6
\&{if} $\R\\{selected}$ \1\&{then}\5
$\\{selected}\K\\{start\_match}$;\2\6
$\\{type\_setting}\K\\{selected}$\par
\U195.\fi

\M197. The \\{do\_eop} procedure is called in order to process an \\{eop};
the stack should be empty.

\Y\P\4\&{procedure}\1\  \37\\{do\_eop};\6
\X254:OUT: Declare local variables (if any) for \\{do\_eop}\X\2\6
\&{begin} \37\&{if} $\\{stack\_ptr}\I0$ \1\&{then}\5
\\{bad\_dvi};\2\6
\X255:OUT: Process an \\{eop}\X\6
\&{if} $\\{max\_pages}>0$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{max\_pages})$;\6
\&{if} $\\{max\_pages}=0$ \1\&{then}\6
\&{begin} \37$\\{selected}\K\\{false}$;\5
$\\{incr}(\\{cur\_select})$;\6
\&{if} $\\{cur\_select}=\\{num\_select}$ \1\&{then}\5
$\\{all\_done}\K\\{true}$;\2\6
\&{end};\2\6
\&{end};\2\6
$\\{type\_setting}\K\\{false}$;\6
\&{end};\par
\fi

\M198. The procedures \\{do\_push} and \\{do\_pop} are called in order to
process
\\{push} and \\{pop} commands; \\{do\_push} must check for stack overflow,
\\{do\_pop} should never be called when the stack is empty.

\Y\P\4\&{procedure}\1\  \37\\{do\_push};\C{push onto stack}\6
\X256:OUT: Declare local variables (if any) for \\{do\_push}\X\2\6
\&{begin} \37$\\{incr\_stack}(\\{stack\_ptr})$;\5
$\\{stack}[\\{stack\_ptr}]\K\\{cur\_stack}$;\6
\X257:OUT: Process a \\{push}\X\6
\&{end};\7
\4\&{procedure}\1\  \37\\{do\_pop};\C{pop from stack}\6
\X258:OUT: Declare local variables (if any) for \\{do\_pop}\X\2\6
\&{begin} \37\&{if} $\\{stack\_ptr}=0$ \1\&{then}\5
\\{bad\_dvi};\2\6
\X259:OUT: Process a \\{pop}\X\6
$\\{cur\_stack}\K\\{stack}[\\{stack\_ptr}]$;\5
$\\{decr}(\\{stack\_ptr})$;\6
\&{end};\par
\fi

\M199. The \\{do\_xxx} procedure is called in order to process a special
command.
The bytes of the special string have been put into \\{byte\_mem} as the
current string. They are converted to a temporary packet and discarded
again.

\Y\P\4\&{procedure}\1\  \37\\{do\_xxx};\6
\X260:OUT: Declare additional local variables for \\{do\_xxx}\X\6
\4\|p: \37\\{pckt\_pointer};\C{temporary packet}\2\6
\&{begin} \37$\|p\K\\{new\_packet}$;\6
\X261:OUT: Process an \\{xxx}\X\6
\\{flush\_packet};\6
\&{end};\par
\fi

\M200. Next are the movement commands:
The \\{do\_right} procedure is called in order to process the horizontal
movement commands \\{right}, \|w, and \|x.

\Y\P\D \37$\\{do\_h\_pixels}(\#)\S$\C{check for proper horizontal pixel
rounding}\6
\&{begin} \37$\\{Incr}(\\{cur\_hh})(\#)$;\5
$\\{temp\_pix}\K\\{h\_pixel\_round}(\\{cur\_h})$;\6
\&{if} $\\{abs}(\\{temp\_pix}-\\{cur\_hh})>\\{max\_h\_drift}$ \1\&{then}\6
\&{if} $\\{temp\_pix}>\\{cur\_hh}$ \1\&{then}\5
$\\{cur\_hh}\K\\{temp\_pix}-\\{max\_h\_drift}$\6
\4\&{else} $\\{cur\_hh}\K\\{temp\_pix}+\\{max\_h\_drift}$;\2\2\6
\&{end}\par
\Y\P\4\&{procedure}\1\  \37\\{do\_right};\6
\X262:OUT: Declare local variables (if any) for \\{do\_right}\X\2\6
\&{begin} \37\&{if} $\\{cur\_class}\G\\{w\_cl}$ \1\&{then}\5
$\\{cur\_w\_x}[\\{cur\_class}-\\{w\_cl}]\K\\{cur\_parm}$\6
\4\&{else} \&{if} $\\{cur\_class}<\\{right\_cl}$ \1\&{then}\5
$\\{cur\_parm}\K\\{cur\_w\_x}[\\{cur\_class}-\\{w0\_cl}]$;\2\2\6
\X263:OUT: Process a \\{right} or \|w or \|x\X\6
$\\{Incr}(\\{cur\_h})(\\{cur\_parm})$;\6
\&{device} \37\&{if} $(\\{cur\_parm}\G\\{font\_space}(\\{cur\_fnt}))\V(\\{cur%
\_parm}\L-4\ast\\{font\_space}(\\{cur\_fnt}))$ \1\&{then}\5
$\\{cur\_hh}\K\\{h\_pixel\_round}(\\{cur\_h})$\6
\4\&{else} $\\{do\_h\_pixels}(\\{h\_pixel\_round}(\\{cur\_parm}))$;\2\6
\&{ecived}\6
\X264:OUT: Move right\X\6
\&{end};\par
\fi

\M201. The \\{do\_down} procedure is called in order to process the vertical
movement commands \\{down}, \|y, and \|z.

\Y\P\D \37$\\{do\_v\_pixels}(\#)\S$\C{check for proper vertical pixel rounding}%
\6
\&{begin} \37$\\{Incr}(\\{cur\_vv})(\#)$;\5
$\\{temp\_pix}\K\\{v\_pixel\_round}(\\{cur\_v})$;\6
\&{if} $\\{abs}(\\{temp\_pix}-\\{cur\_vv})>\\{max\_v\_drift}$ \1\&{then}\6
\&{if} $\\{temp\_pix}>\\{cur\_vv}$ \1\&{then}\5
$\\{cur\_vv}\K\\{temp\_pix}-\\{max\_v\_drift}$\6
\4\&{else} $\\{cur\_vv}\K\\{temp\_pix}+\\{max\_v\_drift}$;\2\2\6
\&{end}\par
\Y\P\4\&{procedure}\1\  \37\\{do\_down};\6
\X265:OUT: Declare local variables (if any) for \\{do\_down}\X\2\6
\&{begin} \37\&{if} $\\{cur\_class}\G\\{y\_cl}$ \1\&{then}\5
$\\{cur\_y\_z}[\\{cur\_class}-\\{y\_cl}]\K\\{cur\_parm}$\6
\4\&{else} \&{if} $\\{cur\_class}<\\{down\_cl}$ \1\&{then}\5
$\\{cur\_parm}\K\\{cur\_y\_z}[\\{cur\_class}-\\{y0\_cl}]$;\2\2\6
\X266:OUT: Process a \\{down} or \|y or \|z\X\6
$\\{Incr}(\\{cur\_v})(\\{cur\_parm})$;\6
\&{device} \37\&{if} $\\{abs}(\\{cur\_parm})\G5\ast\\{font\_space}(\\{cur%
\_fnt})$ \1\&{then}\5
$\\{cur\_vv}\K\\{v\_pixel\_round}(\\{cur\_v})$\6
\4\&{else} $\\{do\_v\_pixels}(\\{v\_pixel\_round}(\\{cur\_parm}))$;\2\6
\&{ecived}\6
\X267:OUT: Move down\X\6
\&{end};\par
\fi

\M202. The \\{do\_width} procedure is called in order to increase the current
horizontal position \\{cur\_h} by \\{cur\_h\_dimen} in exactly the same way
as if a character of width \\{cur\_h\_dimen} had been typeset.

\Y\P\4\&{procedure}\1\  \37\\{do\_width};\6
\X268:OUT: Declare local variables (if any) for \\{do\_width}\X\2\6
\&{begin} \37\X269:OUT: Typeset a \\{width}\X\6
$\\{Incr}(\\{cur\_h})(\\{cur\_h\_dimen})$;\6
\&{device} \37$\\{do\_h\_pixels}(\\{h\_pixels})$;\ \&{ecived}\6
\X264:OUT: Move right\X\6
\&{end};\par
\fi

\M203. Finally we have the commands for the typesetting of rules and
characters;
the global variable \\{cur\_upd} is \\{true} if the horizontal position shall
be updated (\\{set} commands).

Here are two other subroutine that we need: They computes 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
\\{h\_conv} and \\{v\_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\&{device} \37\&{function}\1\  \37$\\{h\_rule\_pixels}(\|x:\\{int\_32})$: %
\37\\{pix\_value};\C{computes $\lceil\\{h\_conv}\cdot x\rceil$}\6
\4\&{var} \37\|n: \37\\{int\_32};\2\6
\&{begin} \37$\|n\K\\{trunc}(\\{h\_conv}\ast\|x)$;\6
\&{if} $\|n<\\{h\_conv}\ast\|x$ \1\&{then}\5
$\\{h\_rule\_pixels}\K\|n+1$\ \&{else} $\\{h\_rule\_pixels}\K\|n$;\2\6
\&{end};\7
\4\&{function}\1\  \37$\\{v\_rule\_pixels}(\|x:\\{int\_32})$: \37\\{pix%
\_value};\C{computes $\lceil\\{v\_conv}\cdot x\rceil$}\6
\4\&{var} \37\|n: \37\\{int\_32};\2\6
\&{begin} \37$\|n\K\\{trunc}(\\{v\_conv}\ast\|x)$;\6
\&{if} $\|n<\\{v\_conv}\ast\|x$ \1\&{then}\5
$\\{v\_rule\_pixels}\K\|n+1$\ \&{else} $\\{v\_rule\_pixels}\K\|n$;\2\6
\&{end};\6
\&{ecived}\par
\fi

\M204. The \\{do\_rule} procedure is called in order to typeset a rule.

\Y\P\4\&{procedure}\1\  \37\\{do\_rule};\6
\X270:OUT: Declare additional local variables \\{do\_rule}\X\6
\4\\{visible}: \37\\{boolean};\2\6
\&{begin} \37\&{if} $(\\{cur\_h\_dimen}>0)\W(\\{cur\_v\_dimen}>0)$ \1\&{then}\6
\&{begin} \37$\\{visible}\K\\{true}$;\6
\&{device} \37$\\{h\_pixels}\K\\{h\_rule\_pixels}(\\{cur\_h\_dimen})$;\5
$\\{v\_pixels}\K\\{v\_rule\_pixels}(\\{cur\_v\_dimen})$;\6
\&{ecived}\6
\X271:OUT: Typeset a visible \\{rule}\X\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{visible}\K\\{false}$;\5
\X272:OUT: Typeset an invisible \\{rule}\X\6
\&{end};\2\6
\&{if} $\\{cur\_upd}$ \1\&{then}\6
\&{begin} \37$\\{Incr}(\\{cur\_h})(\\{cur\_h\_dimen})$;\6
\&{device} \37\&{if} $\R\\{visible}$ \1\&{then}\5
$\\{h\_pixels}\K\\{h\_rule\_pixels}(\\{cur\_h\_dimen})$;\2\6
$\\{do\_h\_pixels}(\\{h\_pixels})$;\6
\&{ecived}\6
\X264:OUT: Move right\X\6
\&{end};\2\6
\&{end};\par
\fi

\M205. Last not least the \\{do\_char} procedure is called in order to typeset
character~\\{cur\_res} with extension~\\{cur\_ext} from the real font~\\{cur%
\_fnt}.

\Y\P\4\&{procedure}\1\  \37\\{do\_char};\6
\X276:OUT: Declare local variables (if any) for \\{do\_char}\X\2\6
\&{begin} \37\X277:OUT: Typeset a \\{char}\X\6
\&{if} $\\{cur\_upd}$ \1\&{then}\6
\&{begin} \37$\\{Incr}(\\{cur\_h})(\\{widths}[\\{cur\_wp}])$;\6
\&{device} \37$\\{do\_h\_pixels}(\\{font\_pixel}(\\{cur\_fnt})(\\{cur\_res}))$;%
\ \&{ecived}\6
\X264:OUT: Move right\X\6
\&{end};\2\6
\&{end};\par
\fi

\M206. If the program terminates abnormally, the following code may be
invoked in the middle of a page.

\Y\P$\4\X206:Finish output file(s)\X\S$\6
\&{begin} \37\&{if} $\\{type\_setting}$ \1\&{then}\5
\X278:OUT: Finish incomplete page\X;\2\6
\X279:OUT: Finish output file(s)\X\6
\&{end}\par
\U230.\fi

\M207. When the first character of font~\\{cur\_fnt} is about to be typeset,
the \\{do\_font} procedure is called in order to decide whether this is
a virtual font or a real font.

One step in this decision is the attempt to find and read the \.{VF}
file for this font; other attempts to locate a font file may be performed
before and after that, depending on the nature of the output device and
on the structure of the file system at a particular installation.

In any case \\{do\_font} must change $\\{font\_type}(\\{cur\_fnt})$ from \\{new%
\_font\_type}
to anything else; as a last resort one might use the \.{TFM} width data
and leave blank spaces in the output.

\Y\P\4\&{procedure}\1\  \37\\{do\_font};\6
\4\&{label} \37\\{done};\6
\X273:OUT: Declare local variables (if any) for \\{do\_font}\X\2\6
\&{begin} \37\X274:OUT: Look for a font file before trying to read the \.{VF}
file; if found \&{goto} \\{done}\X\6
\&{if} $\\{do\_vf}$ \1\&{then}\5
\&{goto} \37\\{done};\C{try to read the \.{VF} file}\2\6
\X275:OUT: Look for a font file after trying to read the \.{VF} file\X\6
\4\\{done}: \37\&{debug} \37\&{if} $\\{font\_type}(\\{cur\_fnt})=\\{new\_font%
\_type}$ \1\&{then}\5
$\\{confusion}(\\{str\_fonts})$;\2\6
\&{gubed}\6
\&{end};\par
\fi

\N208.  Interpreting VF packets.
The \\{pckt\_first\_par} procedure first reads a \.{DVI} command byte from
the packet into \\{cur\_cmd}; then \\{cur\_parm} is set to the value of the
first parameter (if any) and \\{cur\_class} to the command class.

\Y\P\4\&{procedure}\1\  \37\\{pckt\_first\_par};\2\6
\&{begin} \37$\\{cur\_cmd}\K\\{pckt\_ubyte}$;\6
\&{case} $\\{dvi\_par}[\\{cur\_cmd}]$ \1\&{of}\6
\4\\{char\_par}: \37$\\{set\_cur\_char}(\\{pckt\_ubyte})$;\6
\4\\{no\_par}: \37\\{do\_nothing};\6
\4\\{dim1\_par}: \37$\\{cur\_parm}\K\\{pckt\_sbyte}$;\6
\4\\{num1\_par}: \37$\\{cur\_parm}\K\\{pckt\_ubyte}$;\6
\4\\{dim2\_par}: \37$\\{cur\_parm}\K\\{pckt\_spair}$;\6
\4\\{num2\_par}: \37$\\{cur\_parm}\K\\{pckt\_upair}$;\6
\4\\{dim3\_par}: \37$\\{cur\_parm}\K\\{pckt\_strio}$;\6
\4\\{num3\_par}: \37$\\{cur\_parm}\K\\{pckt\_utrio}$;\6
\4$\\{three\_cases}(\\{dim4\_par})$: \37$\\{cur\_parm}\K\\{pckt\_squad}$;\C{%
\\{dim4}, \\{num4}, or \\{numu}}\6
\4\\{rule\_par}: \37\&{begin} \37$\\{cur\_v\_dimen}\K\\{pckt\_squad}$;\5
$\\{cur\_h\_dimen}\K\\{pckt\_squad}$;\5
$\\{cur\_upd}\K(\\{cur\_cmd}=\\{set\_rule})$;\6
\&{end};\6
\4\\{fnt\_par}: \37$\\{cur\_parm}\K\\{cur\_cmd}-\\{fnt\_num\_0}$;\2\6
\&{end};\C{there are no other cases}\6
$\\{cur\_class}\K\\{dvi\_cl}[\\{cur\_cmd}]$;\6
\&{end};\par
\fi

\M209. The \\{do\_vf\_packet} procedure is called in order to interpret the
character packet for a virtual character. Such a packet may contain the
instruction to typeset a character from the same or an other virtual
font; in such cases \\{do\_vf\_packet} calls itself recursively. The
recursion level, i.e., the number of times this has happened, is kept
in the global variable \\{n\_recur} and should not exceed \\{max\_recursion}.

\Y\P$\4\X7:Types in the outer block\X\mathrel{+}\S$\6
$\\{recur\_pointer}=0\to\\{max\_recursion}$;\par
\fi

\M210. The \.{\title} processor should detect an infinite recursion caused by
bad \.{VF} files; thus a new recursion level is entered even in cases
where this could be avoided without difficulty.

If the recursion level exceeds the allowed maximum, we want to give
a traceback how this has happened; thus some of the global variables
used in different invocations of \\{do\_vf\_packet} are saved in a stack,
others are saved as local variables of \\{do\_vf\_packet}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{recur\_fnt}: \37\&{array} $[\\{recur\_pointer}]$ \1\&{of}\5
\\{font\_number};\C{this packet's font}\2\6
\4\\{recur\_ext}: \37\&{array} $[\\{recur\_pointer}]$ \1\&{of}\5
\\{int\_24};\C{this packet's extension}\2\6
\4\\{recur\_res}: \37\&{array} $[\\{recur\_pointer}]$ \1\&{of}\5
\\{eight\_bits};\C{this packet's residue}\2\6
\4\\{recur\_pckt}: \37\&{array} $[\\{recur\_pointer}]$ \1\&{of}\5
\\{pckt\_pointer};\C{the packet}\2\6
\4\\{recur\_loc}: \37\&{array} $[\\{recur\_pointer}]$ \1\&{of}\5
\\{byte\_pointer};\C{next byte of packet}\2\6
\4\\{n\_recur}: \37\\{recur\_pointer};\C{current recursion level}\6
\4\\{recur\_used}: \37\\{recur\_pointer};\C{highest recursion level used so
far}\par
\fi

\M211. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{n\_recur}\K0$;\5
$\\{recur\_used}\K0$;\par
\fi

\M212. Here now is the \\{do\_vf\_packet} procedure.

\Y\P\4\&{procedure}\1\  \37\\{do\_vf\_packet};\6
\4\&{label} \37$\\{continue},\39\\{found},\39\\{done}$;\6
\4\&{var} \37\|k: \37\\{recur\_pointer};\C{loop index}\6
\|f: \37\\{int\_8u};\C{packet type flag}\6
\\{save\_upd}: \37\\{boolean};\C{used to save \\{cur\_upd}}\6
\\{save\_wp}: \37\\{width\_pointer};\C{used to save \\{cur\_wp}}\6
\\{save\_limit}: \37\\{byte\_pointer};\C{used to save \\{cur\_limit}}\2\6
\&{begin} \37\X213:VF: Save values on entry to \\{do\_vf\_packet}\X;\6
\X215:VF: Interpret the \.{DVI} commands in the packet\X\6
\&{if} $\\{save\_upd}$ \1\&{then}\6
\&{begin} \37$\\{cur\_h\_dimen}\K\\{widths}[\\{save\_wp}]$;\6
\&{device} \37$\\{h\_pixels}\K\\{pix\_widths}[\\{save\_wp}]$;\ \&{ecived}\6
\\{do\_width};\6
\&{end};\2\6
\X214:VF: Restore values on exit from \\{do\_vf\_packet}\X;\6
\&{end};\par
\fi

\M213. On entry to \\{do\_vf\_packet} several values must be saved.

\Y\P$\4\X213:VF: Save values on entry to \\{do\_vf\_packet}\X\S$\6
$\\{save\_upd}\K\\{cur\_upd}$;\5
$\\{save\_wp}\K\\{cur\_wp}$;\6
$\\{recur\_fnt}[\\{n\_recur}]\K\\{cur\_fnt}$;\5
$\\{recur\_ext}[\\{n\_recur}]\K\\{cur\_ext}$;\5
$\\{recur\_res}[\\{n\_recur}]\K\\{cur\_res}$\par
\U212.\fi

\M214. Some of these values must be restored on exit from \\{do\_vf\_packet}.

\Y\P$\4\X214:VF: Restore values on exit from \\{do\_vf\_packet}\X\S$\6
$\\{cur\_fnt}\K\\{recur\_fnt}[\\{n\_recur}]$\par
\U212.\fi

\M215. If \\{cur\_pckt} is the empty packet, we manufacture a \\{put} command;
otherwise we read and interpret \.{DVI} commands from the packet.

\Y\P$\4\X215:VF: Interpret the \.{DVI} commands in the packet\X\S$\6
\&{if} $\\{find\_packet}$ \1\&{then}\5
$\|f\K\\{cur\_type}$\ \&{else} \&{goto} \37\\{done};\2\6
$\\{recur\_pckt}[\\{n\_recur}]\K\\{cur\_pckt}$;\5
$\\{save\_limit}\K\\{cur\_limit}$;\5
$\\{cur\_fnt}\K\\{font\_font}(\\{cur\_fnt})$;\6
\&{if} $\\{cur\_pckt}=\\{empty\_packet}$ \1\&{then}\6
\&{begin} \37$\\{cur\_class}\K\\{char\_cl}$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
\&{if} $\\{cur\_loc}\G\\{cur\_limit}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\4\\{continue}: \37\\{pckt\_first\_par};\6
\4\\{found}: \37\&{case} $\\{cur\_class}$ \1\&{of}\6
\4\\{char\_cl}: \37\X216:VF: Typeset a \\{char}\X;\6
\4\\{rule\_cl}: \37\\{do\_rule};\6
\4\\{xxx\_cl}: \37\&{begin} \37$\\{pckt\_room}(\\{cur\_parm})$;\6
\&{while} $\\{cur\_parm}>0$ \1\&{do}\6
\&{begin} \37$\\{append\_byte}(\\{pckt\_ubyte})$;\5
$\\{decr}(\\{cur\_parm})$;\6
\&{end};\2\6
\\{do\_xxx};\6
\&{end};\6
\4\\{push\_cl}: \37\\{do\_push};\6
\4\\{pop\_cl}: \37\\{do\_pop};\6
\4$\\{five\_cases}(\\{w0\_cl})$: \37\\{do\_right};\C{\\{right}, \|w, or \|x}\6
\4$\\{five\_cases}(\\{y0\_cl})$: \37\\{do\_down};\C{\\{down}, \|y, or \|z}\6
\4\\{fnt\_cl}: \37$\\{cur\_fnt}\K\\{cur\_parm}$;\6
\4\&{othercases} \37$\\{confusion}(\\{str\_packets})$;\C{font definition or
invalid}\2\6
\&{endcases};\6
\&{if} $\\{cur\_loc}<\\{cur\_limit}$ \1\&{then}\5
\&{goto} \37\\{continue};\2\6
\4\\{done}: \37\par
\U212.\fi

\M216. When a font is used for the first time, the \\{do\_font} procedure is
called to decide whether this is a virtual font or not.
The final \\{put} of a simple packet may be changed into \\{set\_char} or
\\{set}.

\Y\P$\4\X216:VF: Typeset a \\{char}\X\S$\6
\&{begin} \37$\\{cur\_wp}\K\\{font\_width}(\\{cur\_fnt})(\\{cur\_res})$;\6
\&{if} $\\{font\_type}(\\{cur\_fnt})=\\{new\_font\_type}$ \1\&{then}\5
\\{do\_font};\C{\\{cur\_fnt} was not yet used}\2\6
\&{if} $(\\{cur\_loc}=\\{cur\_limit})\W(\|f=\\{vf\_simple})\W\\{save\_upd}$ \1%
\&{then}\6
\&{begin} \37$\\{save\_upd}\K\\{false}$;\5
$\\{cur\_upd}\K\\{true}$;\6
\&{end};\2\6
\&{if} $\\{font\_type}(\\{cur\_fnt})=\\{vf\_font\_type}$ \1\&{then}\5
\X217:VF: Enter a new recursion level\X\6
\4\&{else} \\{do\_char};\2\6
\&{end}\par
\U215.\fi

\M217. Before entering a new recursion level we must test for overflow; in
addition a few variables must be saved and restored.
A \\{set\_char} or \\{set} followed by \\{pop} is changed into \\{put}.

\Y\P$\4\X217:VF: Enter a new recursion level\X\S$\6
\&{begin} \37$\\{recur\_loc}[\\{n\_recur}]\K\\{cur\_loc}$;\C{save}\6
\&{if} $\\{cur\_loc}<\\{cur\_limit}$ \1\&{then}\6
\&{if} $\\{byte\_mem}[\\{cur\_loc}]=\\{bi}(\\{pop})$ \1\&{then}\5
$\\{cur\_upd}\K\\{false}$;\2\2\6
\&{if} $\\{n\_recur}=\\{recur\_used}$ \1\&{then}\6
\&{if} $\\{recur\_used}=\\{max\_recursion}$ \1\&{then}\5
\X218:VF: Display the recursion traceback and terminate\X\6
\4\&{else} $\\{incr}(\\{recur\_used})$;\2\2\6
$\\{incr}(\\{n\_recur})$;\5
\\{do\_vf\_packet};\5
$\\{decr}(\\{n\_recur})$;\C{recurse}\6
$\\{cur\_loc}\K\\{recur\_loc}[\\{n\_recur}]$;\5
$\\{cur\_limit}\K\\{save\_limit}$;\C{restore}\6
\&{end}\par
\U216.\fi

\M218. \P$\X218:VF: Display the recursion traceback and terminate\X\S$\6
\&{begin} \37$\\{print\_ln}(\.{\'\ !Infinite\ VF\ recursion?\'})$;\6
\&{for} $\|k\K\\{max\_recursion}\mathrel{\&{downto}}0$ \1\&{do}\6
\&{begin} \37$\\{print}(\.{\'level=\'},\39\|k:1,\39\.{\'\ font\'})$;\5
$\\{d\_print}(\.{\'=\'},\39\\{recur\_fnt}[\|k]:1)$;\5
$\\{print\_font}(\\{recur\_fnt}[\|k])$;\5
$\\{print}(\.{\'\ char=\'},\39\\{recur\_res}[\|k]:1)$;\6
\&{if} $\\{recur\_ext}[\|k]\I0$ \1\&{then}\5
$\\{print}(\.{\'.\'},\39\\{recur\_ext}[\|k]:1)$;\2\6
\\{new\_line};\6
\&{debug} \37$\\{hex\_packet}(\\{recur\_pckt}[\|k])$;\5
$\\{print\_ln}(\.{\'loc=\'},\39\\{recur\_loc}[\|k]:1)$;\6
\&{gubed}\6
\&{end};\2\6
$\\{overflow}(\\{str\_recursion},\39\\{max\_recursion})$;\6
\&{end}\par
\U217.\fi

\N219.  Interpreting the DVI file.
The \\{do\_dvi} procedure reads the entire \.{DVI} file and initiates
whatever actions may be necessary.

\Y\P\4\&{procedure}\1\  \37\\{do\_dvi};\6
\4\&{label} \37$\\{done},\39\\{exit}$;\6
\4\&{var} \37\\{temp\_byte}: \37\\{int\_8u};\C{byte for temporary variables}\6
\\{temp\_int}: \37\\{int\_32};\C{integer for temporary variables}\6
\\{dvi\_start}: \37\\{int\_32};\C{starting location}\6
\\{dvi\_bop\_post}: \37\\{int\_32};\C{location of \\{bop} or \\{post}}\6
\\{dvi\_back}: \37\\{int\_32};\C{a back pointer}\6
\|k: \37\\{int\_15};\C{general purpose variable}\2\6
\&{begin} \37\X220:DVI: Process the preamble\X;\6
\&{if} $\\{random\_reading}$ \1\&{then}\5
\X222:DVI: Process the postamble\X;\2\6
\1\&{repeat} \37\\{dvi\_first\_par};\6
\&{while} $\\{cur\_class}=\\{fnt\_def\_cl}$ \1\&{do}\6
\&{begin} \37$\\{dvi\_do\_font}(\\{random\_reading})$;\5
\\{dvi\_first\_par};\6
\&{end};\2\6
\&{if} $\\{cur\_cmd}=\\{bop}$ \1\&{then}\5
\X225:DVI: Process one page\X;\2\6
\4\&{until}\5
$\\{cur\_cmd}\I\\{eop}$;\2\6
\&{if} $\\{cur\_cmd}\I\\{post}$ \1\&{then}\5
\\{bad\_dvi};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M220. \P$\X220:DVI: Process the preamble\X\S$\6
\&{if} $\\{dvi\_ubyte}\I\\{pre}$ \1\&{then}\5
\\{bad\_dvi};\2\6
\&{if} $\\{dvi\_ubyte}\I\\{dvi\_id}$ \1\&{then}\5
\\{bad\_dvi};\2\6
$\\{dvi\_num}\K\\{dvi\_pquad}$;\5
$\\{dvi\_den}\K\\{dvi\_pquad}$;\5
$\\{dvi\_mag}\K\\{dvi\_pquad}$;\5
$\\{tfm\_conv}\K(25400000.0/\\{dvi\_num})\ast(\\{dvi\_den}/473628672)/16.0$;\5
$\\{temp\_byte}\K\\{dvi\_ubyte}$;\5
$\\{pckt\_room}(\\{temp\_byte})$;\6
\&{for} $\|k\K1\mathrel{\&{to}}\\{temp\_byte}$ \1\&{do}\5
$\\{append\_byte}(\\{dvi\_ubyte})$;\2\6
$\\{print}(\.{\'DVI\ file:\ \'}\.{\'\'})$;\5
$\\{print\_packet}(\\{new\_packet})$;\5
$\\{print\_ln}(\.{\'\'}\.{\',\'})$;\5
$\\{print}(\.{\'\ \ \ num=\'},\39\\{dvi\_num}:1,\39\.{\',\ den=\'},\39\\{dvi%
\_den}:1,\39\.{\',\ mag=\'},\39\\{dvi\_mag}:1)$;\6
\&{if} $\\{out\_mag}\L0$ \1\&{then}\5
$\\{out\_mag}\K\\{dvi\_mag}$\ \&{else} $\\{print}(\.{\'\ =>\ \'},\39\\{out%
\_mag}:1)$;\2\6
$\\{print\_ln}(\.{\'.\'})$;\5
\\{do\_pre};\5
\\{flush\_packet}\par
\U219.\fi

\M221. \P$\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{dvi\_num}: \37\\{int\_31};\C{numerator}\6
\4\\{dvi\_den}: \37\\{int\_31};\C{denominator}\6
\4\\{dvi\_mag}: \37\\{int\_31};\C{magnification}\par
\fi

\M222. \P$\X222:DVI: Process the postamble\X\S$\6
\&{begin} \37$\\{dvi\_start}\K\\{dvi\_loc}$;\C{remember start of first page}\6
\X223:DVI: Find the postamble\X;\6
$\\{d\_print\_ln}(\.{\'DVI:\ postamble\ at\ \'},\39\\{dvi\_bop\_post}:1)$;\5
$\\{dvi\_back}\K\\{dvi\_pointer}$;\6
\&{if} $\\{dvi\_num}\I\\{dvi\_pquad}$ \1\&{then}\5
\\{bad\_dvi};\2\6
\&{if} $\\{dvi\_den}\I\\{dvi\_pquad}$ \1\&{then}\5
\\{bad\_dvi};\2\6
\&{if} $\\{dvi\_mag}\I\\{dvi\_pquad}$ \1\&{then}\5
\\{bad\_dvi};\2\6
$\\{temp\_int}\K\\{dvi\_squad}$;\5
$\\{temp\_int}\K\\{dvi\_squad}$;\6
\&{if} $\\{stack\_size}<\\{dvi\_upair}$ \1\&{then}\5
$\\{overflow}(\\{str\_stack},\39\\{stack\_size})$;\2\6
$\\{temp\_int}\K\\{dvi\_upair}$;\5
\\{dvi\_first\_par};\6
\&{while} $\\{cur\_class}=\\{fnt\_def\_cl}$ \1\&{do}\6
\&{begin} \37$\\{dvi\_do\_font}(\\{false})$;\5
\\{dvi\_first\_par};\6
\&{end};\2\6
\&{if} $\\{cur\_cmd}\I\\{post\_post}$ \1\&{then}\5
\\{bad\_dvi};\2\6
\&{if} $\R\\{selected}$ \1\&{then}\5
\X224:DVI: Find the starting page\X;\2\6
$\\{dvi\_move}(\\{dvi\_start})$;\C{go to first or starting page}\6
\&{end}\par
\U219.\fi

\M223. \P$\X223:DVI: Find the postamble\X\S$\6
$\\{temp\_int}\K\\{dvi\_length}-5$;\6
\1\&{repeat} \37\&{if} $\\{temp\_int}<49$ \1\&{then}\5
\\{bad\_dvi};\2\6
$\\{dvi\_move}(\\{temp\_int})$;\5
$\\{temp\_byte}\K\\{dvi\_ubyte}$;\5
$\\{decr}(\\{temp\_int})$;\6
\4\&{until}\5
$\\{temp\_byte}\I223$;\2\6
\&{if} $\\{temp\_byte}\I\\{dvi\_id}$ \1\&{then}\5
\\{bad\_dvi};\2\6
$\\{dvi\_move}(\\{temp\_int}-4)$;\6
\&{if} $\\{dvi\_ubyte}\I\\{post\_post}$ \1\&{then}\5
\\{bad\_dvi};\2\6
$\\{dvi\_bop\_post}\K\\{dvi\_pointer}$;\6
\&{if} $(\\{dvi\_bop\_post}<15)\V(\\{dvi\_bop\_post}>\\{dvi\_loc}-34)$ \1%
\&{then}\5
\\{bad\_dvi};\2\6
$\\{dvi\_move}(\\{dvi\_bop\_post})$;\6
\&{if} $\\{dvi\_ubyte}\I\\{post}$ \1\&{then}\5
\\{bad\_dvi}\2\par
\U222.\fi

\M224. \P$\X224:DVI: Find the starting page\X\S$\6
\&{begin} \37$\\{dvi\_start}\K\\{dvi\_bop\_post}$;\C{just in case}\6
\&{while} $\\{dvi\_back}\I-1$ \1\&{do}\6
\&{begin} \37\&{if} $(\\{dvi\_back}<15)\V(\\{dvi\_back}>\\{dvi\_bop\_post}-46)$
\1\&{then}\5
\\{bad\_dvi};\2\6
$\\{dvi\_bop\_post}\K\\{dvi\_back}$;\5
$\\{dvi\_move}(\\{dvi\_back})$;\6
\&{if} $\\{dvi\_ubyte}\I\\{bop}$ \1\&{then}\5
\\{bad\_dvi};\2\6
\&{for} $\|k\K0\mathrel{\&{to}}9$ \1\&{do}\5
$\\{count}[\|k]\K\\{dvi\_squad}$;\2\6
\&{if} $\\{start\_match}$ \1\&{then}\5
$\\{dvi\_start}\K\\{dvi\_bop\_post}$;\2\6
$\\{dvi\_back}\K\\{dvi\_pointer}$;\6
\&{end};\2\6
\&{end}\par
\U222.\fi

\M225. When a \\{bop} has been read, the \.{DVI} commands for one page are
interpreted until an \\{eop} is found.

\Y\P$\4\X225:DVI: Process one page\X\S$\6
\&{begin} \37\&{for} $\|k\K0\mathrel{\&{to}}9$ \1\&{do}\5
$\\{count}[\|k]\K\\{dvi\_squad}$;\2\6
$\\{temp\_int}\K\\{dvi\_pointer}$;\5
\\{do\_bop};\5
\\{dvi\_first\_par};\6
\&{if} $\\{type\_setting}$ \1\&{then}\5
\X226:DVI: Process a page; then \&{goto} \\{done}\X\6
\4\&{else} \X227:DVI: Skip a page; then \&{goto} \\{done}\X;\2\6
\4\\{done}: \37\&{if} $\\{cur\_cmd}\I\\{eop}$ \1\&{then}\5
\\{bad\_dvi};\2\6
\&{if} $\\{type\_setting}$ \1\&{then}\6
\&{begin} \37\\{do\_eop};\6
\&{if} $\\{all\_done}$ \1\&{then}\5
\&{return};\2\6
\&{end};\2\6
\&{end}\par
\U219.\fi

\M226. All \.{DVI} commands are processed, as long as $\\{cur\_class}\I%
\\{invalid\_cl}$;
then we should have found an \\{eop}.

\Y\P$\4\X226:DVI: Process a page; then \&{goto} \\{done}\X\S$\6
\~ \1\&{loop}\6
\&{begin} \37\&{case} $\\{cur\_class}$ \1\&{of}\6
\4\\{char\_cl}: \37\X228:DVI: Typeset a \\{char}\X;\6
\4\\{rule\_cl}: \37\&{if} $\\{cur\_upd}\W(\\{cur\_v\_dimen}=\\{width\_dimen})$ %
\1\&{then}\6
\&{begin} \37\&{device} \37$\\{h\_pixels}\K\\{h\_pixel\_round}(\\{cur\_h%
\_dimen})$;\ \&{ecived}\6
\\{do\_width};\6
\&{end}\6
\4\&{else} \\{do\_rule};\2\6
\4\\{xxx\_cl}: \37\&{begin} \37$\\{pckt\_room}(\\{cur\_parm})$;\6
\&{while} $\\{cur\_parm}>0$ \1\&{do}\6
\&{begin} \37$\\{append\_byte}(\\{dvi\_ubyte})$;\5
$\\{decr}(\\{cur\_parm})$;\6
\&{end};\2\6
\\{do\_xxx};\6
\&{end};\6
\4\\{push\_cl}: \37\\{do\_push};\6
\4\\{pop\_cl}: \37\\{do\_pop};\6
\4$\\{five\_cases}(\\{w0\_cl})$: \37\\{do\_right};\C{\\{right}, \|w, or \|x}\6
\4$\\{five\_cases}(\\{y0\_cl})$: \37\\{do\_down};\C{\\{down}, \|y, or \|z}\6
\4\\{fnt\_cl}: \37\\{dvi\_font};\6
\4\\{fnt\_def\_cl}: \37$\\{dvi\_do\_font}(\\{random\_reading})$;\6
\4\\{invalid\_cl}: \37\&{goto} \37\\{done};\2\6
\&{end};\C{there are no other cases}\6
\\{dvi\_first\_par};\C{get the next command}\6
\&{end}\2\par
\U225.\fi

\M227. While skipping a page all commands other than font definitions are
ignored.

\Y\P$\4\X227:DVI: Skip a page; then \&{goto} \\{done}\X\S$\6
\~ \1\&{loop}\6
\&{begin} \37\&{case} $\\{cur\_class}$ \1\&{of}\6
\4\\{xxx\_cl}: \37\&{while} $\\{cur\_parm}>0$ \1\&{do}\6
\&{begin} \37$\\{temp\_byte}\K\\{dvi\_ubyte}$;\5
$\\{decr}(\\{cur\_parm})$;\6
\&{end};\2\6
\4\\{fnt\_def\_cl}: \37$\\{dvi\_do\_font}(\\{random\_reading})$;\6
\4\\{invalid\_cl}: \37\&{goto} \37\\{done};\6
\4\&{othercases} \37\\{do\_nothing};\2\6
\&{endcases};\5
\\{dvi\_first\_par};\C{get the next command}\6
\&{end}\2\par
\U225.\fi

\M228. When a font is used for the first time, the \\{do\_font} procedure is
called to decide whether this is a virtual font or not.

\Y\P$\4\X228:DVI: Typeset a \\{char}\X\S$\6
\&{begin} \37$\\{set\_cur\_wp}(\\{cur\_fnt})(\\{bad\_dvi})$;\6
\&{if} $\\{font\_type}(\\{cur\_fnt})=\\{new\_font\_type}$ \1\&{then}\5
\\{do\_font};\C{\\{cur\_fnt} was not yet used}\2\6
\&{if} $\\{font\_type}(\\{cur\_fnt})=\\{vf\_font\_type}$ \1\&{then}\5
\\{do\_vf\_packet}\ \&{else} \\{do\_char};\2\6
\&{end}\par
\U226.\fi

\N229.  The main program.
The code for real devices is still rather incomplete.
Moreover several branches of the program have not been tested because
they are never used with \.{DVI} files made by \TeX\ and \.{VF} files
made by \.{VPtoVF}.

\fi

\M230. At the end of the program the output file(s) have to be finished and
on some systems it may be necessary to close input and\slash or output
files.

\Y\P\4\&{procedure}\1\  \37\\{close\_files\_and\_terminate};\6
\4\&{var} \37\|k: \37\\{int\_15};\C{general purpose index}\2\6
\&{begin} \37$\\{close\_in}(\\{dvi\_file})$;\6
\&{if} $\\{history}<\\{fatal\_message}$ \1\&{then}\5
\X206:Finish output file(s)\X;\2\6
\&{stat} \37\X232:Print memory usage statistics\X;\ \&{tats}\6
\X237:Close output file(s)\X\6
\X233:Print the job \\{history}\X;\6
\&{end};\par
\fi

\M231. Now we are ready to put it all together.
Here is where \.{\title} starts, and where it ends.

\Y\P\&{begin} \37\\{initialize};\C{get all variables initialized}\6
\X45:Initialize predefined strings\X\6
\\{dialog};\C{get options}\6
\X111:Open input file(s)\X\6
\X236:Open output file(s)\X\6
\\{do\_dvi};\C{process the entire \.{DVI} file}\6
\\{close\_files\_and\_terminate};\6
\4\\{final\_end}: \37\&{end}.\par
\fi

\M232. \P$\X232:Print memory usage statistics\X\S$\6
$\\{print\_ln}(\.{\'Memory\ usage\ statistics:\'})$;\5
$\\{print}(\\{dvi\_nf}:1,\39\.{\'\ dvi,\ \'},\39\\{lcl\_nf}:1,\39\.{\'\ local,\
\'})$;\5
\X247:Print more font usage statistics\X\6
$\\{print\_ln}(\.{\'and\ \'},\39\\{nf}:1,\39\.{\'\ internal\ fonts\ of\ \'},\39%
\\{max\_fonts}:1)$;\5
$\\{print\_ln}(\\{n\_widths}:1,\39\.{\'\ widths\ of\ \'},\39\\{max\_widths}:1,%
\39\.{\'\ for\ \'},\39\\{n\_chars}:1,\39\.{\'\ characters\ of\ \'},\39\\{max%
\_chars}:1)$;\5
$\\{print\_ln}(\\{pckt\_ptr}:1,\39\.{\'\ byte\ packets\ of\ \'},\39\\{max%
\_packets}:1,\39\.{\'\ with\ \'},\39\\{byte\_ptr}:1,\39\.{\'\ bytes\ of\ \'},%
\39\\{max\_bytes}:1)$;\5
\X281:Print more memory usage statistics\X\6
$\\{print\_ln}(\\{stack\_used}:1,\39\.{\'\ of\ \'},\39\\{stack\_size}:1,\39\.{%
\'\ stack\ and\ \'},\39\\{recur\_used}:1,\39\.{\'\ of\ \'},\39\\{max%
\_recursion}:1,\39\.{\'\ recursion\ levels.\'})$\par
\U230.\fi

\M233. Some implementations may wish to pass the \\{history} value to the
operating system so that it can be used to govern whether or not other
programs are started. Here we simply report the history to the user.

\Y\P$\4\X233:Print the job \\{history}\X\S$\6
\&{case} $\\{history}$ \1\&{of}\6
\4\\{spotless}: \37$\\{print\_ln}(\.{\'(No\ errors\ were\ found.)\'})$;\6
\4\\{harmless\_message}: \37$\\{print\_ln}(\.{\'(Did\ you\ see\ the\ warning\
message\ above?)\'})$;\6
\4\\{error\_message}: \37$\\{print\_ln}(\.{\'(Pardon\ me,\ but\ I\ think\ I\
spotted\ something\ wrong.)\'})$;\6
\4\\{fatal\_message}: \37$\\{print\_ln}(\.{\'(That\ was\ a\ fatal\ error,\ my\
friend.)\'})$;\2\6
\&{end}\C{there are no other cases}\par
\U230.\fi

\N234.  Low-level output routines.
The program uses the binary file variable \\{out\_file} for its main output
file; \\{out\_loc} is the number of the byte about to be written next on
\\{out\_file}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{out\_file}: \37\\{byte\_file};\C{the \.{DVI} file we are writing}\6
\4\\{out\_loc}: \37\\{int\_32};\C{where we are about to write, in \\{out%
\_file}}\6
\4\\{out\_back}: \37\\{int\_32};\C{a back pointer}\6
\4\\{out\_max\_v}: \37\\{int\_31};\C{maximum \|v value so far}\6
\4\\{out\_max\_h}: \37\\{int\_31};\C{maximum \|h value so far}\6
\4\\{out\_stack}: \37\\{int\_16u};\C{maximum stack depth}\6
\4\\{out\_pages}: \37\\{int\_16u};\C{total number of pages}\par
\fi

\M235. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{out\_loc}\K0$;\5
$\\{out\_back}\K-1$;\5
$\\{out\_max\_v}\K0$;\5
$\\{out\_max\_h}\K0$;\5
$\\{out\_stack}\K0$;\5
$\\{out\_pages}\K0$;\par
\fi

\M236. To prepare \\{out\_file} for output, we \\{rewrite} it.

\Y\P$\4\X236:Open output file(s)\X\S$\6
$\\{rewrite}(\\{out\_file})$;\C{prepares to write packed bytes to \\{out%
\_file}}\par
\U231.\fi

\M237. For some operating systems it may be necessary to close \\{out\_file}.

\Y\P$\4\X237:Close output file(s)\X\S$\par
\U230.\fi

\M238. Writing the \\{out\_file} should be done as efficient as possible for a
particular system; on many systems this means that a large number of
bytes will be accumulated in a buffer and is then written from that
buffer to \\{out\_file}. In order to simplify such system dependent changes
we use the \.{WEB} macro \\{out\_byte} to write the next \.{DVI} byte. Here
we give a simple minded definition for this macro in terms of standard
\PASCAL.

\Y\P\D \37$\\{out\_byte}(\#)\S\\{write}(\\{out\_file},\39\#)$\C{write next %
\.{DVI} byte}\par
\fi

\M239. The \.{WEB} macro \\{out\_one} is used to write one byte and to update
\\{out\_loc}.

\Y\P\D \37$\\{out\_one}(\#)\S$\1\6
\&{begin} \37$\\{out\_byte}(\#)$;\5
$\\{incr}(\\{out\_loc})$;\ \&{end}\2\par
\fi

\M240. First the \\{out\_packet} procedure copies a packet to \\{out\_file}.

\Y\P$\4\X240:Declare typesetting procedures\X\S$\6
\4\&{procedure}\1\  \37$\\{out\_packet}(\|p:\\{pckt\_pointer})$;\6
\4\&{var} \37\|k: \37\\{byte\_pointer};\C{index into \\{byte\_mem}}\2\6
\&{begin} \37$\\{Incr}(\\{out\_loc})(\\{pckt\_length}(\|p))$;\6
\&{for} $\|k\K\\{pckt\_start}[\|p]\mathrel{\&{to}}\\{pckt\_start}[\|p+1]-1$ \1%
\&{do}\5
$\\{out\_byte}(\\{bo}(\\{byte\_mem}[\|k]))$;\2\6
\&{end};\par
\As241, 242, 243, 244\ETs248.
\U180.\fi

\M241. Next are the procedures used to write integer numbers or even complete
\.{DVI} commands to \\{out\_file}; they all keep \\{out\_loc} up to date.

The \\{out\_four} procedure outputs four bytes in two's complement notation,
without risking arithmetic overflow.

\Y\P$\4\X240:Declare typesetting procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{out\_four}(\|x:\\{int\_32})$;\C{output four bytes}\2%
\6
\&{begin\_four} \37;\5
$\\{comp\_four}(\\{out\_byte})$;\5
$\\{Incr}(\\{out\_loc})(4)$;\6
\&{end};\par
\fi

\M242. The \\{out\_char} procedure outputs a \\{set\_char} or \\{set} command
or, if
$\\{upd}=\\{false}$, a \\{put} command.

\Y\P$\4\X240:Declare typesetting procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{out\_char}(\\{upd}:\\{boolean};\,\35\\{ext}:\\{int%
\_32};\,\35\\{res}:\\{eight\_bits})$;\C{output \\{set} or \\{put}}\2\6
\&{begin\_char} \37;\5
$\\{comp\_char}(\\{out\_one})$;\6
\&{end};\par
\fi

\M243. The \\{out\_unsigned} procedure outputs a \\{fnt}, \\{xxx}, or \\{fnt%
\_def}
command with its first parameter (normally unsigned); a \\{fnt} command
is converted into \\{fnt\_num} whenever this is possible.

\Y\P$\4\X240:Declare typesetting procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{out\_unsigned}(\|o:\\{eight\_bits};\,\35\|x:\\{int%
\_32})$;\C{output \\{fnt\_num}, \\{fnt}, \\{xxx}, or \\{fnt\_def}}\2\6
\&{begin\_unsigned} \37;\5
$\\{comp\_unsigned}(\\{out\_one})$;\6
\&{end};\par
\fi

\M244. The \\{out\_signed} procedure outputs a movement (\\{right}, \|w,
\|x, \\{down}, \|y, or \|z) command with its (signed) parameter.

\Y\P$\4\X240:Declare typesetting procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{out\_signed}(\|o:\\{eight\_bits};\,\35\|x:\\{int%
\_32})$;\C{output \\{right}, \|w, \|x, \\{down}, \|y, or \|z}\2\6
\&{begin\_signed} \37;\5
$\\{comp\_signed}(\\{out\_one})$;\6
\&{end};\par
\fi

\M245. For an output font we set $\\{font\_type}(\|f)\K\\{out\_font\_type}$; in
this case
$\\{font\_font}(\|f)$ is the font number used for font~\|f in \\{out\_file}.

The global variable \\{out\_nf} is the number of fonts already used in
\\{out\_file} and the array \\{out\_fnts} contains their internal font numbers;
the current font in \\{out\_file} is called \\{out\_fnt}.

\Y\P$\4\X17:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{out\_fnts}: \37\&{array} $[\\{font\_number}]$ \1\&{of}\5
\\{font\_number};\C{internal font numbers}\2\6
\4\\{out\_nf}: \37\\{font\_number};\C{number of fonts used in \\{out\_file}}\6
\4\\{out\_fnt}: \37\\{font\_number};\C{internal font number of current output
font}\par
\fi

\M246. \P$\X18:Set initial values\X\mathrel{+}\S$\6
$\\{out\_nf}\K0$;\par
\fi

\M247. \P$\X247:Print more font usage statistics\X\S$\6
$\\{print}(\\{out\_nf}:1,\39\.{\'\ out,\ \'})$;\par
\U232.\fi

\M248. The \\{out\_fnt\_def} procedure outputs a complete font definition
command.

\Y\P$\4\X240:Declare typesetting procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{out\_fnt\_def}(\|f:\\{font\_number})$;\6
\4\&{var} \37\|p: \37\\{pckt\_pointer};\C{the font name packet}\6
$\|k,\39\|l$: \37\\{byte\_pointer};\C{indices into \\{byte\_mem}}\6
\|a: \37\\{eight\_bits};\C{length of area part}\2\6
\&{begin} \37$\\{out\_unsigned}(\\{fnt\_def1},\39\\{font\_font}(\|f))$;\5
$\\{out\_four}(\\{font\_check}(\|f))$;\5
$\\{out\_four}(\\{font\_scaled}(\|f))$;\5
$\\{out\_four}(\\{font\_design}(\|f))$;\6
$\|p\K\\{font\_name}(\|f)$;\5
$\|k\K\\{pckt\_start}[\|p]$;\5
$\|l\K\\{pckt\_start}[\|p+1]-1$;\5
$\|a\K\\{bo}(\\{byte\_mem}[\|k])$;\6
$\\{Incr}(\\{out\_loc})(\|l-\|k+2)$;\5
$\\{out\_byte}(\|a)$;\5
$\\{out\_byte}(\|l-\|k-\|a)$;\6
\&{while} $\|k<\|l$ \1\&{do}\6
\&{begin} \37$\\{incr}(\|k)$;\5
$\\{out\_byte}(\\{bo}(\\{byte\_mem}[\|k]))$;\6
\&{end};\2\6
\&{end};\par
\fi

\N249.  Writing the output file.
Here we define the device dependent parts of the typesetting routines
described earlier in this program.

The device dependent code for a real output device must define a few constants;
here we demonstrate how they should be defined.

\Y\P\D \37$\\{h\_resolution}\S300$\C{horizontal resolution in pixels per inch
(dpi)}\par
\P\D \37$\\{v\_resolution}\S300$\C{vertical resolution in pixels per inch
(dpi)}\par
\fi

\M250. These are the local variables (if any) needed for \\{do\_pre}.

\Y\P$\4\X250:OUT: Declare local variables (if any) for \\{do\_pre}\X\S$\6
\4\&{var} \37\|k: \37\\{int\_15};\C{general purpose variable}\6
$\|p,\39\|q,\39\|r$: \37\\{byte\_pointer};\C{indices into \\{byte\_mem}}\6
\\{comment}: \37\&{packed} \37\&{array} $[1\to\\{comm\_length}]$ \1\&{of}\5
\\{char};\C{preamble comment prefix}\2\par
\U194.\fi

\M251. And here is the device dependent code for \\{do\_pre}; the \.{DVI}
preamble
comment written to \\{out\_file} is similar to the one produced by \.{GFtoPK},
but we want to apply our preamble comment prefix only once.

\Y\P$\4\X251:OUT: Process the \\{pre}\X\S$\6
$\\{out\_one}(\\{pre})$;\5
$\\{out\_one}(\\{dvi\_id})$;\5
$\\{out\_four}(\\{dvi\_num})$;\5
$\\{out\_four}(\\{dvi\_den})$;\5
$\\{out\_four}(\\{out\_mag})$;\6
$\|p\K\\{pckt\_start}[\\{pckt\_ptr}-1]$;\5
$\|q\K\\{byte\_ptr}$;\C{location of old \.{DVI} comment}\6
$\\{comment}\K\\{preamble\_comment}$;\5
$\\{pckt\_room}(\\{comm\_length})$;\6
\&{for} $\|k\K1\mathrel{\&{to}}\\{comm\_length}$ \1\&{do}\5
$\\{append\_byte}(\\{xord}[\\{comment}[\|k]])$;\2\6
\&{while} $\\{byte\_mem}[\|p]=\\{bi}(\.{"\ "})$ \1\&{do}\5
$\\{incr}(\|p)$;\C{remove leading blanks}\2\6
\&{if} $\|p=\|q$ \1\&{then}\5
$\\{Decr}(\\{byte\_ptr})(\\{from\_length})$\6
\4\&{else} \&{begin} \37$\|k\K0$;\6
\&{while} $(\|k<\\{comm\_length})\W(\\{byte\_mem}[\|p+\|k]=\\{byte\_mem}[\|q+%
\|k])$ \1\&{do}\5
$\\{incr}(\|k)$;\2\6
\&{if} $\|k=\\{comm\_length}$ \1\&{then}\5
$\\{Incr}(\|p)(\\{comm\_length})$;\2\6
\&{end};\2\6
$\|k\K\\{byte\_ptr}-\|p$;\C{total length}\6
\&{if} $\|k>255$ \1\&{then}\6
\&{begin} \37$\|k\K255$;\5
$\|q\K\|p+255-\\{comm\_length}$;\C{at most 255 bytes}\6
\&{end};\2\6
$\\{out\_one}(\|k)$;\5
$\\{out\_packet}(\\{new\_packet})$;\5
\\{flush\_packet};\6
\&{for} $\|r\K\|p\mathrel{\&{to}}\|q-1$ \1\&{do}\5
$\\{out\_one}(\\{bo}(\\{byte\_mem}[\|r]))$;\2\par
\U194.\fi

\M252. These are the additional local variables (if any) needed for \\{do%
\_bop};
the variables \|i and \|j are already declared.

\Y\P$\4\X252:OUT: Declare additional local variables \\{do\_bop}\X\S$\6
\4\&{var} \37\par
\U195.\fi

\M253. And here is the device dependent code for \\{do\_bop}.

\Y\P$\4\X253:OUT: Process a \\{bop}\X\S$\6
$\\{out\_one}(\\{bop})$;\5
$\\{incr}(\\{out\_pages})$;\6
\&{for} $\|i\K0\mathrel{\&{to}}9$ \1\&{do}\5
$\\{out\_four}(\\{count}[\|i])$;\2\6
$\\{out\_four}(\\{out\_back})$;\5
$\\{out\_back}\K\\{out\_loc}-45$;\5
$\\{out\_fnt}\K\\{invalid\_font}$;\par
\U195.\fi

\M254. These are the local variables (if any) needed for \\{do\_eop}.

\Y\P$\4\X254:OUT: Declare local variables (if any) for \\{do\_eop}\X\S$\par
\U197.\fi

\M255. And here is the device dependent code for \\{do\_eop}.

\Y\P$\4\X255:OUT: Process an \\{eop}\X\S$\6
$\\{out\_one}(\\{eop})$;\par
\U197.\fi

\M256. These are the local variables (if any) needed for \\{do\_push}.

\Y\P$\4\X256:OUT: Declare local variables (if any) for \\{do\_push}\X\S$\par
\U198.\fi

\M257. And here is the device dependent code for \\{do\_push}.

\Y\P$\4\X257:OUT: Process a \\{push}\X\S$\6
\&{if} $\\{stack\_ptr}>\\{out\_stack}$ \1\&{then}\5
$\\{out\_stack}\K\\{stack\_ptr}$;\2\6
$\\{out\_one}(\\{push})$;\par
\U198.\fi

\M258. These are the local variables (if any) needed for \\{do\_pop}.

\Y\P$\4\X258:OUT: Declare local variables (if any) for \\{do\_pop}\X\S$\par
\U198.\fi

\M259. And here is the device dependent code for \\{do\_pop}.

\Y\P$\4\X259:OUT: Process a \\{pop}\X\S$\6
$\\{out\_one}(\\{pop})$;\par
\U198.\fi

\M260. These are the additional local variables (if any) needed for \\{do%
\_xxx};
the variable \|p, the pointer to the packet containing the special
string, is already declared.

\Y\P$\4\X260:OUT: Declare additional local variables for \\{do\_xxx}\X\S$\6
\4\&{var} \37\par
\U199.\fi

\M261. And here is the device dependent code for \\{do\_xxx}.

\Y\P$\4\X261:OUT: Process an \\{xxx}\X\S$\6
$\\{out\_unsigned}(\\{xxx1},\39\\{pckt\_length}(\|p))$;\5
$\\{out\_packet}(\|p)$;\par
\U199.\fi

\M262. These are the local variables (if any) needed for \\{do\_right}.

\Y\P$\4\X262:OUT: Declare local variables (if any) for \\{do\_right}\X\S$\par
\U200.\fi

\M263. And here is the device dependent code for \\{do\_right}.

\Y\P$\4\X263:OUT: Process a \\{right} or \|w or \|x\X\S$\6
\&{if} $\\{cur\_class}<\\{right\_cl}$ \1\&{then}\5
$\\{out\_one}(\\{cur\_cmd})$\C{\\{w0} or \\{x0}}\6
\4\&{else} $\\{out\_signed}(\\{dvi\_right\_cmd}[\\{cur\_class}],\39\\{cur%
\_parm})$;\C{\\{right}, \|w, or \|x}\2\par
\U200.\fi

\M264. Here we update the \\{out\_max\_h} value.

\Y\P$\4\X264:OUT: Move right\X\S$\6
\&{if} $\\{abs}(\\{cur\_h})>\\{out\_max\_h}$ \1\&{then}\5
$\\{out\_max\_h}\K\\{abs}(\\{cur\_h})$;\2\par
\Us200, 202, 204\ETs205.\fi

\M265. These are the local variables (if any) needed for \\{do\_down}.

\Y\P$\4\X265:OUT: Declare local variables (if any) for \\{do\_down}\X\S$\par
\U201.\fi

\M266. And here is the device dependent code for \\{do\_down}.

\Y\P$\4\X266:OUT: Process a \\{down} or \|y or \|z\X\S$\6
\&{if} $\\{cur\_class}<\\{down\_cl}$ \1\&{then}\5
$\\{out\_one}(\\{cur\_cmd})$\C{\\{y0} or \\{z0}}\6
\4\&{else} $\\{out\_signed}(\\{dvi\_down\_cmd}[\\{cur\_class}],\39\\{cur%
\_parm})$;\C{\\{down}, \|y, or \|z}\2\par
\U201.\fi

\M267. Here we update the \\{out\_max\_v} value.

\Y\P$\4\X267:OUT: Move down\X\S$\6
\&{if} $\\{abs}(\\{cur\_v})>\\{out\_max\_v}$ \1\&{then}\5
$\\{out\_max\_v}\K\\{abs}(\\{cur\_v})$;\2\par
\U201.\fi

\M268. These are the local variables (if any) needed for \\{do\_width}.

\Y\P$\4\X268:OUT: Declare local variables (if any) for \\{do\_width}\X\S$\par
\U202.\fi

\M269. And here is the device dependent code for \\{do\_width}.

\Y\P$\4\X269:OUT: Typeset a \\{width}\X\S$\6
$\\{out\_one}(\\{set\_rule})$;\5
$\\{out\_four}(\\{width\_dimen})$;\5
$\\{out\_four}(\\{cur\_h\_dimen})$;\par
\U202.\fi

\M270. These are the additional local variables (if any) needed for \\{do%
\_rule};
the variable \\{visible} is already declared.

\Y\P$\4\X270:OUT: Declare additional local variables \\{do\_rule}\X\S$\6
\4\&{var} \37\par
\U204.\fi

\M271. And here is the device dependent code for \\{do\_rule}.

\Y\P$\4\X271:OUT: Typeset a visible \\{rule}\X\S$\6
$\\{out\_one}(\\{dvi\_rule\_cmd}[\\{cur\_upd}])$;\5
$\\{out\_four}(\\{cur\_v\_dimen})$;\5
$\\{out\_four}(\\{cur\_h\_dimen})$;\par
\Us204\ET272.\fi

\M272. \P$\X272:OUT: Typeset an invisible \\{rule}\X\S$\6
\X271:OUT: Typeset a visible \\{rule}\X\par
\U204.\fi

\M273. These are the local variables (if any) needed for \\{do\_font}.

\Y\P$\4\X273:OUT: Declare local variables (if any) for \\{do\_font}\X\S$\par
\U207.\fi

\M274. And here is the device dependent code for \\{do\_font}; if the \.{VF}
file
for a font could not be found, we simply assume this must be a real font.

\Y\P$\4\X274:OUT: Look for a font file before trying to read the \.{VF} file;
if found \&{goto} \\{done}\X\S$\par
\U207.\fi

\M275. \P$\X275:OUT: Look for a font file after trying to read the \.{VF} file%
\X\S$\6
\&{if} $(\\{out\_nf}\G\\{max\_fonts})$ \1\&{then}\5
$\\{overflow}(\\{str\_fonts},\39\\{max\_fonts})$;\2\6
$\\{print}(\.{\'OUT:\ font\ \'},\39\\{cur\_fnt}:1)$;\5
$\\{d\_print}(\.{\'\ =>\ \'},\39\\{out\_nf}:1)$;\5
$\\{print\_font}(\\{cur\_fnt})$;\5
$\\{d\_print}(\.{\'\ at\ \'},\39\\{font\_scaled}(\\{cur\_fnt}):1,\39\.{\'\ DVI\
units\'})$;\5
$\\{print\_ln}(\.{\'.\'})$;\5
$\\{font\_type}(\\{cur\_fnt})\K\\{out\_font\_type}$;\5
$\\{font\_font}(\\{cur\_fnt})\K\\{out\_nf}$;\5
$\\{out\_fnts}[\\{out\_nf}]\K\\{cur\_fnt}$;\5
$\\{incr}(\\{out\_nf})$;\5
$\\{out\_fnt\_def}(\\{cur\_fnt})$;\par
\U207.\fi

\M276. These are the local variables (if any) needed for \\{do\_char}.

\Y\P$\4\X276:OUT: Declare local variables (if any) for \\{do\_char}\X\S$\par
\U205.\fi

\M277. And here is the device dependent code for \\{do\_char}.

\Y\P$\4\X277:OUT: Typeset a \\{char}\X\S$\6
\&{debug} \37\&{if} $\\{font\_type}(\\{cur\_fnt})\I\\{out\_font\_type}$ \1%
\&{then}\5
$\\{confusion}(\\{str\_fonts})$;\2\6
\&{gubed}\6
\&{if} $\\{cur\_fnt}\I\\{out\_fnt}$ \1\&{then}\6
\&{begin} \37$\\{out\_unsigned}(\\{fnt1},\39\\{font\_font}(\\{cur\_fnt}))$;\5
$\\{out\_fnt}\K\\{cur\_fnt}$;\6
\&{end};\2\6
$\\{out\_char}(\\{cur\_upd},\39\\{cur\_ext},\39\\{cur\_res})$;\par
\U205.\fi

\M278. If the program terminates in the middle of a page, we write as many
\\{pop}s as necessary and one \\{eop}.

\Y\P$\4\X278:OUT: Finish incomplete page\X\S$\6
\&{begin} \37\&{while} $\\{stack\_ptr}>0$ \1\&{do}\6
\&{begin} \37$\\{out\_one}(\\{pop})$;\5
$\\{decr}(\\{stack\_ptr})$;\6
\&{end};\2\6
$\\{out\_one}(\\{eop})$;\6
\&{end}\par
\U206.\fi

\M279. If the output file has been started, we write the postamble; in
addition we print the number of bytes and pages written to \\{out\_file}.

\Y\P$\4\X279:OUT: Finish output file(s)\X\S$\6
\&{if} $\\{out\_loc}>0$ \1\&{then}\6
\&{begin} \37\X280:OUT: Write the postamble\X;\6
$\|k\K7-((\\{out\_loc}-1)\mathbin{\&{mod}}4)$;\C{the number of 223's}\6
\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{out\_one}(223)$;\5
$\\{decr}(\|k)$;\6
\&{end};\2\6
$\\{print}(\.{\'OUT\ file:\ \'},\39\\{out\_loc}:1,\39\.{\'\ bytes,\ \'},\39%
\\{out\_pages}:1,\39\.{\'\ page\'})$;\6
\&{if} $\\{out\_pages}\I1$ \1\&{then}\5
$\\{print}(\.{\'s\'})$;\2\6
\&{end}\6
\4\&{else} $\\{print}(\.{\'OUT\ file:\ no\ output\'})$;\2\6
$\\{print\_ln}(\.{\'\ written.\'})$;\6
\&{if} $\\{out\_pages}=0$ \1\&{then}\5
\\{mark\_harmless};\2\par
\U206.\fi

\M280. Here we simply write the values accumulated during the \.{DVI} output.

\Y\P$\4\X280:OUT: Write the postamble\X\S$\6
$\\{out\_one}(\\{post})$;\5
$\\{out\_four}(\\{out\_back})$;\5
$\\{out\_back}\K\\{out\_loc}-5$;\6
$\\{out\_four}(\\{dvi\_num})$;\5
$\\{out\_four}(\\{dvi\_den})$;\5
$\\{out\_four}(\\{out\_mag})$;\6
$\\{out\_four}(\\{out\_max\_v})$;\5
$\\{out\_four}(\\{out\_max\_h})$;\6
$\\{out\_one}(\\{out\_stack}\mathbin{\&{div}}\H{100})$;\5
$\\{out\_one}(\\{out\_stack}\mathbin{\&{mod}}\H{100})$;\6
$\\{out\_one}(\\{out\_pages}\mathbin{\&{div}}\H{100})$;\5
$\\{out\_one}(\\{out\_pages}\mathbin{\&{mod}}\H{100})$;\6
$\|k\K\\{out\_nf}$;\6
\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\|k)$;\5
$\\{out\_fnt\_def}(\\{out\_fnts}[\|k])$;\6
\&{end};\2\6
$\\{out\_one}(\\{post\_post})$;\5
$\\{out\_four}(\\{out\_back})$;\6
$\\{out\_one}(\\{dvi\_id})$\par
\U279.\fi

\M281. Here we could print more memory usage statistics; this possibility is,
however, not used for \.{DVIcopy}.

\Y\P$\4\X281:Print more memory usage statistics\X\S$\par
\U232.\fi

\N282.  System-dependent changes.
This section should be replaced, if necessary, by changes to the program
that are necessary to make \.{DVIcopy} 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

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

\fi


\inx
\:\|{a}, \[50], \[51], \[52], \[53], \[248].
\:\\{abort}, \[23], 95, 96, 99, 110, 136.
\:\\{abs}, 99, 200, 201, 264, 267.
\:\\{all\_done}, \[187], 194, 197, 225.
\:\\{alpha}, \[105], 106, 142.
\:\\{any}, 155.
\:\\{append\_byte}, \[34], 54, 55, 56, 57, 58, 59, 89, 132, 150, 152, 167, 175,
215, 220, 226, 251.
\:\\{append\_one}, \[34], 161, 163, 164, 166, 168.
\:\\{append\_res\_to\_name}, \[64], 67.
\:\\{append\_to\_name}, \[63], 64, 67.
\:\\{ASCII\_code}, \[14], 17, 31, 44, 48.
\:\|{b}, \[51], \[52], \[53], \[67].
\:\.{Bad char c}, 99.
\:\.{Bad DVI file}, 110.
\:\.{Bad TFM file}, 95.
\:\.{Bad VF file}, 136.
\:\\{bad\_dvi}, \[110], 112, 115, 130, 132, 197, 198, 219, 220, 222, 223, 224,
225, 228.
\:\\{bad\_font}, \[95], 98, 103, 105, 107, 136, 140, 144, 145, 148, 150, 151,
152, 161, 168.
\:\\{bad\_tfm}, \[95].
\:\\{banner}, \[1], 3.
\:\\{bc}, 70, \[100], 103, 104, 108.
\:\&{begin}, 6, 8, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59.
\:\&{begin\_byte}, \[50], \[114], \[141].
\:\&{begin\_char}, \[57], \[242].
\:\&{begin\_four}, \[56], \[241].
\:\&{begin\_one}, \[54].
\:\&{begin\_pair}, \[51], \[114], \[141].
\:\&{begin\_quad}, \[53], \[114], \[141].
\:\&{begin\_signed}, \[59], \[244].
\:\&{begin\_trio}, \[52], \[114], \[141].
\:\&{begin\_two}, \[55].
\:\&{begin\_unsigned}, \[58], \[243].
\:\\{beta}, \[105], 106, 142.
\:\.{beware: char widths do not agree}, 99.
\:\.{beware: check sums do not agree}, 99.
\:\.{beware: design sizes do not agree}, 99.
\:\\{bi}, \[31], 34, 44, 160, 175, 177, 191, 192, 217, 251.
\:\\{bo}, \[31], 41, 48, 49, 60, 61, 240, 248, 251.
\:\\{boolean}, 57, 85, 87, 99, 123, 126, 132, 151, 154, 158, 177, 178, 181,
187, 188, 204, 212, 242.
\:\\{bop}, \[26], 120, 122, 187, 195, 219, 224, 225, 253.
\:\\{break}, 175.
\:\\{build\_packet}, \[90], 160.
\:\\{byte\_file}, \[29], 91, 109, 134, 234.
\:\\{byte\_mem}, 31, \[32], 34, 36, 38, 40, 41, 43, 44, 48, 49, 50, 54, 60, 61,
67, 70, 84, 90, 151, 155, 156, 160, 171, 175, 176, 177, 178, 191, 192, 199,
217, 240, 248, 250, 251.
\:\\{byte\_pointer}, \[31], 32, 40, 48, 49, 60, 61, 67, 89, 90, 151, 157, 176,
177, 210, 212, 240, 248, 250.
\:\\{byte\_ptr}, \[32], 34, 35, 38, 40, 41, 43, 44, 47, 89, 90, 160, 162, 163,
164, 165, 166, 168, 169, 170, 171, 175, 179, 232, 251.
\:\|{c}, \[52], \[53], \[67], \[99].
\:\\{chain\_flag}, \[84], 88, 89.
\:\\{char}, 15, 62, 65, 67, 93, 137, 250.
\:\.{char widths do not agree}, 99.
\:\\{char\_cl}, \[120], 122, 156, 161, 164, 215, 226.
\:\\{char\_code}, 116.
\:\\{char\_ext}, 116.
\:\\{char\_offset}, \[77], 80, 82.
\:\\{char\_packets}, 77, \[78], 82, 108.
\:\\{char\_par}, \[117], 119, 127, 145, 208.
\:\\{char\_pixels}, 77, \[78], 82, 108.
\:\\{char\_pointer}, \[77], 78, 100.
\:\\{char\_res}, 116.
\:\\{char\_widths}, 77, \[78], 80, 82, 100, 104, 107, 108.
\:\.{check sums do not agree}, 99.
\:\\{check\_check\_sum}, \[99], 100, 103, 152.
\:\\{check\_design\_size}, \[99], 100, 103, 152.
\:\\{check\_width}, \[99], 160.
\:\\{chr}, 15, 17, 19.
\:\\{close\_files\_and\_terminate}, \[23], \[230], 231.
\:\\{close\_in}, \[30], 101, 151, 230.
\:\\{cmd\_cl}, \[120], 121, 125.
\:\\{cmd\_par}, \[117], 118.
\:\\{comm\_length}, \[1], 250, 251.
\:\\{comment}, \[250], 251.
\:\\{comp\_char}, \[57], 242.
\:\\{comp\_four}, \[56], 241.
\:\\{comp\_one}, \[54].
\:\\{comp\_sbyte}, \[50], 114.
\:\\{comp\_signed}, \[59], 244.
\:\\{comp\_spair}, \[51], 114.
\:\\{comp\_squad}, \[53], 114, 141.
\:\\{comp\_strio}, \[52], 114, 141.
\:\\{comp\_two}, \[55].
\:\\{comp\_ubyte}, \[50], 114, 141.
\:\\{comp\_unsigned}, \[58], 243.
\:\\{comp\_upair}, \[51], 114, 141.
\:\\{comp\_utrio}, \[52], 114, 141.
\:\\{confusion}, \[24], 45, 49, 89, 207, 215, 277.
\:\\{continue}, \[10], 212, 215.
\:\\{copyright}, \[1], 3.
\:\\{count}, \[187], 188, 195, 224, 225, 253.
\:\\{cur\_class}, \[125], 127, 145, 161, 164, 169, 170, 200, 201, 208, 215,
219, 222, 226, 227, 263, 266.
\:\\{cur\_cmd}, \[125], 127, 145, 151, 153, 160, 161, 208, 219, 222, 225, 263,
266.
\:\\{cur\_ext}, \[85], 87, 88, 89, 99, 127, 151, 160, 165, 205, 213, 277.
\:\\{cur\_fnt}, 67, \[85], 86, 87, 88, 89, 90, 95, 99, 100, 101, 104, 107, 108,
130, 136, 151, 152, 153, 161, 195, 200, 201, 205, 207, 213, 214, 215, 216, 228,
275, 277.
\:\\{cur\_h}, \[184], 200, 202, 204, 205, 264.
\:\\{cur\_h\_dimen}, \[126], 127, 145, 166, 202, 204, 208, 212, 226, 269, 271.
\:\\{cur\_hh}, \[184], 200.
\:\\{cur\_limit}, \[49], 50, \[67], 87, 88, \[89], 212, 215, 216, 217.
\:\\{cur\_loc}, \[49], 50, \[67], 87, 88, \[89], 215, 216, 217.
\:\\{cur\_name}, \[62], 63, 67, 96, 139.
\:\\{cur\_name\_length}, \[62], 63, 64, 67.
\:\\{cur\_packet}, 87.
\:\\{cur\_parm}, \[125], 127, 130, 131, 132, 145, 148, 149, 150, 153, 161, 167,
200, 201, 208, 215, 226, 227, 263, 266.
\:\\{cur\_pckt}, \[49], 87, 215.
\:\\{cur\_pckt\_length}, \[35].
\:\\{cur\_pos}, 113.
\:\\{cur\_res}, \[85], 87, 88, 89, 99, 127, 145, 151, 160, 165, 205, 213, 216,
277.
\:\\{cur\_select}, \[187], 189, 191, 192, 194, 197.
\:\\{cur\_stack}, \[184], 195, 198.
\:\\{cur\_type}, \[85], 87, 215.
\:\\{cur\_upd}, \[126], 127, 145, 151, 164, 165, 166, 169, 203, 204, 205, 208,
212, 213, 216, 217, 226, 271, 277.
\:\\{cur\_v}, \[184], 201, 267.
\:\\{cur\_v\_dimen}, \[126], 127, 145, 166, 204, 208, 226, 271.
\:\\{cur\_vv}, \[184], 201.
\:\\{cur\_w\_x}, \[184], 200.
\:\\{cur\_wp}, \[126], 145, 151, 160, 205, 212, 213, 216.
\:\\{cur\_y\_z}, \[184], 201.
\:\|{d}, \[53], \[60], \[99].
\:\\{d\_print}, \[11], 100, 101, 195, 218, 275.
\:\\{d\_print\_ln}, \[11], 222.
\:\&{debug}, \[8], \[9], \[11], \[44], \[49], \[60], \[89], \[151], \[207], %
\[218], \[277].
\:\\{Decr}, \[12], 67, 105, 127, 171, 174, 251.
\:\\{decr}, \[12], 34, 47, 90, 104, 127, 132, 150, 160, 164, 167, 168, 170,
172, 195, 197, 198, 215, 217, 223, 226, 227, 278, 279, 280.
\:\.{design sizes do not agree}, 99.
\:\&{device}, \[6], \[54], \[55], \[64], \[65], \[66], \[67], \[71], \[72], %
\[73], \[74], \[78], \[82], \[83], \[107], \[108], \[181], \[183], \[185], %
\[194], \[200], \[201], \[202], \[203], \[204], \[205], \[212], \[226].
\:\\{dialog}, \[179], 231.
\:\\{dim1\_par}, \[117], 119, 127, 145, 208.
\:\\{dim2\_par}, \[117], 119, 127, 145, 208.
\:\\{dim3\_par}, \[117], 119, 127, 145, 208.
\:\\{dim4}, 208.
\:\\{dim4\_par}, \[117], 119, 127, 145, 208.
\:\\{do\_bop}, \[195], 225, 252, \[253].
\:\\{do\_char}, \[205], 216, 228, 276, 277.
\:\\{do\_down}, \[201], 215, 226, 265, 266.
\:\\{do\_dvi}, \[219], 231.
\:\\{do\_eop}, \[197], 225, 254, 255.
\:\\{do\_font}, \[207], 216, 228, 273, 274.
\:\\{do\_h\_pixels}, \[200], 202, 204, 205.
\:\\{do\_nothing}, \[12], 30, 127, 145, 208, 227.
\:\\{do\_pop}, \[198], 215, 226, 258, 259.
\:\\{do\_pre}, \[194], 220, 250, 251.
\:\\{do\_push}, \[198], 215, 226, 256, 257.
\:\\{do\_right}, \[200], 215, 226, 262, 263.
\:\\{do\_rule}, \[204], 215, 226, 270, \[271].
\:\\{do\_v\_pixels}, \[201].
\:\\{do\_vf}, \[151], 207.
\:\\{do\_vf\_packet}, 209, 210, \[212], 213, 214, 217, 228.
\:\\{do\_width}, \[202], 212, 226, 268, 269.
\:\\{do\_xxx}, \[199], 215, 226, 260, \[261].
\:\\{done}, \[10], 151, 161, 207, 212, 215, 219, 225, 226, 227.
\:\\{down}, 59, 201, 215, 226, 244, 266.
\:\\{down\_cl}, \[120], 122, 123, 124, 161, 201, 266.
\:\\{down1}, \[26], 119, 122, 123, 124.
\:\.{duplicate packet for character...}, 90.
\:\\{dvi\_back}, \[219], 222, 224.
\:\\{dvi\_bop\_post}, \[219], 222, 223, 224.
\:\\{dvi\_byte}, \[112], 113, 114.
\:\\{dvi\_char\_cmd}, 57, \[123], 124, 127.
\:\\{dvi\_cl}, 116, 120, \[121], 122, 127, 145, 208.
\:\\{DVI\_copy}, \[3].
\:\\{dvi\_den}, 194, 220, \[221], 222, 251, 280.
\:\\{dvi\_do\_font}, \[132], 219, 222, 226, 227.
\:\\{dvi\_down\_cmd}, \[123], 124, 161, 266.
\:\\{dvi\_e\_fnts}, \[128], 131.
\:\\{dvi\_eof}, \[112].
\:\\{dvi\_file}, 1, \[3], \[109], 111, 112, 113, 114, 230.
\:\\{dvi\_first\_par}, \[127], 219, 222, 225, 226, 227.
\:\\{dvi\_font}, \[130], 226.
\:\\{dvi\_i\_fnts}, \[128], 130, 132.
\:\\{dvi\_id}, \[26], 220, 223, 251, 280.
\:\\{dvi\_length}, \[113], 223.
\:\\{dvi\_loc}, \[109], 110, 111, 113, 114, 195, 222, 223.
\:\\{dvi\_mag}, 220, \[221], 222.
\:\\{dvi\_move}, \[113], 222, 223, 224.
\:\\{dvi\_nf}, \[128], 129, 130, 131, 132, 232.
\:\\{dvi\_num}, 194, 220, \[221], 222, 251, 280.
\:\\{dvi\_par}, 116, 117, \[118], 119, 127, 145, 208.
\:\\{dvi\_pointer}, \[115], 222, 223, 224, 225.
\:\\{dvi\_pquad}, \[115], 132, 220, 222.
\:\\{dvi\_right\_cmd}, \[123], 124, 161, 263.
\:\\{dvi\_rule\_cmd}, \[123], 124, 166, 271.
\:\\{dvi\_sbyte}, \[114], 127.
\:\\{dvi\_spair}, \[114], 127.
\:\\{dvi\_squad}, \[114], 115, 127, 132, 222, 224, 225.
\:\\{dvi\_start}, \[219], 222, 224.
\:\\{dvi\_strio}, \[114], 127.
\:\\{dvi\_ubyte}, \[114], 127, 132, 220, 223, 224, 226, 227.
\:\\{dvi\_upair}, \[114], 127, 222.
\:\\{dvi\_uquad}, \[115], 127.
\:\\{dvi\_utrio}, \[114], 127.
\:\|{e}, \[67], \[87], \[89].
\:\\{ec}, 70, \[100], 103, 104.
\:\&{ecived}, \[6].
\:\\{eight\_bits}, \[27], 29, 31, 50, 51, 52, 53, 57, 58, 59, 67, 82, 87, 97,
118, 121, 123, 125, 157, 210, 242, 243, 244, 248.
\:\&{else}, 13.
\:\\{empty\_packet}, \[38], 40, 88, 215.
\:\&{end}, 6, 8, 13.
\:\&{endcases}, \[13].
\:\\{eof}, 96, 98, 112, 113, 139, 140.
\:\\{eoln}, 175.
\:\\{eop}, \[26], 120, 122, 187, 197, 219, 225, 226, 255, 278.
\:\\{error\_message}, \[21], 233.
\:\\{exit}, \[10], 12, 87, 151, 179, 219.
\:\\{ext}, \[57], 70, \[242].
\:\\{ext\_flag}, \[84], 88, 89.
\:\|{f}, \[61], \[87], \[89], \[130], \[132], \[148], \[150], \[212], \[248].
\:\\{f\_res}, \[65], 66.
\:\\{f\_type}, \[80], 82.
\:\\{false}, 2, 57, 87, 89, 90, 124, 126, 132, 151, 152, 159, 161, 164, 169,
177, 178, 182, 187, 188, 191, 194, 197, 204, 216, 217, 222, 242.
\:\\{fatal\_message}, \[21], 230, 233.
\:\\{final\_end}, \[3], 23, 231.
\:\\{find\_packet}, 85, \[87], 215.
\:\\{first\_par}, 116.
\:\\{first\_text\_char}, \[15], 19.
\:\\{five\_cases}, \[116], 215, 226.
\:\\{fix\_word}, 105, 142, 143.
\:\\{flag}, 84.
\:\\{flush\_byte}, \[34], 90.
\:\\{flush\_packet}, \[47], 152, 179, 199, 220, 251.
\:\\{fnt}, 58, 155, 165, 243.
\:\\{fnt\_bc}, \[82].
\:\\{fnt\_chars}, \[82].
\:\\{fnt\_check}, \[82].
\:\\{fnt\_cl}, \[120], 122, 161, 215, 226.
\:\\{fnt\_def}, 243.
\:\\{fnt\_def\_cl}, \[120], 122, 161, 219, 222, 226, 227.
\:\\{fnt\_def1}, \[26], 119, 122, 132, 150, 153, 248.
\:\\{fnt\_def4}, 132, 150.
\:\\{fnt\_design}, \[82].
\:\\{fnt\_ec}, \[82].
\:\\{fnt\_font}, \[82].
\:\\{fnt\_name}, \[82].
\:\\{fnt\_num}, 58, 117, 155, 165, 243.
\:\\{fnt\_num\_0}, \[26], 58, 119, 122, 127, 145, 208.
\:\\{fnt\_par}, \[117], 119, 127, 145, 208.
\:\\{fnt\_scaled}, \[82].
\:\\{fnt\_space}, \[82].
\:\\{fnt\_type}, \[82].
\:\\{fnt1}, \[26], 58, 119, 122, 165, 277.
\:{font types}, \[4], 70, 146, 245.
\:\\{font\_bc}, 80, \[82], 99, 104, 145.
\:\\{font\_chars}, 70, 80, \[82], 104, 108.
\:\\{font\_check}, 80, \[82], 99, 100, 132, 150, 248.
\:\\{font\_data}, 100.
\:\\{font\_design}, 61, 80, \[82], 99, 100, 132, 150, 248.
\:\\{font\_ec}, 80, \[82], 99, 104, 145.
\:\\{font\_font}, \[82], 101, 146, 153, 161, 215, 245, 248, 275, 277.
\:\\{font\_name}, 61, 67, 80, \[82], 100, 132, 150, 248.
\:\\{font\_number}, 61, \[80], 81, 82, 85, 100, 128, 130, 132, 134, 146, 148,
150, 151, 210, 245, 248.
\:\\{font\_packet}, \[82], 84, 87, 88, 89, 90.
\:\\{font\_pixel}, \[82], 205.
\:\\{font\_scaled}, 61, 80, \[82], 100, 101, 107, 132, 150, 152, 248, 275.
\:\\{font\_space}, 80, \[82], 83, 107, 200, 201.
\:\\{font\_type}, 80, \[82], 95, 101, 146, 151, 207, 216, 228, 245, 275, 277.
\:\\{font\_width}, \[82], 99, 145, 216.
\:\\{font\_width\_end}, \[82].
\:\\{forward}, 23.
\:\\{found}, \[10], 40, 43, 74, 76, 87, 88, 89, 212, 215.
\:\\{from\_length}, \[1], 251.
\:\\{get}, 175.
\:\&{goto}, \[23].
\:\&{gubed}, \[8].
\:\|{h}, \[39], \[40], \[74], \[184].
\:\\{h\_conv}, 74, \[181], 194, 203.
\:\\{h\_field}, \[183], 184, 185.
\:\\{h\_pixel\_round}, \[74], 186, 200, 226.
\:\\{h\_pixels}, \[181], 202, 204, 212, 226.
\:\\{h\_resolution}, 194, \[249].
\:\\{h\_rule\_pixels}, \[203], 204.
\:\\{harmless\_message}, \[21], 233.
\:\\{hash\_code}, \[36], 37, 39, 40, 72, 74.
\:\\{hash\_size}, \[36], 38, 41, 73, 75.
\:\\{hex\_packet}, \[60], 218.
\:\\{hh}, 183, \[184], 186.
\:\\{hh\_field}, \[183], 184, 185.
\:\\{history}, \[21], 22, 230, 233.
\:\|{i}, \[16], \[40], \[177], \[195], \[252].
\:\\{id1}, \[44].
\:\\{id10}, \[44], 45.
\:\\{id2}, \[44].
\:\\{id3}, \[44], 135, 193.
\:\\{id4}, \[44], 92.
\:\\{id5}, \[44], 45.
\:\\{id6}, \[44], 45, 193.
\:\\{id7}, \[44], 45.
\:\\{id8}, \[44].
\:\\{id9}, \[44], 45.
\:\\{Incr}, \[12], 44, 54, 55, 56, 57, 58, 59, 89, 114, 132, 141, 143, 144,
150, 160, 200, 201, 202, 204, 205, 240, 241, 248, 251.
\:\\{incr}, \[12], 34, 40, 41, 43, 47, 49, 63, 66, 67, 74, 87, 90, 100, 101,
104, 114, 131, 132, 141, 143, 149, 150, 162, 164, 172, 175, 177, 178, 191, 192,
197, 217, 239, 248, 251, 253, 275.
\:\\{Incr\_Decr}, \[12].
\:\\{incr\_stack}, \[162], 198.
\:\.{Infinite VF recursion?}, 218.
\:\\{initialize}, \[3], 231.
\:\\{input}, 175.
\:\\{input\_ln}, \[175], 179.
\:\\{int\_15}, \[7], 62, 67, 100, 105, 132, 150, 151, 219, \[230], 250.
\:\\{int\_16}, \[7], 16, 51, 74, 100, 114.
\:\\{int\_16u}, \[7], 25, 51, 65, 66, 114, 141, 234.
\:\\{int\_23}, \[7].
\:\\{int\_24}, \[7], 52, 85, 87, 114, 141, 151, 210.
\:\\{int\_24u}, \[7], 52, 114, 141.
\:\\{int\_31}, \[7], 59, 61, 82, 115, 144, 221, 234.
\:\\{int\_32}, \[7], 27, 53, 54, 55, 56, 57, 58, 59, 72, 74, 82, 89, 99, 100,
105, 109, 113, 114, 115, 125, 126, 128, 134, 141, 143, 144, 146, 151, 173, 178,
183, 187, 203, 219, 234, 241, 242, 243, 244.
\:\\{int\_7}, \[7], 65, 85, 177.
\:\\{int\_8}, \[7], 50, 114.
\:\\{int\_8u}, \[7], 50, 60, 85, 89, 114, 141, 151, 212, 219.
\:\\{integer}, 7, 28.
\:\\{invalid\_cl}, \[120], 122, 161, 226, 227.
\:\\{invalid\_font}, \[83], 85, 86, 101, 145, 153, 195, 253.
\:\\{invalid\_packet}, \[38], 87, 88, 89, 108.
\:\\{invalid\_width}, \[73], 82, 99, 107, 145.
\:\|{j}, \[60], \[177], \[195], \[252].
\:\\{jump\_out}, 3, \[23], 24, 25.
\:\|{k}, \[40], \[48], \[60], \[61], \[90], \[132], \[150], \[151], \[175], %
\[177], \[188], \[212], \[219], \[230], \[240], \[248], \[250].
\:{Knuth, Donald Ervin}, 13.
\:\|{l}, \[40], \[60], \[90], \[100], \[151], \[177], \[248].
\:\\{last\_pop}, \[151], 161.
\:\\{last\_text\_char}, \[15], 19.
\:\\{lcl\_nf}, \[146], 147, 150, 232.
\:\\{lh}, \[100], 103.
\:\\{ll}, 64, \[67].
\:\\{long\_char}, \[133], 151, 160.
\:\&{loop}, \[12].
\:\|{m}, \[61].
\:\\{make\_font}, \[100], 105, 132, 150.
\:\\{make\_font\_name}, \[63], 96, 139.
\:\\{make\_font\_name\_end}, \[63].
\:\\{make\_font\_res}, \[64].
\:\\{make\_font\_res\_end}, \[64].
\:\\{make\_name}, 63, 64, \[67].
\:\\{make\_packet}, 36, \[40], 44, 47, 90, 132, 150.
\:\\{make\_res}, 64, \[66].
\:\\{make\_width}, \[74], 107.
\:\\{mark\_error}, \[21], 87, 90, 99.
\:\\{mark\_fatal}, \[21], 23.
\:\\{mark\_harmless}, \[21], 279.
\:\\{match}, \[188].
\:\\{max\_bytes}, \[5], 31, 34, 232.
\:\\{max\_chars}, \[5], 77, 104, 107, 232.
\:\\{max\_cl}, \[120].
\:\\{max\_drift}, 186.
\:\\{max\_font\_type}, \[4], 80.
\:\\{max\_fonts}, \[5], 80, 83, 101, 132, 150, 232, 275.
\:\\{max\_h\_drift}, \[186], 200.
\:\\{max\_packets}, \[5], 31, 38, 40, 47, 232.
\:\\{max\_pages}, \[187], 189, 192, 194, 197.
\:\\{max\_par}, \[117].
\:\\{max\_pix\_value}, \[71].
\:\\{max\_recursion}, \[5], 209, 217, 218, 232.
\:\\{max\_select}, \[5], 187, 192.
\:\\{max\_v\_drift}, \[186], 201.
\:\\{max\_widths}, \[5], 71, 74, 232.
\:\\{min\_pix\_value}, \[71].
\:\.{missing character packet...}, 87.
\:\\{move}, 155.
\:\\{move\_zero}, \[151], 164, 165.
\:\|{n}, \[25], \[67], \[113], \[203].
\:\\{n\_chars}, \[78], 79, 104, 107, 108, 232.
\:\\{n\_recur}, 209, \[210], 211, 213, 214, 215, 217.
\:\\{n\_res\_digits}, 64, \[65], 66.
\:\\{n\_widths}, \[72], 73, 74, 76, 232.
\:\\{name\_length}, \[5], 62, 63, 67.
\:\\{negative}, \[178].
\:\\{new\_font\_type}, \[4], 80, 95, 101, 207, 216, 228.
\:\\{new\_line}, \[11], 60, 95, 99, 100, 110, 218.
\:\\{new\_packet}, \[47], 152, 179, 194, 199, 220, 251.
\:\\{nf}, 80, \[81], 83, 100, 101, 132, 150, 232.
\:\&{nil}, 12.
\:\\{no\_par}, \[117], 119, 127, 145, 208.
\:\\{nop}, \[26], 119, 120, 122, 127, 161.
\:\\{not\_found}, \[10], 89, 139, 151.
\:\\{num\_select}, \[187], 194, 197.
\:\\{numu}, 208.
\:\\{numu\_par}, \[117], 119, 127, 145.
\:\\{num1\_par}, \[117], 119, 127, 145, 208.
\:\\{num2\_par}, \[117], 119, 127, 145, 208.
\:\\{num3\_par}, \[117], 119, 127, 145, 208.
\:\\{num4}, 208.
\:\\{num4\_par}, \[117], 119, 127, 145.
\:\\{nw}, \[100], 103, 107.
\:\|{o}, \[57], \[58], \[59], \[243], \[244].
\:{optimization}, \[7], 50, 54, 98, 105, 112, 140, 238.
\:\\{ord}, 17.
\:\&{othercases}, \[13].
\:\\{others}, 13.
\:\\{out\_back}, \[234], 235, 253, 280.
\:\\{out\_byte}, \[238], 239, 240, 241, 248.
\:\\{out\_char}, \[242], 277.
\:\\{out\_file}, 1, \[3], \[234], 236, 237, 238, 240, 241, 245, 251, 279.
\:\\{out\_fnt}, \[245], 253, 277.
\:\\{out\_fnt\_def}, \[248], 275, 280.
\:\\{out\_fnts}, \[245], 275, 280.
\:\\{out\_font\_type}, \[4], 245, 275, 277.
\:\\{out\_four}, \[241], 248, 251, 253, 269, 271, 280.
\:\\{out\_loc}, \[234], 235, 239, 240, 241, 248, 253, 279, 280.
\:\\{out\_mag}, 61, \[187], 189, 192, 194, 220, 251, 280.
\:\\{out\_max\_h}, \[234], 235, 264, 280.
\:\\{out\_max\_v}, \[234], 235, 267, 280.
\:\\{out\_nf}, \[245], 246, 247, 275, 280.
\:\\{out\_one}, \[239], 242, 243, 244, 251, 253, 255, 257, 259, 263, 266, 269,
271, 278, 279, 280.
\:\\{out\_packet}, \[240], 251, 261.
\:\\{out\_pages}, \[234], 235, 253, 279, 280.
\:\\{out\_signed}, \[244], 263, 266.
\:\\{out\_stack}, \[234], 235, 257, 280.
\:\\{out\_unsigned}, \[243], 248, 261, 277.
\:\\{output}, \[3], 11, 175.
\:\\{overflow}, \[25], 34, 40, 45, 47, 63, 74, 101, 104, 107, 132, 150, 162,
218, 222, 275.
\:\|{p}, \[24], \[25], \[40], \[60], \[61], \[74], \[87], \[89], \[100], %
\[177], \[179], \[199], \[240], \[248], \[250], \[260].
\:\\{p\_hash}, 36, \[37], 38, 42.
\:\\{p\_link}, 36, \[37], 42.
\:\\{packed\_byte}, \[31], 32.
\:\\{pair\_32}, \[183].
\:\\{pckt\_char}, \[57], 165.
\:\\{pckt\_d\_msg}, \[85], 86, 90.
\:\\{pckt\_dup}, \[85], 89, 90.
\:\\{pckt\_ext}, \[85], 89, 90.
\:\\{pckt\_extract}, \[49], 50, 51, 52, 53, 67, 88.
\:\\{pckt\_first\_par}, \[208], 215.
\:\\{pckt\_four}, \[56], 166.
\:\\{pckt\_length}, \[33], 42, 240, 261.
\:\\{pckt\_m\_msg}, \[85], 86, 87.
\:\\{pckt\_one}, \[54].
\:\\{pckt\_pointer}, 24, 25, \[31], 32, 37, 40, 46, 47, 48, 49, 60, 61, 67, 77,
78, 82, 85, 87, 89, 91, 134, 177, 179, 187, 199, 210, 240, 248.
\:\\{pckt\_prev}, \[85], 89, 90.
\:\\{pckt\_ptr}, \[32], 35, 38, 40, 42, 43, 47, 89, 90, 160, 175, 232, 251.
\:\\{pckt\_res}, \[85], 89, 90, 160.
\:\\{pckt\_room}, \[34], 44, 54, 55, 56, 57, 58, 59, 89, 132, 150, 152, 167,
175, 215, 220, 226, 251.
\:\\{pckt\_s\_msg}, \[85], 86, 87.
\:\\{pckt\_sbyte}, \[50], 208.
\:\\{pckt\_signed}, \[59], 161.
\:\\{pckt\_spair}, \[51], 208.
\:\\{pckt\_squad}, \[53], 208.
\:\\{pckt\_start}, 31, \[32], 33, 35, 38, 40, 43, 47, 48, 60, 61, 67, 88, 89,
90, 160, 175, 177, 240, 248, 251.
\:\\{pckt\_strio}, \[52], 88, 208.
\:\\{pckt\_two}, \[55].
\:\\{pckt\_ubyte}, \[50], 88, 208, 215.
\:\\{pckt\_unsigned}, \[58], 165, 167.
\:\\{pckt\_upair}, \[51], 88, 208.
\:\\{pckt\_utrio}, \[52], 208.
\:\\{pid\_init}, \[44].
\:\\{pid0}, \[44].
\:\\{pid1}, \[44].
\:\\{pid10}, \[44].
\:\\{pid2}, \[44].
\:\\{pid3}, \[44].
\:\\{pid4}, \[44].
\:\\{pid5}, \[44].
\:\\{pid6}, \[44].
\:\\{pid7}, \[44].
\:\\{pid8}, \[44].
\:\\{pid9}, \[44].
\:\\{pix\_value}, \[71], 72, 78, 181, 183, 203.
\:\\{pix\_widths}, 71, \[72], 73, 74, 77, 108, 212.
\:\\{pop}, \[26], 69, 122, 151, 155, 156, 161, 168, 169, 198, 217, 259, 278.
\:\\{pop\_cl}, \[120], 122, 161, 170, 215, 226.
\:\\{post}, \[26], 120, 151, 219, 223, 280.
\:\\{post\_post}, \[26], 222, 223, 280.
\:\\{pre}, \[26], 120, 122, 152, 220, 251.
\:\\{preamble\_comment}, \[1], 251.
\:\\{print}, \[11], 24, 25, 48, 60, 61, 90, 95, 99, 110, 132, 136, 150, 151,
152, 175, 195, 218, 220, 232, 247, 275, 279.
\:\\{print\_font}, \[61], 95, 99, 100, 136, 151, 152, 218, 275.
\:\\{print\_ln}, 3, \[11], 23, 24, 25, 60, 87, 90, 95, 99, 110, 136, 151, 152,
179, 190, 192, 195, 218, 220, 232, 233, 275, 279.
\:\\{print\_nl}, \[11], 99, 152.
\:\\{print\_packet}, 24, 25, \[48], 152, 220.
\:\\{push}, 5, \[26], 69, 122, 155, 156, 157, 161, 162, 163, 164, 198, 257.
\:\\{push\_cl}, \[120], 122, 161, 215, 226.
\:\\{put}, 57, 117, 126, 155, 156, 169, 173, 215, 216, 217, 242.
\:\\{put\_rule}, \[26], 117, 119, 122, 123, 124, 155, 169.
\:\\{put1}, \[26], 57, 116, 119, 122, 123, 124, 127.
\:\\{put4}, 116.
\:\|{q}, \[87], \[89], \[100], \[250].
\:\|{r}, \[66], \[250].
\:\\{random\_reading}, \[2], 110, 113, 219, 226, 227.
\:\\{read}, 98, 112, 140.
\:\\{read\_ln}, 175.
\:\\{read\_tfm\_word}, \[98], 103, 104, 107.
\:\\{real}, 102, 181.
\:\\{recur\_ext}, \[210], 213, 218.
\:\\{recur\_fnt}, \[210], 213, 214, 218.
\:\\{recur\_loc}, \[210], 217, 218.
\:\\{recur\_pckt}, \[210], 215, 218.
\:\\{recur\_pointer}, \[209], 210, 212.
\:\\{recur\_res}, \[210], 213, 218.
\:\\{recur\_used}, \[210], 211, 217, 232.
\:{recursion}, 209.
\:\\{res}, \[57], 70, 84, \[242].
\:\\{res\_ASCII}, \[64].
\:\\{res\_char}, \[64].
\:\\{res\_digits}, 64, \[65], 66.
\:\\{reset}, 96, 111, 139, 175.
\:\\{restart}, \[10].
\:\\{reswitch}, \[10], 151, 161, 164, 170.
\:\&{return}, 10, \[12].
\:\\{rewrite}, 236.
\:\\{right}, 59, 200, 215, 226, 244, 263.
\:\\{right\_cl}, \[120], 122, 123, 124, 161, 200, 263.
\:\\{right1}, \[26], 119, 122, 123, 124, 155, 173.
\:\\{round}, 61, 74, 103, 150, 152.
\:\\{rule\_cl}, \[120], 122, 156, 164, 215, 226.
\:\\{rule\_par}, \[117], 119, 127, 145, 208.
\:\|{s}, \[40].
\:\\{save\_ext}, \[151].
\:\\{save\_fnt}, \[100].
\:\\{save\_limit}, \[212], 215, 217.
\:\\{save\_res}, \[151].
\:\\{save\_upd}, \[151], \[212], 213, 216.
\:\\{save\_wp}, \[151], \[212], 213.
\:\\{scan\_count}, \[191], 192.
\:\\{scan\_init}, \[175], 179.
\:\\{scan\_int}, \[178], 191, 192.
\:\\{scan\_keyword}, \[177], 192.
\:\\{scan\_ptr}, 175, \[176], 177, 178, 179, 191, 192.
\:\\{scan\_skip}, \[175], 177, 178, 191.
\:\\{second}, \[132].
\:\\{select\_count}, \[187].
\:\\{select\_max}, \[187].
\:\\{select\_there}, \[187].
\:\\{select\_vals}, \[187].
\:\\{selected}, \[187], 189, 191, 196, 197, 222.
\:\\{set\_char}, 57, 155, 156, 165, 169, 173, 216, 217, 242.
\:\\{set\_char\_0}, \[26], 116, 122.
\:\\{set\_cur\_char}, \[127], 145, 208.
\:\\{set\_cur\_wp}, \[145], 228.
\:\\{set\_cur\_wp\_end}, \[145].
\:\\{set\_pos}, 113.
\:\\{set\_rule}, \[26], 117, 119, 122, 123, 124, 126, 127, 145, 155, 156, 169,
173, 208, 269.
\:\\{set1}, \[26], 57, 123, 124, 127.
\:\\{set4}, 116.
\:\\{signed\_byte}, \[27].
\:\\{signed\_pair}, \[27].
\:\\{signed\_quad}, \[27].
\:\\{signed\_trio}, \[27].
\:\\{sixteen\_bits}, \[27].
\:\.{Sorry, {\title} capacity exceeded}, 25.
\:\\{spotless}, \[21], 22, 233.
\:\\{stack}, \[184], 198.
\:\\{stack\_index}, \[183], 184.
\:\\{stack\_pointer}, 157, \[183], 184.
\:\\{stack\_ptr}, 157, \[184], 195, 197, 198, 257, 278.
\:\\{stack\_record}, \[183], 184.
\:\\{stack\_size}, \[5], 162, 183, 222, 232.
\:\\{stack\_used}, \[157], 159, 162, 232.
\:\\{start\_count}, \[187], 188, 191.
\:\\{start\_match}, \[188], 196, 224.
\:\\{start\_packet}, \[89], 160.
\:\\{start\_there}, \[187], 188, 191.
\:\\{start\_vals}, \[187], 188, 191, 192.
\:\&{stat}, \[8].
\:\\{str\_bytes}, 34, 45, \[46].
\:\\{str\_chars}, 45, \[46], 104, 107.
\:\\{str\_fonts}, 45, \[46], 101, 132, 150, 207, 275, 277.
\:\\{str\_mag}, \[187], 192, 193.
\:\\{str\_name\_length}, 45, \[46], 63.
\:\\{str\_packets}, 40, 45, \[46], 47, 49, 89, 215.
\:\\{str\_recursion}, 45, \[46], 218.
\:\\{str\_select}, \[187], 192, 193.
\:\\{str\_stack}, 45, \[46], 162, 222.
\:\\{str\_widths}, 45, \[46], 74.
\:\.{substituted character packet...}, 87.
\:{system dependencies}, \[2], 3, 7, 9, 13, 15, 23, \[27], 28, 31, 50, 54, 61,
63, 64, 67, 74, 93, 96, 98, 103, 105, 112, 113, 137, 139, 140, 175, 179, 230,
231, 233, 238, 282.
\:\|{t}, \[89].
\:\&{tats}, \[8].
\:\\{temp\_byte}, \[151], 152, \[219], 220, 223, 227.
\:\\{temp\_int}, \[151], \[219], 222, 223, 225.
\:\\{temp\_pix}, \[181], 200, 201.
\:\\{terminal\_line\_length}, \[5], 175.
\:\\{text\_char}, \[15], 17.
\:\\{text\_file}, \[15].
\:\.{TFM {\rm files}}, 69.
\:\.{TFM file can\'t be opened}, 96.
\:\\{tfm\_byte}, \[98].
\:\\{tfm\_b0}, \[97], 98, 103, 104, 105, 107, 143, 144.
\:\\{tfm\_b01}, \[103].
\:\\{tfm\_b1}, \[97], 98, 103, 105, 107, 143, 144.
\:\\{tfm\_b2}, \[97], 98, 103, 105, 107, 143, 144.
\:\\{tfm\_b23}, \[103].
\:\\{tfm\_b3}, \[97], 98, 103, 105, 107, 143, 144.
\:\\{tfm\_conv}, \[102], 103, 150, 152, 220.
\:\\{TFM\_default\_area}, \[93], 94, 96.
\:\\{TFM\_default\_area\_name}, \[93], 94.
\:\\{TFM\_default\_area\_name\_length}, \[93], 96.
\:\\{tfm\_ext}, \[91], 92, 96.
\:\\{tfm\_file}, \[91], 96, 98, 101.
\:\\{tfm\_fix1}, \[105], 143.
\:\\{tfm\_fix2}, \[105], 143.
\:\\{tfm\_fix3}, \[105], 143.
\:\\{tfm\_fix3u}, \[105], 143, 144.
\:\\{tfm\_fix4}, \[105], 107, 143.
\:\\{tfm\_squad}, \[103].
\:\\{tfm\_uquad}, \[103].
\:\.{This can't happen}, 24.
\:\\{three\_cases}, \[116], 161, 208.
\:\\{title}, \[1], 25.
\:\\{true}, 2, 12, 87, 89, 100, 103, 112, 113, 124, 126, 127, 132, 140, 151,
159, 161, 164, 165, 177, 178, 181, 187, 188, 189, 191, 197, 203, 204, 216.
\:\\{trunc}, 203.
\:\\{twentyfour\_bits}, \[27].
\:\\{two\_cases}, \[116], 127, 161.
\:\\{type\_flag}, \[84], 85, 89.
\:\\{type\_setting}, \[181], 182, 195, 196, 197, 206, 225.
\:\|{u}, \[99].
\:\\{upd}, \[57], \[242].
\:\\{update\_terminal}, \[175].
\:\.{Use DVItype}, 110.
\:\.{Use TFtoPL/PLtoTF}, 95.
\:\.{Use VFtoVP/VPtoVF}, 136.
\:\|{v}, \[184].
\:\\{v\_conv}, 74, \[181], 194, 203.
\:\\{v\_field}, \[183], 184, 185.
\:\\{v\_pixel\_round}, \[74], 186, 201.
\:\\{v\_pixels}, \[181], 204.
\:\\{v\_resolution}, 194, \[249].
\:\\{v\_rule\_pixels}, \[203], 204.
\:\\{vf\_byte}, \[140], 141, 143, 144.
\:\\{vf\_char\_type}, \[158], 159, 165.
\:\\{vf\_complex}, \[160], 173.
\:\\{vf\_cur\_fnt}, \[134], 145, 148, 161, 164, 165.
\:\\{VF\_default\_area}, \[137], 138, 139.
\:\\{VF\_default\_area\_name}, \[137], 138.
\:\\{VF\_default\_area\_name\_length}, \[137], 139.
\:\\{vf\_do\_font}, \[150], 153.
\:\\{vf\_e\_fnts}, \[146], 149.
\:\\{vf\_eof}, \[140].
\:\\{vf\_ext}, \[134], 135, 139.
\:\\{vf\_file}, \[134], 139, 140, 141, 151.
\:\\{vf\_first\_par}, \[145], 161.
\:\\{vf\_fixp}, \[144], 150.
\:\\{vf\_fix1}, \[143], 145.
\:\\{vf\_fix2}, \[143], 145.
\:\\{vf\_fix3}, \[143], 145.
\:\\{vf\_fix3u}, \[143], 160.
\:\\{vf\_fix4}, \[143], 145, 160.
\:\\{vf\_fnt}, \[151], 161, 164, 165.
\:\\{vf\_font}, \[148], 161.
\:\\{vf\_font\_type}, \[4], 136, 146, 151, 216, 228.
\:\\{vf\_group}, \[156], 168.
\:\\{vf\_i\_fnts}, \[146], 148, 150, 153.
\:\\{vf\_id}, \[133], 152.
\:\\{vf\_last}, 156, \[157], 160, 163, 165, 166, 167, 168, 169, 171.
\:\\{vf\_last\_end}, 156, \[157], 160, 163, 164, 168, 171.
\:\\{vf\_last\_loc}, 156, \[157], 160, 165, 166, 168, 171.
\:\\{vf\_limit}, \[134], 160, 161.
\:\\{vf\_loc}, \[134], 136, 139, 141, 143, 144, 160, 161.
\:\\{vf\_move}, \[157], 159, 161, 163, 170.
\:\\{vf\_nf}, \[146], 148, 149, 150, 153.
\:\\{vf\_other}, \[156], 159, 160, 163, 165, 167, 171.
\:\\{vf\_pquad}, \[144], 150, 152.
\:\\{vf\_ptr}, 156, \[157], 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172.
\:\\{vf\_push\_loc}, 156, \[157], 160, 162, 163, 164, 168, 169.
\:\\{vf\_push\_num}, 156, \[157], 162, 168, 170, 172.
\:\\{vf\_put}, \[156], 159, 160.
\:\\{vf\_rule}, \[156], 159, 168.
\:\\{vf\_rule\_type}, \[158], 159, 166.
\:\\{vf\_set}, \[156], 159.
\:\\{vf\_simple}, \[160], 173, 216.
\:\\{vf\_squad}, \[141], 144, 145, 150, 152, 153.
\:\\{vf\_state}, \[154], 157.
\:\\{vf\_strio}, \[141], 160.
\:\\{vf\_type}, \[156], 157, 158.
\:\\{vf\_ubyte}, \[141], 145, 150, 152, 153, 160, 167.
\:\\{vf\_upair}, \[141], 145, 153.
\:\\{vf\_uquad}, \[144], 145, 160.
\:\\{vf\_utrio}, \[141], 145, 153.
\:\\{vf\_wp}, \[151], 160.
\:\\{visible}, \[204], \[270].
\:\\{vv}, 183, \[184], 186.
\:\\{vv\_field}, \[183], 184, 185.
\:\|{w}, \[74], \[100], \[184].
\:\\{w\_cl}, \[120], 122, 124, 161, 200.
\:\\{w\_hash}, 71, \[72], 73, 76.
\:\\{w\_link}, 71, \[72], 73, 76.
\:\\{w\_x\_field}, \[183], 184, 185.
\:\.{WEB}, 33.
\:\\{width\_dimen}, \[173], 174, 226, 269.
\:\\{width\_pointer}, \[71], 72, 74, 77, 78, 99, 100, 126, 151, 212.
\:\\{widths}, 71, \[72], 73, 74, 76, 82, 99, 100, 205, 212.
\:\\{wp}, \[99].
\:\\{write}, 11, 238.
\:\\{write\_ln}, 11.
\:\\{w0}, \[26], 122, 154, 263.
\:\\{w0\_cl}, \[120], 122, 161, 200, 215, 226.
\:\\{w1}, \[26], 119, 122, 123, 124.
\:\|{x}, \[54], \[55], \[56], \[58], \[59], \[74], \[115], \[143], \[144], %
\[178], \[184], \[241], \[243], \[244].
\:\\{x\_cl}, \[120], 122, 123, 124.
\:\\{xchr}, \[17], 18, 19, 48, 60, 61, 66, 67.
\:\&{xclause}, 12.
\:\\{xord}, \[17], 19, 64, 175, 251.
\:\\{xx}, \[59].
\:\\{xxx}, 58, 155, 164, 243.
\:\\{xxx\_cl}, \[120], 122, 164, 215, 226, 227.
\:\\{xxx1}, \[26], 119, 122, 167, 261.
\:\\{xxx4}, \[26].
\:\\{x0}, \[26], 122, 154, 263.
\:\\{x0\_cl}, \[120], 122.
\:\\{x1}, \[26], 119, 122, 123, 124.
\:\\{x4}, 173.
\:\|{y}, \[184].
\:\\{y\_cl}, \[120], 122, 124, 161, 201.
\:\\{y\_z\_field}, \[183], 184, 185.
\:\\{y0}, \[26], 122, 154, 266.
\:\\{y0\_cl}, \[120], 122, 161, 201, 215, 226.
\:\\{y1}, \[26], 119, 122, 123, 124.
\:\|{z}, \[105], \[184].
\:\\{z\_cl}, \[120], 122, 123, 124.
\:\\{zero}, 155.
\:\\{zero\_stack}, \[184], 185, 195.
\:\\{zero\_width}, \[73].
\:\\{z0}, \[26], 122, 154, 266.
\:\\{z0\_cl}, \[120], 122.
\:\\{z1}, \[26], 119, 122, 123, 124.
\:\\{z4}, 155.
\fin
\:\X175, 177, 178, 191:Action procedures for \\{dialog}\X
\U179.
\:\X48, 60, 61:Basic printing procedures\X
\U23.
\:\X192:Cases for options\X
\U179.
\:\X136:Cases for \\{bad\_font}\X
\U95.
\:\X237:Close output file(s)\X
\U230.
\:\X43:Compare packet \|p with current packet, \&{goto} \\{found} if equal\X
\U42.
\:\X9:Compiler directives\X
\U3.
\:\X41:Compute the packet hash code \|h\X
\U40.
\:\X42:Compute the packet location \|p\X
\U40.
\:\X75:Compute the width hash code \|h\X
\U74.
\:\X76:Compute the width location \|p, \&{goto}  found unless the value is new\X
\U74.
\:\X5:Constants in the outer block\X
\U3.
\:\X223:DVI: Find the postamble\X
\U222.
\:\X224:DVI: Find the starting page\X
\U222.
\:\X131:DVI: Locate font \\{cur\_parm}\X
\Us130\ET132.
\:\X226:DVI: Process a page; then \&{goto} \\{done}\X
\U225.
\:\X225:DVI: Process one page\X
\U219.
\:\X222:DVI: Process the postamble\X
\U219.
\:\X220:DVI: Process the preamble\X
\U219.
\:\X227:DVI: Skip a page; then \&{goto} \\{done}\X
\U225.
\:\X228:DVI: Typeset a \\{char}\X
\U226.
\:\X240, 241, 242, 243, 244, 248:Declare typesetting procedures\X
\U180.
\:\X101:Define a new font\X
\U100.
\:\X196:Determine whether this page should be processed or skipped\X
\U195.
\:\X23, 24, 25, 95, 110:Error handling procedures\X
\U3.
\:\X206:Finish output file(s)\X
\U230.
\:\X17, 21, 32, 37, 46, 49, 62, 65, 72, 78, 81, 82, 85, 91, 93, 97, 102, 109,
118, 121, 123, 125, 126, 128, 134, 137, 142, 146, 157, 158, 173, 176, 181, 184,
187, 210, 221, 234, 245:Globals in the outer block\X
\U3.
\:\X189:Initialize options\X
\U179.
\:\X45, 92, 135, 193:Initialize predefined strings\X
\U231.
\:\X16, 39:Local variables for initialization\X
\U3.
\:\X88:Locate a character packet and \&{goto} \\{found} if found\X
\Us87\ET89.
\:\X260:OUT: Declare additional local variables for \\{do\_xxx}\X
\U199.
\:\X252:OUT: Declare additional local variables \\{do\_bop}\X
\U195.
\:\X270:OUT: Declare additional local variables \\{do\_rule}\X
\U204.
\:\X276:OUT: Declare local variables (if any) for \\{do\_char}\X
\U205.
\:\X265:OUT: Declare local variables (if any) for \\{do\_down}\X
\U201.
\:\X254:OUT: Declare local variables (if any) for \\{do\_eop}\X
\U197.
\:\X273:OUT: Declare local variables (if any) for \\{do\_font}\X
\U207.
\:\X258:OUT: Declare local variables (if any) for \\{do\_pop}\X
\U198.
\:\X250:OUT: Declare local variables (if any) for \\{do\_pre}\X
\U194.
\:\X256:OUT: Declare local variables (if any) for \\{do\_push}\X
\U198.
\:\X262:OUT: Declare local variables (if any) for \\{do\_right}\X
\U200.
\:\X268:OUT: Declare local variables (if any) for \\{do\_width}\X
\U202.
\:\X278:OUT: Finish incomplete page\X
\U206.
\:\X279:OUT: Finish output file(s)\X
\U206.
\:\X275:OUT: Look for a font file after trying to read the \.{VF} file\X
\U207.
\:\X274:OUT: Look for a font file before trying to read the \.{VF} file; if
found \&{goto} \\{done}\X
\U207.
\:\X267:OUT: Move down\X
\U201.
\:\X264:OUT: Move right\X
\Us200, 202, 204\ETs205.
\:\X253:OUT: Process a \\{bop}\X
\U195.
\:\X266:OUT: Process a \\{down} or \|y or \|z\X
\U201.
\:\X259:OUT: Process a \\{pop}\X
\U198.
\:\X257:OUT: Process a \\{push}\X
\U198.
\:\X263:OUT: Process a \\{right} or \|w or \|x\X
\U200.
\:\X255:OUT: Process an \\{eop}\X
\U197.
\:\X261:OUT: Process an \\{xxx}\X
\U199.
\:\X251:OUT: Process the \\{pre}\X
\U194.
\:\X271:OUT: Typeset a visible \\{rule}\X
\Us204\ET272.
\:\X277:OUT: Typeset a \\{char}\X
\U205.
\:\X269:OUT: Typeset a \\{width}\X
\U202.
\:\X272:OUT: Typeset an invisible \\{rule}\X
\U204.
\:\X280:OUT: Write the postamble\X
\U279.
\:\X111:Open input file(s)\X
\U231.
\:\X236:Open output file(s)\X
\U231.
\:\X232:Print memory usage statistics\X
\U230.
\:\X247:Print more font usage statistics\X
\U232.
\:\X281:Print more memory usage statistics\X
\U232.
\:\X233:Print the job \\{history}\X
\U230.
\:\X190:Print valid options\X
\U179.
\:\X106:Replace \|z by $\|z^\prime$ and compute $\alpha,\beta$\X
\Us107\ET152.
\:\X18, 19, 22, 38, 73, 79, 83, 86, 94, 119, 122, 124, 129, 138, 147, 159, 174,
182, 185, 211, 235, 246:Set initial values\X
\U3.
\:\X108:TFM: Convert character-width indices to character-width pointers\X
\U101.
\:\X96:TFM: Open \\{tfm\_file}\X
\U101.
\:\X107:TFM: Read and convert the width values\X
\U101.
\:\X103:TFM: Read past the header data\X
\U101.
\:\X104:TFM: Store character-width indices\X
\U101.
\:\X7, 14, 15, 27, 29, 31, 36, 71, 77, 80, 84, 117, 120, 154, 156, 183,
209:Types in the outer block\X
\U3.
\:\X161:VF: Append \.{DVI} commands to the character packet\X
\U160.
\:\X170:VF: Apply rule 3 or 4\X
\U168.
\:\X172:VF: Apply rule 5\X
\U168.
\:\X171:VF: Apply rule 6\X
\U168.
\:\X160:VF: Build a character packet\X
\U151.
\:\X218:VF: Display the recursion traceback and terminate\X
\U217.
\:\X164:VF: Do a \\{char}, \\{rule}, or \\{xxx}\X
\U161.
\:\X165:VF: Do a \\{fnt}, a \\{char}, or both\X
\U164.
\:\X168:VF: Do a \\{pop}\X
\U161.
\:\X162:VF: Do a \\{push}\X
\U161.
\:\X166:VF: Do a \\{rule}\X
\U164.
\:\X167:VF: Do an \\{xxx}\X
\U164.
\:\X217:VF: Enter a new recursion level\X
\U216.
\:\X215:VF: Interpret the \.{DVI} commands in the packet\X
\U212.
\:\X149:VF: Locate font \\{cur\_parm}\X
\Us148\ET150.
\:\X139:VF: Open \\{vf\_file} or \&{goto} \\{not\_found}\X
\U151.
\:\X169:VF: Prepare for rule 4\X
\U168.
\:\X153:VF: Process the font definitions\X
\U151.
\:\X152:VF: Process the preamble\X
\U151.
\:\X214:VF: Restore values on exit from \\{do\_vf\_packet}\X
\U212.
\:\X213:VF: Save values on entry to \\{do\_vf\_packet}\X
\U212.
\:\X163:VF: Start a new level\X
\Us162\ET172.
\:\X216:VF: Typeset a \\{char}\X
\U215.
\:\X105:Variables for scaling computation\X
\Us100\ET142.
\con
