~ubuntu-branches/ubuntu/jaunty/texlive-bin/jaunty-security

« back to all changes in this revision

Viewing changes to build/source/texk/web2c/omegaware/ovp2ovf.web

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2008-06-26 23:14:59 UTC
  • mfrom: (2.1.30 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080626231459-y02rjsrgtafu83yr
Tags: 2007.dfsg.2-3
add missing source roadmap.fig of roadmap.eps in fontinst documentation
(Closes: #482915) (urgency medium due to RC bug)
(new patch add-missing-fontinst-source)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
2
% This file is part of the Omega project, which
 
3
% is based in the web2c distribution of TeX.
 
4
%
 
5
% Copyright (c) 1994--2000 John Plaice and Yannis Haralambous
 
6
% applies only to the changes to the original vptovf.web.
 
7
%
 
8
% This program by D. E. Knuth is not copyrighted and can be used freely.
 
9
% Version 1 was implemented in December 1989.
 
10
% Version 1.1 fixed some for-loop indices for stricter Pascal (April 1990).
 
11
% Version 1.2 fixed `nonexistent char 0' bug, and a bit more (September 1990).
 
12
% Version 1.3 has more robust `out_scaled' (March 1991).
 
13
% Version 1.4 (March 1995) initialized lk_step_ended (Armin K\"ollner).
 
14
 
 
15
% Here is TeX material that gets inserted after \input webmac
 
16
\def\hang{\hangindent 3em\indent\ignorespaces}
 
17
\font\ninerm=cmr9
 
18
\let\mc=\ninerm % medium caps for names like SAIL
 
19
\def\PASCAL{Pascal}
 
20
\font\logo=logo10 % for the METAFONT logo
 
21
\def\MF{{\logo METAFONT}}
 
22
 
 
23
\def\(#1){} % this is used to make section names sort themselves better
 
24
\def\9#1{} % this is used for sort keys in the index
 
25
 
 
26
\def\title{OVP2OVF}
 
27
\def\contentspagenumber{201}
 
28
\def\topofcontents{\null
 
29
  \def\titlepage{F} % include headline on the contents page
 
30
  \def\rheader{\mainfont\hfil \contentspagenumber}
 
31
  \vfill
 
32
  \centerline{\titlefont The {\ttitlefont OVP2OVF} processor}
 
33
  \vskip 15pt
 
34
  \centerline{(Version 1.11, February 2000)}
 
35
  \vfill}
 
36
\def\botofcontents{\vfill
 
37
  \centerline{\hsize 5in\baselineskip9pt
 
38
    \vbox{\ninerm\noindent
 
39
    The preparation of this program
 
40
    was supported in part by the National Science
 
41
    Foundation and by the System Development Foundation. `\TeX' is a
 
42
    trademark of the American Mathematical Society.}}}
 
43
\pageno=\contentspagenumber \advance\pageno by 1
 
44
 
 
45
@* Introduction.
 
46
The \.{OVP2OVF} utility program converts virtual-property-list (``\.{VPL}''
 
47
and ``\.{OVP}'') files into an equivalent pair of files called a virtual
 
48
font (``\.{OVF}'') file and an $\Omega$ font metric (``\.{OFM}'') file.
 
49
It also makes a thorough check of the given \.{VPL} or \.{OVP} file,
 
50
so that the \.{OVF} file should be acceptable to device drivers and
 
51
the \.{OFM} file should be acceptable to $\Omega$.
 
52
 
 
53
In the following documentation, all unchanged references to
 
54
the \.{VPtoVF} program and to \.{VPL}, \.{VF} and \.{TFM} files also apply to
 
55
the \.{OVP2OVF} program and to \.{OVP}, \.{OVF} and \.{OFM} files.
 
56
 
 
57
\indent\.{VPtoVF} is an extended version of the program \.{PLtoTF}, which
 
58
is part of the standard \TeX ware library.
 
59
\.{OVP2OVF} is an extended version of \.{VPtoVF} that allows
 
60
much larger fonts.
 
61
The idea of a virtual font was inspired by the work of David R. Fuchs
 
62
@^Fuchs, David Raymond@>
 
63
who designed a similar set of conventions in 1984 while developing a
 
64
device driver for ArborText, Inc. He wrote a somewhat similar program
 
65
called \.{PLFONT}.
 
66
 
 
67
The |banner| string defined here should be changed whenever \.{OVP2OVF}
 
68
gets modified.
 
69
 
 
70
@d banner=='This is OVP2OVF, Version 1.11'
 
71
{printed when the program starts}
 
72
 
 
73
@ This program is written entirely in standard \PASCAL, except that
 
74
it has to do some slightly system-dependent character code conversion
 
75
on input. Furthermore, lower case letters are used in error messages;
 
76
they could be converted to upper case if necessary. The input is read
 
77
from |vpl_file|, and the output is written on |vf_file| and |tfm_file|;
 
78
error messages and
 
79
other remarks are written on the |output| file, which the user may
 
80
choose to assign to the terminal if the system permits it.
 
81
@^system dependencies@>
 
82
 
 
83
The term |print| is used instead of |write| when this program writes on
 
84
the |output| file, so that all such output can be easily deflected.
 
85
 
 
86
@d print(#)==write(#)
 
87
@d print_ln(#)==write_ln(#)
 
88
 
 
89
@p program OVP2OVF(@!vpl_file,@!vf_file,@!tfm_file,@!output);
 
90
const @<Constants in the outer block@>@/
 
91
type @<Types in the outer block@>@/
 
92
var @<Globals in the outer block@>@/
 
93
procedure initialize; {this procedure gets things started properly}
 
94
  var @<Local variables for initialization@>@/
 
95
  begin print_ln(banner);@/
 
96
  @<Set initial values@>@/
 
97
  end;
 
98
 
 
99
@ The following parameters can be changed at compile time to extend or
 
100
reduce \.{VPtoVF}'s capacity.
 
101
 
 
102
@<Constants...@>=
 
103
@!ofm_type=0;     {16-bit OFM; sufficient for most purposes}
 
104
@!max_char=65535; {the largest character number in a font}
 
105
@!xmax_char=65536; {|max_char|+1}
 
106
@!xxmax_char=65537;{|max_char|+2}
 
107
@!mem_size=262148; {|max_char|*4+8}
 
108
@!max_font=1000; {the largest font number}
 
109
@!xmax_font=1001;  {|max_font|+1}
 
110
@!xxmax_font=1002;  {|max_font|+2}
 
111
@!max_width=65535; {the largest character width number}
 
112
@!max_height=255; {the largest character height number}
 
113
@!max_depth=255; {the largest character depth number}
 
114
@!max_italic=255; {the largest character italic correction number}
 
115
@!buf_size=60; {length of lines displayed in error messages}
 
116
@!max_header_bytes=100; {four times the maximum number of words allowed in
 
117
  the \.{TFM} file header block, must be 1024 or less}
 
118
@!vf_size=200000; {maximum length of |vf| data, in bytes}
 
119
@!max_stack=100; {maximum depth of simulated \.{DVI} stack}
 
120
@!max_param_words=100; {the maximum number of \.{fontdimen} parameters allowed}
 
121
@!max_lig_steps=800000; {maximum length of ligature program}
 
122
@!xmax_label=800001; {must be greater than |max_lig_steps|}
 
123
@!hash_size=130003; {preferably a prime number,
 
124
  a bit larger than |max_lig_steps|, the number
 
125
  of character pairs in lig/kern steps}
 
126
@!hash_mult=16007; {another prime}
 
127
@!max_kerns=100000; {the maximum number of distinct kern values}
 
128
 
 
129
@ Here are some macros for common programming idioms.
 
130
 
 
131
@d incr(#) == #:=#+1 {increase a variable by unity}
 
132
@d decr(#) == #:=#-1 {decrease a variable by unity}
 
133
@d do_nothing == {empty statement}
 
134
 
 
135
@* Property list description of font metric data.
 
136
The idea behind \.{VPL} files is that precise details about fonts, i.e., the
 
137
facts that are needed by typesetting routines like \TeX, sometimes have to
 
138
be supplied by hand. The nested property-list format provides a reasonably
 
139
convenient way to do this.
 
140
 
 
141
A good deal of computation is necessary to parse and process a
 
142
\.{VPL} file, so it would be inappropriate for \TeX\ itself to do this
 
143
every time it loads a font. \TeX\ deals only with the compact descriptions
 
144
of font metric data that appear in \.{TFM} files. Such data is so compact,
 
145
however, it is almost impossible for anybody but a computer to read it.
 
146
 
 
147
Device drivers also need a compact way to describe mappings from \TeX's idea
 
148
of a font to the actual characters a device can produce. They can do this
 
149
conveniently when given a packed sequence of bytes called a \.{VF} file.
 
150
 
 
151
The purpose of \.{VPtoVF} is to convert from a human-oriented file of text
 
152
to computer-oriented files of binary numbers. There's a companion program,
 
153
\.{VFtoVP}, which goes the other way.
 
154
 
 
155
@<Glob...@>=
 
156
@!vpl_file:text;
 
157
 
 
158
@ @<Set init...@>=
 
159
reset(vpl_file);
 
160
 
 
161
@ A \.{VPL} file is like a \.{PL} file with a few extra features, so we
 
162
can begin to define it by reviewing the definition of \.{PL} files. The
 
163
material in the next few sections is copied from the program \.{PLtoTF}.
 
164
An \.{OVP} file is simply a \.{VPL} file that does not restrict fonts
 
165
to 256 characters.
 
166
 
 
167
A \.{PL} file is a list of entries of the form
 
168
$$\.{(PROPERTYNAME VALUE)}$$
 
169
where the property name is one of a finite set of names understood by
 
170
this program, and the value may itself in turn be a property list.
 
171
The idea is best understood by looking at an example, so let's consider
 
172
a fragment of the \.{PL} file for a hypothetical font.
 
173
$$\vbox{\halign{\.{#}\hfil\cr
 
174
(FAMILY NOVA)\cr
 
175
(FACE F MIE)\cr
 
176
(CODINGSCHEME ASCII)\cr
 
177
(DESIGNSIZE D 10)\cr
 
178
(DESIGNUNITS D 18)\cr
 
179
(COMMENT A COMMENT IS IGNORED)\cr
 
180
(COMMENT (EXCEPT THIS ONE ISN'T))\cr
 
181
(COMMENT (ACTUALLY IT IS, EVEN THOUGH\cr
 
182
\qquad\qquad IT SAYS IT ISN'T))\cr
 
183
(FONTDIMEN\cr
 
184
\qquad   (SLANT R -.25)\cr
 
185
\qquad   (SPACE D 6)\cr
 
186
\qquad   (SHRINK D 2)\cr
 
187
\qquad   (STRETCH D 3)\cr
 
188
\qquad   (XHEIGHT R 10.55)\cr
 
189
\qquad   (QUAD D 18)\cr
 
190
\qquad   )\cr
 
191
(LIGTABLE\cr
 
192
\qquad   (LABEL C f)\cr
 
193
\qquad   (LIG C f O 200)\cr
 
194
\qquad   (SKIP D 1)\cr
 
195
\qquad   (LABEL O 200)\cr
 
196
\qquad   (LIG C i O 201)\cr
 
197
\qquad   (KRN O 51 R 1.5)\cr
 
198
\qquad   (/LIG C ? C f)\cr
 
199
\qquad   (STOP)\cr
 
200
\qquad   )\cr
 
201
(CHARACTER C f\cr
 
202
\qquad   (CHARWD D 6)\cr
 
203
\qquad   (CHARHT R 13.5)\cr
 
204
\qquad   (CHARIC R 1.5)\cr
 
205
\qquad   )\cr}}$$
 
206
This example says that the font whose metric information is being described
 
207
belongs to the hypothetical
 
208
\.{NOVA} family; its face code is medium italic extended;
 
209
and the characters appear in ASCII code positions. The design size is 10 points,
 
210
and all other sizes in this \.{PL} file are given in units such that 18 units
 
211
equals the design size. The font is slanted with a slope of $-.25$ (hence the
 
212
letters actually slant backward---perhaps that is why the family name is
 
213
\.{NOVA}). The normal space between words is 6 units (i.e., one third of
 
214
the 18-unit design size), with glue that shrinks by 2 units or stretches by 3.
 
215
The letters for which accents don't need to be raised or lowered are 10.55
 
216
units high, and one em equals 18 units.
 
217
 
 
218
The example ligature table is a bit trickier. It specifies that the
 
219
letter \.f followed by another \.f is changed to code @'200, while
 
220
code @'200 followed by \.i is changed to @'201; presumably codes @'200
 
221
and @'201 represent the ligatures `ff' and `ffi'.  Moreover, in both cases
 
222
\.f and @'200, if the following character is the code @'51 (which is a
 
223
right parenthesis), an additional 1.5 units of space should be inserted
 
224
before the @'51.  (The `\.{SKIP}~\.D~\.1' skips over one \.{LIG} or
 
225
\.{KRN} command, which in this case is the second \.{LIG}; in this way
 
226
two different ligature/kern programs can come together.)
 
227
Finally, if either \.f or @'200 is followed by a question mark,
 
228
the question mark is replaced by \.f and the ligature program is
 
229
started over. (Thus, the character pair `\.{f?}' would actually become
 
230
the ligature `ff', and `\.{ff?}' or `\.{f?f}' would become `fff'. To
 
231
avoid this restart procedure, the \.{/LIG} command could be replaced
 
232
by \.{/LIG>}; then `\.{f?} would become `f\kern0ptf' and `\.{f?f}'
 
233
would become `f\kern0ptff'.)
 
234
 
 
235
Character \.f itself is 6 units wide and 13.5 units tall, in this example.
 
236
Its depth is zero (since \.{CHARDP} is not given), and its italic correction
 
237
is 1.5 units.
 
238
 
 
239
@ The example above illustrates most of the features found in \.{PL} files.
 
240
Note that some property names, like \.{FAMILY} or \.{COMMENT}, take a
 
241
string as their value; this string continues until the first unmatched
 
242
right parenthesis. But most property names, like \.{DESIGNSIZE} and \.{SLANT}
 
243
and \.{LABEL}, take a number as their value. This number can be expressed in
 
244
a variety of ways, indicated by a prefixed code; \.D stands for decimal,
 
245
\.H for hexadecimal, \.O for octal, \.R for real, \.C for character, and
 
246
\.F for ``face.''  Other property names, like \.{LIG}, take two numbers as
 
247
their value.  And still other names, like \.{FONTDIMEN} and \.{LIGTABLE} and
 
248
\.{CHARACTER}, have more complicated values that involve property lists.
 
249
 
 
250
A property name is supposed to be used only in an appropriate property
 
251
list.  For example, \.{CHARWD} shouldn't occur on the outer level or
 
252
within \.{FONTDIMEN}.
 
253
 
 
254
The individual property-and-value pairs in a property list can appear in
 
255
any order. For instance, `\.{SHRINK}' precedes `\.{STRETCH}' in the above
 
256
example, although the \.{TFM} file always puts the stretch parameter first.
 
257
One could even give the information about characters like `\.f' before
 
258
specifying the number of units in the design size, or before specifying the
 
259
ligature and kerning table. However, the \.{LIGTABLE} itself is an exception
 
260
to this rule; the individual elements of the \.{LIGTABLE} property list
 
261
can be reordered only to a certain extent without changing the meaning
 
262
of that table.
 
263
 
 
264
If property-and-value pairs are omitted, a default value is used. For example,
 
265
we have already noted that the default for \.{CHARDP} is zero. The default
 
266
for {\sl every\/} numeric value is, in fact, zero, unless otherwise stated
 
267
below.
 
268
 
 
269
If the same property name is used more than once, \.{VPtoVF} will not notice
 
270
the discrepancy; it simply uses the final value given. Once again, however, the
 
271
\.{LIGTABLE} is an exception to this rule; \.{VPtoVF} will complain if there
 
272
is more than one label for some character. And of course many of the
 
273
entries in the \.{LIGTABLE} property list have the same property name.
 
274
 
 
275
@ A \.{VPL} file also includes information about how to create each character,
 
276
by typesetting characters from other fonts and/or by drawing lines, etc.
 
277
Such information is the value of the `\.{MAP}' property, which can be
 
278
illustrated as follows:
 
279
$$\vbox{\halign{\.{#}\hfil\cr
 
280
(MAPFONT D 0 (FONTNAME Times-Roman))\cr
 
281
(MAPFONT D 1 (FONTNAME Symbol))\cr
 
282
(MAPFONT D 2 (FONTNAME cmr10)(FONTAT D 20))\cr
 
283
(CHARACTER O 0 (MAP (SELECTFONT D 1)(SETCHAR C G)))\cr
 
284
(CHARACTER O 76 (MAP (SETCHAR O 277)))\cr
 
285
(CHARACTER D 197 (MAP\cr
 
286
\qquad(PUSH)(SETCHAR C A)(POP)\cr
 
287
\qquad(MOVEUP R 0.937)(MOVERIGHT R 1.5)(SETCHAR O 312)))\cr
 
288
(CHARACTER O 200 (MAP (MOVEDOWN R 2.1)(SETRULE R 1 R 8)))\cr
 
289
(CHARACTER O 201 (MAP\cr
 
290
\qquad (SPECIAL ps: /SaveGray currentgray def .5 setgray)\cr
 
291
\qquad (SELECTFONT D 2)(SETCHAR C A)\cr
 
292
\qquad (SPECIAL ps: SaveGray setgray)))\cr
 
293
}}$$
 
294
(These specifications appear in addition to the conventional \.{PL}
 
295
information. The \.{MAP} attribute can be mixed in with other attributes
 
296
like \.{CHARWD} or it can be given separately.)
 
297
 
 
298
In this example, the virtual font is composed of characters that can be
 
299
fabricated from three actual fonts, `\.{Times-Roman}',
 
300
`\.{Symbol}', and `\.{cmr10} \.{at} \.{20\\u}' (where \.{\\u}
 
301
is the unit size in this \.{VPL} file). Character |@'0| is typeset as
 
302
a `G' from the symbol font. Character |@'76| is typeset as character |@'277|
 
303
from the ordinary Times font. (If no other font is selected, font
 
304
number~0 is the default. If no \.{MAP} attribute is given, the default map
 
305
is a character of the same number in the default font.)
 
306
 
 
307
Character 197 (decimal) is more interesting: First an A is typeset (in the
 
308
default font Times), and this is enclosed by \.{PUSH} and \.{POP} so that
 
309
the original position is restored. Then the accent character |@'312| is
 
310
typeset, after moving up .937 units and right 1.5 units.
 
311
 
 
312
To typeset character |@'200| in this virtual font, we move down 2.1 units,
 
313
then typeset a rule that is 1 unit high and 8 units wide.
 
314
 
 
315
Finally, to typeset character |@'201|, we do something that requires a
 
316
special ability to interpret PostScript commands; this example
 
317
sets the PostScript ``color'' to 50\char`\%\ gray and typesets an `A'
 
318
from \.{cmr10} in that color.
 
319
 
 
320
In general, the \.{MAP} attribute of a virtual character can be any sequence
 
321
of typesetting commands that might appear in a page of a \.{DVI} file.
 
322
A single character might map into an entire page.
 
323
 
 
324
@ But instead of relying on a hypothetical example, let's consider a complete
 
325
grammar for \.{VPL} files, beginning with the (unchanged) grammatical rules
 
326
for \.{PL} files. At the outer level, the following property names
 
327
are valid in any \.{PL} file:
 
328
 
 
329
\yskip\hang\.{CHECKSUM} (four-byte value). The value, which should be a
 
330
nonnegative integer less than $2^{32}$, is used to identify a particular
 
331
version of a font; it should match the check sum value stored with the font
 
332
itself. An explicit check sum of zero is used to bypass
 
333
check sum testing. If no checksum is specified in the \.{VPL} file,
 
334
\.{VPtoVF} will compute the checksum that \MF\ would compute from the
 
335
same data.
 
336
 
 
337
\yskip\hang\.{DESIGNSIZE} (numeric value, default is 10). The value, which
 
338
should be a real number in the range |1.0<=x<2048|, represents the default
 
339
amount by which all quantities will be scaled if the font is not loaded
 
340
with an `\.{at}' specification. For example, if one says
 
341
`\.{\\font\\A=cmr10 at 15pt}' in \TeX\ language, the design size in the \.{TFM}
 
342
file is ignored and effectively replaced by 15 points; but if one simply
 
343
says `\.{\\font\\A=cmr10}' the stated design size is used. This quantity is
 
344
always in units of printer's points.
 
345
 
 
346
\yskip\hang\.{DESIGNUNITS} (numeric value, default is 1). The value
 
347
should be a positive real number; it says how many units equals the design
 
348
size (or the eventual `\.{at}' size, if the font is being scaled). For
 
349
example, suppose you have a font that has been digitized with 600 pixels per
 
350
em, and the design size is one em; then you could say `\.{(DESIGNUNITS R 600)}'
 
351
if you wanted to give all of your measurements in units of pixels.
 
352
 
 
353
\yskip\hang\.{CODINGSCHEME} (string value, default is `\.{UNSPECIFIED}').
 
354
The string should not contain parentheses, and its length must be less than 40.
 
355
It identifies the correspondence between the numeric codes and font characters.
 
356
(\TeX\ ignores this information, but other software programs make use of it.)
 
357
 
 
358
\yskip\hang\.{FAMILY} (string value, default is `\.{UNSPECIFIED}').
 
359
The string should not contain parentheses, and its length must be less than 20.
 
360
It identifies the name of the family to which this font belongs, e.g.,
 
361
`\.{HELVETICA}'.  (\TeX\ ignores this information; but it is needed, for
 
362
example, when converting \.{DVI} files to \.{PRESS} files for Xerox
 
363
equipment.)
 
364
 
 
365
\yskip\hang\.{FACE} (one-byte value). This number, which must lie between
 
366
0 and 255 inclusive, is a subsidiary ident\-ifi\-ca\-tion of the font within its
 
367
family. For example, bold italic condensed fonts might have the same family name
 
368
as light roman extended fonts, differing only in their face byte.  (\TeX\
 
369
ignores this information; but it is needed, for example, when converting
 
370
\.{DVI} files to \.{PRESS} files for Xerox equipment.)
 
371
 
 
372
\yskip\hang\.{SEVENBITSAFEFLAG} (string value, default is `\.{FALSE}'). The
 
373
value should start with either `\.T' (true) or `\.F' (false). If true, character
 
374
codes less than 128 cannot lead to codes of 128 or more via ligatures or
 
375
charlists or extensible characters. (\TeX82 ignores this flag, but older
 
376
versions of \TeX\ would only accept \.{TFM} files that were seven-bit safe.)
 
377
\.{VPtoVF} computes the correct value of this flag and gives an error message
 
378
only if a claimed ``true'' value is incorrect.
 
379
 
 
380
\yskip\hang\.{HEADER} (a one-byte value followed by a four-byte value).
 
381
The one-byte value should be between 18 and a maximum limit that can be
 
382
raised or lowered depending on the compile-time setting of |max_header_bytes|.
 
383
The four-byte value goes into the header word whose index is the one-byte
 
384
value; for example, to set |header[18]:=1|, one may write
 
385
`\.{(HEADER D 18 O 1)}'. This notation is used for header information that
 
386
is presently unnamed. (\TeX\ ignores it.)
 
387
 
 
388
\yskip\hang\.{FONTDIMEN} (property list value). See below for the names
 
389
allowed in this property list.
 
390
 
 
391
\yskip\hang\.{LIGTABLE} (property list value). See below for the rules
 
392
about this special kind of property list.
 
393
 
 
394
\yskip\hang\.{BOUNDARYCHAR} (integer value). If this character appears in
 
395
a \.{LIGTABLE} command, it matches ``end of word'' as well as itself.
 
396
If no boundary character is given and no \.{LABEL} \.{BOUNDARYCHAR} occurs
 
397
within \.{LIGTABLE}, word boundaries will not affect ligatures or kerning.
 
398
 
 
399
\yskip\hang\.{CHARACTER}. The value is an integer followed by
 
400
a property list. The integer represents the number of a character that is
 
401
present in the font; the property list of a character is defined below.
 
402
The default is an empty property list.
 
403
 
 
404
@ Numeric property list values can be given in various forms identified by
 
405
a prefixed letter.
 
406
 
 
407
\yskip\hang\.C denotes an ASCII character, which should be a standard visible
 
408
character that is not a parenthesis. The numeric value will therefore be
 
409
between @'41 and @'176 but not @'50 or @'51.
 
410
 
 
411
\yskip\hang\.D denotes an unsigned decimal integer, which must be
 
412
less than $2^{32}$, i.e., at most `\.{D 4294967295}'.
 
413
 
 
414
\yskip\hang\.F denotes a three-letter Xerox face code; the admissible codes
 
415
are \.{MRR}, \.{MIR}, \.{BRR}, \.{BIR}, \.{LRR}, \.{LIR}, \.{MRC}, \.{MIC},
 
416
\.{BRC}, \.{BIC}, \.{LRC}, \.{LIC}, \.{MRE}, \.{MIE}, \.{BRE}, \.{BIE},
 
417
\.{LRE}, and \.{LIE}, denoting the integers 0 to 17, respectively.
 
418
 
 
419
\yskip\hang\.O denotes an unsigned octal integer, which must be less than
 
420
$2^{32}$, i.e., at most `\.{O 37777777777}'.
 
421
 
 
422
\yskip\hang\.H denotes an unsigned hexadecimal integer, which must be less than
 
423
$2^{32}$, i.e., at most `\.{H FFFFFFFF}'.
 
424
 
 
425
\yskip\hang\.R denotes a real number in decimal notation, optionally preceded
 
426
by a `\.+' or `\.-' sign, and optionally including a decimal point. The
 
427
absolute value must be less than 2048.
 
428
 
 
429
@ The property names allowed in a \.{FONTDIMEN} property list correspond to
 
430
various \TeX\ parameters, each of which has a (real) numeric value. All
 
431
of the parameters except \.{SLANT} are in design units. The admissible
 
432
names are \.{SLANT}, \.{SPACE}, \.{STRETCH}, \.{SHRINK}, \.{XHEIGHT},
 
433
\.{QUAD}, \.{EXTRASPACE}, \.{NUM1}, \.{NUM2}, \.{NUM3}, \.{DENOM1},
 
434
\.{DENOM2}, \.{SUP1}, \.{SUP2}, \.{SUP3}, \.{SUB1}, \.{SUB2}, \.{SUPDROP},
 
435
\.{SUBDROP}, \.{DELIM1}, \.{DELIM2}, and \.{AXISHEIGHT}, for parameters
 
436
1~to~22. The alternate names \.{DEFAULTRULETHICKNESS},
 
437
\.{BIGOPSPACING1}, \.{BIGOPSPACING2}, \.{BIGOPSPACING3},
 
438
\.{BIGOPSPACING4}, and \.{BIGOPSPACING5}, may also be used for parameters
 
439
8 to 13.
 
440
 
 
441
The notation `\.{PARAMETER} $n$' provides another way to specify the
 
442
$n$th parameter; for example, `\.{(PARAMETER} \.{D 1 R -.25)}' is another way
 
443
to specify that the \.{SLANT} is $-0.25$. The value of $n$ must be positive
 
444
and less than |max_param_words|.
 
445
 
 
446
@ The elements of a \.{CHARACTER} property list can be of six different types.
 
447
 
 
448
\yskip\hang\.{CHARWD} (real value) denotes the character's width in
 
449
design units.
 
450
 
 
451
\yskip\hang\.{CHARHT} (real value) denotes the character's height in
 
452
design units.
 
453
 
 
454
\yskip\hang\.{CHARDP} (real value) denotes the character's depth in
 
455
design units.
 
456
 
 
457
\yskip\hang\.{CHARIC} (real value) denotes the character's italic correction in
 
458
design units.
 
459
 
 
460
\yskip\hang\.{NEXTLARGER} (integer value), specifies the character that
 
461
follows the present one in a ``charlist.'' The value must be the number of a
 
462
character in the font, and there must be no infinite cycles of supposedly
 
463
larger and larger characters.
 
464
 
 
465
\yskip\hang\.{VARCHAR} (property list value), specifies an extensible character.
 
466
This option and \.{NEXTLARGER} are mutually exclusive; i.e., they cannot
 
467
both be used within the same \.{CHARACTER} list.
 
468
 
 
469
\yskip\noindent
 
470
The elements of a \.{VARCHAR} property list are either \.{TOP}, \.{MID},
 
471
\.{BOT} or \.{REP}; the values are integers, which must be zero or the number
 
472
of a character in the font. A zero value for \.{TOP}, \.{MID}, or \.{BOT} means
 
473
that the corresponding piece of the extensible character is absent. A nonzero
 
474
value, or a \.{REP} value of zero, denotes the character code used to make
 
475
up the top, middle, bottom, or replicated piece of an extensible character.
 
476
 
 
477
@ A \.{LIGTABLE} property list contains elements of four kinds, specifying a
 
478
program in a simple command language that \TeX\ uses for ligatures and kerns.
 
479
If several \.{LIGTABLE} lists appear, they are effectively concatenated into
 
480
a single list.
 
481
 
 
482
\yskip\hang\.{LABEL} (integer value) means that the program for the
 
483
stated character value starts here. The integer must be the number of a
 
484
character in the font; its \.{CHARACTER} property list must not have a
 
485
\.{NEXTLARGER} or \.{VARCHAR} field. At least one \.{LIG} or \.{KRN} step
 
486
must follow.
 
487
 
 
488
\yskip\hang\.{LABEL} \.{BOUNDARYCHAR} means that the program for
 
489
beginning-of-word ligatures starts here.
 
490
 
 
491
\yskip\hang\.{LIG} (two integer values). The instruction `\.{(LIG} $c$ $r$\.)'
 
492
means, ``If the next character is $c$, then insert character~$r$ and
 
493
possibly delete the current character and/or~$c$;
 
494
otherwise go on to the next instruction.''
 
495
Characters $r$ and $c$ must be present in the font. \.{LIG} may be immediately
 
496
preceded or followed by a slash, and then immediately followed by \.>
 
497
characters not exceeding the number of slashes. Thus there are eight
 
498
possible forms:
 
499
$$\hbox to .8\hsize{\.{LIG}\hfil\.{/LIG}\hfil\.{/LIG>}\hfil
 
500
\.{LIG/}\hfil\.{LIG/>}\hfil\.{/LIG/}\hfil\.{/LIG/>}\hfil\.{/LIG/>>}}$$
 
501
The slashes specify retention of the left or right original character; the
 
502
\.> signs specify passing over the result without further ligature processing.
 
503
 
 
504
\yskip\hang\.{KRN} (an integer value and a real value). The instruction
 
505
`\.{(KRN} $c$ $r$\.)' means, ``If the next character is $c$, then insert
 
506
a blank space of width $r$ between the current character character and $c$;
 
507
otherwise go on to the next intruction.'' The value of $r$, which is in
 
508
units of the design size, is often negative. Character code $c$ must exist
 
509
in the font.
 
510
 
 
511
\yskip\hang\.{STOP} (no value). This instruction ends a ligature/kern program.
 
512
It must follow either a \.{LIG} or \.{KRN} instruction, not a \.{LABEL}
 
513
or \.{STOP} or \.{SKIP}.
 
514
 
 
515
\yskip\hang\.{SKIP} (value in the range |0..127|). This instruction specifies
 
516
continuation of a ligature/kern program after the specified number of \.{LIG}
 
517
or \.{KRN} has been skipped over. The number of subsequent \.{LIG} and \.{KRN}
 
518
instructions must therefore exceed this specified amount.
 
519
 
 
520
@ In addition to all these possibilities, the property name \.{COMMENT} is
 
521
allowed in any property list. Such comments are ignored.
 
522
 
 
523
@ So that is what \.{PL} files hold. In a \.{VPL} file additional
 
524
properties are recognized; two of these are valid on the outermost level:
 
525
 
 
526
\yskip\hang\.{VTITLE} (string value, default is empty). The value will be
 
527
reproduced at the beginning of the \.{VF} file (and printed on the terminal
 
528
by \.{VFtoVP} when it examines that file).
 
529
 
 
530
\yskip\hang\.{MAPFONT}. The value is a nonnegative integer followed by
 
531
a property list. The integer represents an identifying number for fonts
 
532
used in \.{MAP} attributes. The property list, which identifies the font and
 
533
relative size, is defined below.
 
534
 
 
535
\yskip\noindent
 
536
And one additional ``virtual property'' is valid within a \.{CHARACTER}:
 
537
 
 
538
\yskip\hang\.{MAP}. The value is a property list consisting of typesetting
 
539
commands. Default is the single command \.{SETCHAR}~$c$, where $c$ is
 
540
the current character number.
 
541
 
 
542
@ The elements of a \.{MAPFONT} property list can be of the following types.
 
543
 
 
544
\yskip\hang\.{FONTNAME} (string value, default is \.{NULL}).
 
545
This is the font's identifying name.
 
546
 
 
547
\yskip\hang\.{FONTAREA} (string value, default is empty). If the font appears
 
548
in a nonstandard directory, according to local conventions, the directory
 
549
name is given here. (This is system dependent, just as in \.{DVI} files.)
 
550
 
 
551
\yskip\hang\.{FONTCHECKSUM} (four-byte value, default is zero). This value,
 
552
which should be a nonnegative integer less than $2^{32}$, can be used to
 
553
check that the font being referred to matches the intended font. If nonzero,
 
554
it should equal the \.{CHECKSUM} parameter in that font.
 
555
 
 
556
\yskip\hang\.{FONTAT} (numeric value, default is the \.{DESIGNUNITS} of the
 
557
present virtual font). This value is relative to the design units of
 
558
the present virtual font, hence it will be scaled when the virtual
 
559
font is magnified or reduced.  It represents the value that will
 
560
effectively replace the design size of the font being referred to,
 
561
so that all characters will be scaled appropriately.
 
562
 
 
563
\yskip\hang\.{FONTDSIZE} (numeric value, default is 10). This value is
 
564
absolute, in units of printer's points. It should equal the \.{DESIGNSIZE}
 
565
parameter in the font being referred to.
 
566
 
 
567
\yskip\noindent
 
568
If any of the
 
569
string values contain parentheses, the parentheses must be balanced. Leading
 
570
blanks are removed from the strings, but trailing blanks are not.
 
571
 
 
572
@ Finally, the elements of a \.{MAP} property list are an ordered sequence
 
573
of typesetting commands chosen from among the following:
 
574
 
 
575
\yskip\hang\.{SELECTFONT} (four-byte integer value). The value must be the
 
576
number of a previously defined \.{MAPFONT}. This font (or more precisely, the
 
577
final font that is mapped to that code number, if two \.{MAPFONT} properties
 
578
happen to specify the same code) will be used in subsequent \.{SETCHAR}
 
579
instructions until overridden by another \.{SELECTFONT}. The first-specified
 
580
\.{MAPFONT} is implicitly selected before the first \.{SELECTFONT} in every
 
581
character's map.
 
582
 
 
583
\yskip\hang\.{SETCHAR} (integer value). There must be a character of
 
584
this number in the currently selected font. (\.{VPtoVF} doesn't check that
 
585
the character is valid, but \.{VFtoVP} does.) That character is typeset at the
 
586
current position, and the typesetter moves right by the \.{CHARWD} in
 
587
that character's \.{TFM} file.
 
588
 
 
589
\yskip\hang\.{SETRULE} (two real values). The first value specifies height,
 
590
the second specifies width, in design units. If both height and width are
 
591
positive, a rule is typeset at the current position. Then the typesetter
 
592
moves right, by the specified width.
 
593
 
 
594
\yskip\hang\.{MOVERIGHT}, \.{MOVELEFT}, \.{MOVEUP}, \.{MOVEDOWN} (real
 
595
value). The typesetter moves its current position
 
596
by the number of design units specified.
 
597
 
 
598
\yskip\hang\.{PUSH} The current typesetter position is remembered, to
 
599
be restored on a subsequent \.{POP}.
 
600
 
 
601
\yskip\hang\.{POP} The current typesetter position is reset to where it
 
602
was on the most recent unmatched \.{PUSH}. The \.{PUSH} and \.{POP}
 
603
commands in any \.{MAP} must be properly nested like balanced parentheses.
 
604
 
 
605
\yskip\hang\.{SPECIAL} (string value). The subsequent characters, starting
 
606
with the first nonblank and ending just before the first `\.)' that has no
 
607
matching `\.(', are interpreted according to local conventions with the
 
608
same system-dependent meaning as a `special' (\\{xxx}) command
 
609
in a \.{DVI} file.
 
610
 
 
611
\yskip\hang\.{SPECIALHEX} (hexadecimal string value). The subsequent
 
612
nonblank characters before the next `\.)' must consist entirely of
 
613
hexadecimal digits, and they must contain an even number of such digits.
 
614
Each pair of hex digits specifies a byte, and this string of bytes is
 
615
treated just as the value of a \.{SPECIAL}. (This convention permits
 
616
arbitrary byte strings to be represented in an ordinary text file.)
 
617
 
 
618
@ Virtual font mapping is a recursive process, like macro expansion.
 
619
Thus, a \.{MAPFONT} might
 
620
specify another virtual font, whose characters are themselves mapped to
 
621
other fonts. As an example of this possibility, consider the
 
622
following curious file called \.{recurse.vpl}, which defines a
 
623
virtual font that is self-contained and self-referential:
 
624
$$\vbox{\halign{\.{#}\cr
 
625
(VTITLE Example of recursion)\cr
 
626
(MAPFONT D 0 (FONTNAME recurse)(FONTAT D 2))\cr
 
627
(CHARACTER C A (CHARWD D 1)(CHARHT D 1)(MAP (SETRULE D 1 D 1)))\cr
 
628
(CHARACTER C B (CHARWD D 2)(CHARHT D 2)(MAP (SETCHAR C A)))\cr
 
629
(CHARACTER C C (CHARWD D 4)(CHARHT D 4)(MAP (SETCHAR C B)))\cr
 
630
}}$$
 
631
The design size is 10 points (the default), hence the character \.A
 
632
in font \.{recurse} is a $10\times10$ point black square. Character \.B
 
633
is typeset as character \.A in \.{recurse} {scaled} {2000}, hence it
 
634
is a $20\times20$ point black square. And character \.C is typeset as
 
635
character \.{B} in \.{recurse} {scaled} {2000}, hence its size is
 
636
$40\times40$.
 
637
 
 
638
Users are responsible for making sure that infinite recursion doesn't happen.
 
639
 
 
640
@ So that is what \.{VPL} files hold. From these rules,
 
641
you can guess (correctly) that \.{VPtoVF} operates in four main stages.
 
642
First it assigns the default values to all properties; then it scans
 
643
through the \.{VPL} file, changing property values as new ones are seen; then
 
644
it checks the information and corrects any problems; and finally it outputs
 
645
the \.{VF} and \.{TFM} files.
 
646
 
 
647
@ The next question is, ``What are \.{VF} and
 
648
\.{TFM} files?'' A complete answer to that question appears in the
 
649
documentation of the companion programs, \.{VFtoVP} and
 
650
\.{TFtoPL}, so the details will not
 
651
be repeated here. Suffice it to say that a \.{VF} or
 
652
\.{TFM} file stores all of the
 
653
relevant font information in a sequence of 8-bit bytes. The number of
 
654
bytes is always a multiple of 4, so we could regard the files
 
655
as sequences of 32-bit words; but \TeX\ uses the byte interpretation,
 
656
and so does \.{VPtoVF}. Note that the bytes are considered to be unsigned
 
657
numbers.
 
658
 
 
659
@<Glob...@>=
 
660
@!vf_file:packed file of 0..255;
 
661
@!tfm_file:packed file of 0..255;
 
662
 
 
663
@ On some systems you may have to do something special to write a
 
664
packed file of bytes. For example, the following code didn't work
 
665
when it was first tried at Stanford, because packed files have to be
 
666
opened with a special switch setting on the \PASCAL\ that was used.
 
667
@^system dependencies@>
 
668
 
 
669
@<Set init...@>=
 
670
rewrite(vf_file); rewrite(tfm_file);
 
671
 
 
672
@* Basic input routines.
 
673
For the purposes of this program, a |byte| is an unsigned 16-bit quantity,
 
674
and an |ASCII_code| is an integer between @'40 and @'177. Such ASCII codes
 
675
correspond to one-character constants like \.{"A"} in \.{WEB} language.
 
676
 
 
677
@<Types...@>=
 
678
@!byte=0..65535; {unsigned 16-bit quantity}
 
679
@!ASCII_code=@'40..@'177; {standard ASCII code numbers}
 
680
 
 
681
@ One of the things \.{VPtoVF} has to do is convert characters of strings
 
682
to ASCII form, since that is the code used for the family name and the
 
683
coding scheme in a \.{TFM} file. An array |xord| is used to do the
 
684
conversion from |char|; the method below should work with little or no change
 
685
on most \PASCAL\ systems.
 
686
@^system dependencies@>
 
687
 
 
688
@d first_ord=0 {ordinal number of the smallest element of |char|}
 
689
@d last_ord=127 {ordinal number of the largest element of |char|}
 
690
 
 
691
@<Global...@>=
 
692
@!xord:array[char] of ASCII_code; {conversion table}
 
693
 
 
694
@ @<Local variables for init...@>=
 
695
@!k:integer; {all-purpose initialization index}
 
696
 
 
697
@ Characters that should not appear in \.{VPL} files (except in comments)
 
698
are mapped into @'177.
 
699
 
 
700
@d invalid_code=@'177 {code deserving an error message}
 
701
 
 
702
@<Set init...@>=
 
703
for k:=first_ord to last_ord do xord[chr(k)]:=invalid_code;
 
704
xord[' ']:=" "; xord['!']:="!"; xord['"']:=""""; xord['#']:="#";
 
705
xord['$']:="$"; xord['%']:="%"; xord['&']:="&"; xord['''']:="'";
 
706
xord['(']:="("; xord[')']:=")"; xord['*']:="*"; xord['+']:="+"; xord[',']:=",";
 
707
xord['-']:="-"; xord['.']:="."; xord['/']:="/"; xord['0']:="0"; xord['1']:="1";
 
708
xord['2']:="2"; xord['3']:="3"; xord['4']:="4"; xord['5']:="5"; xord['6']:="6";
 
709
xord['7']:="7"; xord['8']:="8"; xord['9']:="9"; xord[':']:=":"; xord[';']:=";";
 
710
xord['<']:="<"; xord['=']:="="; xord['>']:=">"; xord['?']:="?";
 
711
xord['@@']:="@@"; xord['A']:="A"; xord['B']:="B"; xord['C']:="C";
 
712
xord['D']:="D"; xord['E']:="E"; xord['F']:="F"; xord['G']:="G"; xord['H']:="H";
 
713
xord['I']:="I"; xord['J']:="J"; xord['K']:="K"; xord['L']:="L"; xord['M']:="M";
 
714
xord['N']:="N"; xord['O']:="O"; xord['P']:="P"; xord['Q']:="Q"; xord['R']:="R";
 
715
xord['S']:="S"; xord['T']:="T"; xord['U']:="U"; xord['V']:="V"; xord['W']:="W";
 
716
xord['X']:="X"; xord['Y']:="Y"; xord['Z']:="Z"; xord['[']:="["; xord['\']:="\";
 
717
xord[']']:="]"; xord['^']:="^"; xord['_']:="_"; xord['`']:="`"; xord['a']:="a";
 
718
xord['b']:="b"; xord['c']:="c"; xord['d']:="d"; xord['e']:="e"; xord['f']:="f";
 
719
xord['g']:="g"; xord['h']:="h"; xord['i']:="i"; xord['j']:="j"; xord['k']:="k";
 
720
xord['l']:="l"; xord['m']:="m"; xord['n']:="n"; xord['o']:="o"; xord['p']:="p";
 
721
xord['q']:="q"; xord['r']:="r"; xord['s']:="s"; xord['t']:="t"; xord['u']:="u";
 
722
xord['v']:="v"; xord['w']:="w"; xord['x']:="x"; xord['y']:="y"; xord['z']:="z";
 
723
xord['{']:="{"; xord['|']:="|"; xord['}']:="}"; xord['~']:="~";
 
724
 
 
725
@ In order to help catch errors of badly nested parentheses, \.{VPtoVF}
 
726
assumes that the user will begin each line with a number of blank spaces equal
 
727
to some constant times the number of open parentheses at the beginning of
 
728
that line. However, the program doesn't know in advance what the constant
 
729
is, nor does it want to print an error message on every line for a user
 
730
who has followed no consistent pattern of indentation.
 
731
 
 
732
Therefore the following strategy is adopted: If the user has been consistent
 
733
with indentation for ten or more lines, an indentation error will be
 
734
reported. The constant of indentation is reset on every line that should
 
735
have nonzero indentation.
 
736
 
 
737
@<Glob...@>=
 
738
@!line:integer; {the number of the current line}
 
739
@!good_indent:integer; {the number of lines since the last bad indentation}
 
740
@!indent: integer; {the number of spaces per open parenthesis, zero if unknown}
 
741
@!level: integer; {the current number of open parentheses}
 
742
 
 
743
@ @<Set init...@>=
 
744
line:=0; good_indent:=0; indent:=0; level:=0;
 
745
 
 
746
@ The input need not really be broken into lines of any maximum length, and
 
747
we could read it character by character without any buffering. But we shall
 
748
place it into a small buffer so that offending lines can be displayed in error
 
749
messages.
 
750
 
 
751
@<Glob...@>=
 
752
@!left_ln,@!right_ln:boolean; {are the left and right ends of the buffer
 
753
  at end-of-line marks?}
 
754
@!limit:0..buf_size; {position of the last character present in the buffer}
 
755
@!loc:0..buf_size; {position of the last character read in the buffer}
 
756
@!buffer:array[1..buf_size] of char;
 
757
@!input_has_ended:boolean; {there is no more input to read}
 
758
 
 
759
@ @<Set init...@>=
 
760
limit:=0; loc:=0; left_ln:=true; right_ln:=true; input_has_ended:=false;
 
761
 
 
762
@ Just before each  \.{CHARACTER} property list is evaluated, the character
 
763
code is printed in octal notation. Up to eight such codes appear on a line;
 
764
so we have a variable to keep track of how many are currently there.
 
765
 
 
766
@<Glob...@>=
 
767
@!chars_on_line:0..8; {the number of characters printed on the current line}
 
768
 
 
769
@ @<Set init...@>=
 
770
chars_on_line:=0;
 
771
 
 
772
@ The following routine prints an error message and an indication of
 
773
where the error was detected. The error message should not include any
 
774
final punctuation, since this procedure supplies its own.
 
775
 
 
776
@d err_print(#)==begin if chars_on_line>0 then print_ln(' ');
 
777
  print(#); show_error_context;
 
778
  end
 
779
 
 
780
@p procedure show_error_context; {prints the current scanner location}
 
781
var k:0..buf_size; {an index into |buffer|}
 
782
begin print_ln(' (line ',line:1,').');
 
783
if not left_ln then print('...');
 
784
for k:=1 to loc do print(buffer[k]); {print the characters already scanned}
 
785
print_ln(' ');
 
786
if not left_ln then print('   ');
 
787
for k:=1 to loc do print(' '); {space out the second line}
 
788
for k:=loc+1 to limit do print(buffer[k]); {print the characters yet unseen}
 
789
if right_ln then print_ln(' ')@+else print_ln('...');
 
790
chars_on_line:=0;
 
791
end;
 
792
 
 
793
@ Here is a procedure that does the right thing when we are done
 
794
reading the present contents of the buffer. It keeps |buffer[buf_size]|
 
795
empty, in order to avoid range errors on certain \PASCAL\ compilers.
 
796
 
 
797
An infinite sequence of right parentheses is placed at the end of the
 
798
file, so that the program is sure to get out of whatever level of nesting
 
799
it is in.
 
800
 
 
801
On some systems it is desirable to modify this code so that tab marks
 
802
in the buffer are replaced by blank spaces. (Simply setting
 
803
|xord[chr(@'11)]:=" "| would not work; for example, two-line
 
804
error messages would not come out properly aligned.)
 
805
@^system dependencies@>
 
806
 
 
807
@p procedure fill_buffer;
 
808
begin left_ln:=right_ln; limit:=0; loc:=0;
 
809
if left_ln then begin
 
810
  if line>0 then read_ln(vpl_file);
 
811
  incr(line);
 
812
  end;
 
813
if eof(vpl_file) then begin
 
814
  limit:=1; buffer[1]:=')'; right_ln:=false; input_has_ended:=true;
 
815
  end
 
816
else begin
 
817
  while (limit<buf_size-1)and(not eoln(vpl_file)) do begin
 
818
    incr(limit); read(vpl_file,buffer[limit]);
 
819
    end;
 
820
  buffer[limit+1]:=' '; right_ln:=eoln(vpl_file);
 
821
  if left_ln then @<Set |loc| to the number of leading blanks in
 
822
    the buffer, and check the indentation@>;
 
823
  end;
 
824
end;
 
825
 
 
826
@ The interesting part about |fill_buffer| is the part that learns what
 
827
indentation conventions the user is following, if any.
 
828
 
 
829
@d bad_indent(#)==begin if good_indent>=10 then err_print(#);
 
830
  good_indent:=0; indent:=0;
 
831
  end
 
832
 
 
833
@<Set |loc|...@>=
 
834
begin while (loc<limit)and(buffer[loc+1]=' ') do incr(loc);
 
835
if loc<limit then begin
 
836
  if level=0 then
 
837
    if loc=0 then incr(good_indent)
 
838
    else bad_indent('Warning: Indented line occurred at level zero')
 
839
@.Warning: Indented line...@>
 
840
  else if indent=0 then
 
841
    if loc mod level=0 then begin
 
842
      indent:=loc div level; good_indent:=1;
 
843
      end
 
844
    else good_indent:=0
 
845
  else if indent*level=loc then incr(good_indent)
 
846
  else bad_indent('Warning: Inconsistent indentation; ',
 
847
@.Warning: Inconsistent indentation...@>
 
848
    'you are at parenthesis level ',level:1);
 
849
  end;
 
850
end
 
851
 
 
852
@* Basic scanning routines.
 
853
The global variable |cur_char| holds the ASCII code corresponding to the
 
854
character most recently read from the input buffer, or to a character that
 
855
has been substituted for the real one.
 
856
 
 
857
@<Global...@>=
 
858
@!cur_char:ASCII_code; {we have just read this}
 
859
 
 
860
@ Here is a procedure that sets |cur_char| to an ASCII code for the
 
861
next character of input, if that character is a letter or digit or slash
 
862
or \.>. Otherwise
 
863
it sets |cur_char:=" "|, and the input system will be poised to reread the
 
864
character that was rejected, whether or not it was a space.
 
865
Lower case letters are converted to upper case.
 
866
 
 
867
@p procedure get_keyword_char;
 
868
begin while (loc=limit)and(not right_ln) do fill_buffer;
 
869
if loc=limit then cur_char:=" " {end-of-line counts as a delimiter}
 
870
else begin
 
871
  cur_char:=xord[buffer[loc+1]];
 
872
  if cur_char>="a" then cur_char:=cur_char-@'40;
 
873
  if ((cur_char>="0")and(cur_char<="9")) then incr(loc)
 
874
  else if ((cur_char>="A")and(cur_char<="Z")) then incr(loc)
 
875
  else if cur_char="/" then incr(loc)
 
876
  else if cur_char=">" then incr(loc)
 
877
  else cur_char:=" ";
 
878
  end;
 
879
end;
 
880
 
 
881
@ The following procedure sets |cur_char| to the next character code,
 
882
and converts lower case to upper case. If the character is a left or
 
883
right parenthesis, it will not be ``digested''; the character will
 
884
be read again and again, until the calling routine does something
 
885
like `|incr(loc)|' to get past it. Such special treatment of parentheses
 
886
insures that the structural information they contain won't be lost in
 
887
the midst of other error recovery operations.
 
888
 
 
889
@d backup==begin if (cur_char>")")or(cur_char<"(") then decr(loc);
 
890
  end {undoes the effect of |get_next|}
 
891
 
 
892
@p procedure get_next; {sets |cur_char| to next, balks at parentheses}
 
893
begin while loc=limit do fill_buffer;
 
894
incr(loc); cur_char:=xord[buffer[loc]];
 
895
if cur_char>="a" then
 
896
  if cur_char<="z" then cur_char:=cur_char-@'40 {uppercasify}
 
897
  else begin
 
898
    if cur_char=invalid_code then begin
 
899
      err_print('Illegal character in the file');
 
900
@.Illegal character...@>
 
901
      cur_char:="?";
 
902
      end;
 
903
    end
 
904
else if (cur_char<=")")and(cur_char>="(") then decr(loc);
 
905
end;
 
906
 
 
907
@ Here's a procedure that scans a hexadecimal digit or a right parenthesis.
 
908
 
 
909
@p function get_hex:byte;
 
910
var @!a:integer; {partial result}
 
911
begin repeat get_next;
 
912
until cur_char<>" ";
 
913
a:=cur_char-")";
 
914
if a>0 then begin
 
915
  a:=cur_char-"0";
 
916
  if cur_char>"9" then
 
917
    if cur_char<"A" then a:=-1 else a:=cur_char-"A"+10;
 
918
  end;
 
919
if (a<0)or(a>15) then begin
 
920
  err_print('Illegal hexadecimal digit'); get_hex:=0;
 
921
@.Illegal hexadecimal digit@>
 
922
  end
 
923
else get_hex:=a;
 
924
end;
 
925
 
 
926
@ The next procedure is used to ignore the text of a comment, or to pass over
 
927
erroneous material. As such, it has the privilege of passing parentheses.
 
928
It stops after the first right parenthesis that drops the level below
 
929
the level in force when the procedure was called.
 
930
 
 
931
@p procedure skip_to_end_of_item;
 
932
var l:integer; {initial value of |level|}
 
933
begin l:=level;
 
934
while level>=l do begin
 
935
  while loc=limit do fill_buffer;
 
936
  incr(loc);
 
937
  if buffer[loc]=')' then decr(level)
 
938
  else if buffer[loc]='(' then incr(level);
 
939
  end;
 
940
if input_has_ended then err_print('File ended unexpectedly: No closing ")"');
 
941
@.File ended unexpectedly...@>
 
942
cur_char:=" "; {now the right parenthesis has been read and digested}
 
943
end;
 
944
 
 
945
@ A similar procedure copies the bytes remaining in an item. The copied bytes
 
946
go into an array |vf| that we'll declare later. Leading blanks are ignored.
 
947
 
 
948
@d vf_store(#)==
 
949
    begin vf[vf_ptr]:=#;
 
950
    if vf_ptr=vf_size then err_print('I''m out of memory---increase my vfsize!')
 
951
@.I'm out of memory...@>
 
952
    else incr(vf_ptr);
 
953
    end
 
954
 
 
955
@p procedure copy_to_end_of_item;
 
956
label 30;
 
957
var l:integer; {initial value of |level|}
 
958
@!nonblank_found:boolean; {have we seen a nonblank character yet?}
 
959
begin l:=level; nonblank_found:=false;
 
960
while true do begin
 
961
  while loc=limit do fill_buffer;
 
962
  if buffer[loc+1]=')' then
 
963
    if level=l then goto 30@+else decr(level);
 
964
  incr(loc);
 
965
  if buffer[loc]='(' then incr(level);
 
966
  if buffer[loc]<>' ' then nonblank_found:=true;
 
967
  if nonblank_found then
 
968
    if xord[buffer[loc]]=invalid_code then begin
 
969
      err_print('Illegal character in the file');
 
970
@.Illegal character...@>
 
971
      vf_store("?");
 
972
      end
 
973
    else vf_store(xord[buffer[loc]]);
 
974
  end;
 
975
30:end;
 
976
 
 
977
@ Sometimes we merely want to skip past characters in the input until we
 
978
reach a left or a right parenthesis. For example, we do this whenever we
 
979
have finished scanning a property value and we hope that a right parenthesis
 
980
is next (except for possible blank spaces).
 
981
 
 
982
@d skip_to_paren==repeat get_next@;@+ until (cur_char="(")or(cur_char=")")
 
983
@d skip_error(#)==begin err_print(#); skip_to_paren;
 
984
  end {this gets to the right parenthesis if something goes wrong}
 
985
@d flush_error(#)==begin err_print(#); skip_to_end_of_item;
 
986
  end {this gets past the right parenthesis if something goes wrong}
 
987
 
 
988
@ After a property value has been scanned, we want to move just past the
 
989
right parenthesis that should come next in the input (except for possible
 
990
blank spaces).
 
991
 
 
992
@p procedure finish_the_property; {do this when the value has been scanned}
 
993
begin while cur_char=" " do get_next;
 
994
if cur_char<>")" then err_print('Junk after property value will be ignored');
 
995
@.Junk after property value...@>
 
996
skip_to_end_of_item;
 
997
end;
 
998
 
 
999
@* Scanning property names.
 
1000
We have to figure out the meaning of names that appear in the \.{VPL} file,
 
1001
by looking them up in a dictionary of known keywords. Keyword number $n$
 
1002
appears in locations |start[n]| through |start[n+1]-1| of an array called
 
1003
|dictionary|.
 
1004
 
 
1005
@d max_name_index=300 {upper bound on the number of keywords}
 
1006
@d max_letters=3000 {upper bound on the total length of all keywords}
 
1007
 
 
1008
@<Global...@>=
 
1009
@!start:array[1..max_name_index] of 0..max_letters;
 
1010
@!dictionary:array[0..max_letters] of ASCII_code;
 
1011
@!start_ptr:0..max_name_index; {the first available place in |start|}
 
1012
@!dict_ptr:0..max_letters; {the first available place in |dictionary|}
 
1013
 
 
1014
@ @<Set init...@>=
 
1015
start_ptr:=1; start[1]:=0; dict_ptr:=0;
 
1016
 
 
1017
@ When we are looking for a name, we put it into the |cur_name| array.
 
1018
When we have found it, the corresponding |start| index will go into
 
1019
the global variable |name_ptr|.
 
1020
 
 
1021
@d longest_name=20 {length of \.{DEFAULTRULETHICKNESS}}
 
1022
 
 
1023
@<Glob...@>=
 
1024
@!cur_name:array[1..longest_name] of ASCII_code; {a name to look up}
 
1025
@!name_length:0..longest_name; {its length}
 
1026
@!name_ptr:0..max_name_index; {its ordinal number in the dictionary}
 
1027
 
 
1028
@ A conventional hash table with linear probing (cf.\ Algorithm 6.4L
 
1029
in {\sl The Art of Computer Pro\-gram\-ming\/}) is used for the dictionary
 
1030
operations. If |nhash[h]=0|, the table position is empty, otherwise |nhash[h]|
 
1031
points into the |start| array.
 
1032
 
 
1033
@d hash_prime=307 {size of the hash table}
 
1034
 
 
1035
@<Glob...@>=
 
1036
@!nhash:array[0..hash_prime-1] of 0..max_name_index;
 
1037
@!cur_hash:0..hash_prime-1; {current position in the hash table}
 
1038
 
 
1039
@ @<Local...@>=
 
1040
@!h:0..hash_prime-1; {runs through the hash table}
 
1041
 
 
1042
@ @<Set init...@>=
 
1043
for h:=0 to hash_prime-1 do nhash[h]:=0;
 
1044
 
 
1045
@ Since there is no chance of the hash table overflowing, the procedure
 
1046
is very simple. After |lookup| has done its work, |cur_hash| will point
 
1047
to the place where the given name was found, or where it should be inserted.
 
1048
 
 
1049
@p procedure lookup; {finds |cur_name| in the dictionary}
 
1050
var k:0..longest_name; {index into |cur_name|}
 
1051
@!j:0..max_letters; {index into |dictionary|}
 
1052
@!not_found:boolean; {clumsy thing necessary to avoid |goto| statement}
 
1053
@!cur_hash_reset:boolean;
 
1054
begin @<Compute the hash code, |cur_hash|, for |cur_name|@>;
 
1055
not_found:=true;
 
1056
cur_hash_reset:=false;   
 
1057
while not_found do begin
 
1058
  if (cur_hash=0) and (cur_hash_reset) then
 
1059
    not_found:=false
 
1060
  else begin
 
1061
    if cur_hash=0 then begin
 
1062
      cur_hash:=hash_prime-1;
 
1063
      cur_hash_reset:=true
 
1064
      end
 
1065
    else decr(cur_hash);
 
1066
    if nhash[cur_hash]=0 then not_found:=false
 
1067
    else begin
 
1068
      j:=start[nhash[cur_hash]];
 
1069
      if start[nhash[cur_hash]+1]=j+name_length then begin
 
1070
        not_found:=false;
 
1071
        for k:=1 to name_length do
 
1072
        if dictionary[j+k-1]<>cur_name[k] then not_found:=true;
 
1073
        end
 
1074
      end  
 
1075
    end
 
1076
  end;
 
1077
name_ptr:=nhash[cur_hash];
 
1078
end;
 
1079
 
 
1080
@ @<Compute the hash...@>=
 
1081
cur_hash:=cur_name[1];
 
1082
for k:=2 to name_length do
 
1083
  cur_hash:=(cur_hash+cur_hash+cur_name[k]) mod hash_prime
 
1084
 
 
1085
@ The ``meaning'' of the keyword that begins at |start[k]| in the
 
1086
dictionary is kept in |equiv[k]|. The numeric |equiv| codes are given
 
1087
symbolic meanings by the following definitions.
 
1088
 
 
1089
@d comment_code=0
 
1090
@d check_sum_code=1
 
1091
@d design_size_code=2
 
1092
@d design_units_code=3
 
1093
@d coding_scheme_code=4
 
1094
@d family_code=5
 
1095
@d face_code=6
 
1096
@d seven_bit_safe_flag_code=7
 
1097
@d header_code= 8
 
1098
@d font_dimen_code=9
 
1099
@d lig_table_code=10
 
1100
@d boundary_char_code=11
 
1101
@d virtual_title_code=12
 
1102
@d map_font_code=13
 
1103
@d font_dir_code=14
 
1104
@d n_font_dir_code=15
 
1105
@d character_code=16
 
1106
@d font_name_code=21
 
1107
@d font_area_code=22
 
1108
@d font_checksum_code=23
 
1109
@d font_at_code=24
 
1110
@d font_dsize_code=25
 
1111
@d parameter_code=30
 
1112
@d char_info_code=70
 
1113
@d width=1
 
1114
@d height=2
 
1115
@d depth=3
 
1116
@d italic=4
 
1117
@d sec_width=5
 
1118
@d sec_height=6
 
1119
@d sec_depth=7
 
1120
@d sec_italic=8
 
1121
@d accent=9
 
1122
@d prim_top_axis=10
 
1123
@d prim_top_axis_bis=11
 
1124
@d prim_bot_axis=12
 
1125
@d prim_bot_axis_bis=13
 
1126
@d prim_mid_hor=14
 
1127
@d prim_mid_vert=15
 
1128
@d prim_base_slant=16
 
1129
@d sec_top_axis=17
 
1130
@d sec_top_axis_bis=18
 
1131
@d sec_bot_axis=19
 
1132
@d sec_bot_axis_bis=20
 
1133
@d sec_mid_hor=21
 
1134
@d sec_mid_vert=22
 
1135
@d sec_base_slant=23
 
1136
@d char_wd_code=char_info_code+width
 
1137
@d char_ht_code=char_info_code+height
 
1138
@d char_dp_code=char_info_code+depth
 
1139
@d char_ic_code=char_info_code+italic
 
1140
@d sec_width_code=char_info_code+sec_width
 
1141
@d sec_height_code=char_info_code+sec_height
 
1142
@d sec_depth_code=char_info_code+sec_depth
 
1143
@d sec_italic_code=char_info_code+sec_italic
 
1144
@d accent_code=char_info_code+accent
 
1145
@d prim_top_axis_code=char_info_code+prim_top_axis
 
1146
@d prim_top_axis_bis_code=char_info_code+prim_top_axis_bis
 
1147
@d prim_bot_axis_code=char_info_code+prim_bot_axis
 
1148
@d prim_bot_axis_bis_code=char_info_code+prim_bot_axis_bis
 
1149
@d prim_mid_hor_code=char_info_code+prim_mid_hor
 
1150
@d prim_mid_vert_code=char_info_code+prim_mid_vert
 
1151
@d prim_base_slant_code=char_info_code+prim_base_slant
 
1152
@d sec_top_axis_code=char_info_code+sec_top_axis
 
1153
@d sec_top_axis_bis_code=char_info_code+sec_top_axis_bis
 
1154
@d sec_bot_axis_code=char_info_code+sec_bot_axis
 
1155
@d sec_bot_axis_bis_code=char_info_code+sec_bot_axis_bis
 
1156
@d sec_mid_hor_code=char_info_code+sec_mid_hor
 
1157
@d sec_mid_vert_code=char_info_code+sec_mid_vert
 
1158
@d sec_base_slant_code=char_info_code+sec_base_slant
 
1159
@d next_larger_code=100
 
1160
@d map_code=101
 
1161
@d var_char_code=102
 
1162
@d select_font_code=110
 
1163
@d set_char_code=111
 
1164
@d set_rule_code=112
 
1165
@d move_right_code=113
 
1166
@d move_down_code=115
 
1167
@d push_code=117
 
1168
@d pop_code=118
 
1169
@d special_code=119
 
1170
@d special_hex_code=120
 
1171
@d label_code=130
 
1172
@d stop_code=131
 
1173
@d skip_code=132
 
1174
@d krn_code=133
 
1175
@d lig_code=134
 
1176
@d ofm_level_code=140
 
1177
@d char_repeat_code=150
 
1178
@d char_ivalue_code=151
 
1179
@d char_fvalue_code=152
 
1180
@d char_mvalue_code=153
 
1181
@d char_rule_code=154
 
1182
@d char_glue_code=155
 
1183
@d char_penalty_code=156
 
1184
@d font_rule_code=160 
 
1185
@d rule_code=161   
 
1186
@d rule_width_code=162
 
1187
@d rule_height_code=163
 
1188
@d rule_depth_code=164
 
1189
@d font_glue_code=170
 
1190
@d glue_code=171   
 
1191
@d glue_type_code=172
 
1192
@d glue_stretch_order_code=173
 
1193
@d glue_shrink_order_code=174
 
1194
@d glue_width_code=175
 
1195
@d glue_stretch_code=176
 
1196
@d glue_shrink_code=177
 
1197
@d glue_char_code=178
 
1198
@d glue_rule_code=179
 
1199
@d order_unit_code=181
 
1200
@d order_fi_code=182
 
1201
@d order_fil_code=183
 
1202
@d order_fill_code=184
 
1203
@d order_filll_code=185
 
1204
@d type_normal_code=186
 
1205
@d type_aleaders_code=187
 
1206
@d type_cleaders_code=188
 
1207
@d type_xleaders_code=189
 
1208
@d font_penalty_code=190
 
1209
@d penalty_code=191   
 
1210
@d penalty_val_code=192
 
1211
@d font_mvalue_code=200
 
1212
@d mvalue_code=201   
 
1213
@d mvalue_val_code=202
 
1214
@d font_fvalue_code=210
 
1215
@d fvalue_code=211   
 
1216
@d fvalue_val_code=212
 
1217
@d font_ivalue_code=220
 
1218
@d ivalue_code=221   
 
1219
@d ivalue_val_code=222
 
1220
@d clabel_code=231  
 
1221
@d cpen_code=232
 
1222
@d cglue_code=233
 
1223
@d cpenglue_code=234
 
1224
@d ckrn_code=235
 
1225
@d TL_dir_code=240
 
1226
@d LT_dir_code=241
 
1227
@d TR_dir_code=242
 
1228
@d LB_dir_code=243
 
1229
@d BL_dir_code=244
 
1230
@d RT_dir_code=245
 
1231
@d BR_dir_code=246
 
1232
@d RB_dir_code=247
 
1233
 
 
1234
@<Glo...@>=
 
1235
@!equiv:array[0..max_name_index] of byte;
 
1236
@!cur_code:byte; {equivalent most recently found in |equiv|}
 
1237
 
 
1238
@ We have to get the keywords into the hash table and into the dictionary in
 
1239
the first place (sigh). The procedure that does this has the desired
 
1240
|equiv| code as a parameter. In order to facilitate \.{WEB} macro writing
 
1241
for the initialization, the keyword being initialized is placed into the
 
1242
last positions of |cur_name|, instead of the first positions.
 
1243
 
 
1244
@p procedure enter_name(v:byte); {|cur_name| goes into the dictionary}
 
1245
var k:0..longest_name;
 
1246
begin for k:=1 to name_length do
 
1247
  cur_name[k]:=cur_name[k+longest_name-name_length];
 
1248
{now the name has been shifted into the correct position}
 
1249
lookup; {this sets |cur_hash| to the proper insertion place}
 
1250
nhash[cur_hash]:=start_ptr; equiv[start_ptr]:=v;
 
1251
for k:=1 to name_length do begin
 
1252
  dictionary[dict_ptr]:=cur_name[k]; incr(dict_ptr);
 
1253
  end;
 
1254
incr(start_ptr); start[start_ptr]:=dict_ptr;
 
1255
end;
 
1256
 
 
1257
@ Here are the macros to load a name of up to 20 letters into the
 
1258
dictionary. For example, the macro |load5| is used for five-letter keywords.
 
1259
 
 
1260
@d tail(#)==enter_name(#)
 
1261
@d t20(#)==cur_name[20]:=#;tail
 
1262
@d t19(#)==cur_name[19]:=#;t20
 
1263
@d t18(#)==cur_name[18]:=#;t19
 
1264
@d t17(#)==cur_name[17]:=#;t18
 
1265
@d t16(#)==cur_name[16]:=#;t17
 
1266
@d t15(#)==cur_name[15]:=#;t16
 
1267
@d t14(#)==cur_name[14]:=#;t15
 
1268
@d t13(#)==cur_name[13]:=#;t14
 
1269
@d t12(#)==cur_name[12]:=#;t13
 
1270
@d t11(#)==cur_name[11]:=#;t12
 
1271
@d t10(#)==cur_name[10]:=#;t11
 
1272
@d t9(#)==cur_name[9]:=#;t10
 
1273
@d t8(#)==cur_name[8]:=#;t9
 
1274
@d t7(#)==cur_name[7]:=#;t8
 
1275
@d t6(#)==cur_name[6]:=#;t7
 
1276
@d t5(#)==cur_name[5]:=#;t6
 
1277
@d t4(#)==cur_name[4]:=#;t5
 
1278
@d t3(#)==cur_name[3]:=#;t4
 
1279
@d t2(#)==cur_name[2]:=#;t3
 
1280
@d t1(#)==cur_name[1]:=#;t2
 
1281
@d load2==name_length:=2;t19
 
1282
@d load3==name_length:=3;t18
 
1283
@d load4==name_length:=4;t17
 
1284
@d load5==name_length:=5;t16
 
1285
@d load6==name_length:=6;t15
 
1286
@d load7==name_length:=7;t14
 
1287
@d load8==name_length:=8;t13
 
1288
@d load9==name_length:=9;t12
 
1289
@d load10==name_length:=10;t11
 
1290
@d load11==name_length:=11;t10
 
1291
@d load12==name_length:=12;t9
 
1292
@d load13==name_length:=13;t8
 
1293
@d load14==name_length:=14;t7
 
1294
@d load15==name_length:=15;t6
 
1295
@d load16==name_length:=16;t5
 
1296
@d load17==name_length:=17;t4
 
1297
@d load18==name_length:=18;t3
 
1298
@d load19==name_length:=19;t2
 
1299
@d load20==name_length:=20;t1
 
1300
 
 
1301
@ (Thank goodness for keyboard macros in the text editor used to create this
 
1302
\.{WEB} file.)
 
1303
 
 
1304
@<Enter all the \.{PL} names and their equivalents,
 
1305
 except the parameter names@>=
 
1306
equiv[0]:=comment_code; {this is used after unknown keywords}
 
1307
load8("C")("H")("E")("C")("K")("S")("U")("M")(check_sum_code);@/
 
1308
load10("D")("E")("S")("I")("G")("N")("S")("I")("Z")("E")(design_size_code);@/
 
1309
load11("D")("E")("S")("I")("G")("N")
 
1310
  ("U")("N")("I")("T")("S")(design_units_code);@/
 
1311
load12("C")("O")("D")("I")("N")("G")
 
1312
  ("S")("C")("H")("E")("M")("E")(coding_scheme_code);@/
 
1313
load6("F")("A")("M")("I")("L")("Y")(family_code);@/
 
1314
load4("F")("A")("C")("E")(face_code);@/
 
1315
load16("S")("E")("V")("E")("N")("B")("I")("T")@/@t\hskip2em@>
 
1316
  ("S")("A")("F")("E")("F")("L")("A")("G")(seven_bit_safe_flag_code);@/
 
1317
load6("H")("E")("A")("D")("E")("R")(header_code);@/
 
1318
load9("F")("O")("N")("T")("D")("I")("M")("E")("N")(font_dimen_code);@/
 
1319
load8("L")("I")("G")("T")("A")("B")("L")("E")(lig_table_code);@/
 
1320
load12("B")("O")("U")("N")("D")("A")("R")("Y")("C")("H")("A")("R")
 
1321
  (boundary_char_code);@/
 
1322
load9("C")("H")("A")("R")("A")("C")("T")("E")("R")(character_code);@/
 
1323
load9("P")("A")("R")("A")("M")("E")("T")("E")("R")(parameter_code);@/
 
1324
load6("C")("H")("A")("R")("W")("D")(char_wd_code);@/
 
1325
load6("C")("H")("A")("R")("H")("T")(char_ht_code);@/
 
1326
load6("C")("H")("A")("R")("D")("P")(char_dp_code);@/
 
1327
load6("C")("H")("A")("R")("I")("C")(char_ic_code);@/
 
1328
load5("S")("E")("C")("W")("D")(sec_width_code);@/
 
1329
load5("S")("E")("C")("H")("T")(sec_height_code);@/
 
1330
load5("S")("E")("C")("D")("P")(sec_depth_code);@/
 
1331
load5("S")("E")("C")("I")("C")(sec_italic_code);@/
 
1332
load6("A")("C")("C")("E")("N")("T")(accent_code);@/
 
1333
load11("P")("R")("I")("M")("T")("O")("P")("A")("X")("I")("S")(prim_top_axis_code);@/
 
1334
load14("P")("R")("I")("M")("T")("O")("P")("A")("X")("I")("S")("B")("I")("S")(prim_top_axis_bis_code);@/
 
1335
load11("P")("R")("I")("M")("B")("O")("T")("A")("X")("I")("S")(prim_bot_axis_code);@/
 
1336
load14("P")("R")("I")("M")("B")("O")("T")("A")("X")("I")("S")("B")("I")("S")(prim_bot_axis_bis_code);@/
 
1337
load10("P")("R")("I")("M")("M")("I")("D")("H")("O")("R")(prim_mid_hor_code);@/
 
1338
load10("P")("R")("I")("M")("M")("I")("D")("V")("E")("R")(prim_mid_vert_code);@/
 
1339
load13("P")("R")("I")("M")("B")("A")("S")("E")("S")("L")("A")("N")("T")(prim_base_slant_code);@/
 
1340
load10("S")("E")("C")("T")("O")("P")("A")("X")("I")("S")(sec_top_axis_code);@/
 
1341
load13("S")("E")("C")("T")("O")("P")("A")("X")("I")("S")("B")("I")("S")(sec_top_axis_bis_code);@/
 
1342
load10("S")("E")("C")("B")("O")("T")("A")("X")("I")("S")(sec_bot_axis_code);@/
 
1343
load13("S")("E")("C")("B")("O")("T")("A")("X")("I")("S")("B")("I")("S")(sec_bot_axis_bis_code);@/
 
1344
load9("S")("E")("C")("M")("I")("D")("H")("O")("R")(sec_mid_hor_code);@/
 
1345
load9("S")("E")("C")("M")("I")("D")("V")("E")("R")(sec_mid_vert_code);@/
 
1346
load12("S")("E")("C")("B")("A")("S")("E")("S")("L")("A")("N")("T")(sec_base_slant_code);@/
 
1347
load10("N")("E")("X")("T")("L")("A")("R")("G")("E")("R")(next_larger_code);@/
 
1348
load7("V")("A")("R")("C")("H")("A")("R")(var_char_code);@/
 
1349
load3("T")("O")("P")(var_char_code+1);@/
 
1350
load3("M")("I")("D")(var_char_code+2);@/
 
1351
load3("B")("O")("T")(var_char_code+3);@/
 
1352
load3("R")("E")("P")(var_char_code+4);@/
 
1353
load3("E")("X")("T")(var_char_code+4); {compatibility with older \.{PL} format}
 
1354
load7("C")("O")("M")("M")("E")("N")("T")(comment_code);@/
 
1355
load5("L")("A")("B")("E")("L")(label_code);@/
 
1356
load4("S")("T")("O")("P")(stop_code);@/
 
1357
load4("S")("K")("I")("P")(skip_code);@/
 
1358
load3("K")("R")("N")(krn_code);@/
 
1359
load3("L")("I")("G")(lig_code);@/
 
1360
load4("/")("L")("I")("G")(lig_code+2);@/
 
1361
load5("/")("L")("I")("G")(">")(lig_code+6);@/
 
1362
load4("L")("I")("G")("/")(lig_code+1);@/
 
1363
load5("L")("I")("G")("/")(">")(lig_code+5);@/
 
1364
load5("/")("L")("I")("G")("/")(lig_code+3);@/
 
1365
load6("/")("L")("I")("G")("/")(">")(lig_code+7);@/
 
1366
load7("/")("L")("I")("G")("/")(">")(">")(lig_code+11);@/
 
1367
load6("C")("L")("A")("B")("E")("L")(clabel_code);@/
 
1368
load4("C")("P")("E")("N")(cpen_code);@/
 
1369
load5("C")("G")("L")("U")("E")(cglue_code);@/
 
1370
load8("C")("P")("E")("N")("G")("L")("U")("E")(cpenglue_code);@/
 
1371
load4("C")("K")("R")("N")(ckrn_code);@/
 
1372
load8("O")("F")("M")("L")("E")("V")("E")("L")(ofm_level_code);@/
 
1373
load7("F")("O")("N")("T")("D")("I")("R")(font_dir_code);@/
 
1374
load8("N")("F")("O")("N")("T")("D")("I")("R")(n_font_dir_code);@/
 
1375
load10("C")("H")("A")("R")("R")("E")("P")("E")("A")("T")(char_repeat_code);@/
 
1376
load10("C")("H")("A")("R")("I")("V")("A")("L")("U")("E")(char_ivalue_code);@/
 
1377
load10("C")("H")("A")("R")("F")("V")("A")("L")("U")("E")(char_fvalue_code);@/
 
1378
load10("C")("H")("A")("R")("M")("V")("A")("L")("U")("E")(char_mvalue_code);@/
 
1379
load8("C")("H")("A")("R")("R")("U")("L")("E")(char_rule_code);@/
 
1380
load8("C")("H")("A")("R")("G")("L")("U")("E")(char_glue_code);@/
 
1381
load11("C")("H")("A")("R")("P")("E")("N")("A")("L")("T")("Y")(char_penalty_code);@/
 
1382
load8("F")("O")("N")("T")("R")("U")("L")("E")(font_rule_code);@/
 
1383
load4("R")("U")("L")("E")(rule_code);@/
 
1384
load6("R")("U")("L")("E")("W")("D")(rule_width_code);@/
 
1385
load6("R")("U")("L")("E")("H")("T")(rule_height_code);@/
 
1386
load6("R")("U")("L")("E")("D")("P")(rule_depth_code);@/
 
1387
load8("F")("O")("N")("T")("G")("L")("U")("E")(font_glue_code);@/
 
1388
load4("G")("L")("U")("E")(glue_code);@/
 
1389
load8("G")("L")("U")("E")("T")("Y")("P")("E")(glue_type_code);@/
 
1390
load16("G")("L")("U")("E")("S")("T")("R")("E")("T")("C")("H")("O")("R")("D")("E")("R")(glue_stretch_order_code);@/
 
1391
load15("G")("L")("U")("E")("S")("H")("R")("I")("N")("K")("O")("R")("D")("E")("R")(glue_shrink_order_code);@/
 
1392
load8("G")("L")("U")("E")("R")("U")("L")("E")(glue_rule_code);@/
 
1393
load8("G")("L")("U")("E")("C")("H")("A")("R")(glue_char_code);@/
 
1394
load6("G")("L")("U")("E")("W")("D")(glue_width_code);@/
 
1395
load11("G")("L")("U")("E")("S")("T")("R")("E")("T")("C")("H")(glue_stretch_code);@/
 
1396
load10("G")("L")("U")("E")("S")("H")("R")("I")("N")("K")(glue_shrink_code);@/
 
1397
load4("U")("N")("I")("T")(order_unit_code);@/
 
1398
load2("F")("I")(order_fi_code);@/
 
1399
load3("F")("I")("L")(order_fil_code);@/
 
1400
load4("F")("I")("L")("L")(order_fill_code);@/
 
1401
load5("F")("I")("L")("L")("L")(order_filll_code);@/
 
1402
load6("N")("O")("R")("M")("A")("L")(type_normal_code);@/
 
1403
load8("A")("L")("E")("A")("D")("E")("R")("S")(type_aleaders_code);@/
 
1404
load8("C")("L")("E")("A")("D")("E")("R")("S")(type_cleaders_code);@/
 
1405
load8("X")("L")("E")("A")("D")("E")("R")("S")(type_xleaders_code);@/
 
1406
load11("F")("O")("N")("T")("P")("E")("N")("A")("L")("T")("Y")(font_penalty_code);@/
 
1407
load7("P")("E")("N")("A")("L")("T")("Y")(penalty_code);@/
 
1408
load10("P")("E")("N")("A")("L")("T")("Y")("V")("A")("L")(penalty_val_code);@/
 
1409
load10("F")("O")("N")("T")("M")("V")("A")("L")("U")("E")(font_mvalue_code);@/
 
1410
load6("M")("V")("A")("L")("U")("E")(mvalue_code);@/
 
1411
load9("M")("V")("A")("L")("U")("E")("V")("A")("L")(mvalue_val_code);@/
 
1412
load10("F")("O")("N")("T")("F")("V")("A")("L")("U")("E")(font_fvalue_code);@/
 
1413
load6("F")("V")("A")("L")("U")("E")(fvalue_code);@/
 
1414
load9("F")("V")("A")("L")("U")("E")("V")("A")("L")(fvalue_val_code);@/
 
1415
load10("F")("O")("N")("T")("I")("V")("A")("L")("U")("E")(font_ivalue_code);@/
 
1416
load6("I")("V")("A")("L")("U")("E")(ivalue_code);@/
 
1417
load9("I")("V")("A")("L")("U")("E")("V")("A")("L")(ivalue_val_code);@/
 
1418
load2("T")("L")(TL_dir_code);
 
1419
load2("L")("T")(LT_dir_code);
 
1420
load2("T")("R")(TR_dir_code);
 
1421
load2("L")("B")(LB_dir_code);
 
1422
load2("B")("L")(BL_dir_code);
 
1423
load2("R")("T")(RT_dir_code);
 
1424
load2("B")("R")(BR_dir_code);
 
1425
load2("R")("B")(RB_dir_code);
 
1426
 
 
1427
@ \.{VPL} files may contain the following in addition to the \.{PL} names.
 
1428
 
 
1429
@<Enter all the \.{VPL} names@>=
 
1430
load6("V")("T")("I")("T")("L")("E")(virtual_title_code);@/
 
1431
load7("M")("A")("P")("F")("O")("N")("T")(map_font_code);@/
 
1432
load3("M")("A")("P")(map_code);@/
 
1433
load8("F")("O")("N")("T")("N")("A")("M")("E")(font_name_code);@/
 
1434
load8("F")("O")("N")("T")("A")("R")("E")("A")(font_area_code);@/
 
1435
load12("F")("O")("N")("T")
 
1436
 ("C")("H")("E")("C")("K")("S")("U")("M")(font_checksum_code);@/
 
1437
load6("F")("O")("N")("T")("A")("T")(font_at_code);@/
 
1438
load9("F")("O")("N")("T")("D")("S")("I")("Z")("E")(font_dsize_code);@/
 
1439
load10("S")("E")("L")("E")("C")("T")("F")("O")("N")("T")(select_font_code);@/
 
1440
load7("S")("E")("T")("C")("H")("A")("R")(set_char_code);@/
 
1441
load7("S")("E")("T")("R")("U")("L")("E")(set_rule_code);@/
 
1442
load9("M")("O")("V")("E")("R")("I")("G")("H")("T")(move_right_code);@/
 
1443
load8("M")("O")("V")("E")("L")("E")("F")("T")(move_right_code+1);@/
 
1444
load8("M")("O")("V")("E")("D")("O")("W")("N")(move_down_code);@/
 
1445
load6("M")("O")("V")("E")("U")("P")(move_down_code+1);@/
 
1446
load4("P")("U")("S")("H")(push_code);@/
 
1447
load3("P")("O")("P")(pop_code);@/
 
1448
load7("S")("P")("E")("C")("I")("A")("L")(special_code);@/
 
1449
load10("S")("P")("E")("C")("I")("A")("L")("H")("E")("X")(special_hex_code);@/
 
1450
 
 
1451
@ @<Enter the parameter names@>=
 
1452
load5("S")("L")("A")("N")("T")(parameter_code+1);@/
 
1453
load5("S")("P")("A")("C")("E")(parameter_code+2);@/
 
1454
load7("S")("T")("R")("E")("T")("C")("H")(parameter_code+3);@/
 
1455
load6("S")("H")("R")("I")("N")("K")(parameter_code+4);@/
 
1456
load7("X")("H")("E")("I")("G")("H")("T")(parameter_code+5);@/
 
1457
load4("Q")("U")("A")("D")(parameter_code+6);@/
 
1458
load10("E")("X")("T")("R")("A")("S")("P")("A")("C")("E")(parameter_code+7);@/
 
1459
load4("N")("U")("M")("1")(parameter_code+8);@/
 
1460
load4("N")("U")("M")("2")(parameter_code+9);@/
 
1461
load4("N")("U")("M")("3")(parameter_code+10);@/
 
1462
load6("D")("E")("N")("O")("M")("1")(parameter_code+11);@/
 
1463
load6("D")("E")("N")("O")("M")("2")(parameter_code+12);@/
 
1464
load4("S")("U")("P")("1")(parameter_code+13);@/
 
1465
load4("S")("U")("P")("2")(parameter_code+14);@/
 
1466
load4("S")("U")("P")("3")(parameter_code+15);@/
 
1467
load4("S")("U")("B")("1")(parameter_code+16);@/
 
1468
load4("S")("U")("B")("2")(parameter_code+17);@/
 
1469
load7("S")("U")("P")("D")("R")("O")("P")(parameter_code+18);@/
 
1470
load7("S")("U")("B")("D")("R")("O")("P")(parameter_code+19);@/
 
1471
load6("D")("E")("L")("I")("M")("1")(parameter_code+20);@/
 
1472
load6("D")("E")("L")("I")("M")("2")(parameter_code+21);@/
 
1473
load10("A")("X")("I")("S")("H")("E")("I")("G")("H")("T")(parameter_code+22);@/
 
1474
load20("D")("E")("F")("A")("U")("L")("T")("R")("U")("L")("E")@/@t\hskip2em@>
 
1475
  ("T")("H")("I")("C")("K")("N")("E")("S")("S")(parameter_code+8);@/
 
1476
load13("B")("I")("G")("O")("P")
 
1477
  ("S")("P")("A")("C")("I")("N")("G")("1")(parameter_code+9);@/
 
1478
load13("B")("I")("G")("O")("P")
 
1479
  ("S")("P")("A")("C")("I")("N")("G")("2")(parameter_code+10);@/
 
1480
load13("B")("I")("G")("O")("P")
 
1481
  ("S")("P")("A")("C")("I")("N")("G")("3")(parameter_code+11);@/
 
1482
load13("B")("I")("G")("O")("P")
 
1483
  ("S")("P")("A")("C")("I")("N")("G")("4")(parameter_code+12);@/
 
1484
load13("B")("I")("G")("O")("P")
 
1485
  ("S")("P")("A")("C")("I")("N")("G")("5")(parameter_code+13);@/
 
1486
 
 
1487
@ When a left parenthesis has been scanned, the following routine
 
1488
is used to interpret the keyword that follows, and to store the
 
1489
equivalent value in |cur_code|.
 
1490
 
 
1491
@p procedure get_name;
 
1492
begin incr(loc); incr(level); {pass the left parenthesis}
 
1493
cur_char:=" ";
 
1494
while cur_char=" " do get_next;
 
1495
if (cur_char>")")or(cur_char<"(") then decr(loc); {back up one character}
 
1496
name_length:=0; get_keyword_char; {prepare to scan the name}
 
1497
while cur_char<>" " do begin
 
1498
  if name_length=longest_name then cur_name[1]:="X" {force error}
 
1499
  else incr(name_length);
 
1500
  cur_name[name_length]:=cur_char;
 
1501
  get_keyword_char;
 
1502
  end;
 
1503
lookup;
 
1504
if name_ptr=0 then err_print('Sorry, I don''t know that property name');
 
1505
@.Sorry, I don't know...@>
 
1506
cur_code:=equiv[name_ptr];
 
1507
end;
 
1508
 
 
1509
@* Scanning numeric data.
 
1510
The next thing we need is a trio of subroutines to read the one-byte,
 
1511
four-byte, and real numbers that may appear as property values.
 
1512
These subroutines are careful to stick to numbers between $-2^{31}$
 
1513
and $2^{31}-1$, inclusive, so that a computer with two's complement
 
1514
32-bit arithmetic will not be interrupted by overflow.
 
1515
 
 
1516
@ The first number scanner, which returns a one-byte value, surely has
 
1517
no problems of arithmetic overflow.
 
1518
 
 
1519
@p function get_byte:byte; {scans a one-byte property value}
 
1520
var acc:integer; {an accumulator}
 
1521
@!t:ASCII_code; {the type of value to be scanned}
 
1522
begin repeat get_next;
 
1523
until cur_char<>" "; {skip the blanks before the type code}
 
1524
t:=cur_char; acc:=0;
 
1525
repeat get_next;
 
1526
until cur_char<>" "; {skip the blanks after the type code}
 
1527
if t="C" then @<Scan an ASCII character code@>
 
1528
else if t="D" then @<Scan a small decimal number@>
 
1529
else if t="O" then @<Scan a small octal number@>
 
1530
else if t="H" then @<Scan a small hexadecimal number@>
 
1531
else if t="F" then @<Scan a face code@>
 
1532
else skip_error('You need "C" or "D" or "O" or "H" or "F" here');
 
1533
@.You need "C" or "D" ...here@>
 
1534
cur_char:=" "; get_byte:=acc;
 
1535
end;
 
1536
 
 
1537
@ The |get_next| routine converts lower case to upper case, but it leaves
 
1538
the character in the buffer, so we can unconvert it.
 
1539
 
 
1540
@<Scan an ASCII...@>=
 
1541
if (cur_char>=@'41)and(cur_char<=@'176)and
 
1542
 ((cur_char<"(")or(cur_char>")")) then
 
1543
  acc:=xord[buffer[loc]]
 
1544
else skip_error('"C" value must be standard ASCII and not a paren')
 
1545
@:C value}\.{"C" value must be...@>
 
1546
 
 
1547
@ @<Scan a small dec...@>=
 
1548
begin while (cur_char>="0")and(cur_char<="9") do begin
 
1549
  acc:=acc*10+cur_char-"0";
 
1550
  if acc>65535 then begin
 
1551
    skip_error('This value shouldn''t exceed 65535');
 
1552
@.This value shouldn't...@>
 
1553
    acc:=0; cur_char:=" ";
 
1554
    end
 
1555
  else get_next;
 
1556
  end;
 
1557
backup;
 
1558
end
 
1559
 
 
1560
@ @<Scan a small oct...@>=
 
1561
begin while (cur_char>="0")and(cur_char<="7") do begin
 
1562
  acc:=acc*8+cur_char-"0";
 
1563
  if acc>65535 then begin
 
1564
    skip_error('This value shouldn''t exceed ''177777');
 
1565
@.This value shouldn't...@>
 
1566
    acc:=0; cur_char:=" ";
 
1567
    end
 
1568
  else get_next;
 
1569
  end;
 
1570
backup;
 
1571
end
 
1572
 
 
1573
@ @<Scan a small hex...@>=
 
1574
begin while ((cur_char>="0")and(cur_char<="9"))or
 
1575
   ((cur_char>="A")and(cur_char<="F")) do begin
 
1576
  if cur_char>="A" then cur_char:=cur_char+"0"+10-"A";
 
1577
  acc:=acc*16+cur_char-"0";
 
1578
  if acc>65535 then begin
 
1579
    skip_error('This value shouldn''t exceed "FFFF');
 
1580
@.This value shouldn't...@>
 
1581
    acc:=0; cur_char:=" ";
 
1582
    end
 
1583
  else get_next;
 
1584
  end;
 
1585
backup;
 
1586
end
 
1587
 
 
1588
@ @<Scan a face...@>=
 
1589
begin if cur_char="B" then acc:=2
 
1590
else if cur_char="L" then acc:=4
 
1591
else if cur_char<>"M" then acc:=18;
 
1592
get_next;
 
1593
if cur_char="I" then incr(acc)
 
1594
else if cur_char<>"R" then acc:=18;
 
1595
get_next;
 
1596
if cur_char="C" then acc:=acc+6
 
1597
else if cur_char="E" then acc:=acc+12
 
1598
else if cur_char<>"R" then acc:=18;
 
1599
if acc>=18 then begin
 
1600
  skip_error('Illegal face code, I changed it to MRR');
 
1601
@.Illegal face code...@>
 
1602
  acc:=0;
 
1603
  end;
 
1604
end
 
1605
 
 
1606
@ The routine that scans a four-byte value puts its output into |cur_bytes|,
 
1607
which is a record containing (yes, you guessed it) four bytes.
 
1608
 
 
1609
@<Types...@>=
 
1610
@!four_bytes=record @!b0:byte;@+@!b1:byte;@+@!b2:byte;@+@!b3:byte;@+end;
 
1611
 
 
1612
@ @d c0==cur_bytes.b0
 
1613
@d c1==cur_bytes.b1
 
1614
@d c2==cur_bytes.b2
 
1615
@d c3==cur_bytes.b3
 
1616
 
 
1617
@<Glob...@>=
 
1618
@!cur_bytes:four_bytes; {a four-byte accumulator}
 
1619
@!zero_bytes:four_bytes; {four bytes all zero}
 
1620
 
 
1621
@ @<Set init...@>=
 
1622
zero_bytes.b0:=0; zero_bytes.b1:=0; zero_bytes.b2:=0; zero_bytes.b3:=0;
 
1623
 
 
1624
@ Since the |get_four_bytes| routine is used very infrequently, no attempt
 
1625
has been made to make it fast; we only want it to work.
 
1626
This is no longer the case, but we hope it's not too slow.
 
1627
 
 
1628
@p procedure get_four_bytes; {scans an unsigned constant and sets |four_bytes|}
 
1629
var c:integer; {local two-byte accumulator}
 
1630
@!r:integer; {radix}
 
1631
begin repeat get_next;
 
1632
until cur_char<>" "; {skip the blanks before the type code}
 
1633
r:=0; cur_bytes:=zero_bytes; {start with the accumulator zero}
 
1634
if cur_char="H" then r:=16
 
1635
else if cur_char="O" then r:=8
 
1636
else if cur_char="D" then r:=10
 
1637
else skip_error('Decimal ("D"), octal ("O"), or hex ("H") value needed here');
 
1638
@.Decimal ("D"), octal ("O"), or hex...@>
 
1639
if r>0 then begin
 
1640
  repeat get_next;
 
1641
  until cur_char<>" "; {skip the blanks after the type code}
 
1642
  while ((cur_char>="0")and(cur_char<="9"))or@|
 
1643
      ((cur_char>="A")and(cur_char<="F")) do
 
1644
    @<Multiply by |r|, add |cur_char-"0"|, and |get_next|@>;
 
1645
  end;
 
1646
end;
 
1647
 
 
1648
function get_integer:integer; {scans an integer property value}
 
1649
begin get_four_bytes;
 
1650
get_integer:=(c0*@"1000000)+(c1*@"10000)+(c2*@"100)+c3;
 
1651
end;
 
1652
 
 
1653
 
 
1654
@ @<Multiply by |r|...@>=
 
1655
begin if cur_char>="A" then cur_char:=cur_char+"0"+10-"A";
 
1656
if cur_char>="0"+r then skip_error('Illegal digit')
 
1657
@.Illegal digit@>
 
1658
else begin
 
1659
  c:=c3*r+cur_char-"0"; c3:=c mod 256;@/
 
1660
  c:=c2*r+c div 256; c2:=c mod 256;@/
 
1661
  c:=c1*r+c div 256; c1:=c mod 256;@/
 
1662
  c:=c0*r+c div 256;
 
1663
  if c<256 then c0:=c
 
1664
  else begin
 
1665
    cur_bytes:=zero_bytes;
 
1666
    if r=8 then
 
1667
      skip_error('Sorry, the maximum octal value is O 37777777777')
 
1668
@.Sorry, the maximum...@>
 
1669
    else if r=10 then
 
1670
      skip_error('Sorry, the maximum decimal value is D 4294967295')
 
1671
    else skip_error('Sorry, the maximum hex value is H FFFFFFFF');
 
1672
    end;
 
1673
  get_next;
 
1674
  end;
 
1675
end
 
1676
 
 
1677
@ The remaining scanning routine is the most interesting. It scans a real
 
1678
constant and returns the nearest |fix_word| approximation to that constant.
 
1679
A |fix_word| is a 32-bit integer that represents a real value that
 
1680
has been multiplied by $2^{20}$. Since \.{VPtoVF} restricts the magnitude
 
1681
of reals to 2048, the |fix_word| will have a magnitude less than $2^{31}$.
 
1682
 
 
1683
@d unity==@'4000000 {$2^{20}$, the |fix_word| 1.0}
 
1684
 
 
1685
@<Types...@>=
 
1686
@!fix_word=integer; {a scaled real value with 20 bits of fraction}
 
1687
@!unsigned_integer=integer;
 
1688
 
 
1689
@ When a real value is desired, we might as well treat `\.D' and `\.R'
 
1690
formats as if they were identical.
 
1691
 
 
1692
@p function get_fix:fix_word; {scans a real property value}
 
1693
var negative:boolean; {was there a minus sign?}
 
1694
@!acc:integer; {an accumulator}
 
1695
@!int_part:integer; {the integer part}
 
1696
@!j:0..7; {the number of decimal places stored}
 
1697
begin repeat get_next;
 
1698
until cur_char<>" "; {skip the blanks before the type code}
 
1699
negative:=false; acc:=0; {start with the accumulators zero}
 
1700
if (cur_char<>"R")and(cur_char<>"D") then
 
1701
  skip_error('An "R" or "D" value is needed here')
 
1702
@.An "R" or "D" ... needed here@>
 
1703
else  begin @<Scan the blanks and/or signs after the type code@>;
 
1704
  while (cur_char>="0") and (cur_char<="9") do
 
1705
    @<Multiply by 10, add |cur_char-"0"|, and |get_next|@>;
 
1706
  int_part:=acc; acc:=0;
 
1707
  if cur_char="." then @<Scan the fraction part and put it in |acc|@>;
 
1708
  if (acc>=unity)and(int_part=2047) then
 
1709
    skip_error('Real constants must be less than 2048')
 
1710
@.Real constants must be...@>
 
1711
  else acc:=int_part*unity+acc;
 
1712
  end;
 
1713
if negative then get_fix:=-acc@+else get_fix:=acc;
 
1714
end;
 
1715
 
 
1716
@ @<Scan the blanks...@>=
 
1717
repeat get_next;
 
1718
if cur_char="-" then begin
 
1719
  cur_char:=" "; negative:=true;
 
1720
  end
 
1721
else if cur_char="+" then cur_char:=" ";
 
1722
until cur_char<>" "
 
1723
 
 
1724
@ @<Multiply by 10...@>=
 
1725
begin acc:=acc*10+cur_char-"0";
 
1726
if acc>=2048 then begin
 
1727
  skip_error('Real constants must be less than 2048');
 
1728
@.Real constants must be...@>
 
1729
  acc:=0; cur_char:=" ";
 
1730
  end
 
1731
else get_next;
 
1732
end
 
1733
 
 
1734
@ To scan the fraction $.d_1d_2\ldots\,$, we keep track of up to seven
 
1735
of the digits $d_j$. A correct result is obtained if we first compute
 
1736
$f^\prime=\lfloor 2^{21}(d_1\ldots d_j)/10^j\rfloor$, after which
 
1737
$f=\lfloor(f^\prime+1)/2\rfloor$. It is possible to have $f=1.0$.
 
1738
 
 
1739
@<Glob...@>=
 
1740
@!fraction_digits:array[1..7] of integer; {$2^{21}$ times $d_j$}
 
1741
 
 
1742
@ @<Scan the frac...@>=
 
1743
begin j:=0; get_next;
 
1744
while (cur_char>="0")and(cur_char<="9") do begin
 
1745
  if j<7 then begin
 
1746
    incr(j); fraction_digits[j]:=@'10000000*(cur_char-"0");
 
1747
    end;
 
1748
  get_next;
 
1749
  end;
 
1750
acc:=0;
 
1751
while j>0 do begin
 
1752
  acc:=fraction_digits[j]+(acc div 10); decr(j);
 
1753
  end;
 
1754
acc:=(acc+10) div 20;
 
1755
end
 
1756
 
 
1757
@* Storing the property values.
 
1758
When property values have been found, they are squirreled away in a bunch
 
1759
of arrays. The header information is unpacked into bytes in an array
 
1760
called |header_bytes|. The ligature/kerning program is stored in an array
 
1761
of type |four_bytes|.
 
1762
Another |four_bytes| array holds the specifications of extensible characters.
 
1763
The kerns and parameters are stored in separate arrays of |fix_word| values.
 
1764
Virtual font data goes into an array |vf| of single-byte values.
 
1765
 
 
1766
We maintain information about at most |max_font+1| local fonts.
 
1767
 
 
1768
Instead of storing the design size in the header array, we will keep it
 
1769
in a |fix_word| variable until the last minute. The number of units in the
 
1770
design size is also kept in a |fix_word|.
 
1771
 
 
1772
@<Glob...@>=
 
1773
@!header_bytes:array[header_index] of byte; {the header block}
 
1774
@!header_ptr:header_index; {the number of header bytes in use}
 
1775
@!design_size:fix_word; {the design size}
 
1776
@!design_units:fix_word; {reciprocal of the scaling factor}
 
1777
@!frozen_du:boolean; {have we used |design_units| irrevocably?}
 
1778
@!seven_bit_safe_flag:boolean; {does the file claim to be seven-bit-safe?}
 
1779
@!lig_kern:array[0..max_lig_steps] of four_bytes; {the ligature program}
 
1780
@!nl:unsigned_integer; {the number of ligature/kern instructions so far}
 
1781
@!min_nl:unsigned_integer; {the final value of |nl| must be at least this}
 
1782
@!kern:array[0..max_kerns] of fix_word; {the distinct kerning amounts}
 
1783
@!nk:0..max_kerns; {the number of entries of |kern|}
 
1784
@!exten:array[char_type] of four_bytes; {extensible character specs}
 
1785
@!ne:xchar_type; {the number of extensible characters}
 
1786
@!param:array[1..max_param_words] of fix_word; {\.{FONTDIMEN} parameters}
 
1787
@!np:0..max_param_words; {the largest parameter set nonzero}
 
1788
@!check_sum_specified:boolean; {did the user name the check sum?}
 
1789
@!bchar:xchar_type; {right boundary character, |xmax_char| if unspecified}
 
1790
@!font_dir:integer; {font direction}
 
1791
@!vf:array[0..vf_size] of byte; {stored bytes for \.{VF} file}
 
1792
@!vf_ptr:0..vf_size; {first unused location in |vf|}
 
1793
@!vtitle_start:0..vf_size; {starting location of \.{VTITLE} string}
 
1794
@!vtitle_length:byte; {length of \.{VTITLE} string}
 
1795
@!packet_start:array[char_type] of 0..vf_size;
 
1796
  {beginning location of character packet}
 
1797
@!packet_length:array[char_type] of integer; {length of character packet}
 
1798
@!font_ptr:xfont_type; {number of distinct local fonts seen}
 
1799
@!cur_font:xfont_type; {number of the current local font}
 
1800
@!fname_start:array[font_type] of 0..vf_size; {beginning of local font name}
 
1801
@!fname_length:array[font_type] of byte; {length of local font name}
 
1802
@!farea_start:array[font_type] of 0..vf_size; {beginning of local font area}
 
1803
@!farea_length:array[font_type] of byte; {length of local font area}
 
1804
@!font_checksum:array[font_type] of four_bytes; {local font checksum}
 
1805
@!font_number:array[xfont_type] of integer; {local font id number}
 
1806
@!font_at:array[font_type] of fix_word; {local font ``at size''}
 
1807
@!font_dsize:array[font_type] of fix_word; {local font design size}
 
1808
 
 
1809
@ @<Types...@>=
 
1810
@!char_type=0..max_char;
 
1811
@!xchar_type=0..xmax_char;
 
1812
@!xxchar_type=0..xxmax_char;
 
1813
@!font_type=0..max_font;
 
1814
@!xfont_type=0..xmax_font;
 
1815
@!header_index=0..max_header_bytes;
 
1816
@!indx=xxchar_type;
 
1817
 
 
1818
@ @<Local...@>=
 
1819
@!d:header_index; {an index into |header_bytes|}
 
1820
 
 
1821
@ We start by setting up the default values.
 
1822
 
 
1823
@d check_sum_loc=0
 
1824
@d design_size_loc=4
 
1825
@d coding_scheme_loc=8
 
1826
@d family_loc=coding_scheme_loc+40
 
1827
@d seven_flag_loc=family_loc+20
 
1828
@d face_loc=seven_flag_loc+3
 
1829
 
 
1830
@<Set init...@>=
 
1831
for d:=0 to 18*4-1 do header_bytes[d]:=0;
 
1832
header_bytes[8]:=11; header_bytes[9]:="U";
 
1833
header_bytes[10]:="N";
 
1834
header_bytes[11]:="S";
 
1835
header_bytes[12]:="P";
 
1836
header_bytes[13]:="E";
 
1837
header_bytes[14]:="C";
 
1838
header_bytes[15]:="I";
 
1839
header_bytes[16]:="F";
 
1840
header_bytes[17]:="I";
 
1841
header_bytes[18]:="E";
 
1842
header_bytes[19]:="D";
 
1843
@.UNSPECIFIED@>
 
1844
for d:=family_loc to family_loc+11 do header_bytes[d]:=header_bytes[d-40];
 
1845
design_size:=10*unity; design_units:=unity; frozen_du:=false;
 
1846
seven_bit_safe_flag:=false;@/
 
1847
header_ptr:=18*4; nl:=0; min_nl:=0; nk:=0; ne:=0; np:=0;@/
 
1848
check_sum_specified:=false; bchar:=xmax_char;@/
 
1849
font_dir:=0;
 
1850
vf_ptr:=0; vtitle_start:=0; vtitle_length:=0; font_ptr:=0;
 
1851
for k:=0 to max_char do packet_start[k]:=vf_size;
 
1852
for k:=0 to 127 do packet_length[k]:=1;
 
1853
for k:=128 to 255 do packet_length[k]:=2;
 
1854
for k:=256 to max_char do packet_length[k]:=3;
 
1855
 
 
1856
@ Most of the dimensions, however, go into the |memory| array. There are
 
1857
at most |max_char+2| widths, |max_char+2| heights,
 
1858
|max_char+2| depths, and |max_char+2| italic corrections,
 
1859
since the value 0 is required but it need not be used. So |memory| has room
 
1860
for |4*max_char+8| entries, each of which is a |fix_word|. An auxiliary table called
 
1861
|link| is used to link these words together in linear lists, so that
 
1862
sorting and other operations can be done conveniently.
 
1863
 
 
1864
We also add four ``list head'' words to the |memory| and |link| arrays;
 
1865
these are in locations |width| through |italic|, i.e., 1 through 4.
 
1866
For example, |link[height]| points to the smallest element in
 
1867
the sorted list of distinct heights that have appeared so far, and
 
1868
|memory[height]| is the number of distinct heights.
 
1869
 
 
1870
@<Types...@>=
 
1871
@!pointer=0..mem_size; {an index into memory}
 
1872
 
 
1873
@ The arrays |char_wd|, |char_ht|, |char_dp|, and |char_ic| contain
 
1874
pointers to the |memory| array entries where the corresponding dimensions
 
1875
appear. Two other arrays, |char_tag| and |char_remainder|, hold
 
1876
the other information that \.{TFM} files pack into a |char_info_word|.
 
1877
 
 
1878
@d no_tag=0 {vanilla character}
 
1879
@d lig_tag=1 {character has a ligature/kerning program}
 
1880
@d list_tag=2 {character has a successor in a charlist}
 
1881
@d ext_tag=3 {character is extensible}
 
1882
@d bchar_label==char_remainder[xmax_char]
 
1883
  {beginning of ligature program for left boundary}
 
1884
 
 
1885
@<Glob...@>=
 
1886
@!memory:array[pointer] of fix_word; {character dimensions and kerns}
 
1887
@!mem_ptr:pointer; {largest |memory| word in use}
 
1888
@!link:array[pointer] of pointer; {to make lists of |memory| items}
 
1889
@!char_wd:array[char_type] of pointer; {pointers to the widths}
 
1890
@!char_ht:array[char_type] of pointer; {pointers to the heights}
 
1891
@!char_dp:array[char_type] of pointer; {pointers to the depths}
 
1892
@!char_ic:array[char_type] of pointer; {pointers to italic corrections}
 
1893
@!char_tag:array[char_type] of no_tag..ext_tag; {character tags}
 
1894
@!char_remainder:array[xchar_type] of xchar_type;
 
1895
   {pointers to ligature labels,
 
1896
    next larger characters, or extensible characters}
 
1897
@!top_width,@!top_height,@!top_depth,@!top_italic:integer;
 
1898
 
 
1899
@ @<Local...@>=
 
1900
@!c:integer; {runs through all character codes}
 
1901
 
 
1902
@ @<Set init...@>=
 
1903
bchar_label:=xmax_label;
 
1904
for c:=0 to max_char do begin
 
1905
  char_wd[c]:=0; char_ht[c]:=0; char_dp[c]:=0; char_ic[c]:=0;@/
 
1906
  char_tag[c]:=no_tag; char_remainder[c]:=0;
 
1907
  end;
 
1908
memory[0]:=@'17777777777; {an ``infinite'' element at the end of the lists}
 
1909
memory[width]:=0; link[width]:=0; {width list is empty}
 
1910
memory[height]:=0; link[height]:=0; {height list is empty}
 
1911
memory[depth]:=0; link[depth]:=0; {depth list is empty}
 
1912
memory[italic]:=0; link[italic]:=0; {italic list is empty}
 
1913
mem_ptr:=italic;
 
1914
 
 
1915
@ As an example of these data structures, let us consider the simple
 
1916
routine that inserts a potentially new element into one of the dimension
 
1917
lists. The first parameter indicates the list head (i.e., |h=width| for
 
1918
the width list, etc.); the second parameter is the value that is to be
 
1919
inserted into the list if it is not already present.  The procedure
 
1920
returns the value of the location where the dimension appears in |memory|.
 
1921
The fact that |memory[0]| is larger than any legal dimension makes the
 
1922
algorithm particularly short.
 
1923
 
 
1924
We do have to handle two somewhat subtle situations. A width of zero must be
 
1925
put into the list, so that a zero-width character in the font will not appear
 
1926
to be nonexistent (i.e., so that its |char_wd| index will not be zero), but
 
1927
this does not need to be done for heights, depths, or italic corrections.
 
1928
Furthermore, it is necessary to test for memory overflow even though we
 
1929
have provided room for the maximum number of different dimensions in any
 
1930
legal font, since the \.{VPL} file might foolishly give any number of
 
1931
different sizes to the same character.
 
1932
 
 
1933
@p function sort_in(@!h:pointer;@!d:fix_word):pointer; {inserts into list}
 
1934
var p:pointer; {the current node of interest}
 
1935
begin if (d=0)and(h<>width) then sort_in:=0
 
1936
else begin p:=h;
 
1937
  while d>=memory[link[p]] do p:=link[p];
 
1938
  if (d=memory[p])and(p<>h) then sort_in:=p
 
1939
  else if mem_ptr=mem_size then begin
 
1940
    err_print('Memory overflow: too many widths, etc');
 
1941
@.Memory overflow...@>
 
1942
    print_ln('Congratulations! It''s hard to make this error.');
 
1943
    sort_in:=p;
 
1944
    end
 
1945
  else begin
 
1946
    incr(mem_ptr); memory[mem_ptr]:=d;
 
1947
    link[mem_ptr]:=link[p]; link[p]:=mem_ptr; incr(memory[h]);
 
1948
    sort_in:=mem_ptr;
 
1949
    end;
 
1950
  end;
 
1951
end;
 
1952
 
 
1953
@ When these lists of dimensions are eventually written to the \.{OFM}
 
1954
file, we may have to do some rounding of values, because the \.{OFM} file
 
1955
allows at most 65536 widths, 256 heights, 256 depths, and 256 italic
 
1956
corrections. The following procedure takes a given list head |h| and a
 
1957
given dimension |d|, and returns the minimum $m$ such that the elements
 
1958
of the list can be covered by $m$ intervals of width $d$.  It also sets
 
1959
|next_d| to the smallest value $d^\prime>d$ such that the covering found
 
1960
by this procedure would be different.  In particular, if $d=0$ it computes
 
1961
the number of elements of the list, and sets |next_d| to the smallest
 
1962
distance between two list elements. (The covering by intervals of width
 
1963
|next_d| is not guaranteed to have fewer than $m$ elements, but in
 
1964
practice this seems to happen most of the time.)
 
1965
 
 
1966
@<Glob...@>=
 
1967
@!next_d:fix_word; {the next larger interval that is worth trying}
 
1968
 
 
1969
@ Once again we can make good use of the fact that |memory[0]| is ``infinite.''
 
1970
 
 
1971
@p function min_cover(@!h:pointer;@!d:fix_word):integer;
 
1972
var p:pointer; {the current node of interest}
 
1973
@!l:fix_word; {the least element covered by the current interval}
 
1974
@!m:integer; {the current size of the cover being generated}
 
1975
begin m:=0; p:=link[h]; next_d:=memory[0];
 
1976
while p<>0 do begin
 
1977
  incr(m); l:=memory[p];
 
1978
  while memory[link[p]]<=l+d do p:=link[p];
 
1979
  p:=link[p];
 
1980
  if memory[p]-l<next_d then next_d:=memory[p]-l;
 
1981
  end;
 
1982
min_cover:=m;
 
1983
end;
 
1984
 
 
1985
@ The following procedure uses |min_cover| to determine the smallest $d$
 
1986
such that a given list can be covered with at most a given number of
 
1987
intervals.
 
1988
 
 
1989
@p function shorten(@!h:pointer;m:integer):fix_word; {finds best way to round}
 
1990
var d:fix_word; {the current trial interval length}
 
1991
@!k:integer; {the size of a minimum cover}
 
1992
begin if memory[h]>m then begin
 
1993
  excess:=memory[h]-m;
 
1994
  k:=min_cover(h,0); d:=next_d; {now the answer is at least |d|}
 
1995
  repeat d:=d+d; k:=min_cover(h,d);
 
1996
  until k<=m; {first we ascend rapidly until finding the range}
 
1997
  d:=d div 2; k:=min_cover(h,d); {now we run through the feasible steps}
 
1998
  while k>m do begin
 
1999
    d:=next_d; k:=min_cover(h,d);
 
2000
    end;
 
2001
  shorten:=d;
 
2002
  end
 
2003
else shorten:=0;
 
2004
end;
 
2005
 
 
2006
@ When we are nearly ready to output the \.{TFM} file, we will set
 
2007
|index[p]:=k| if the dimension in |memory[p]| is being rounded to the
 
2008
|k|th element of its list.
 
2009
 
 
2010
@<Glob...@>=
 
2011
@!index:array[pointer] of byte;
 
2012
@!excess:byte; {number of words to remove, if list is being shortened}
 
2013
 
 
2014
@ Here is the procedure that sets the |index| values. It also shortens
 
2015
the list so that there is only one element per covering interval;
 
2016
the remaining elements are the midpoints of their clusters.
 
2017
 
 
2018
@p procedure set_indices(@!h:pointer;@!d:fix_word); {reduces and indexes a list}
 
2019
var p:pointer; {the current node of interest}
 
2020
@!q:pointer; {trails one step behind |p|}
 
2021
@!m:byte; {index number of nodes in the current interval}
 
2022
@!l:fix_word; {least value in the current interval}
 
2023
begin q:=h; p:=link[q]; m:=0;
 
2024
while p<>0 do begin
 
2025
  incr(m); l:=memory[p]; index[p]:=m;
 
2026
  while memory[link[p]]<=l+d do begin
 
2027
    p:=link[p]; index[p]:=m; decr(excess);
 
2028
    if excess=0 then d:=0;
 
2029
    end;
 
2030
  link[q]:=p; memory[p]:=l+(memory[p]-l) div 2; q:=p; p:=link[p];
 
2031
  end;
 
2032
memory[h]:=m;
 
2033
end;
 
2034
 
 
2035
@* The input phase.
 
2036
We're ready now to read and parse the \.{VPL} file, storing property
 
2037
values as we go.
 
2038
 
 
2039
@<Glob...@>=
 
2040
@!c:integer; {the current character or byte being processed}
 
2041
@!cprime:char_type; {Processing for several characters together}
 
2042
@!crange:char_type; {ditto}
 
2043
@!x:fix_word; {current dimension of interest}
 
2044
@!k:integer; {general-purpose index}
 
2045
 
 
2046
@ @<Read all the input@>=
 
2047
cur_char:=" ";
 
2048
repeat while cur_char=" " do get_next;
 
2049
if cur_char="(" then @<Read a font property value@>
 
2050
else if (cur_char=")")and not input_has_ended then begin
 
2051
  err_print('Extra right parenthesis');
 
2052
  incr(loc); cur_char:=" ";
 
2053
  end
 
2054
@.Extra right parenthesis@>
 
2055
else if not input_has_ended then junk_error;
 
2056
until input_has_ended
 
2057
 
 
2058
@ The |junk_error| routine just referred to is called when something
 
2059
appears in the forbidden area between properties of a property list.
 
2060
 
 
2061
@p procedure junk_error; {gets past no man's land}
 
2062
begin err_print('There''s junk here that is not in parentheses');
 
2063
@.There's junk here...@>
 
2064
skip_to_paren;
 
2065
end;
 
2066
 
 
2067
@ For each font property, we are supposed to read the data from the
 
2068
left parenthesis that is the current value of |cur_char| to the right
 
2069
parenthesis that matches it in the input. The main complication is
 
2070
to recover with reasonable grace from various error conditions that
 
2071
might arise.
 
2072
 
 
2073
@<Read a font property value@>=
 
2074
begin get_name;
 
2075
if cur_code=comment_code then skip_to_end_of_item
 
2076
else if (cur_code<110) and (cur_code>character_code) then
 
2077
  flush_error('This property name doesn''t belong on the outer level')
 
2078
else if (cur_code>=110) and ((cur_code mod 10)<>0) then
 
2079
  flush_error('This property name doesn''t belong on the outer level')
 
2080
@.This property name doesn't belong...@>
 
2081
else begin
 
2082
  @<Read the font property value specified by |cur_code|@>;
 
2083
  finish_the_property;
 
2084
  end;
 
2085
end
 
2086
 
 
2087
@ @<Read the font property value spec...@>=
 
2088
case cur_code of
 
2089
check_sum_code: begin check_sum_specified:=true; read_four_bytes(check_sum_loc);
 
2090
  end;
 
2091
design_size_code: @<Read the design size@>;
 
2092
design_units_code: @<Read the design units@>;
 
2093
coding_scheme_code: read_BCPL(coding_scheme_loc,40);
 
2094
family_code: read_BCPL(family_loc,20);
 
2095
face_code: begin c:=get_byte; if c>255 then begin
 
2096
  err_print('FACE clipped to 255'); c:=255 end;
 
2097
  header_bytes[face_loc]:=c
 
2098
  end;
 
2099
seven_bit_safe_flag_code: @<Read the seven-bit-safe flag@>;
 
2100
header_code: @<Read an indexed header word@>;
 
2101
font_dimen_code: @<Read font parameter list@>;
 
2102
lig_table_code: read_lig_kern;
 
2103
boundary_char_code: bchar:=get_byte;
 
2104
virtual_title_code: begin vtitle_start:=vf_ptr; copy_to_end_of_item;
 
2105
  if vf_ptr>vtitle_start+255 then begin
 
2106
    err_print('VTITLE clipped to 255 characters'); vtitle_length:=255;
 
2107
@.VTITLE clipped...@>
 
2108
    end
 
2109
  else vtitle_length:=vf_ptr-vtitle_start;
 
2110
  end;
 
2111
map_font_code:@<Read a local font list@>;
 
2112
character_code: read_char_info;
 
2113
ofm_level_code:    @<Read OFM level code@>;
 
2114
font_dir_code:     @<Read font direction code@>;
 
2115
n_font_dir_code:   @<Read natural font direction code@>;
 
2116
char_repeat_code:  read_repeated_character_info;
 
2117
font_rule_code:    read_font_rule_list;
 
2118
font_glue_code:    read_font_glue_list;
 
2119
font_penalty_code: read_font_penalty_list;
 
2120
font_mvalue_code:  read_font_mvalue_list;
 
2121
font_fvalue_code:  read_font_fvalue_list;
 
2122
font_ivalue_code:  read_font_ivalue_list;
 
2123
end
 
2124
 
 
2125
@ The |case| statement just given makes use of three subroutines that we
 
2126
haven't defined yet. The first of these puts a 32-bit octal quantity
 
2127
into four specified bytes of the header block.
 
2128
 
 
2129
@p procedure read_four_bytes(l:header_index);
 
2130
begin get_four_bytes;
 
2131
header_bytes[l]:=c0;
 
2132
header_bytes[l+1]:=c1;
 
2133
header_bytes[l+2]:=c2;
 
2134
header_bytes[l+3]:=c3;
 
2135
end;
 
2136
 
 
2137
@ The second little procedure is used to scan a string and to store it in
 
2138
the ``{\mc BCPL} format'' required by \.{TFM} files. The string is supposed
 
2139
to contain at most |n| bytes, including the first byte (which holds the
 
2140
length of the rest of the string).
 
2141
 
 
2142
@p procedure read_BCPL(l:header_index;n:byte);
 
2143
var k:header_index;
 
2144
begin k:=l;
 
2145
while cur_char=" " do get_next;
 
2146
while (cur_char<>"(")and(cur_char<>")") do begin
 
2147
  if k<l+n then incr(k);
 
2148
  if k<l+n then header_bytes[k]:=cur_char;
 
2149
  get_next;
 
2150
  end;
 
2151
if k=l+n then begin
 
2152
  err_print('String is too long; its first ',n-1:1,
 
2153
@.String is too long...@>
 
2154
    ' characters will be kept'); decr(k);
 
2155
  end;
 
2156
header_bytes[l]:=k-l;
 
2157
while k<l+n-1 do begin {tidy up the remaining bytes by setting them to nulls}
 
2158
  incr(k); header_bytes[k]:=0;
 
2159
  end;
 
2160
end;
 
2161
 
 
2162
@ @<Read the design size@>=
 
2163
begin next_d:=get_fix;
 
2164
if next_d<unity then
 
2165
  err_print('The design size must be at least 1')
 
2166
@.The design size must...@>
 
2167
else design_size:=next_d;
 
2168
end
 
2169
 
 
2170
@ @<Read the design units@>=
 
2171
begin next_d:=get_fix;
 
2172
if next_d<=0 then
 
2173
  err_print('The number of units per design size must be positive')
 
2174
@.The number of units...@>
 
2175
else if frozen_du then
 
2176
  err_print('Sorry, it''s too late to change the design units')
 
2177
@.Sorry, it's too late...@>
 
2178
else design_units:=next_d;
 
2179
end
 
2180
 
 
2181
@ @<Read the seven-bit-safe...@>=
 
2182
begin while cur_char=" " do get_next;
 
2183
if cur_char="T" then seven_bit_safe_flag:=true
 
2184
else if cur_char="F" then seven_bit_safe_flag:=false
 
2185
else err_print('The flag value should be "TRUE" or "FALSE"');
 
2186
@.The flag value should be...@>
 
2187
skip_to_paren;
 
2188
end
 
2189
 
 
2190
@ @<Read an indexed header word@>=
 
2191
begin c:=get_byte;
 
2192
if c<18 then skip_error('HEADER indices should be 18 or more')
 
2193
@.HEADER indices...@>
 
2194
else if 4*c+4>max_header_bytes then
 
2195
  skip_error('This HEADER index is too big for my present table size')
 
2196
@.This HEADER index is too big...@>
 
2197
else begin
 
2198
  while header_ptr<4*c+4 do begin
 
2199
    header_bytes[header_ptr]:=0; incr(header_ptr);
 
2200
    end;
 
2201
  read_four_bytes(4*c);
 
2202
  end;
 
2203
end
 
2204
 
 
2205
@ The remaining kinds of font property values that need to be read are
 
2206
those that involve property lists on higher levels. Each of these has a
 
2207
loop similar to the one that was used at level zero. Then we put the
 
2208
right parenthesis back so that `|finish_the_property|' will be happy;
 
2209
there is probably a more elegant way to do this.
 
2210
 
 
2211
@d finish_inner_property_list==begin decr(loc); incr(level); cur_char:=")";
 
2212
  end
 
2213
 
 
2214
@<Read font parameter list@>=
 
2215
begin while level=1 do
 
2216
  begin while cur_char=" " do get_next;
 
2217
  if cur_char="(" then @<Read a parameter value@>
 
2218
  else if cur_char=")" then skip_to_end_of_item
 
2219
  else junk_error;
 
2220
  end;
 
2221
finish_inner_property_list;
 
2222
end
 
2223
 
 
2224
@ @<Read a parameter value@>=
 
2225
begin get_name;
 
2226
if cur_code=comment_code then skip_to_end_of_item
 
2227
else if (cur_code<parameter_code)or(cur_code>=char_wd_code) then
 
2228
  flush_error('This property name doesn''t belong in a FONTDIMEN list')
 
2229
@.This property name doesn't belong...@>
 
2230
else  begin if cur_code=parameter_code then c:=get_integer
 
2231
  else c:=cur_code-parameter_code;
 
2232
  if c=0 then flush_error('PARAMETER index must not be zero')
 
2233
@.PARAMETER index must not...@>
 
2234
  else if c>max_param_words then
 
2235
    flush_error('This PARAMETER index is too big for my present table size')
 
2236
@.This PARAMETER index is too big...@>
 
2237
  else begin
 
2238
    while np<c do begin
 
2239
      incr(np); param[np]:=0;
 
2240
      end;
 
2241
    param[c]:=get_fix;
 
2242
    finish_the_property;
 
2243
    end;
 
2244
  end;
 
2245
end
 
2246
 
 
2247
@ @<Read a local font list@>=
 
2248
begin font_number[font_ptr]:=get_integer; cur_font:=0;
 
2249
while font_number[font_ptr]<>font_number[cur_font] do incr(cur_font);
 
2250
if cur_font=font_ptr then {it's a new font number}
 
2251
  if font_ptr<xmax_font then @<Initialize a new local font@>
 
2252
  else err_print('Sorry, too many different mapfonts');
 
2253
@.Sorry, too many different mapfonts@>
 
2254
if cur_font=font_ptr then skip_to_end_of_item
 
2255
else while level=1 do begin
 
2256
  while cur_char=" " do get_next;
 
2257
  if cur_char="(" then @<Read a local font property@>
 
2258
  else if cur_char=")" then skip_to_end_of_item
 
2259
  else junk_error;
 
2260
  end;
 
2261
finish_inner_property_list;
 
2262
end
 
2263
 
 
2264
@ @<Initialize a new local font@>=
 
2265
begin incr(font_ptr);
 
2266
fname_start[cur_font]:=vf_size; fname_length[cur_font]:=4; {\.{NULL}}
 
2267
farea_start[cur_font]:=vf_size; farea_length[cur_font]:=0;
 
2268
font_checksum[cur_font]:=zero_bytes;
 
2269
font_at[cur_font]:=@'4000000; {denotes design size of this virtual font}
 
2270
font_dsize[cur_font]:=@'50000000; {the |fix_word| for 10}
 
2271
end
 
2272
 
 
2273
@ @<Read a local font property@>=
 
2274
begin get_name;
 
2275
if cur_code=comment_code then skip_to_end_of_item
 
2276
else if (cur_code<font_name_code)or(cur_code>font_dsize_code) then
 
2277
  flush_error('This property name doesn''t belong in a MAPFONT list')
 
2278
@.This property name doesn't belong...@>
 
2279
else begin
 
2280
  case cur_code of
 
2281
    font_name_code:@<Read a local font name@>;
 
2282
    font_area_code:@<Read a local font area@>;
 
2283
    font_checksum_code:begin
 
2284
      get_four_bytes; font_checksum[cur_font]:=cur_bytes;
 
2285
      end;
 
2286
    font_at_code: begin frozen_du:=true;
 
2287
      if design_units=unity then font_at[cur_font]:=get_fix
 
2288
      else font_at[cur_font]:=round((get_fix/design_units)*1048576.0);
 
2289
      end;
 
2290
    font_dsize_code:font_dsize[cur_font]:=get_fix;
 
2291
    end; {there are no other cases}
 
2292
  finish_the_property;
 
2293
  end;
 
2294
end
 
2295
 
 
2296
@ @<Read a local font name@>=
 
2297
begin fname_start[cur_font]:=vf_ptr; copy_to_end_of_item;
 
2298
if vf_ptr>fname_start[cur_font]+255 then begin
 
2299
  err_print('FONTNAME clipped to 255 characters');
 
2300
@.FONTNAME clipped...@>
 
2301
  fname_length[cur_font]:=255;
 
2302
  end
 
2303
else fname_length[cur_font]:=vf_ptr-fname_start[cur_font];
 
2304
end
 
2305
 
 
2306
@ @<Read a local font area@>=
 
2307
begin farea_start[cur_font]:=vf_ptr; copy_to_end_of_item;
 
2308
if vf_ptr>farea_start[cur_font]+255 then begin
 
2309
  err_print('FONTAREA clipped to 255 characters');
 
2310
@.FONTAREA clipped...@>
 
2311
  farea_length[cur_font]:=255;
 
2312
  end
 
2313
else farea_length[cur_font]:=vf_ptr-farea_start[cur_font];
 
2314
end
 
2315
 
 
2316
@ @<Read ligature/kern list@>=
 
2317
begin lk_step_ended:=false;
 
2318
while level=1 do
 
2319
  begin while cur_char=" " do get_next;
 
2320
  if cur_char="(" then read_lig_kern_command
 
2321
  else if cur_char=")" then skip_to_end_of_item
 
2322
  else junk_error;
 
2323
  end;
 
2324
finish_inner_property_list;
 
2325
end
 
2326
 
 
2327
@ @<Read a ligature/kern command@>=
 
2328
begin get_name;
 
2329
if cur_code=comment_code then skip_to_end_of_item
 
2330
else if (cur_code>=label_code) and (cur_code<=(lig_code+11)) then begin
 
2331
  case cur_code of
 
2332
    label_code:@<Read a label step@>;
 
2333
    stop_code:@<Read a stop step@>;
 
2334
    skip_code:@<Read a skip step@>;
 
2335
    krn_code:@<Read a kerning step@>;
 
2336
    lig_code,lig_code+1,lig_code+2,lig_code+3,lig_code+5,lig_code+6,
 
2337
      lig_code+7,lig_code+11:@<Read a ligature step@>;
 
2338
    end; {there are no other cases |>=label_code|}
 
2339
  finish_the_property;
 
2340
  end
 
2341
else if (cur_code>=clabel_code) and (cur_code<=cpenglue_code) then begin
 
2342
  case cur_code of
 
2343
    clabel_code:@<Read an extended label step@>;
 
2344
    cpen_code:@<Read an extended penalty step@>;
 
2345
    cglue_code:@<Read an extended glue step@>;
 
2346
    cpenglue_code:@<Read an extended penalty/glue step@>;
 
2347
    ckrn_code:@<Read an extended kern step@>;
 
2348
    end; {there are no other cases |>=label_code|}
 
2349
  finish_the_property;
 
2350
  end
 
2351
else flush_error('This property name doesn''t belong in a LIGTABLE list');
 
2352
@.This property name doesn't belong...@>
 
2353
end
 
2354
 
 
2355
@ When a character is about to be tagged, we call the following
 
2356
procedure so that an error message is given in case of multiple tags.
 
2357
 
 
2358
@p procedure check_tag(c:byte); {print error if |c| already tagged}
 
2359
begin case char_tag[c] of
 
2360
no_tag: do_nothing;
 
2361
lig_tag: err_print('This character already appeared in a LIGTABLE LABEL');
 
2362
@.This character already...@>
 
2363
list_tag: err_print('This character already has a NEXTLARGER spec');
 
2364
ext_tag: err_print('This character already has a VARCHAR spec');
 
2365
end;
 
2366
end;
 
2367
 
 
2368
@ @<Read a label step@>=
 
2369
begin while cur_char=" " do get_next;
 
2370
if cur_char="B" then begin
 
2371
  bchar_label:=nl; skip_to_paren; {\.{LABEL BOUNDARYCHAR}}
 
2372
  end
 
2373
else begin
 
2374
  backup; c:=get_byte;
 
2375
  check_tag(c); char_tag[c]:=lig_tag; char_remainder[c]:=nl;
 
2376
  end;
 
2377
if min_nl<=nl then min_nl:=nl+1;
 
2378
lk_step_ended:=false;
 
2379
end
 
2380
 
 
2381
@ @d stop_flag=128 {value indicating `\.{STOP}' in a lig/kern program}
 
2382
@d kern_flag=128 {op code for a kern step}
 
2383
 
 
2384
@<Globals...@>=
 
2385
@!lk_step_ended:boolean;
 
2386
  {was the last \.{LIGTABLE} property \.{LIG} or \.{KRN}?}
 
2387
@!krn_ptr:0..max_kerns; {an index into |kern|}
 
2388
 
 
2389
@ @<Read a stop step@>=
 
2390
if not lk_step_ended then
 
2391
  err_print('STOP must follow LIG or KRN')
 
2392
@.STOP must follow LIG or KRN@>
 
2393
else begin
 
2394
  lig_kern[nl-1].b0:=lig_kern[nl-1].b0 div 256 * 256 + stop_flag;
 
2395
  lk_step_ended:=false;
 
2396
  end
 
2397
 
 
2398
@ @<Read a skip step@>=
 
2399
if not lk_step_ended then
 
2400
  err_print('SKIP must follow LIG or KRN')
 
2401
@.SKIP must follow LIG or KRN@>
 
2402
else begin
 
2403
  c:=get_byte;
 
2404
  if c>=128 then err_print('Maximum SKIP amount is 127')
 
2405
@.Maximum SKIP amount...@>
 
2406
  else if nl+c>=max_lig_steps then
 
2407
    err_print('Sorry, LIGTABLE too long for me to handle')
 
2408
@.Sorry, LIGTABLE too long...@>
 
2409
  else begin
 
2410
    lig_kern[nl-1].b0:=c;
 
2411
    if min_nl<=nl+c then min_nl:=nl+c+1;
 
2412
    end;
 
2413
  lk_step_ended:=false;
 
2414
  end
 
2415
 
 
2416
@ @<Read a ligature step@>=
 
2417
begin lig_kern[nl].b0:=0;
 
2418
lig_kern[nl].b2:=cur_code-lig_code;
 
2419
lig_kern[nl].b1:=get_byte;
 
2420
lig_kern[nl].b3:=get_byte;
 
2421
if nl>=max_lig_steps-1 then
 
2422
  err_print('Sorry, LIGTABLE too long for me to handle')
 
2423
@.Sorry, LIGTABLE too long...@>
 
2424
else incr(nl);
 
2425
lk_step_ended:=true;
 
2426
end
 
2427
 
 
2428
@ @<Read a kerning step@>=
 
2429
begin lig_kern[nl].b0:=0; lig_kern[nl].b1:=get_byte;
 
2430
kern[nk]:=get_fix; krn_ptr:=0;
 
2431
while kern[krn_ptr]<>kern[nk] do incr(krn_ptr);
 
2432
if krn_ptr=nk then begin
 
2433
  if nk<max_kerns then incr(nk)
 
2434
  else begin
 
2435
    err_print('Sorry, too many different kerns for me to handle');
 
2436
@.Sorry, too many different kerns...@>
 
2437
    decr(krn_ptr);
 
2438
    end;
 
2439
  end;
 
2440
if ofm_level=-1 then begin 
 
2441
  lig_kern[nl].b2:=kern_flag+(krn_ptr div 256);
 
2442
  lig_kern[nl].b3:=krn_ptr mod 256;
 
2443
  end 
 
2444
else begin 
 
2445
  lig_kern[nl].b2:=kern_flag+(krn_ptr div 65536);
 
2446
  lig_kern[nl].b3:=krn_ptr mod 65536;
 
2447
  end;
 
2448
if nl>=max_lig_steps-1 then
 
2449
  err_print('Sorry, LIGTABLE too long for me to handle')
 
2450
@.Sorry, LIGTABLE too long...@>
 
2451
else incr(nl);
 
2452
lk_step_ended:=true;
 
2453
end
 
2454
 
 
2455
@ @<Global...@>=
 
2456
@!category_remainders:array[0..256] of integer;
 
2457
@!ivalue_category,@!max_ivalue_category:integer;
 
2458
@!glue_category,@!max_glue_category:integer;
 
2459
@!penalty_category,@!max_penalty_category:integer;
 
2460
 
 
2461
@ @<Set init...@>=
 
2462
for ivalue_category:=0 to 256 do begin
 
2463
  category_remainders[ivalue_category]:=-1;
 
2464
end;
 
2465
max_ivalue_category:=-1;
 
2466
max_glue_category:=-1;
 
2467
max_penalty_category:=-1;
 
2468
 
 
2469
@ @<Read an extended label step@>=
 
2470
begin
 
2471
c:=get_byte;
 
2472
category_remainders[c]:=nl;
 
2473
if max_ivalue_category<c then max_ivalue_category:=c;
 
2474
if min_nl<=nl then min_nl:=nl+1;
 
2475
lk_step_ended:=false;
 
2476
end
 
2477
 
 
2478
@ @<Read an extended penalty step@>=
 
2479
begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
 
2480
lig_kern[nl].b2:=17;
 
2481
penalty_category:=get_byte;
 
2482
if max_penalty_category<penalty_category then
 
2483
  max_penalty_category:=penalty_category;
 
2484
lig_kern[nl].b3:=penalty_category;
 
2485
if nl>=max_lig_steps-1 then
 
2486
  err_print('Sorry, LIGTABLE too long for me to handle')
 
2487
@.Sorry, LIGTABLE too long...@>
 
2488
else incr(nl);
 
2489
lk_step_ended:=true;
 
2490
end
 
2491
 
 
2492
@ @<Read an extended glue step@>=
 
2493
begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
 
2494
lig_kern[nl].b2:=18;
 
2495
glue_category:=get_byte;
 
2496
if max_glue_category<glue_category then
 
2497
  max_glue_category:=glue_category;
 
2498
lig_kern[nl].b3:=glue_category;
 
2499
if nl>=max_lig_steps-1 then
 
2500
  err_print('Sorry, LIGTABLE too long for me to handle')
 
2501
@.Sorry, LIGTABLE too long...@>
 
2502
else incr(nl);
 
2503
lk_step_ended:=true;
 
2504
end
 
2505
 
 
2506
@ @<Read an extended penalty/glue step@>=
 
2507
begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
 
2508
lig_kern[nl].b2:=19;
 
2509
penalty_category:=get_byte;
 
2510
if max_penalty_category<penalty_category then
 
2511
  max_penalty_category:=penalty_category;
 
2512
glue_category:=get_byte;
 
2513
if max_glue_category<glue_category then
 
2514
  max_glue_category:=glue_category;
 
2515
lig_kern[nl].b3:=penalty_category*256+glue_category;
 
2516
if nl>=max_lig_steps-1 then
 
2517
  err_print('Sorry, LIGTABLE too long for me to handle')
 
2518
@.Sorry, LIGTABLE too long...@>
 
2519
else incr(nl);
 
2520
lk_step_ended:=true;
 
2521
end
 
2522
 
 
2523
@ @<Read an extended kern step@>=
 
2524
begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
 
2525
lig_kern[nl].b2:=20;
 
2526
kern[nk]:=get_fix; krn_ptr:=0;
 
2527
while kern[krn_ptr]<>kern[nk] do incr(krn_ptr);
 
2528
if krn_ptr=nk then begin
 
2529
  if nk<max_kerns then incr(nk)
 
2530
  else begin
 
2531
    err_print('Sorry, too many different kerns for me to handle');
 
2532
@.Sorry, too many different kerns...@>
 
2533
    decr(krn_ptr);
 
2534
    end;
 
2535
  end;
 
2536
if krn_ptr>65535 then
 
2537
  err_print('Sorry, too many different kerns for me to handle');
 
2538
lig_kern[nl].b3:=krn_ptr;
 
2539
if nl>=max_lig_steps-1 then
 
2540
  err_print('Sorry, LIGTABLE too long for me to handle')
 
2541
@.Sorry, LIGTABLE too long...@>
 
2542
else incr(nl);
 
2543
lk_step_ended:=true;
 
2544
end
 
2545
 
 
2546
@ @<Globals...@>=
 
2547
@!char_extended_tag:array [char_type] of boolean;
 
2548
 
 
2549
@ @<Set init...@>=
 
2550
for c:=0 to max_char do
 
2551
  char_extended_tag[c]:=false;
 
2552
 
 
2553
@ @<Finish up the extended font stuff@>=
 
2554
begin
 
2555
if max_penalty_category>0 then begin
 
2556
  if nkp=0 then
 
2557
    err_print('No PENALTY table')
 
2558
  else if npp[0]<max_penalty_category then
 
2559
    err_print('Not enough PENALTY entries');
 
2560
  end;
 
2561
if max_glue_category>0 then begin
 
2562
  if nkg=0 then
 
2563
    err_print('No GLUE table')
 
2564
  else if npg[0]<max_glue_category then
 
2565
    err_print('Not enough GLUE entries');
 
2566
  end;
 
2567
if max_ivalue_category>0 then begin
 
2568
  if nki=0 then
 
2569
    err_print('No IVALUE table')
 
2570
  else if npi[0]<max_ivalue_category then
 
2571
    err_print('Not enough IVALUE entries')
 
2572
  else begin
 
2573
    for c:=0 to max_char do begin
 
2574
      if (char_wd[c]<>0) then begin
 
2575
        for j:=0 to max_ivalue_category do
 
2576
          if char_table[c,0]=j then begin
 
2577
            if category_remainders[j]<>-1 then begin
 
2578
              if char_tag[c]<>0 then
 
2579
                err_print('Character already has a tag')
 
2580
              else begin
 
2581
                char_extended_tag[c]:=true;
 
2582
                char_remainder[c]:=category_remainders[j];
 
2583
                end;
 
2584
              end;
 
2585
            end;
 
2586
        end;
 
2587
      end; 
 
2588
    end; 
 
2589
  end; 
 
2590
end
 
2591
 
 
2592
@ @<Global...@>=
 
2593
tables_read:boolean;
 
2594
 
 
2595
@ @<Set init...@>=
 
2596
tables_read:=false;
 
2597
 
 
2598
@ Finally we come to the part of \.{VPtoVF}'s input mechanism
 
2599
that is used most, the processing of individual character data.
 
2600
 
 
2601
@<Read character info list@>=
 
2602
begin
 
2603
if not tables_read then begin
 
2604
  @<Compute the new header information for OFM files@>;
 
2605
  tables_read:=true;   
 
2606
  end;
 
2607
c:=get_byte; {read the character code that is being specified}
 
2608
@<Print |c| in hex notation@>;
 
2609
while level=1 do begin
 
2610
  while cur_char=" " do get_next;
 
2611
  if cur_char="(" then read_character_property
 
2612
  else if cur_char=")" then skip_to_end_of_item
 
2613
  else junk_error;
 
2614
  end;
 
2615
if char_wd[c]=0 then char_wd[c]:=sort_in(width,0); {legitimatize |c|}
 
2616
finish_inner_property_list;
 
2617
end
 
2618
 
 
2619
@ @<Globals...@>=
 
2620
@!char_original:array [0..max_char] of integer;
 
2621
@!char_repeats:array [0..max_char] of integer;
 
2622
@!diff:boolean;
 
2623
@!needed_space,@!extra_bytes:integer;
 
2624
 
 
2625
@ @<Set init...@>=
 
2626
for ch_entry:=0 to max_char do begin
 
2627
  char_original[ch_entry]:=ch_entry;
 
2628
  char_repeats[ch_entry]:=0;
 
2629
  end;
 
2630
 
 
2631
@ @<Read repeated character info@>=
 
2632
begin
 
2633
if not tables_read then begin
 
2634
  compute_new_header_ofm;
 
2635
  tables_read:=true;
 
2636
  end;
 
2637
c:=get_byte; {read the character code that is being specified}
 
2638
@<Print |c| in hex notation@>;
 
2639
crange:=get_byte; {read how many characters are being defined}
 
2640
if (crange<0) then begin
 
2641
  err_print('Character ranges must be positive');
 
2642
  crange:=0;
 
2643
  end;
 
2644
if ((c+crange)>max_char) then begin
 
2645
  err_print('Character range too large');
 
2646
  crange:=0;
 
2647
  end;
 
2648
print('-'); print_hex(c+crange);
 
2649
while level=1 do begin
 
2650
  while cur_char=" " do get_next;
 
2651
  if cur_char="(" then read_character_property
 
2652
  else if cur_char=")" then skip_to_end_of_item
 
2653
  else junk_error;
 
2654
  end;
 
2655
if char_wd[c]=0 then char_wd[c]:=sort_in(width,0); {legitimatize |c|}
 
2656
finish_inner_property_list;
 
2657
cprime:=c;
 
2658
for c:=(cprime+1) to (cprime+crange) do begin
 
2659
  char_wd[c]:=char_wd[cprime];
 
2660
  char_ht[c]:=char_ht[cprime];
 
2661
  char_dp[c]:=char_dp[cprime];
 
2662
  char_ic[c]:=char_ic[cprime];
 
2663
  for tab:=0 to (nki+nkf+nkr+nkg+nkp-1) do begin
 
2664
    char_table[c,tab]:= char_table[cprime,tab];
 
2665
    end;
 
2666
  end;
 
2667
end
 
2668
 
 
2669
@ Tables for character parameters
 
2670
 
 
2671
@d char_param_tables==8
 
2672
 
 
2673
@<Globals...@>=
 
2674
@!char_table:array [0..max_char,0..char_param_tables] of integer;
 
2675
@!ch_table,@!ch_entry:integer;
 
2676
@!temp_value:integer;
 
2677
 
 
2678
@ @<Set init...@>=
 
2679
for c:=0 to max_char do
 
2680
  for ch_table:=0 to char_param_tables do
 
2681
    char_table[c,ch_table]:=0;
 
2682
 
 
2683
@ @<Read a character property@>=
 
2684
begin get_name;
 
2685
if cur_code=comment_code then skip_to_end_of_item
 
2686
else if (cur_code<char_wd_code) or
 
2687
        ((cur_code>var_char_code) and not
 
2688
         ((cur_code>=char_ivalue_code) and (cur_code<=char_penalty_code)))
 
2689
  then
 
2690
  flush_error('This property name doesn''t belong in a CHARACTER list')
 
2691
@.This property name doesn't belong...@>
 
2692
else begin
 
2693
  case cur_code of
 
2694
    char_wd_code:char_wd[c]:=sort_in(width,get_fix);
 
2695
    char_ht_code:char_ht[c]:=sort_in(height,get_fix);
 
2696
    char_dp_code:char_dp[c]:=sort_in(depth,get_fix);
 
2697
    char_ic_code:char_ic[c]:=sort_in(italic,get_fix);
 
2698
    sec_width_code:temp_value:=get_fix;
 
2699
    sec_height_code:temp_value:=get_fix;
 
2700
    sec_depth_code:temp_value:=get_fix;
 
2701
    sec_italic_code:temp_value:=get_fix;
 
2702
    accent_code:temp_value:=get_fix;
 
2703
    prim_top_axis_code:temp_value:=get_fix;
 
2704
    prim_top_axis_bis_code:temp_value:=get_fix;
 
2705
    prim_bot_axis_code:temp_value:=get_fix;
 
2706
    prim_bot_axis_bis_code:temp_value:=get_fix;
 
2707
    prim_mid_hor_code:temp_value:=get_fix;
 
2708
    prim_mid_vert_code:temp_value:=get_fix;
 
2709
    prim_base_slant_code:temp_value:=get_fix;
 
2710
    sec_top_axis_code:temp_value:=get_fix;
 
2711
    sec_top_axis_bis_code:temp_value:=get_fix;
 
2712
    sec_bot_axis_code:temp_value:=get_fix;
 
2713
    sec_bot_axis_bis_code:temp_value:=get_fix;
 
2714
    sec_mid_hor_code:temp_value:=get_fix;
 
2715
    sec_mid_vert_code:temp_value:=get_fix;
 
2716
    sec_base_slant_code:temp_value:=get_fix;
 
2717
    next_larger_code:begin check_tag(c); char_tag[c]:=list_tag;
 
2718
      char_remainder[c]:=get_byte;
 
2719
      end;
 
2720
    map_code:read_packet(c);
 
2721
    var_char_code:@<Read an extensible recipe for |c|@>;
 
2722
    char_ivalue_code: begin
 
2723
      ch_table:=get_integer;
 
2724
      ch_entry:=get_integer;
 
2725
      char_table[c,ch_table]:=ch_entry;
 
2726
      if ch_table>nkci then nkci:=ch_table;
 
2727
      end;
 
2728
    char_fvalue_code: begin
 
2729
      ch_table:=get_integer+nki;
 
2730
      ch_entry:=get_integer;
 
2731
      char_table[c,ch_table]:=ch_entry;
 
2732
      if ch_table>nkcf then nkcf:=ch_table;
 
2733
      end;
 
2734
    char_mvalue_code: begin
 
2735
      ch_table:=get_integer+nki+nkf;
 
2736
      ch_entry:=get_integer;
 
2737
      char_table[c,ch_table]:=ch_entry;
 
2738
      if ch_table>nkcm then nkcm:=ch_table;
 
2739
      end;
 
2740
    char_rule_code: begin
 
2741
      ch_table:=get_integer+nki+nkf+nkm;
 
2742
      ch_entry:=get_integer;
 
2743
      char_table[c,ch_table]:=ch_entry;
 
2744
      if ch_table>nkcr then nkcr:=ch_table;
 
2745
      end;
 
2746
    char_glue_code: begin
 
2747
      ch_table:=get_integer+nki+nkf+nkm+nkr;
 
2748
      ch_entry:=get_integer;
 
2749
      char_table[c,ch_table]:=ch_entry;
 
2750
      if ch_table>nkcg then nkcg:=ch_table;
 
2751
      end;
 
2752
    char_penalty_code: begin
 
2753
      ch_table:=get_integer+nki+nkf+nkm+nkr+nkg;
 
2754
      ch_entry:=get_integer;
 
2755
      char_table[c,ch_table]:=ch_entry;
 
2756
      if ch_table>nkcp then nkcp:=ch_table;
 
2757
      end;
 
2758
    end;@/
 
2759
  finish_the_property;
 
2760
  end;
 
2761
end
 
2762
 
 
2763
@ @<Read an extensible r...@>=
 
2764
begin if ne=xmax_char then
 
2765
  err_print('Sorry, too many VARCHAR specs')
 
2766
@.Sorry, too many VARCHAR specs@>
 
2767
else begin
 
2768
  check_tag(c); char_tag[c]:=ext_tag; char_remainder[c]:=ne;@/
 
2769
  exten[ne]:=zero_bytes;
 
2770
  while level=2 do begin
 
2771
    while cur_char=" " do get_next;
 
2772
    if cur_char="(" then @<Read an extensible piece@>
 
2773
    else if cur_char=")" then skip_to_end_of_item
 
2774
    else junk_error;
 
2775
    end;
 
2776
  incr(ne);
 
2777
  finish_inner_property_list;
 
2778
  end;
 
2779
end
 
2780
 
 
2781
@ @<Read an extensible p...@>=
 
2782
begin get_name;
 
2783
if cur_code=comment_code then skip_to_end_of_item
 
2784
else if (cur_code<var_char_code+1)or(cur_code>var_char_code+4) then
 
2785
  flush_error('This property name doesn''t belong in a VARCHAR list')
 
2786
@.This property name doesn't belong...@>
 
2787
else begin
 
2788
  case cur_code-(var_char_code+1) of
 
2789
    0:exten[ne].b0:=get_byte;
 
2790
    1:exten[ne].b1:=get_byte;
 
2791
    2:exten[ne].b2:=get_byte;
 
2792
    3:exten[ne].b3:=get_byte;
 
2793
    end;@/
 
2794
  finish_the_property;
 
2795
  end;
 
2796
end
 
2797
 
 
2798
@ The input routine is now complete except for the following code,
 
2799
which prints a progress report as the file is being read.
 
2800
 
 
2801
@ @<Glob...@>=
 
2802
@!HEX: packed array [1..32] of char;
 
2803
 
 
2804
@ @<Set init...@>=
 
2805
HEX:='0123456789ABCDEF';@/
 
2806
 
 
2807
@ The array |dig| will hold a sequence of digits to be output.
 
2808
 
 
2809
@<Glob...@>=
 
2810
@!dig:array[0..32] of integer;
 
2811
 
 
2812
@ Here, in fact, are two procedures that output
 
2813
|dig[j-1]|$\,\ldots\,$|dig[0]|, given $j>0$.
 
2814
 
 
2815
@p procedure out_digs(j:integer); {outputs |j| digits}
 
2816
begin repeat decr(j); out(HEX[1+dig[j]]);
 
2817
  until j=0;
 
2818
end;
 
2819
@#
 
2820
procedure print_digs(j:integer); {prints |j| digits}
 
2821
begin repeat decr(j); print(HEX[1+dig[j]]);
 
2822
  until j=0;
 
2823
end;
 
2824
 
 
2825
@ The |print_number| procedure indicates how |print_digs| can be used.
 
2826
This procedure can print in octal, decimal or hex notation.
 
2827
 
 
2828
@d print_hex(#)==print_number(#,16)
 
2829
@d print_octal(#)==print_number(#,8)
 
2830
@d print_decimal(#)==print_number(#,10)
 
2831
 
 
2832
@p procedure print_number(c:integer; form:integer); {prints value of
 
2833
|c|}
 
2834
var j:0..32; {index into |dig|}
 
2835
begin
 
2836
j:=0;
 
2837
if (c<0) then begin
 
2838
  print_ln('Internal error: print_number (negative value)');
 
2839
  c:=0;
 
2840
  end;
 
2841
if form=8 then
 
2842
  print('''') {an apostrophe indicates the octal notation}
 
2843
else if form=16 then
 
2844
  print('"')  { a double apostrophe indicates the hexadecimal
 
2845
notation}
 
2846
else if form<>10 then begin
 
2847
  print_ln('Internal error: print_number (form)');
 
2848
  form:=16;
 
2849
  end;
 
2850
while (c>0) or (j=0) do begin
 
2851
  dig[j]:=c mod form; c:=c div form;
 
2852
  j:=j+1;
 
2853
  end;
 
2854
print_digs(j);
 
2855
end;
 
2856
 
 
2857
@ @<Print |c| in hex...@>=
 
2858
begin if chars_on_line=8 then begin
 
2859
  print_ln(' '); chars_on_line:=1;
 
2860
  end
 
2861
else begin
 
2862
  if chars_on_line>0 then print(' ');
 
2863
  incr(chars_on_line);
 
2864
  end;
 
2865
print_hex(c); {progress report}
 
2866
end
 
2867
 
 
2868
 
 
2869
@* Assembling the mappings.
 
2870
Each \.{MAP} property is a sequence of \.{DVI} instructions, for which
 
2871
we need to know some of the opcodes.
 
2872
We add afterwards the definitions for outputting typesetting commands.
 
2873
 
 
2874
@d set_char_0=0 {\.{DVI} command to typeset character 0 and move right}
 
2875
@d set1=128 {typeset a character and move right}
 
2876
@d set_rule=132 {typeset a rule and move right}
 
2877
@d push=141 {save the current positions}
 
2878
@d pop=142 {restore previous positions}
 
2879
@d right1=143 {move right}
 
2880
@d w0=147 {move right by |w|}
 
2881
@d w1=148 {move right and set |w|}
 
2882
@d x0=152 {move right by |x|}
 
2883
@d x1=153 {move right and set |x|}
 
2884
@d down1=157 {move down}
 
2885
@d y0=161 {move down by |y|}
 
2886
@d y1=162 {move down and set |y|}
 
2887
@d z0=166 {move down by |z|}
 
2888
@d z1=167 {move down and set |z|}
 
2889
@d fnt_num_0=171 {set current font to 0}
 
2890
@d fnt1=235 {set current font}
 
2891
@d xxx1=239 {extension to \.{DVI} primitives}
 
2892
@d xxx4=242 {potentially long extension to \.{DVI} primitives}
 
2893
@d fnt_def1=243 {define the meaning of a font number}
 
2894
@d pre=247 {preamble}
 
2895
@d post=248 {postamble beginning}
 
2896
@d Incr_Decr(#) == #
 
2897
@d Incr(#) == #:=#+Incr_Decr {increase a variable}
 
2898
 
 
2899
@d out_four(#) ==
 
2900
if x>=0 then #(x div @"1000000)
 
2901
else  begin Incr(x)(@"40000000); Incr(x)(@"40000000);
 
2902
  #((x div @"1000000) + 128);
 
2903
  end;
 
2904
x:=x mod @"1000000; #(x div @"10000);
 
2905
x:=x mod @"10000; #(x div @"100);
 
2906
#(x mod @"100)
 
2907
 
 
2908
@d out_cmd(#) ==
 
2909
if (x<@"100)and(x>=0) then begin
 
2910
  if (o<>set1)or(x>127) then
 
2911
  if (o=fnt1)and(x<64) then Incr(x)(fnt_num_0) @+ else #(o);
 
2912
  end
 
2913
else begin
 
2914
  if (x<@"10000)and(x>=0) then #(o+1) @+ else  begin
 
2915
    if (x<@"1000000)and(x>=0) then #(o+2) @+ else begin
 
2916
      #(o+3);
 
2917
      if x>=0 then #(x div @"1000000)
 
2918
      else begin
 
2919
        Incr(x)(@"40000000); Incr(x)(@"40000000);
 
2920
        #((x div @"1000000) + 128); x:=x mod @"1000000;
 
2921
        end;
 
2922
      #(x div @"10000); x:=x mod @"10000;
 
2923
      end;
 
2924
    #(x div @"10000); x:=x mod @"10000;
 
2925
    end;
 
2926
  #(x div @"100); x:=x mod @"100;
 
2927
  end;
 
2928
#(x)
 
2929
 
 
2930
@p
 
2931
procedure vf_store_set(@!x:integer);
 
2932
var @!o:byte;
 
2933
begin o:=set1; out_cmd(vf_store);
 
2934
end;
 
2935
 
 
2936
procedure vfout_set(@!x:integer);
 
2937
var @!o:byte;
 
2938
begin o:=set1; out_cmd(vout);
 
2939
end;
 
2940
 
 
2941
procedure vf_store_fnt(@!x:integer);
 
2942
var @!o:byte;
 
2943
begin o:=fnt1; out_cmd(vf_store);
 
2944
end;
 
2945
 
 
2946
procedure vfout_fntdef(@!x:integer);
 
2947
var @!o:byte;
 
2948
begin o:=fnt_def1; out_cmd(vout);
 
2949
end;
 
2950
 
 
2951
procedure vfout_char(@!x:integer);
 
2952
begin out_four(vout);
 
2953
end;
 
2954
 
 
2955
 
 
2956
@ We keep stacks of movement values, in order to optimize the \.{DVI} code
 
2957
in simple cases.
 
2958
 
 
2959
@<Glob...@>=
 
2960
@!hstack:array[0..max_stack] of 0..2; {number of known horizontal movements}
 
2961
@!vstack:array[0..max_stack] of 0..2; {number of known vertical movements}
 
2962
@!wstack,@!xstack,@!ystack,@!zstack:array[0..max_stack] of fix_word;
 
2963
@!stack_ptr:0..max_stack;
 
2964
 
 
2965
@ The packet is built by straightforward assembly of \.{DVI} instructions.
 
2966
 
 
2967
@p @<Declare the |vf_fix| procedure@>@;@/
 
2968
procedure read_packet(@!c:byte);
 
2969
var @!cc:char_type; {character being typeset}
 
2970
@!x:fix_word; {movement}
 
2971
@!h,@!v:0..2; {top of |hstack| and |vstack|}
 
2972
@!special_start:0..vf_size; {location of |xxx1| command}
 
2973
@!k:0..vf_size; {loop index}
 
2974
begin packet_start[c]:=vf_ptr; stack_ptr:=0; h:=0; v:=0;
 
2975
cur_font:=0;
 
2976
while level=2 do begin
 
2977
  while cur_char=" " do get_next;
 
2978
  if cur_char="(" then @<Read and assemble a list of \.{DVI} commands@>
 
2979
  else if cur_char=")" then skip_to_end_of_item
 
2980
  else junk_error;
 
2981
  end;
 
2982
while stack_ptr>0 do begin
 
2983
  err_print('Missing POP supplied');
 
2984
@.Missing POP supplied@>
 
2985
  vf_store(pop); decr(stack_ptr);
 
2986
  end;
 
2987
packet_length[c]:=vf_ptr-packet_start[c];
 
2988
finish_inner_property_list;
 
2989
end;
 
2990
 
 
2991
@ @<Read and assemble a list of \.{DVI}...@>=
 
2992
begin get_name;
 
2993
if cur_code=comment_code then skip_to_end_of_item
 
2994
else if (cur_code<select_font_code)or(cur_code>special_hex_code) then
 
2995
  flush_error('This property name doesn''t belong in a MAP list')
 
2996
@.This property name doesn't belong...@>
 
2997
else begin
 
2998
  case cur_code of
 
2999
    select_font_code:@<Assemble a font selection@>;
 
3000
    set_char_code:@<Assemble a typesetting instruction@>;
 
3001
    set_rule_code:@<Assemble a rulesetting instruction@>;
 
3002
    move_right_code,move_right_code+1:@<Assemble a horizontal movement@>;
 
3003
    move_down_code,move_down_code+1:@<Assemble a vertical movement@>;
 
3004
    push_code:@<Assemble a stack push@>;
 
3005
    pop_code:@<Assemble a stack pop@>;
 
3006
    special_code,special_hex_code:@<Assemble a special command@>;
 
3007
    end;@/
 
3008
  finish_the_property;
 
3009
  end;
 
3010
end
 
3011
 
 
3012
@ @<Assemble a font selection@>=
 
3013
begin font_number[font_ptr]:=get_integer;
 
3014
cur_font:=0;
 
3015
while font_number[font_ptr]<>font_number[cur_font] do incr(cur_font);
 
3016
if cur_font=font_ptr then err_print('Undefined MAPFONT cannot be selected')
 
3017
@.Undefined MAPFONT...@>
 
3018
else vf_store_fnt(cur_font);
 
3019
end
 
3020
 
 
3021
@ @<Assemble a typesetting instruction@>=
 
3022
if cur_font=font_ptr then
 
3023
  err_print('Character cannot be typeset in undefined font')
 
3024
@.Character cannot be typeset...@>
 
3025
else begin
 
3026
  cc:=get_byte; vf_store_set(cc);
 
3027
  end
 
3028
 
 
3029
@ Here's a procedure that converts a |fix_word| to a sequence of
 
3030
\.{DVI} bytes.
 
3031
 
 
3032
@<Declare the |vf_fix|...@>=
 
3033
procedure vf_fix(@!opcode:byte;@!x:fix_word);
 
3034
var negative:boolean;
 
3035
@!k:0..4; {number of bytes to typeset}
 
3036
@!t:integer; {threshold}
 
3037
begin frozen_du:=true;
 
3038
if design_units<>unity then x:=round((x/design_units)*1048576.0);
 
3039
if x>0 then negative:=false
 
3040
else begin negative:=true; x:=-1-x;@+end;
 
3041
if opcode=0 then begin
 
3042
  k:=4; t:=@'100000000;@+end
 
3043
else begin
 
3044
  t:=127; k:=1;
 
3045
  while x>t do begin
 
3046
    t:=256*t+255; incr(k);
 
3047
    end;
 
3048
  vf_store(opcode+k-1); t:=t div 128 +1;
 
3049
  end;
 
3050
repeat if negative then begin
 
3051
  vf_store(255-(x div t)); negative:=false;
 
3052
  x:=(x div t)*t+t-1-x;
 
3053
  end
 
3054
else vf_store((x div t) mod 256);
 
3055
decr(k); t:=t div 256;
 
3056
until k=0;
 
3057
end;
 
3058
 
 
3059
@ @<Assemble a rulesetting instruction@>=
 
3060
begin vf_store(set_rule); vf_fix(0,get_fix); vf_fix(0,get_fix);
 
3061
end
 
3062
 
 
3063
@ @<Assemble a horizontal movement@>=
 
3064
begin if cur_code=move_right_code then x:=get_fix@+else x:=-get_fix;
 
3065
if h=0 then begin
 
3066
  wstack[stack_ptr]:=x; h:=1; vf_fix(w1,x);@+end
 
3067
else if x=wstack[stack_ptr] then vf_store(w0)
 
3068
else if h=1 then begin
 
3069
  xstack[stack_ptr]:=x; h:=2; vf_fix(x1,x);@+end
 
3070
else if x=xstack[stack_ptr] then vf_store(x0)
 
3071
else vf_fix(right1,x);
 
3072
end
 
3073
 
 
3074
@ @<Assemble a vertical movement@>=
 
3075
begin if cur_code=move_down_code then x:=get_fix@+else x:=-get_fix;
 
3076
if v=0 then begin
 
3077
  ystack[stack_ptr]:=x; v:=1; vf_fix(y1,x);@+end
 
3078
else if x=ystack[stack_ptr] then vf_store(y0)
 
3079
else if v=1 then begin
 
3080
  zstack[stack_ptr]:=x; v:=2; vf_fix(z1,x);@+end
 
3081
else if x=zstack[stack_ptr] then vf_store(z0)
 
3082
else vf_fix(down1,x);
 
3083
end
 
3084
 
 
3085
@ @<Assemble a stack push@>=
 
3086
if stack_ptr=max_stack then {too pushy}
 
3087
  err_print('Don''t push so much---stack is full!')
 
3088
@.Don't push so much...@>
 
3089
else begin
 
3090
  vf_store(push); hstack[stack_ptr]:=h; vstack[stack_ptr]:=v;
 
3091
  incr(stack_ptr); h:=0; v:=0;
 
3092
  end
 
3093
 
 
3094
@ @<Assemble a stack pop@>=
 
3095
if stack_ptr=0 then
 
3096
  err_print('Empty stack cannot be popped')
 
3097
@.Empty stack...@>
 
3098
else begin
 
3099
  vf_store(pop); decr(stack_ptr);
 
3100
  h:=hstack[stack_ptr]; v:=vstack[stack_ptr];
 
3101
  end
 
3102
 
 
3103
@ @<Assemble a special command@>=
 
3104
begin vf_store(xxx1); vf_store(0); {dummy length}
 
3105
special_start:=vf_ptr;
 
3106
if cur_code=special_code then copy_to_end_of_item
 
3107
else begin
 
3108
  repeat x:=get_hex;
 
3109
  if cur_char>")" then vf_store(x*16+get_hex);
 
3110
  until cur_char<=")";
 
3111
  end;
 
3112
if vf_ptr-special_start>255 then @<Convert |xxx1| command to |xxx4|@>
 
3113
else vf[special_start-1]:=vf_ptr-special_start;
 
3114
end
 
3115
 
 
3116
@ @<Convert |xxx1|...@>=
 
3117
if vf_ptr+3>vf_size then begin
 
3118
  err_print('Special command being clipped---no room left!');
 
3119
@.Special command being clipped...@>
 
3120
  vf_ptr:=special_start+255; vf[special_start-1]:=255;
 
3121
  end
 
3122
else begin
 
3123
  for k:=vf_ptr downto special_start do vf[k+3]:=vf[k];
 
3124
  x:=vf_ptr-special_start; vf_ptr:=vf_ptr+3;
 
3125
  vf[special_start-2]:=xxx4;
 
3126
  vf[special_start-1]:=x div @'100000000;
 
3127
  vf[special_start]:=(x div @'200000) mod 256;
 
3128
  vf[special_start+1]:=(x div @'400) mod 256;
 
3129
  vf[special_start+2]:=x mod 256;
 
3130
  end
 
3131
 
 
3132
@* The checking and massaging phase.
 
3133
Once the whole \.{VPL} file has been read in, we must check it for consistency
 
3134
and correct any errors. This process consists mainly of running through
 
3135
the characters that exist and seeing if they refer to characters that
 
3136
don't exist. We also compute the true value of |seven_unsafe|; we make sure
 
3137
that the charlists and ligature programs contain no loops; and we
 
3138
shorten the lists of widths, heights, depths, and italic corrections,
 
3139
if necessary, to keep from exceeding the required maximum sizes.
 
3140
 
 
3141
@<Glob...@>=
 
3142
@!seven_unsafe:boolean; {do seven-bit characters generate eight-bit ones?}
 
3143
 
 
3144
@ @<Correct and check the information@>=
 
3145
if nl>0 then @<Make sure the ligature/kerning program ends appropriately@>;
 
3146
seven_unsafe:=false;
 
3147
for c:=0 to max_char do if char_wd[c]<>0 then
 
3148
    @<For all characters |g| generated by |c|,
 
3149
    make sure that |char_wd[g]| is nonzero, and
 
3150
    set |seven_unsafe| if |c<128<=g|@>;
 
3151
if bchar_label<xmax_label then begin
 
3152
  c:=xmax_char; @<Check ligature program of |c|@>;
 
3153
  end;
 
3154
if seven_bit_safe_flag and seven_unsafe then
 
3155
  print_ln('The font is not really seven-bit-safe!');
 
3156
@.The font is not...safe@>
 
3157
@<Check for infinite ligature loops@>;
 
3158
@<Doublecheck the lig/kern commands and the extensible recipes@>;
 
3159
finish_extended_font;
 
3160
for c:=0 to max_char do
 
3161
  @<Make sure that |c| is not the largest element of a charlist cycle@>;
 
3162
@<Put the width, height, depth, and italic lists into final form@>
 
3163
 
 
3164
@ The checking that we need in several places is accomplished by three
 
3165
macros that are only slightly tricky.
 
3166
 
 
3167
@d existence_tail(#)==begin char_wd[g]:=sort_in(width,0);
 
3168
    print(#,' '); print_hex(c);
 
3169
    print_ln(' had no CHARACTER spec.');
 
3170
    end;
 
3171
  end
 
3172
@d check_existence_and_safety(#)==begin g:=#;
 
3173
  if (g>=128)and(c<128) then seven_unsafe:=true;
 
3174
  if char_wd[g]=0 then existence_tail
 
3175
@d check_existence(#)==begin g:=#;
 
3176
  if char_wd[g]=0 then existence_tail
 
3177
 
 
3178
@<For all characters |g| generated by |c|...@>=
 
3179
case char_tag[c] of
 
3180
no_tag: do_nothing;
 
3181
lig_tag: @<Check ligature program of |c|@>;
 
3182
list_tag: check_existence_and_safety(char_remainder[c])
 
3183
  ('The character NEXTLARGER than');
 
3184
@.The character NEXTLARGER...@>
 
3185
ext_tag:@<Check the pieces of |exten[c]|@>;
 
3186
end
 
3187
 
 
3188
@ @<Check the pieces...@>=
 
3189
begin if exten[char_remainder[c]].b0>0 then
 
3190
  check_existence_and_safety(exten[char_remainder[c]].b0)
 
3191
    ('TOP piece of character');
 
3192
@.TOP piece of character...@>
 
3193
if exten[char_remainder[c]].b1>0 then
 
3194
  check_existence_and_safety(exten[char_remainder[c]].b1)
 
3195
    ('MID piece of character');
 
3196
@.MID piece of character...@>
 
3197
if exten[char_remainder[c]].b2>0 then
 
3198
  check_existence_and_safety(exten[char_remainder[c]].b2)
 
3199
    ('BOT piece of character');
 
3200
@.BOT piece of character...@>
 
3201
check_existence_and_safety(exten[char_remainder[c]].b3)
 
3202
    ('REP piece of character');
 
3203
@.REP piece of character...@>
 
3204
end
 
3205
 
 
3206
@ @<Make sure that |c| is not the largest element of a charlist cycle@>=
 
3207
if char_tag[c]=list_tag then begin
 
3208
  g:=char_remainder[c];
 
3209
  while (g<c)and(char_tag[g]=list_tag) do g:=char_remainder[g];
 
3210
  if g=c then begin
 
3211
    char_tag[c]:=no_tag;
 
3212
    print('A cycle of NEXTLARGER characters has been broken at ');
 
3213
@.A cycle of NEXTLARGER...@>
 
3214
    print_hex(c); print_ln('.');
 
3215
    end;
 
3216
  end
 
3217
 
 
3218
@ @<Glob...@>=
 
3219
@!delta:fix_word; {size of the intervals needed for rounding}
 
3220
 
 
3221
@ @d round_message(#)==if delta>0 then print_ln('I had to round some ',
 
3222
@.I had to round...@>
 
3223
  #,'s by ',(((delta+1) div 2)/@'4000000):1:7,' units.')
 
3224
 
 
3225
@<Put the width, height, depth, and italic lists into final form@>=
 
3226
case ofm_level of
 
3227
  -1: begin
 
3228
    top_width:=255; top_depth:=15; top_height:=15; top_italic:=63;
 
3229
    end;
 
3230
  0: begin 
 
3231
    top_width:=65535; top_depth:=255; top_height:=255; top_italic:=255;
 
3232
    end;
 
3233
  1: begin
 
3234
    top_width:=65535; top_depth:=255; top_height:=255; top_italic:=255;
 
3235
    end;
 
3236
  end;
 
3237
delta:=shorten(width,max_width); set_indices(width,delta);
 
3238
  round_message('width');@/
 
3239
delta:=shorten(height,max_height); set_indices(height,delta);
 
3240
  round_message('height');@/
 
3241
delta:=shorten(depth,max_depth); set_indices(depth,delta);
 
3242
  round_message('depth');@/
 
3243
delta:=shorten(italic,max_italic); set_indices(italic,delta);
 
3244
  round_message('italic correction');
 
3245
 
 
3246
@ @d clear_lig_kern_entry== {make an unconditional \.{STOP}}
 
3247
  lig_kern[nl].b0:=255; lig_kern[nl].b1:=0;
 
3248
  lig_kern[nl].b2:=0; lig_kern[nl].b3:=0
 
3249
 
 
3250
@<Make sure the ligature/kerning program ends...@>=
 
3251
begin if bchar_label<xmax_label then begin {make room for it}
 
3252
  clear_lig_kern_entry; incr(nl);
 
3253
  end; {|bchar_label| will be stored later}
 
3254
while min_nl>nl do begin
 
3255
  clear_lig_kern_entry; incr(nl);
 
3256
  end;
 
3257
if (lig_kern[nl-1].b0 mod 256)=0 then
 
3258
   lig_kern[nl-1].b0:=lig_kern[nl-1].b0 div 256 * 256 + stop_flag;
 
3259
end
 
3260
 
 
3261
@ It's not trivial to check for infinite loops generated by repeated
 
3262
insertion of ligature characters. But fortunately there is a nice
 
3263
algorithm for such testing, copied here from the program \.{TFtoPL}
 
3264
where it is explained further.
 
3265
 
 
3266
@d simple=0 {$f(x,y)=z$}
 
3267
@d left_z=1 {$f(x,y)=f(z,y)$}
 
3268
@d right_z=2 {$f(x,y)=f(x,z)$}
 
3269
@d both_z=3 {$f(x,y)=f(f(x,z),y)$}
 
3270
@d pending=4 {$f(x,y)$ is being evaluated}
 
3271
 
 
3272
 
 
3273
@ @<Glo...@>=
 
3274
@!lig_ptr:0..max_lig_steps; {an index into |lig_kern|}
 
3275
@!hash:array[0..hash_size] of integer;
 
3276
@!class:array[0..hash_size] of simple..pending;
 
3277
@!lig_z:array[0..hash_size] of xxchar_type;
 
3278
@!hash_ptr:0..hash_size; {the number of nonzero entries in |hash|}
 
3279
@!hash_list:array[0..hash_size] of 0..hash_size; {list of those nonzero entries}
 
3280
@!h,@!hh:0..hash_size; {indices into the hash table}
 
3281
@!tt:indx; {temporary register}
 
3282
@!x_lig_cycle,@!y_lig_cycle:xchar_type; {problematic ligature pair}
 
3283
 
 
3284
@ @<Set init...@>=
 
3285
hash_ptr:=0; y_lig_cycle:=xmax_char;
 
3286
for k:=0 to hash_size do hash[k]:=0;
 
3287
 
 
3288
@ @d lig_exam==lig_kern[lig_ptr].b1
 
3289
@d lig_gen==lig_kern[lig_ptr].b3
 
3290
 
 
3291
@<Check lig...@>=
 
3292
begin lig_ptr:=char_remainder[c];
 
3293
repeat if hash_input(lig_ptr,c) then begin
 
3294
  if lig_kern[lig_ptr].b2<kern_flag then begin
 
3295
    if lig_exam<>bchar then
 
3296
      check_existence(lig_exam)('LIG character examined by');
 
3297
@.LIG character examined...@>
 
3298
    check_existence(lig_gen)('LIG character generated by');
 
3299
@.LIG character generated...@>
 
3300
    if lig_gen>=128 then if(c<128)or(c=bchar) then
 
3301
      if(lig_exam<128)or(lig_exam=bchar) then seven_unsafe:=true;
 
3302
    end
 
3303
  else if lig_exam<>bchar then
 
3304
    check_existence(lig_exam)('KRN character examined by');
 
3305
@.KRN character examined...@>
 
3306
  end;
 
3307
if (lig_kern[lig_ptr].b0 mod 256)>=stop_flag then lig_ptr:=nl
 
3308
else lig_ptr:=lig_ptr+1+lig_kern[lig_ptr].b0;
 
3309
until lig_ptr>=nl;
 
3310
end
 
3311
 
 
3312
@ The |hash_input| procedure is copied from \.{TFtoPL}, but it is made
 
3313
into a boolean function that returns |false| if the ligature command
 
3314
was masked by a previous one.
 
3315
 
 
3316
@p function hash_input(@!p,@!c:indx):boolean;
 
3317
 {enter data for character |c| and command in location |p|, unless it isn't new}
 
3318
label 30; {go here for a quick exit}
 
3319
var @!cc:simple..both_z; {class of data being entered}
 
3320
@!zz:char_type; {function value or ligature character being entered}
 
3321
@!y:char_type; {the character after the cursor}
 
3322
@!key:integer; {value to be stored in |hash|}
 
3323
@!t:integer; {temporary register for swapping}
 
3324
begin if hash_ptr=hash_size then
 
3325
  begin hash_input:=false; goto 30;@+end;
 
3326
@<Compute the command parameters |y|, |cc|, and |zz|@>;
 
3327
key:=xmax_char*c+y+1; h:=(hash_mult*(key mod hash_size)) mod hash_size;
 
3328
while hash[h]>0 do begin
 
3329
  if hash[h]<=key then begin
 
3330
    if hash[h]=key then begin
 
3331
      hash_input:=false; goto 30; {unused ligature command}
 
3332
      end;
 
3333
    t:=hash[h]; hash[h]:=key; key:=t; {do ordered-hash-table insertion}
 
3334
    t:=class[h]; class[h]:=cc; cc:=t; {namely, do a swap}
 
3335
    t:=lig_z[h]; lig_z[h]:=zz; zz:=t;
 
3336
    end;
 
3337
  if h>0 then decr(h)@+else h:=hash_size;
 
3338
  end;
 
3339
hash[h]:=key; class[h]:=cc; lig_z[h]:=zz;
 
3340
incr(hash_ptr); hash_list[hash_ptr]:=h;
 
3341
hash_input:=true;
 
3342
30:end;
 
3343
 
 
3344
@ @<Compute the command param...@>=
 
3345
y:=lig_kern[p].b1; t:=lig_kern[p].b2; cc:=simple;
 
3346
zz:=lig_kern[p].b3;
 
3347
if t>=kern_flag then zz:=y
 
3348
else begin
 
3349
  case t of
 
3350
    0,6:do_nothing; {\.{LIG},\.{/LIG>}}
 
3351
    5,11:zz:=y; {\.{LIG/>}, \.{/LIG/>>}}
 
3352
    1,7:cc:=left_z; {\.{LIG/}, \.{/LIG/>}}
 
3353
    2:cc:=right_z; {\.{/LIG}}
 
3354
    3:cc:=both_z; {\.{/LIG/}}
 
3355
    end; {there are no other cases}
 
3356
  end
 
3357
 
 
3358
@ (More good stuff from \.{TFtoPL}.)
 
3359
 
 
3360
@p function f(@!h,@!x,@!y:indx):indx; forward;@t\2@>
 
3361
  {compute $f$ for arguments known to be in |hash[h]|}
 
3362
function eval(@!x,@!y:indx):indx; {compute $f(x,y)$ with hashtable lookup}
 
3363
var @!key:integer; {value sought in hash table}
 
3364
begin key:=xmax_char*x+y+1; h:=(hash_mult*(key mod hash_size)) mod hash_size;
 
3365
while hash[h]>key do
 
3366
  if h>0 then decr(h)@+else h:=hash_size;
 
3367
if hash[h]<key then eval:=y {not in ordered hash table}
 
3368
else eval:=f(h,x,y);
 
3369
end;
 
3370
 
 
3371
@ Pascal's beastly convention for |forward| declarations prevents us from
 
3372
saying |function f(h,x,y:indx):indx| here.
 
3373
 
 
3374
@p function f;
 
3375
begin case class[h] of
 
3376
  simple: do_nothing;
 
3377
  left_z: begin class[h]:=pending; lig_z[h]:=eval(lig_z[h],y); class[h]:=simple;
 
3378
    end;
 
3379
  right_z: begin class[h]:=pending; lig_z[h]:=eval(x,lig_z[h]); class[h]:=simple;
 
3380
    end;
 
3381
  both_z: begin class[h]:=pending; lig_z[h]:=eval(eval(x,lig_z[h]),y);
 
3382
    class[h]:=simple;
 
3383
    end;
 
3384
  pending: begin x_lig_cycle:=x; y_lig_cycle:=y;
 
3385
    lig_z[h]:=xxmax_char; class[h]:=simple;
 
3386
    end; {the value |xxmax_char| will break all cycles, since it's not in |hash|}
 
3387
  end; {there are no other cases}
 
3388
f:=lig_z[h];
 
3389
end;
 
3390
 
 
3391
@ @<Check for infinite...@>=
 
3392
if hash_ptr<hash_size then for hh:=1 to hash_ptr do begin
 
3393
  tt:=hash_list[hh];
 
3394
  if class[tt]>simple then {make sure $f$ is well defined}
 
3395
  tt:=f(tt,(hash[tt]-1)div xmax_char,(hash[tt]-1)mod xmax_char);
 
3396
  end;
 
3397
if(hash_ptr=hash_size)or(y_lig_cycle<xmax_char) then begin
 
3398
  if hash_ptr<hash_size then begin
 
3399
    print('Infinite ligature loop starting with ');
 
3400
@.Infinite ligature loop...@>
 
3401
    if x_lig_cycle=xmax_char
 
3402
    then print('boundary')@+else print_hex(x_lig_cycle);
 
3403
    print(' and '); print_hex(y_lig_cycle); print_ln('!');
 
3404
    end
 
3405
  else print_ln('Sorry, I haven''t room for so many ligature/kern pairs!');
 
3406
@.Sorry, I haven't room...@>
 
3407
  print_ln('All ligatures will be cleared.');
 
3408
  for c:=0 to max_char do if char_tag[c]=lig_tag then begin
 
3409
    char_tag[c]:=no_tag; char_remainder[c]:=0;
 
3410
    end;
 
3411
  nl:=0; bchar:=xmax_char; bchar_label:=xmax_label;
 
3412
  end
 
3413
 
 
3414
@ The lig/kern program may still contain references to nonexistent characters,
 
3415
if parts of that program are never used. Similarly, there may be extensible
 
3416
characters that are never used, because they were overridden by
 
3417
\.{NEXTLARGER}, say. This would produce an invalid \.{TFM} file; so we
 
3418
must fix such errors.
 
3419
 
 
3420
@d double_check_tail(#)==@t\1@>if char_wd[0]=0
 
3421
      then char_wd[0]:=sort_in(width,0);
 
3422
    print('Unused ',#,' refers to nonexistent character ');
 
3423
    print_hex(c); print_ln('!');
 
3424
    end;
 
3425
  end
 
3426
@d double_check_lig(#)==begin c:=lig_kern[lig_ptr].#;
 
3427
  if char_wd[c]=0 then if c<>bchar then
 
3428
    begin lig_kern[lig_ptr].#:=0; double_check_tail
 
3429
@d double_check_ext(#)==begin c:=exten[g].#;
 
3430
  if c>0 then if char_wd[c]=0 then
 
3431
    begin exten[g].#:=0; double_check_tail
 
3432
@d double_check_rep(#)==begin c:=exten[g].#;
 
3433
  if char_wd[c]=0 then
 
3434
    begin exten[g].#:=0; double_check_tail
 
3435
 
 
3436
@<Doublecheck...@>=
 
3437
if nl>0 then for lig_ptr:=0 to nl-1 do
 
3438
  if (lig_kern[lig_ptr].b0 div 256)=0 then begin
 
3439
    if lig_kern[lig_ptr].b2<kern_flag then begin
 
3440
      if lig_kern[lig_ptr].b0<255 then begin
 
3441
        double_check_lig(b1)('LIG step'); double_check_lig(b3)('LIG step');
 
3442
        end;
 
3443
      end
 
3444
    else double_check_lig(b1)('KRN step');
 
3445
    end;
 
3446
@.Unused LIG step...@>
 
3447
@.Unused KRN step...@>
 
3448
if ne>0 then for g:=0 to ne-1 do begin
 
3449
  double_check_ext(b0)('VARCHAR TOP');
 
3450
  double_check_ext(b1)('VARCHAR MID');
 
3451
  double_check_ext(b2)('VARCHAR BOT');
 
3452
  double_check_rep(b3)('VARCHAR REP');
 
3453
@.Unused VARCHAR...@>
 
3454
  end
 
3455
 
 
3456
@* The TFM output phase.
 
3457
Now that we know how to get all of the font data correctly stored in
 
3458
\.{VPtoVF}'s memory, it only remains to write the answers out.
 
3459
 
 
3460
First of all, it is convenient to have an abbreviation for output to the
 
3461
\.{TFM} file:
 
3462
 
 
3463
@d out(#)==write(tfm_file,#)
 
3464
 
 
3465
@p procedure out_int(@!x:integer);
 
3466
begin out_four(out);
 
3467
end;
 
3468
 
 
3469
 
 
3470
@ The general plan for producing \.{TFM} files is long but simple:
 
3471
 
 
3472
@<Do the font metric output@>=
 
3473
compute_subfile_sizes;
 
3474
output_subfile_sizes;
 
3475
@<Output the header block@>;
 
3476
output_new_information_ofm;
 
3477
output_character_info;
 
3478
@<Output the dimensions themselves@>;
 
3479
@<Output the ligature/kern program@>;
 
3480
@<Output the extensible character recipes@>;
 
3481
@<Output the parameters@>
 
3482
 
 
3483
@ A \.{TFM} file begins with 12 numbers that tell how big its subfiles are.
 
3484
We already know most of these numbers; for example, the number of distinct
 
3485
widths is |memory[width]+1|, where the $+1$ accounts for the zero width that
 
3486
is always supposed to be present. But we still should compute the beginning
 
3487
and ending character codes (|bc| and |ec|), the number of header words (|lh|),
 
3488
and the total number of words in the \.{TFM} file (|lf|).
 
3489
 
 
3490
@<Gl...@>=
 
3491
@!bc:char_type; {the smallest character code in the font}
 
3492
@!ec:char_type; {the largest character code in the font}
 
3493
@!lh:char_type; {the number of words in the header block}
 
3494
@!lf:unsigned_integer; {the number of words in the entire \.{TFM} file}
 
3495
@!not_found:boolean; {has a font character been found?}
 
3496
@!temp_width:fix_word; {width being used to compute a check sum}
 
3497
@!ncw,@!nco,@!npc:integer;
 
3498
 
 
3499
@ It might turn out that no characters exist at all. But \.{VPtoVF} keeps
 
3500
going and writes the \.{TFM} anyway. In this case |ec| will be~0 and |bc|
 
3501
will be~1.
 
3502
 
 
3503
@<Compute the subfile sizes@>=
 
3504
case ofm_level of
 
3505
  -1: begin
 
3506
    lh:=header_ptr div 4;@/
 
3507
    not_found:=true; bc:=0;
 
3508
    while not_found do
 
3509
      if (char_wd[bc]>0)or(bc=255) then not_found:=false
 
3510
      else incr(bc);
 
3511
    not_found:=true; ec:=255;
 
3512
    while not_found do
 
3513
      if (char_wd[ec]>0)or(ec=0) then not_found:=false
 
3514
      else decr(ec);
 
3515
    if bc>ec then bc:=1;
 
3516
    incr(memory[width]); incr(memory[height]); incr(memory[depth]);
 
3517
    incr(memory[italic]);@/
 
3518
    @<Compute the ligature/kern program offset@>;
 
3519
    lf:=6+lh+(ec-bc+1)+memory[width]+memory[height]+memory[depth]+
 
3520
    memory[italic]+nl+lk_offset+nk+ne+np;
 
3521
    end;
 
3522
  0: begin
 
3523
    lh:=header_ptr div 4;@/
 
3524
    not_found:=true; bc:=0;
 
3525
    while not_found do
 
3526
      if (char_wd[bc]>0)or(bc=max_char) then not_found:=false
 
3527
      else incr(bc);
 
3528
    not_found:=true; ec:=max_char;
 
3529
    while not_found do
 
3530
      if (char_wd[ec]>0)or(ec=0) then not_found:=false
 
3531
      else decr(ec);
 
3532
    if bc>ec then bc:=1;
 
3533
    incr(memory[width]); incr(memory[height]); incr(memory[depth]);
 
3534
    incr(memory[italic]);@/
 
3535
    @<Compute the ligature/kern program offset@>;
 
3536
    lf:=14+lh+2*(ec-bc+1)+memory[width]+memory[height]+memory[depth]+
 
3537
    memory[italic]+2*nl+lk_offset+nk+2*ne+np;
 
3538
    end;
 
3539
  1: begin
 
3540
    lh:=header_ptr div 4;@/
 
3541
    not_found:=true; bc:=0;
 
3542
    while not_found do
 
3543
      if (char_wd[bc]>0)or(bc=max_char) then not_found:=false
 
3544
      else incr(bc);
 
3545
    not_found:=true; ec:=max_char;
 
3546
    while not_found do
 
3547
      if (char_wd[ec]>0)or(ec=0) then not_found:=false
 
3548
      else decr(ec);
 
3549
    if bc>ec then bc:=1;
 
3550
    incr(memory[width]); incr(memory[height]); incr(memory[depth]);
 
3551
    incr(memory[italic]);@/
 
3552
    @<Compute the ligature/kern program offset@>;
 
3553
    @<Compute the character info size@>;
 
3554
    lf:=29+lh+ncw+memory[width]+memory[height]+memory[depth]+
 
3555
    memory[italic]+2*(nl+lk_offset)+nk+2*ne+np+
 
3556
    nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
 
3557
    nco:=29+lh+nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
 
3558
    end;
 
3559
  end;
 
3560
 
 
3561
@ @d out_size(#)==out((#) div 256); out((#) mod 256)
 
3562
  @d out_integer(#)==out((#) div @"1000000);
 
3563
                     out(((#) mod @"1000000) div @"10000);
 
3564
                     out(((#) mod @"10000) div @"100);
 
3565
                     out((#) mod @"100)
 
3566
 
 
3567
@<Output the subfile sizes@>=
 
3568
case ofm_level of
 
3569
  -1: begin
 
3570
    out_size(lf); out_size(lh); out_size(bc); out_size(ec);
 
3571
    out_size(memory[width]); out_size(memory[height]);
 
3572
    out_size(memory[depth]); out_size(memory[italic]);
 
3573
    out_size(nl+lk_offset); out_size(nk); out_size(ne); out_size(np);
 
3574
    end;
 
3575
  0: begin
 
3576
    out_integer(0);
 
3577
    out_integer(lf); out_integer(lh); out_integer(bc); out_integer(ec);
 
3578
    out_integer(memory[width]); out_integer(memory[height]);
 
3579
    out_integer(memory[depth]); out_integer(memory[italic]);
 
3580
    out_integer(nl+lk_offset); out_integer(nk);
 
3581
    out_integer(ne); out_integer(np); out_integer(font_dir);
 
3582
    end;
 
3583
  1: begin
 
3584
    out_integer(1);
 
3585
    out_integer(lf); out_integer(lh);
 
3586
    out_integer(bc); out_integer(ec);
 
3587
    out_integer(memory[width]); out_integer(memory[height]);
 
3588
    out_integer(memory[depth]); out_integer(memory[italic]);
 
3589
    out_integer(nl+lk_offset); out_integer(nk);
 
3590
    out_integer(ne); out_integer(np); out_integer(font_dir);
 
3591
    out_integer(nco); out_integer(ncw); out_integer(npc);
 
3592
    out_integer(nki); out_integer(nwi); out_integer(nkf); out_integer(nwf);
 
3593
    out_integer(nkm); out_integer(nwm); out_integer(nkr); out_integer(nwr);
 
3594
    out_integer(nkg); out_integer(nwg); out_integer(nkp); out_integer(nwp);
 
3595
    end;
 
3596
  end;
 
3597
 
 
3598
@ The routines that follow need a few temporary variables of different types.
 
3599
 
 
3600
@<Gl...@>=
 
3601
@!j:0..max_header_bytes; {index into |header_bytes|}
 
3602
@!p:pointer; {index into |memory|}
 
3603
@!q:width..italic; {runs through the list heads for dimensions}
 
3604
@!par_ptr:0..max_param_words; {runs through the parameters}
 
3605
 
 
3606
@ The header block follows the subfile sizes. The necessary information all
 
3607
appears in |header_bytes|, except that the design size and the seven-bit-safe
 
3608
flag must still be set.
 
3609
 
 
3610
@<Output the header block@>=
 
3611
if not check_sum_specified then @<Compute the check sum@>;
 
3612
header_bytes[design_size_loc]:=design_size div @'100000000;
 
3613
  {this works since |design_size>0|}
 
3614
header_bytes[design_size_loc+1]:=(design_size div @'200000) mod 256;
 
3615
header_bytes[design_size_loc+2]:=(design_size div 256) mod 256;
 
3616
header_bytes[design_size_loc+3]:=design_size  mod 256;
 
3617
if not seven_unsafe then header_bytes[seven_flag_loc]:=128;
 
3618
for j:=0 to header_ptr-1 do out(header_bytes[j]);
 
3619
 
 
3620
@ @<Compute the check sum@>=
 
3621
begin c0:=bc; c1:=ec; c2:=bc; c3:=ec;
 
3622
for c:=bc to ec do if char_wd[c]>0 then begin
 
3623
  temp_width:=memory[char_wd[c]];
 
3624
  if design_units<>unity then
 
3625
    temp_width:=round((temp_width/design_units)*1048576.0);
 
3626
  temp_width:=temp_width + (c+4)*@'20000000; {this should be positive}
 
3627
  c0:=(c0+c0+temp_width) mod 255;
 
3628
  c1:=(c1+c1+temp_width) mod 253;
 
3629
  c2:=(c2+c2+temp_width) mod 251;
 
3630
  c3:=(c3+c3+temp_width) mod 247;
 
3631
  end;
 
3632
header_bytes[check_sum_loc]:=c0;
 
3633
header_bytes[check_sum_loc+1]:=c1;
 
3634
header_bytes[check_sum_loc+2]:=c2;
 
3635
header_bytes[check_sum_loc+3]:=c3;
 
3636
end
 
3637
 
 
3638
@ @<Global...@>=
 
3639
@!tab:integer;
 
3640
 
 
3641
@
 
3642
@<Compute the character info size@>=
 
3643
if ofm_level=1 then begin
 
3644
  ncw:=0;
 
3645
  if nkcp>-1 then
 
3646
    npc:=nki+nkf+nkr+nkg+nkcp+1
 
3647
  else if nkcg>-1 then
 
3648
    npc:=nki+nkf+nkr+nkcg+1
 
3649
  else if nkcr>-1 then
 
3650
    npc:=nki+nkf+nkcr+1
 
3651
  else if nkcf>-1 then
 
3652
    npc:=nki+nkcf+1
 
3653
  else if nkci>-1 then
 
3654
    npc:=nkci+1    
 
3655
  else   
 
3656
    npc:=0;
 
3657
  needed_space:=(12+npc*2) div 4;
 
3658
  extra_bytes:=(needed_space*4) - (10+npc*2);
 
3659
  for c:=bc to ec do begin
 
3660
    if char_original[c]=c then begin
 
3661
      cprime:=c+1;
 
3662
      diff:=false;
 
3663
      while (not diff) and (cprime<=ec) do begin
 
3664
        if index[char_wd[c]]<>index[char_wd[cprime]] then diff:=true;
 
3665
        if index[char_ht[c]]<>index[char_ht[cprime]] then diff:=true;
 
3666
        if index[char_dp[c]]<>index[char_dp[cprime]] then diff:=true;
 
3667
        if index[char_ic[c]]<>index[char_ic[cprime]] then diff:=true;
 
3668
        if char_remainder[c]<>char_remainder[cprime] then diff:=true;
 
3669
        for tab:=0 to npc-1 do begin
 
3670
          if char_table[c,tab]<>char_table[cprime,tab] then diff:=true;
 
3671
          end;
 
3672
        if not diff then begin
 
3673
          char_original[cprime]:=c;
 
3674
          cprime:=cprime+1;
 
3675
          end;
 
3676
        end;
 
3677
      if cprime>(c+1) then begin
 
3678
        char_repeats[c]:=cprime-c-1;
 
3679
        end;
 
3680
      ncw:=ncw+needed_space;
 
3681
      end;
 
3682
    end; 
 
3683
  end;
 
3684
 
 
3685
@ The next block contains packed |char_info|.
 
3686
 
 
3687
@d out_two(#)==out((#) div 256); out((#) mod 256)
 
3688
 
 
3689
@d out_three(#)==out((#) div 65536); out_two((#) mod 65536)
 
3690
 
 
3691
 
 
3692
@<Output the character info@>=
 
3693
index[0]:=0;
 
3694
for c:=bc to ec do
 
3695
case ofm_level of
 
3696
  -1: begin
 
3697
    out(index[char_wd[c]]);
 
3698
    out(index[char_ht[c]]*16+index[char_dp[c]]);
 
3699
    out(index[char_ic[c]]*4+char_tag[c]);
 
3700
    out(char_remainder[c]);
 
3701
    end;
 
3702
  0: begin
 
3703
    out(index[char_wd[c]] div 256); out(index[char_wd[c]] mod 256);
 
3704
    out(index[char_ht[c]]); out(index[char_dp[c]]);
 
3705
    out(index[char_ic[c]] div 64);out((index[char_ic[c]] mod 64)*4+char_tag[c]);
 
3706
    out(char_remainder[c] div 256); out(char_remainder[c] mod 256);
 
3707
    end;   
 
3708
  1: begin
 
3709
    if c=char_original[c] then begin
 
3710
      out(index[char_wd[c]] div 256); out(index[char_wd[c]] mod 256);
 
3711
      out(index[char_ht[c]]); out(index[char_dp[c]]);
 
3712
      out(index[char_ic[c]]);
 
3713
      tab:=char_tag[c];
 
3714
      if char_extended_tag[c] then begin
 
3715
        tab:=5;
 
3716
        end; 
 
3717
      out(tab);
 
3718
      out(char_remainder[c] div 256); out(char_remainder[c] mod 256);
 
3719
      out_size(char_repeats[c]);
 
3720
      for tab:=0 to npc-1 do begin
 
3721
        out(char_table[c,tab] div 256); out(char_table[c,tab] mod 256);
 
3722
        end; 
 
3723
      for tab:=1 to extra_bytes do begin
 
3724
        out(0);
 
3725
        end; 
 
3726
      end; 
 
3727
    end; 
 
3728
  end;
 
3729
 
 
3730
@ When a scaled quantity is output, we may need to divide it by |design_units|.
 
3731
The following subroutine takes care of this, using floating point arithmetic
 
3732
only if |design_units<>1.0|.
 
3733
 
 
3734
@p procedure out_scaled(x:fix_word); {outputs a scaled |fix_word|}
 
3735
var @!n:byte; {the first byte after the sign}
 
3736
@!m:0..65535; {the two least significant bytes}
 
3737
begin if abs(x/design_units)>=16.0 then begin
 
3738
  print_ln('The relative dimension ',x/@'4000000:1:3,
 
3739
    ' is too large.');
 
3740
@.The relative dimension...@>
 
3741
  print('  (Must be less than 16*designsize');
 
3742
  if design_units<>unity then print(' =',design_units/@'200000:1:3,
 
3743
      ' designunits');
 
3744
  print_ln(')'); x:=0;
 
3745
  end;
 
3746
if design_units<>unity then x:=round((x/design_units)*1048576.0);
 
3747
if x<0 then begin
 
3748
  out(255); x:=x+@'100000000;
 
3749
  if x<=0 then x:=1;
 
3750
  end
 
3751
else begin
 
3752
  out(0);
 
3753
  if x>=@'100000000 then x:=@'77777777;
 
3754
  end;
 
3755
n:=x div @'200000; m:=x mod @'200000;
 
3756
out(n); out(m div 256); out(m mod 256);
 
3757
end;
 
3758
 
 
3759
@ We have output the packed indices for individual characters.
 
3760
The scaled widths, heights, depths, and italic corrections are next.
 
3761
 
 
3762
@<Output the dimensions themselves@>=
 
3763
for q:=width to italic do begin
 
3764
  out(0); out(0); out(0); out(0); {output the zero word}
 
3765
  p:=link[q]; {head of list}
 
3766
  while p>0 do begin
 
3767
    out_scaled(memory[p]);
 
3768
    p:=link[p];
 
3769
    end;
 
3770
  end;
 
3771
 
 
3772
@ One embarrassing problem remains: The ligature/kern program might be very
 
3773
long, but the starting addresses in |char_remainder| can be at most~65535.
 
3774
Therefore we need to output some indirect address information; we want to
 
3775
compute |lk_offset| so that addition of |lk_offset| to all remainders makes
 
3776
all but |lk_offset| distinct remainders less than~65536.
 
3777
 
 
3778
For this we need a sorted table of all relevant remainders.
 
3779
 
 
3780
@<Glob...@>=
 
3781
@!label_table:array[xchar_type] of record
 
3782
  @!rr: -1..xmax_label; {sorted label values}
 
3783
  @!cc: char_type; {associated characters}
 
3784
  end;
 
3785
@!label_ptr:xchar_type; {index of highest entry in |label_table|}
 
3786
@!sort_ptr:xchar_type; {index into |label_table|}
 
3787
@!lk_offset:xchar_type; {smallest offset value that might work}
 
3788
@!t:0..xmax_label; {label value that is being redirected}
 
3789
@!extra_loc_needed:boolean; {do we need a special word for |bchar|?}
 
3790
 
 
3791
@ @<Compute the ligature/kern program offset@>=
 
3792
@<Insert all labels into |label_table|@>;
 
3793
if bchar<xmax_char then begin
 
3794
  extra_loc_needed:=true; lk_offset:=1;
 
3795
  end
 
3796
else begin
 
3797
  extra_loc_needed:=false; lk_offset:=0;
 
3798
  end;
 
3799
@<Find the minimum |lk_offset| and adjust all remainders@>;
 
3800
if bchar_label<xmax_label then begin
 
3801
  lig_kern[nl-1].b2:=(bchar_label+lk_offset)div 65536;
 
3802
  lig_kern[nl-1].b3:=(bchar_label+lk_offset)mod 65536;
 
3803
  end
 
3804
 
 
3805
@ @<Insert all labels...@>=
 
3806
label_ptr:=0; label_table[0].rr:=-1; {sentinel}
 
3807
for c:=bc to ec do if char_tag[c]=lig_tag then begin
 
3808
  sort_ptr:=label_ptr; {there's a hole at position |sort_ptr+1|}
 
3809
  while label_table[sort_ptr].rr>char_remainder[c] do begin
 
3810
    label_table[sort_ptr+1]:=label_table[sort_ptr];
 
3811
    decr(sort_ptr); {move the hole}
 
3812
    end;
 
3813
  label_table[sort_ptr+1].cc:=c;
 
3814
  label_table[sort_ptr+1].rr:=char_remainder[c];
 
3815
  incr(label_ptr);
 
3816
  end
 
3817
 
 
3818
@ @<Find the minimum |lk_offset| and adjust all remainders@>=
 
3819
begin sort_ptr:=label_ptr; {the largest unallocated label}
 
3820
if ofm_level=-1 then begin 
 
3821
  if label_table[sort_ptr].rr+lk_offset > 255 then begin
 
3822
    lk_offset:=0; extra_loc_needed:=false; {location 0 can do double duty}
 
3823
    repeat char_remainder[label_table[sort_ptr].cc]:=lk_offset;
 
3824
    while label_table[sort_ptr-1].rr=label_table[sort_ptr].rr do begin
 
3825
      decr(sort_ptr); char_remainder[label_table[sort_ptr].cc]:=lk_offset;
 
3826
      end;
 
3827
    incr(lk_offset); decr(sort_ptr);
 
3828
    until lk_offset+label_table[sort_ptr].rr<256;
 
3829
      {N.B.: |lk_offset=256| satisfies this when |sort_ptr=0|}
 
3830
    end;
 
3831
  end 
 
3832
else begin 
 
3833
  if label_table[sort_ptr].rr+lk_offset > 65535 then begin
 
3834
    lk_offset:=0; extra_loc_needed:=false; {location 0 can do double duty}
 
3835
    repeat char_remainder[label_table[sort_ptr].cc]:=lk_offset;
 
3836
    while label_table[sort_ptr-1].rr=label_table[sort_ptr].rr do begin
 
3837
      decr(sort_ptr); char_remainder[label_table[sort_ptr].cc]:=lk_offset;
 
3838
      end;
 
3839
    incr(lk_offset); decr(sort_ptr);
 
3840
    until lk_offset+label_table[sort_ptr].rr<65536;
 
3841
      {N.B.: |lk_offset=65536| satisfies this when |sort_ptr=0|}
 
3842
    end;
 
3843
  end;
 
3844
if lk_offset>0 then
 
3845
  while sort_ptr>0 do begin
 
3846
    char_remainder[label_table[sort_ptr].cc]:=
 
3847
    char_remainder[label_table[sort_ptr].cc]+lk_offset;
 
3848
    decr(sort_ptr);
 
3849
    end;
 
3850
end
 
3851
 
 
3852
@ @<Output the ligature/kern program@>=
 
3853
if ofm_level=-1 then begin
 
3854
  if extra_loc_needed then begin {|lk_offset=1|}
 
3855
    out(255); out(bchar); out(0); out(0);
 
3856
    end
 
3857
  else for sort_ptr:=1 to lk_offset do begin {output the redirection specs}
 
3858
    t:=label_table[label_ptr].rr;
 
3859
    if bchar<256 then begin
 
3860
      out(255); out(bchar);
 
3861
      end
 
3862
    else begin
 
3863
      out(254); out(0);
 
3864
      end;
 
3865
    out_size(t+lk_offset);
 
3866
    repeat decr(label_ptr); until label_table[label_ptr].rr<t;
 
3867
    end;
 
3868
  if nl>0 then for lig_ptr:=0 to nl-1 do begin
 
3869
    out(lig_kern[lig_ptr].b0);
 
3870
    out(lig_kern[lig_ptr].b1);
 
3871
    out(lig_kern[lig_ptr].b2);
 
3872
    out(lig_kern[lig_ptr].b3);
 
3873
    end;
 
3874
  if nk>0 then for krn_ptr:=0 to nk-1 do out_scaled(kern[krn_ptr])
 
3875
  end
 
3876
else begin
 
3877
  if extra_loc_needed then begin {|lk_offset=1|}
 
3878
    out_size(255); out_size(bchar); out_size(0); out_size(0);
 
3879
    end
 
3880
  else for sort_ptr:=1 to lk_offset do begin {output the redirection specs}
 
3881
    t:=label_table[label_ptr].rr;
 
3882
    if bchar<xmax_char then begin
 
3883
      out_size(255); out_size(bchar);
 
3884
      end
 
3885
    else begin
 
3886
      out_size(254); out_size(0);
 
3887
      end;
 
3888
    out_size((t+lk_offset) div 256);
 
3889
    out_size((t+lk_offset) mod 256);
 
3890
    repeat decr(label_ptr); until label_table[label_ptr].rr<t;
 
3891
    end; 
 
3892
  if nl>0 then for lig_ptr:=0 to nl-1 do begin
 
3893
    out_size(lig_kern[lig_ptr].b0);
 
3894
    out_size(lig_kern[lig_ptr].b1);
 
3895
    out_size(lig_kern[lig_ptr].b2);
 
3896
    out_size(lig_kern[lig_ptr].b3);
 
3897
    end;
 
3898
  if nk>0 then for krn_ptr:=0 to nk-1 do out_scaled(kern[krn_ptr])
 
3899
  end
 
3900
 
 
3901
@ @<Output the extensible character recipes@>=
 
3902
if ofm_level=-1 then begin
 
3903
  if ne>0 then for c:=0 to ne-1 do begin
 
3904
    out(exten[c].b0);
 
3905
    out(exten[c].b1);
 
3906
    out(exten[c].b2);
 
3907
    out(exten[c].b3);
 
3908
    end;
 
3909
  end
 
3910
else begin
 
3911
  if ne>0 then for c:=0 to ne-1 do begin
 
3912
    out_size(exten[c].b0);
 
3913
    out_size(exten[c].b1);
 
3914
    out_size(exten[c].b2);
 
3915
    out_size(exten[c].b3);
 
3916
    end;
 
3917
  end;
 
3918
 
 
3919
@ For our grand finale, we wind everything up by outputting the parameters.
 
3920
 
 
3921
@<Output the parameters@>=
 
3922
for par_ptr:=1 to np do begin
 
3923
  if par_ptr=1 then
 
3924
    @<Output the slant (|param[1]|) without scaling@>
 
3925
  else out_scaled(param[par_ptr]);
 
3926
  end
 
3927
 
 
3928
@ @<Output the slant...@>=
 
3929
begin if param[1]<0 then begin
 
3930
  param[1]:=param[1]+@'10000000000;
 
3931
  out((param[1] div @'100000000)+256-64);
 
3932
  end
 
3933
else out(param[1] div @'100000000);
 
3934
out((param[1] div @'200000) mod 256);
 
3935
out((param[1] div 256) mod 256);
 
3936
out(param[1] mod 256);
 
3937
end
 
3938
 
 
3939
@* The VF output phase.
 
3940
Output to |vf_file| is considerably simpler.
 
3941
 
 
3942
@d id_byte=202 {current version of \.{VF} format}
 
3943
@d vout(#)==write(vf_file,#)
 
3944
 
 
3945
@<Glob...@>=
 
3946
@!vcount:integer; {number of bytes written to |vf_file|}
 
3947
 
 
3948
@ We need a routine to output integers as four bytes. Negative values
 
3949
will never be less than $-2^{24}$.
 
3950
 
 
3951
@p procedure vout_int(@!x:integer);
 
3952
begin if x>=0 then vout(x div @'100000000)
 
3953
else begin
 
3954
  vout(255); x:=x+@'100000000;
 
3955
  end;
 
3956
vout((x div @'200000) mod 256);
 
3957
vout((x div @'400) mod 256); vout(x mod 256);
 
3958
end;
 
3959
 
 
3960
@ @<Do the \.{VF} output@>=
 
3961
vout(pre); vout(id_byte); vout(vtitle_length);
 
3962
for k:=0 to vtitle_length-1 do vout(vf[vtitle_start+k]);
 
3963
for k:=check_sum_loc to design_size_loc+3 do vout(header_bytes[k]);
 
3964
vcount:=vtitle_length+11;
 
3965
for cur_font:=0 to font_ptr-1 do @<Output a local font definition@>;
 
3966
for c:=bc to ec do if char_wd[c]>0 then
 
3967
  @<Output a packet for character |c|@>;
 
3968
repeat vout(post); incr(vcount);
 
3969
until vcount mod 4 = 0
 
3970
 
 
3971
@ @<Output a local font definition@>=
 
3972
begin vfout_fntdef(cur_font);@/
 
3973
vout(font_checksum[cur_font].b0);
 
3974
vout(font_checksum[cur_font].b1);
 
3975
vout(font_checksum[cur_font].b2);
 
3976
vout(font_checksum[cur_font].b3);
 
3977
vout_int(font_at[cur_font]);
 
3978
vout_int(font_dsize[cur_font]);
 
3979
vout(farea_length[cur_font]);
 
3980
vout(fname_length[cur_font]);
 
3981
for k:=0 to farea_length[cur_font]-1 do vout(vf[farea_start[cur_font]+k]);
 
3982
if fname_start[cur_font]=vf_size then begin
 
3983
  vout("N"); vout("U"); vout("L"); vout("L");
 
3984
  end
 
3985
else for k:=0 to fname_length[cur_font]-1 do vout(vf[fname_start[cur_font]+k]);
 
3986
vcount:=vcount+12+farea_length[cur_font]+fname_length[cur_font];
 
3987
end
 
3988
 
 
3989
@ @<Output a packet for character |c|@>=
 
3990
begin x:=memory[char_wd[c]];
 
3991
if design_units<>unity then x:=round((x/design_units)*1048576.0);
 
3992
if (packet_length[c]>241)or(x<0)or(x>=@'100000000)or(c<0)or(c>255) then begin
 
3993
  vout(242); vout_int(packet_length[c]); vfout_char(c); vout_int(x);
 
3994
  vcount:=vcount+13+packet_length[c];
 
3995
  end
 
3996
else begin
 
3997
  vout(packet_length[c]); vout(c); vout(x div @'200000);
 
3998
  vout((x div @'400) mod 256); vout(x mod 256);
 
3999
  vcount:=vcount+5+packet_length[c];
 
4000
  end;
 
4001
if packet_start[c]=vf_size then
 
4002
  vfout_set(c)
 
4003
else for k:=0 to packet_length[c]-1 do vout(vf[packet_start[c]+k]);
 
4004
end
 
4005
 
 
4006
@* The main program.
 
4007
The routines sketched out so far need to be packaged into separate procedures,
 
4008
on some systems, since some \PASCAL\ compilers place a strict limit on the
 
4009
size of a routine. The packaging is done here in an attempt to avoid some
 
4010
system-dependent changes.
 
4011
 
 
4012
@p procedure param_enter;
 
4013
begin @<Enter the parameter names@>;
 
4014
end;
 
4015
@#
 
4016
procedure vpl_enter;
 
4017
begin @<Enter all the \.{VPL} names@>;
 
4018
end;
 
4019
@#
 
4020
procedure name_enter; {enter all names and their equivalents}
 
4021
begin @<Enter all the \.{PL} names...@>;
 
4022
vpl_enter; param_enter;
 
4023
end;
 
4024
@#
 
4025
procedure read_lig_kern;
 
4026
var @!krn_ptr:0..max_kerns; {an index into |kern|}
 
4027
@!c:byte; {runs through all character codes}
 
4028
begin @<Read ligature/kern list@>;
 
4029
end;
 
4030
@#
 
4031
procedure output_new_information_ofm;
 
4032
begin @<Output the new information for OFM files@>;
 
4033
end;
 
4034
@#
 
4035
procedure compute_new_header_ofm;
 
4036
begin @<Compute the new header information for OFM files@>;
 
4037
end;
 
4038
@#
 
4039
procedure finish_extended_font;
 
4040
begin @<Finish up the extended font stuff@>;
 
4041
end;
 
4042
@#
 
4043
procedure output_subfile_sizes;
 
4044
begin @<Output the subfile sizes@>;
 
4045
end;
 
4046
@#
 
4047
procedure compute_subfile_sizes;
 
4048
begin @<Compute the subfile sizes@>;
 
4049
end;
 
4050
@#
 
4051
procedure output_character_info;
 
4052
begin @<Output the character info@>;
 
4053
end;
 
4054
@#
 
4055
@#
 
4056
procedure read_font_rule_list;
 
4057
begin @<Read font rule list@>;
 
4058
end;
 
4059
@#
 
4060
procedure read_font_glue_list;
 
4061
begin @<Read font glue list@>;
 
4062
end;
 
4063
@#
 
4064
procedure read_font_penalty_list;
 
4065
begin @<Read font penalty list@>;
 
4066
end;
 
4067
@#
 
4068
procedure read_font_mvalue_list;
 
4069
begin @<Read font mvalue list@>;
 
4070
end;
 
4071
@#
 
4072
procedure read_font_fvalue_list;
 
4073
begin @<Read font fvalue list@>;
 
4074
end;
 
4075
@#
 
4076
procedure read_font_ivalue_list;
 
4077
begin @<Read font ivalue list@>;
 
4078
end;
 
4079
@#
 
4080
procedure read_repeated_character_info;
 
4081
begin @<Read repeated character info@>;
 
4082
end;
 
4083
@#
 
4084
procedure read_lig_kern_command;
 
4085
begin @<Read a ligature/kern command@>;
 
4086
end;
 
4087
@#
 
4088
procedure read_character_property;
 
4089
begin @<Read a character property@>;
 
4090
end;
 
4091
@#
 
4092
procedure read_char_info;
 
4093
begin @<Read character info list@>;
 
4094
end;
 
4095
@#
 
4096
procedure read_input;
 
4097
var @!c:byte; {header or parameter index}
 
4098
begin @<Read all the input@>;
 
4099
end;
 
4100
@#
 
4101
procedure corr_and_check;
 
4102
var @!c:xchar_type; {runs through all character codes}
 
4103
@!hh:0..hash_size; {an index into |hash_list|}
 
4104
@!lig_ptr:0..max_lig_steps; {an index into |lig_kern|}
 
4105
@!g:byte; {a character generated by the current character |c|}
 
4106
begin @<Correct and check the information@>
 
4107
end;
 
4108
@#
 
4109
procedure vf_output;
 
4110
var @!c:char_type; {runs through all character codes}
 
4111
@!cur_font:xfont_type; {runs through all local fonts}
 
4112
@!k:integer; {loop index}
 
4113
begin @<Do the \.{VF} output@>;
 
4114
end;
 
4115
 
 
4116
@ Here is where \.{VPtoVF} begins and ends.
 
4117
 
 
4118
@p begin initialize;@/
 
4119
name_enter;@/
 
4120
read_input; print_ln('.');@/
 
4121
corr_and_check;@/
 
4122
@<Do the font metric output@>;
 
4123
vf_output;
 
4124
end.
 
4125
 
 
4126
@ @<Global...@>=
 
4127
@!ofm_level:integer;
 
4128
 
 
4129
@ @<Set init...@>=
 
4130
ofm_level:=0; {Suppose that it is a level 0 OFM file}
 
4131
 
 
4132
@ @<Read OFM level code@>=
 
4133
begin
 
4134
ofm_level:=get_integer;
 
4135
if (ofm_level<0) or (ofm_level>1) then begin
 
4136
  flush_error('OFMLEVEL must be 0 or 1 -- 1 assumed');
 
4137
  ofm_level:=1;
 
4138
  end;
 
4139
end
 
4140
 
 
4141
@ @<Read font direction code@>=
 
4142
begin
 
4143
font_dir:=-1;
 
4144
repeat get_next;
 
4145
until cur_char<>" ";
 
4146
case cur_char of
 
4147
  "T": begin get_next;
 
4148
    if cur_char="L" then font_dir:=0
 
4149
    else if cur_char="R" then font_dir:=2;
 
4150
    end;
 
4151
  "B": begin get_next;
 
4152
    if cur_char="L" then font_dir:=4
 
4153
    else if cur_char="R" then font_dir:=6;
 
4154
    end;
 
4155
  "R": begin get_next;
 
4156
    if cur_char="T" then font_dir:=5
 
4157
    else if cur_char="B" then font_dir:=7;
 
4158
    end;
 
4159
  "L": begin get_next;
 
4160
    if cur_char="T" then font_dir:=1
 
4161
    else if cur_char="B" then font_dir:=3;
 
4162
    end;
 
4163
  end;
 
4164
while cur_char<>")" do get_next;
 
4165
if font_dir = -1 then begin
 
4166
  flush_error('FONTDIR must be valid direction, -- TR assumed');
 
4167
  font_dir:=0;
 
4168
  end;
 
4169
end
 
4170
 
 
4171
@ @<Read natural font direction code@>=
 
4172
begin
 
4173
font_dir:=-1;
 
4174
repeat get_next;
 
4175
until cur_char<>" ";
 
4176
case cur_char of
 
4177
  "T": begin get_next;
 
4178
    if cur_char="L" then font_dir:=8
 
4179
    else if cur_char="R" then font_dir:=10;
 
4180
    end;
 
4181
  "B": begin get_next;
 
4182
    if cur_char="L" then font_dir:=12
 
4183
    else if cur_char="R" then font_dir:=14;
 
4184
    end;
 
4185
  "R": begin get_next;
 
4186
    if cur_char="T" then font_dir:=13
 
4187
    else if cur_char="B" then font_dir:=15;
 
4188
    end;
 
4189
  "L": begin get_next;
 
4190
    if cur_char="T" then font_dir:=9
 
4191
    else if cur_char="B" then font_dir:=11;
 
4192
    end;
 
4193
  end;
 
4194
while cur_char<>")" do get_next;
 
4195
if font_dir = -1 then begin
 
4196
  flush_error('NFONTDIR must be valid direction, -- TR assumed');
 
4197
  font_dir:=8;
 
4198
  end;
 
4199
end
 
4200
 
 
4201
@
 
4202
Here are some general values for the various entries.
 
4203
They can all be changed.
 
4204
 
 
4205
@d arrays_per_kind==20
 
4206
@d entries_per_array==200
 
4207
 
 
4208
@ @<Constants...@>=
 
4209
@!rule_arrays=arrays_per_kind;
 
4210
@!rule_entries=entries_per_array;
 
4211
 
 
4212
@ @<Types...@>=
 
4213
rule_array_type=0..rule_arrays;
 
4214
rule_entry_type=0..rule_entries;
 
4215
rule_node=
 
4216
record
 
4217
  rn_width:     fix_word;
 
4218
  rn_height:    fix_word;
 
4219
  rn_depth:     fix_word;
 
4220
end;
 
4221
 
 
4222
@ @<Global...@>=
 
4223
@!rules:array[rule_array_type,rule_entry_type] of rule_node;
 
4224
@!npr:array[rule_array_type] of integer;
 
4225
@!nkr:integer;
 
4226
@!nkcr:integer;
 
4227
@!nwr:integer;
 
4228
@!r_array:integer;
 
4229
@!r_number:integer;
 
4230
 
 
4231
@ @<Set init...@>=
 
4232
for r_array := 0 to rule_arrays do begin
 
4233
  npr[r_array]:=0;
 
4234
  @<Null out the rule@>;
 
4235
  end;
 
4236
nkr:=-1;
 
4237
nkcr:=-1;
 
4238
 
 
4239
@ @<Read font rule list@>=
 
4240
begin
 
4241
if tables_read then
 
4242
  flush_error('All parameter tables must appear before character info');
 
4243
r_array:=get_integer;
 
4244
if r_array>rule_arrays then
 
4245
  flush_error('This FONTRULE table index is too big for my present size')
 
4246
else if r_array<0 then
 
4247
  flush_error('This FONTRULE index is negative')
 
4248
else begin
 
4249
  if r_array>nkr then nkr:=r_array;
 
4250
  while level=1 do begin
 
4251
    while cur_char=" " do get_next;
 
4252
    if cur_char="(" then @<Read a rule@>
 
4253
    else if cur_char=")" then skip_to_end_of_item
 
4254
    else junk_error;
 
4255
    end;
 
4256
  finish_inner_property_list;
 
4257
  end;
 
4258
end
 
4259
 
 
4260
@ @<Read a rule@>= 
 
4261
begin
 
4262
get_name; 
 
4263
if cur_code=comment_code then skip_to_end_of_item 
 
4264
else if cur_code<>rule_code then 
 
4265
  flush_error('This property name doesn''t belong in a RULE list') 
 
4266
else begin
 
4267
  r_number:=get_integer;
 
4268
  if r_number>rule_entries then 
 
4269
    flush_error('This RULE index is too big for my present table size') 
 
4270
  else if r_number<0 then
 
4271
    flush_error('This RULE index is negative')
 
4272
  else begin
 
4273
    while npr[r_array]<r_number do begin
 
4274
      incr(npr[r_array]); @<Null out the rule@>;
 
4275
      end; 
 
4276
    @<Read all of a rule's values@>;
 
4277
    finish_the_property; 
 
4278
    end;
 
4279
  end; 
 
4280
end 
 
4281
 
 
4282
@ @<Null out the rule@>=
 
4283
begin
 
4284
rules[r_array,npr[r_array]].rn_width:=0;
 
4285
rules[r_array,npr[r_array]].rn_depth:=0;
 
4286
rules[r_array,npr[r_array]].rn_height:=0;
 
4287
end
 
4288
 
 
4289
@ @<Read all of a rule's values@>=
 
4290
begin
 
4291
while level=2 do begin
 
4292
  while cur_char=" " do get_next;
 
4293
  if cur_char="(" then @<Read a single rule value@>
 
4294
  else if cur_char=")" then skip_to_end_of_item
 
4295
  else junk_error;
 
4296
  end;
 
4297
finish_inner_property_list;
 
4298
end
 
4299
 
 
4300
@ @<Read a single rule value@>=
 
4301
begin
 
4302
get_name;
 
4303
case cur_code of
 
4304
  rule_width_code:
 
4305
    rules[r_array,r_number].rn_width:=get_fix; 
 
4306
  rule_height_code:
 
4307
    rules[r_array,r_number].rn_height:=get_fix; 
 
4308
  rule_depth_code:
 
4309
    rules[r_array,r_number].rn_depth:=get_fix; 
 
4310
  end;
 
4311
finish_the_property;
 
4312
end
 
4313
 
 
4314
@ @<Header information for rules@>=
 
4315
begin
 
4316
nwr:=0;
 
4317
for r_array := 0 to nkr do begin
 
4318
  incr(npr[r_array]);
 
4319
  nwr := nwr + 3*npr[r_array];
 
4320
  end;
 
4321
incr(nkr);
 
4322
end
 
4323
 
 
4324
@ @<Output the rules@>=
 
4325
begin
 
4326
for r_array:= 0 to nkr-1 do
 
4327
  for r_number:=0 to npr[r_array]-1 do begin
 
4328
    out_scaled(rules[r_array,r_number].rn_width);
 
4329
    out_scaled(rules[r_array,r_number].rn_height);
 
4330
    out_scaled(rules[r_array,r_number].rn_depth);
 
4331
    end;
 
4332
end
 
4333
 
 
4334
@ @<Output the rule headers@>=
 
4335
begin
 
4336
for r_array:= 0 to nkr-1 do begin
 
4337
  out_integer(npr[r_array]);
 
4338
  end;
 
4339
end
 
4340
 
 
4341
@ @<Constants...@>=
 
4342
@!glue_arrays=arrays_per_kind;
 
4343
@!glue_entries=entries_per_array;
 
4344
 
 
4345
 
4346
@d t_normal==0
 
4347
@d t_aleaders==1
 
4348
@d t_cleaders==2
 
4349
@d t_xleaders==3
 
4350
 
 
4351
@d o_unit==0
 
4352
@d o_fi==1
 
4353
@d o_fil==2
 
4354
@d o_fill==3
 
4355
@d o_filll==4
 
4356
 
 
4357
@d g_space==0
 
4358
@d g_rule==1
 
4359
@d g_char==2
 
4360
 
 
4361
@<Types...@>=
 
4362
glue_array_type=0..glue_arrays;
 
4363
glue_entry_type=0..glue_entries;
 
4364
glue_node=
 
4365
record
 
4366
  gn_width:             fix_word;
 
4367
  gn_stretch:           fix_word;
 
4368
  gn_shrink:            fix_word;
 
4369
  gn_type:              integer;
 
4370
  gn_arg_type:          g_space..g_char;
 
4371
  gn_stretch_order:     integer;
 
4372
  gn_shrink_order:      integer;
 
4373
  gn_argument:          integer;
 
4374
end;
 
4375
 
 
4376
@ @<Global...@>=
 
4377
@!glues:array[glue_array_type,glue_entry_type] of glue_node;
 
4378
@!npg:array[glue_array_type] of integer;
 
4379
@!nkg:integer;
 
4380
@!nkcg:integer;
 
4381
@!nwg:integer;
 
4382
@!g_array:integer;
 
4383
@!g_byte:integer;
 
4384
@!g_number:integer;
 
4385
 
 
4386
@ @<Set init...@>=
 
4387
for g_array := 0 to glue_arrays do
 
4388
begin
 
4389
  npg[g_array]:=0;
 
4390
  @<Null out the glue@>;
 
4391
end;
 
4392
nkg:=-1;
 
4393
nkcg:=-1;
 
4394
 
 
4395
@ @<Read font glue list@>=
 
4396
begin
 
4397
if tables_read then
 
4398
  flush_error('All parameter tables must appear before character info');
 
4399
g_array:=get_integer;
 
4400
if g_array>glue_arrays then
 
4401
  flush_error('This FONTGLUE table index is too big for my present size')
 
4402
else if g_array<0 then
 
4403
  flush_error('This FONTGLUE index is negative')
 
4404
else begin
 
4405
  if g_array>nkg then nkg:=g_array;
 
4406
  while level=1 do begin
 
4407
    while cur_char=" " do get_next;
 
4408
    if cur_char="(" then @<Read a glue@>
 
4409
    else if cur_char=")" then skip_to_end_of_item
 
4410
    else junk_error;
 
4411
    end;
 
4412
  finish_inner_property_list;
 
4413
  end;
 
4414
end
 
4415
 
 
4416
@ @<Read a glue@>= 
 
4417
begin
 
4418
get_name; 
 
4419
if cur_code=comment_code then skip_to_end_of_item 
 
4420
else if cur_code<>glue_code then 
 
4421
  flush_error('This property name doesn''t belong in a GLUE list') 
 
4422
else begin
 
4423
  g_number:=get_integer;
 
4424
  if g_number>glue_entries then 
 
4425
    flush_error('This GLUE index is too big for my present table size') 
 
4426
  else if g_number<0 then
 
4427
    flush_error('This GLUE index is negative')
 
4428
  else begin
 
4429
    while npg[g_array]<g_number do begin
 
4430
      incr(npg[g_array]); @<Null out the glue@>;
 
4431
      end; 
 
4432
    @<Read all of a glue's values@>;
 
4433
    finish_the_property; 
 
4434
    end; 
 
4435
  end; 
 
4436
end 
 
4437
 
 
4438
@ @<Null out the glue@>=
 
4439
begin
 
4440
glues[g_array,npg[g_array]].gn_width:=0;
 
4441
glues[g_array,npg[g_array]].gn_stretch:=0;
 
4442
glues[g_array,npg[g_array]].gn_shrink:=0;
 
4443
glues[g_array,npg[g_array]].gn_type:=0;
 
4444
glues[g_array,npg[g_array]].gn_arg_type:=0;
 
4445
glues[g_array,npg[g_array]].gn_stretch_order:=0;
 
4446
glues[g_array,npg[g_array]].gn_shrink_order:=0;
 
4447
glues[g_array,npg[g_array]].gn_argument:=0;
 
4448
end
 
4449
 
 
4450
@ @<Read all of a glue's values@>=
 
4451
begin
 
4452
while level=2 do begin
 
4453
  while cur_char=" " do get_next;
 
4454
  if cur_char="(" then @<Read a single glue value@>
 
4455
  else if cur_char=")" then skip_to_end_of_item
 
4456
  else junk_error;
 
4457
  end;
 
4458
finish_inner_property_list;
 
4459
end
 
4460
 
 
4461
@ @<Read a single glue value@>=
 
4462
begin
 
4463
get_name;
 
4464
case cur_code of
 
4465
  glue_width_code:
 
4466
    glues[g_array,g_number].gn_width:=get_fix; 
 
4467
  glue_stretch_code:
 
4468
    glues[g_array,g_number].gn_stretch:=get_fix; 
 
4469
  glue_shrink_code:
 
4470
    glues[g_array,g_number].gn_shrink:=get_fix; 
 
4471
  glue_type_code: begin
 
4472
    g_byte:=get_integer;
 
4473
    if (g_byte<0) or (g_byte>3) then begin
 
4474
      g_byte:=0;
 
4475
      end;
 
4476
    glues[g_array,g_number].gn_type:=g_byte;
 
4477
    end;
 
4478
  glue_stretch_order_code: begin
 
4479
    g_byte:=get_integer;
 
4480
    if (g_byte<0) or (g_byte>4) then begin
 
4481
      g_byte:=0;
 
4482
      end;
 
4483
    glues[g_array,g_number].gn_stretch_order:=g_byte;
 
4484
    end;
 
4485
  glue_shrink_order_code: begin
 
4486
    g_byte:=get_integer;
 
4487
    if (g_byte<0) or (g_byte>4) then begin
 
4488
      g_byte:=0;
 
4489
      end;
 
4490
    glues[g_array,g_number].gn_shrink_order:=g_byte;
 
4491
    end;
 
4492
  glue_char_code: begin
 
4493
    glues[g_array,g_number].gn_argument:=get_integer;
 
4494
    glues[g_array,g_number].gn_arg_type:=g_char;
 
4495
    end;
 
4496
  glue_rule_code: begin
 
4497
    glues[g_array,g_number].gn_argument:=get_integer;
 
4498
    glues[g_array,g_number].gn_arg_type:=g_rule;
 
4499
    end;
 
4500
  end;
 
4501
finish_the_property;
 
4502
end
 
4503
 
 
4504
@ @<Header information for glues@>=
 
4505
begin
 
4506
nwg:=0;
 
4507
for g_array := 0 to nkg do begin
 
4508
  incr(npg[g_array]);
 
4509
  nwg := nwg + 4*npg[g_array];
 
4510
  end;
 
4511
incr(nkg);
 
4512
end
 
4513
 
 
4514
@ @<Output the glues@>=
 
4515
begin
 
4516
for g_array:= 0 to nkg-1 do
 
4517
  for g_number:=0 to npg[g_array]-1 do begin
 
4518
    g_byte:=glues[g_array,g_number].gn_type*16+
 
4519
            glues[g_array,g_number].gn_arg_type;
 
4520
    out(g_byte);
 
4521
    g_byte:=glues[g_array,g_number].gn_stretch_order*16+
 
4522
            glues[g_array,g_number].gn_shrink_order;
 
4523
    out(g_byte);
 
4524
    g_byte:=glues[g_array,g_number].gn_argument div 256;
 
4525
    out(g_byte);
 
4526
    g_byte:=glues[g_array,g_number].gn_argument mod 256;
 
4527
    out(g_byte);
 
4528
    out_scaled(glues[g_array,g_number].gn_width);
 
4529
    out_scaled(glues[g_array,g_number].gn_stretch);
 
4530
    out_scaled(glues[g_array,g_number].gn_shrink);
 
4531
  end;
 
4532
end
 
4533
 
 
4534
@ @<Output the glue headers@>=
 
4535
begin
 
4536
for g_array:= 0 to nkg-1 do begin
 
4537
  out_integer(npg[g_array]);
 
4538
  end;
 
4539
end
 
4540
 
 
4541
@ @<Constants...@>=
 
4542
@!penalty_arrays=arrays_per_kind;
 
4543
@!penalty_entries=entries_per_array;
 
4544
 
 
4545
@ @<Types...@>=
 
4546
penalty_array_type=0..penalty_arrays;
 
4547
penalty_entry_type=0..penalty_entries;
 
4548
penalty_node=
 
4549
record
 
4550
  pn_val: integer;
 
4551
end;
 
4552
 
 
4553
@ @<Global...@>=
 
4554
@!penalties:array[penalty_array_type,penalty_entry_type] of penalty_node;
 
4555
@!npp:array[penalty_array_type] of integer;
 
4556
@!nkp:integer;
 
4557
@!nkcp:integer;
 
4558
@!nwp:integer;
 
4559
@!p_array:integer;
 
4560
@!p_number:integer;
 
4561
 
 
4562
@ @<Set init...@>=
 
4563
for p_array := 0 to penalty_arrays do begin
 
4564
  npp[p_array]:=0;
 
4565
  @<Null out the penalty@>;
 
4566
  end;
 
4567
nkp:=-1;
 
4568
nkcp:=-1;
 
4569
 
 
4570
@ @<Read font penalty list@>=
 
4571
begin
 
4572
if tables_read then
 
4573
  flush_error('All parameter tables must appear before character info');
 
4574
p_array:=get_integer;
 
4575
if p_array>penalty_arrays then
 
4576
  flush_error('This FONTPENALTY table index is too big for my present size')
 
4577
else if p_array<0 then
 
4578
  flush_error('This FONTPENALTY index is negative')
 
4579
else begin
 
4580
  if p_array>nkp then nkp:=p_array;
 
4581
  while level=1 do begin
 
4582
    while cur_char=" " do get_next;
 
4583
    if cur_char="(" then @<Read a penalty@>
 
4584
    else if cur_char=")" then skip_to_end_of_item
 
4585
    else junk_error;
 
4586
    end;
 
4587
  finish_inner_property_list;
 
4588
  end;
 
4589
end
 
4590
 
 
4591
@ @<Read a penalty@>= 
 
4592
begin
 
4593
get_name; 
 
4594
if cur_code=comment_code then skip_to_end_of_item 
 
4595
else if cur_code<>penalty_code then 
 
4596
  flush_error('This property name doesn''t belong in a PENALTY list') 
 
4597
else begin
 
4598
  p_number:=get_integer;
 
4599
  if p_number>penalty_entries then 
 
4600
    flush_error('This PENALTY index is too big for my present table size') 
 
4601
  else if p_number<0 then
 
4602
    flush_error('This PENALTY index is negative')
 
4603
  else begin
 
4604
    while npp[p_array]<p_number do begin
 
4605
      incr(npp[p_array]); @<Null out the penalty@>;
 
4606
      end; 
 
4607
    @<Read all of a penalty's values@>;
 
4608
    finish_the_property; 
 
4609
    end; 
 
4610
  end; 
 
4611
end 
 
4612
 
 
4613
@ @<Null out the penalty@>=
 
4614
begin
 
4615
penalties[p_array,npp[p_array]].pn_val:=0;
 
4616
end
 
4617
 
 
4618
@ @<Read all of a penalty's values@>=
 
4619
begin
 
4620
while level=2 do begin
 
4621
  while cur_char=" " do get_next;
 
4622
  if cur_char="(" then @<Read a single penalty value@>
 
4623
  else if cur_char=")" then skip_to_end_of_item
 
4624
  else junk_error;
 
4625
  end;
 
4626
finish_inner_property_list;
 
4627
end
 
4628
 
 
4629
@ @<Read a single penalty value@>=
 
4630
begin
 
4631
get_name;
 
4632
case cur_code of
 
4633
  penalty_val_code:
 
4634
    penalties[p_array,p_number].pn_val:=get_integer; 
 
4635
  end;
 
4636
finish_the_property;
 
4637
end
 
4638
 
 
4639
@ @<Header information for penalties@>=
 
4640
begin
 
4641
nwp:=0;
 
4642
for p_array := 0 to nkp do begin
 
4643
  incr(npp[p_array]);
 
4644
  nwp := nwp + npp[p_array];
 
4645
  end;
 
4646
incr(nkp);
 
4647
end
 
4648
 
 
4649
@ @<Output the penalties@>=
 
4650
begin
 
4651
for p_array:= 0 to nkp-1 do
 
4652
  for p_number:=0 to npp[p_array]-1 do begin
 
4653
    out_integer(penalties[p_array,p_number].pn_val);
 
4654
    end;
 
4655
end
 
4656
 
 
4657
@ @<Output the penalty headers@>=
 
4658
begin
 
4659
for p_array:= 0 to nkp-1 do begin
 
4660
  out_integer(npp[p_array]);
 
4661
  end;
 
4662
end
 
4663
 
 
4664
@ @<Constants...@>=
 
4665
@!mvalue_arrays=arrays_per_kind;
 
4666
@!mvalue_entries=entries_per_array;
 
4667
 
 
4668
@ @<Types...@>=
 
4669
mvalue_array_type=0..mvalue_arrays;
 
4670
mvalue_entry_type=0..mvalue_entries;
 
4671
mvalue_node=
 
4672
record
 
4673
  fn_val:     fix_word;
 
4674
end;
 
4675
 
 
4676
@ @<Global...@>=
 
4677
@!mvalues:array[mvalue_array_type,mvalue_entry_type] of mvalue_node;
 
4678
@!npm:array[mvalue_array_type] of integer;
 
4679
@!nkm:integer;
 
4680
@!nkcm:integer;
 
4681
@!nwm:integer;
 
4682
@!m_array:integer;
 
4683
@!m_number:integer;
 
4684
 
 
4685
@ @<Set init...@>=
 
4686
for m_array := 0 to mvalue_arrays do begin
 
4687
  npm[m_array]:=0;
 
4688
  @<Null out the mvalue@>;
 
4689
  end;
 
4690
nkm:=-1;
 
4691
nkcm:=-1;
 
4692
 
 
4693
@ @<Read font mvalue list@>=
 
4694
begin
 
4695
if tables_read then
 
4696
  flush_error('All parameter tables must appear before character info');
 
4697
m_array:=get_integer;
 
4698
if m_array>mvalue_arrays then
 
4699
  flush_error('This FONTMVALUE table index is too big for my present size')
 
4700
else if m_array<0 then
 
4701
  flush_error('This FONTMVALUE index is negative')
 
4702
else begin
 
4703
  if m_array>nkm then nkm:=m_array;
 
4704
  while level=1 do begin
 
4705
    while cur_char=" " do get_next;
 
4706
    if cur_char="(" then @<Read an mvalue@>
 
4707
    else if cur_char=")" then skip_to_end_of_item
 
4708
    else junk_error;
 
4709
    end;
 
4710
  finish_inner_property_list;
 
4711
  end;
 
4712
end
 
4713
 
 
4714
@ @<Read an mvalue@>= 
 
4715
begin
 
4716
get_name; 
 
4717
if cur_code=comment_code then skip_to_end_of_item 
 
4718
else if cur_code<>mvalue_code then 
 
4719
  flush_error('This property name doesn''t belong in an MVALUE list') 
 
4720
else begin
 
4721
  m_number:=get_integer;
 
4722
  if m_number>mvalue_entries then 
 
4723
    flush_error('This MVALUE index is too big for my present table size') 
 
4724
  else if m_number<0 then
 
4725
    flush_error('This MVALUE index is negative')
 
4726
  else begin
 
4727
    while npm[m_array]<m_number do begin
 
4728
      incr(npm[m_array]); @<Null out the mvalue@>;
 
4729
      end; 
 
4730
    @<Read all of an mvalue's values@>;
 
4731
    finish_the_property; 
 
4732
    end; 
 
4733
  end; 
 
4734
end 
 
4735
 
 
4736
@ @<Null out the mvalue@>=
 
4737
begin
 
4738
mvalues[m_array,npm[m_array]].fn_val:=0;
 
4739
end
 
4740
 
 
4741
@ @<Read all of an mvalue's values@>=
 
4742
begin
 
4743
while level=2 do begin
 
4744
  while cur_char=" " do get_next;
 
4745
  if cur_char="(" then @<Read a single mvalue value@>
 
4746
  else if cur_char=")" then skip_to_end_of_item
 
4747
  else junk_error;
 
4748
  end;
 
4749
finish_inner_property_list;
 
4750
end
 
4751
 
 
4752
@ @<Read a single mvalue value@>=
 
4753
begin
 
4754
get_name;
 
4755
case cur_code of
 
4756
  mvalue_val_code:
 
4757
    mvalues[m_array,m_number].fn_val:=get_fix; 
 
4758
  end;
 
4759
finish_the_property;
 
4760
end
 
4761
 
 
4762
@ @<Header information for mvalues@>=
 
4763
begin
 
4764
nwm:=0;
 
4765
for m_array := 0 to nkm do begin
 
4766
  incr(npm[m_array]);
 
4767
  nwm := nwm + npm[m_array];
 
4768
  end;
 
4769
incr(nkm);
 
4770
end
 
4771
 
 
4772
@ @<Output the mvalues@>=
 
4773
begin
 
4774
for m_array:= 0 to nkm-1 do
 
4775
  for m_number:=0 to npm[m_array]-1 do begin
 
4776
    out_scaled(mvalues[m_array,m_number].fn_val);
 
4777
    end;
 
4778
end
 
4779
 
 
4780
@ @<Output the mvalue headers@>=
 
4781
begin
 
4782
for m_array:= 0 to nkm-1 do begin
 
4783
  out_integer(npm[m_array]);
 
4784
  end;
 
4785
end
 
4786
 
 
4787
@ @<Constants...@>=
 
4788
@!fvalue_arrays=arrays_per_kind;
 
4789
@!fvalue_entries=entries_per_array;
 
4790
 
 
4791
@ @<Types...@>=
 
4792
fvalue_array_type=0..fvalue_arrays;
 
4793
fvalue_entry_type=0..fvalue_entries;
 
4794
fvalue_node=
 
4795
record
 
4796
  fn_val:     fix_word;
 
4797
end;
 
4798
 
 
4799
@ @<Global...@>=
 
4800
@!fvalues:array[fvalue_array_type,fvalue_entry_type] of fvalue_node;
 
4801
@!npf:array[fvalue_array_type] of integer;
 
4802
@!nkf:integer;
 
4803
@!nkcf:integer;
 
4804
@!nwf:integer;
 
4805
@!f_array:integer;
 
4806
@!f_number:integer;
 
4807
 
 
4808
@ @<Set init...@>=
 
4809
for f_array := 0 to fvalue_arrays do begin
 
4810
  npf[f_array]:=0;
 
4811
  @<Null out the fvalue@>;
 
4812
  end;
 
4813
nkf:=-1;
 
4814
nkcf:=-1;
 
4815
 
 
4816
@ @<Read font fvalue list@>=
 
4817
begin
 
4818
if tables_read then
 
4819
  flush_error('All parameter tables must appear before character info');
 
4820
f_array:=get_integer;
 
4821
if f_array>fvalue_arrays then
 
4822
  flush_error('This FONTFVALUE table index is too big for my present size')
 
4823
else if f_array<0 then
 
4824
  flush_error('This FONTFVALUE index is negative')
 
4825
else begin
 
4826
  if f_array>nkf then nkf:=f_array;
 
4827
  while level=1 do begin
 
4828
    while cur_char=" " do get_next;
 
4829
    if cur_char="(" then @<Read an fvalue@>
 
4830
    else if cur_char=")" then skip_to_end_of_item
 
4831
    else junk_error;
 
4832
    end;
 
4833
  finish_inner_property_list;
 
4834
  end;
 
4835
end
 
4836
 
 
4837
@ @<Read an fvalue@>= 
 
4838
begin
 
4839
get_name; 
 
4840
if cur_code=comment_code then skip_to_end_of_item 
 
4841
else if cur_code<>fvalue_code then 
 
4842
  flush_error('This property name doesn''t belong in an FVALUE list') 
 
4843
else begin
 
4844
  f_number:=get_integer;
 
4845
  if f_number>fvalue_entries then 
 
4846
    flush_error('This FVALUE index is too big for my present table size') 
 
4847
  else if f_number<0 then
 
4848
    flush_error('This FVALUE index is negative')
 
4849
  else begin
 
4850
    while npf[f_array]<f_number do begin
 
4851
      incr(npf[f_array]); @<Null out the fvalue@>;
 
4852
      end; 
 
4853
    @<Read all of an fvalue's values@>;
 
4854
    finish_the_property; 
 
4855
    end; 
 
4856
  end; 
 
4857
end 
 
4858
 
 
4859
@ @<Null out the fvalue@>=
 
4860
begin
 
4861
fvalues[f_array,npf[f_array]].fn_val:=0;
 
4862
end
 
4863
 
 
4864
@ @<Read all of an fvalue's values@>=
 
4865
begin
 
4866
while level=2 do begin
 
4867
  while cur_char=" " do get_next;
 
4868
  if cur_char="(" then @<Read a single fvalue value@>
 
4869
  else if cur_char=")" then skip_to_end_of_item
 
4870
  else junk_error;
 
4871
  end;
 
4872
finish_inner_property_list;
 
4873
end
 
4874
 
 
4875
@ @<Read a single fvalue value@>=
 
4876
begin
 
4877
get_name;
 
4878
case cur_code of
 
4879
  fvalue_val_code:
 
4880
    fvalues[f_array,f_number].fn_val:=get_fix; 
 
4881
  end;
 
4882
finish_the_property;
 
4883
end
 
4884
 
 
4885
@ @<Header information for fvalues@>=
 
4886
begin
 
4887
nwf:=0;
 
4888
for f_array := 0 to nkf do begin
 
4889
  incr(npf[f_array]);
 
4890
  nwf := nwf + npf[f_array];
 
4891
  end;
 
4892
incr(nkf);
 
4893
end
 
4894
 
 
4895
@ @<Output the fvalues@>=
 
4896
begin
 
4897
for f_array:= 0 to nkf-1 do
 
4898
  for f_number:=0 to npf[f_array]-1 do begin
 
4899
    out_scaled(fvalues[f_array,f_number].fn_val);
 
4900
    end;
 
4901
end
 
4902
 
 
4903
@ @<Output the fvalue headers@>=
 
4904
begin
 
4905
for f_array:= 0 to nkf-1 do begin
 
4906
  out_integer(npf[f_array]);
 
4907
  end;
 
4908
end
 
4909
 
 
4910
@ @<Constants...@>=
 
4911
@!ivalue_arrays=arrays_per_kind;
 
4912
@!ivalue_entries=entries_per_array;
 
4913
 
 
4914
@ @<Types...@>=
 
4915
ivalue_array_type=0..ivalue_arrays;
 
4916
ivalue_entry_type=0..ivalue_entries;
 
4917
ivalue_node=
 
4918
record
 
4919
  in_val:       integer;
 
4920
end;
 
4921
 
 
4922
@ @<Global...@>=
 
4923
@!ivalues:array[ivalue_array_type,ivalue_entry_type] of ivalue_node;
 
4924
@!npi:array[ivalue_array_type] of integer;
 
4925
@!font_i_array:boolean;
 
4926
@!nki:integer;
 
4927
@!nkci:integer;
 
4928
@!nwi:integer;
 
4929
@!i_array:integer;
 
4930
@!i_number:integer;
 
4931
 
 
4932
@ @<Set init...@>=
 
4933
for i_array := 0 to ivalue_arrays do begin
 
4934
  npi[i_array]:=0;
 
4935
  @<Null out the ivalue@>;
 
4936
  end;
 
4937
nki:=-1;
 
4938
nkci:=-1;
 
4939
 
 
4940
@ @<Read font ivalue list@>=
 
4941
begin
 
4942
if tables_read then
 
4943
  flush_error('All parameter tables must appear before character info');
 
4944
i_array:=get_integer;
 
4945
if i_array>ivalue_arrays then
 
4946
  flush_error('This FONTIVALUE table index is too big for my present size')
 
4947
else if i_array<0 then
 
4948
  flush_error('This FONTIVALUE index is negative')
 
4949
else begin
 
4950
  if i_array>nki then nki:=i_array;
 
4951
  while level=1 do begin
 
4952
    while cur_char=" " do get_next;
 
4953
    if cur_char="(" then @<Read an ivalue@>
 
4954
    else if cur_char=")" then skip_to_end_of_item
 
4955
    else junk_error;
 
4956
    end;
 
4957
  finish_inner_property_list;
 
4958
  end;
 
4959
end
 
4960
 
 
4961
@ @<Read an ivalue@>= 
 
4962
begin
 
4963
get_name; 
 
4964
if cur_code=comment_code then skip_to_end_of_item 
 
4965
else if cur_code<>ivalue_code then 
 
4966
  flush_error('This property name doesn''t belong in an IVALUE list') 
 
4967
else begin
 
4968
  i_number:=get_integer;
 
4969
  if i_number>ivalue_entries then 
 
4970
    flush_error('This IVALUE index is too big for my present table size') 
 
4971
  else if i_number<0 then
 
4972
    flush_error('This IVALUE index is negative')
 
4973
  else begin
 
4974
    while npi[i_array]<i_number do begin
 
4975
      incr(npi[i_array]); @<Null out the ivalue@>;
 
4976
      end; 
 
4977
    @<Read all of an ivalue's values@>;
 
4978
    finish_the_property; 
 
4979
    end; 
 
4980
  end; 
 
4981
end 
 
4982
 
 
4983
@ @<Null out the ivalue@>=
 
4984
begin
 
4985
ivalues[i_array,npi[i_array]].in_val:=0;
 
4986
end
 
4987
 
 
4988
@ @<Read all of an ivalue's values@>=
 
4989
begin
 
4990
while level=2 do begin
 
4991
  while cur_char=" " do get_next;
 
4992
  if cur_char="(" then @<Read a single ivalue value@>
 
4993
  else if cur_char=")" then skip_to_end_of_item
 
4994
  else junk_error;
 
4995
  end;
 
4996
finish_inner_property_list;
 
4997
end
 
4998
 
 
4999
@ @<Read a single ivalue value@>=
 
5000
begin
 
5001
get_name;
 
5002
case cur_code of
 
5003
  ivalue_val_code:
 
5004
    ivalues[i_array,i_number].in_val:=get_integer; 
 
5005
  end;
 
5006
finish_the_property;
 
5007
end
 
5008
 
 
5009
@ @<Header information for ivalues@>=
 
5010
begin
 
5011
nwi:=0;
 
5012
for i_array := 0 to nki do begin
 
5013
  incr(npi[i_array]);
 
5014
  nwi := nwi + npi[i_array];
 
5015
  end;
 
5016
incr(nki);
 
5017
end
 
5018
 
 
5019
@ @<Output the ivalues@>=
 
5020
begin
 
5021
for i_array:= 0 to nki-1 do
 
5022
  for i_number:=0 to npi[i_array]-1 do begin
 
5023
    out_integer(ivalues[i_array,i_number].in_val);
 
5024
    end;
 
5025
end
 
5026
 
 
5027
@ @<Output the ivalue headers@>=
 
5028
begin
 
5029
for i_array:= 0 to nki-1 do begin
 
5030
  out_integer(npi[i_array]);
 
5031
  end;
 
5032
end
 
5033
 
 
5034
@ @<Compute the new header information for OFM files@>=
 
5035
begin
 
5036
@<Header information for ivalues@>;
 
5037
@<Header information for fvalues@>;
 
5038
@<Header information for mvalues@>;
 
5039
@<Header information for rules@>;
 
5040
@<Header information for glues@>;
 
5041
@<Header information for penalties@>;
 
5042
end
 
5043
 
 
5044
@ @<Output the new information for OFM files@>=
 
5045
begin
 
5046
@<Output the ivalue headers@>;
 
5047
@<Output the fvalue headers@>;
 
5048
@<Output the mvalue headers@>;
 
5049
@<Output the rule headers@>;
 
5050
@<Output the glue headers@>;
 
5051
@<Output the penalty headers@>;
 
5052
@<Output the ivalues@>;
 
5053
@<Output the fvalues@>;
 
5054
@<Output the rules@>;
 
5055
@<Output the glues@>;
 
5056
@<Output the penalties@>;
 
5057
end
 
5058
 
 
5059
@* System-dependent changes.
 
5060
This section should be replaced, if necessary, by changes to the program
 
5061
that are necessary to make \.{VPtoVF} work at a particular installation.
 
5062
It is usually best to design your change file so that all changes to
 
5063
previous sections preserve the section numbering; then everybody's version
 
5064
will be consistent with the printed program. More extensive changes,
 
5065
which introduce new sections, can be inserted here; then only the index
 
5066
itself will get a new section number.
 
5067
@^system dependencies@>
 
5068
 
 
5069
@* Index.
 
5070
Pointers to error messages appear here together with the section numbers
 
5071
where each ident\-i\-fier is used.