Debian Codegraph @

texk/web2c/mft.ch

raw
1 % mft.ch for C compilation with web2c.
2 %
3 % From Pierre Mackay's version for pc, which was in turn based on Howard
4 % Trickey's and Pavel Curtis's change file for weave.
5 % Support for MP included from a changefile by Wlodek Bzyl.
6 % This file is in the public domain.
7
8 @x [0] l.17 - WEAVE: use logo font to get the S
9 \font\logo=manfnt % font used for the METAFONT logo
10 \def\MF{{\logo META}\-{\logo FONT}}
11 @y
12 \font\logo=manfnt % font used for the METAFONT logo
13 \font\tenlogo=logo10 % font used for the METAPOST logo
14 \def\MF{{\logo META}\-{\logo FONT}}
15 \def\MP{{\tenlogo META}\-{\tenlogo POST}}
16 @z
17
18 @x [0] l.26
19 \def\title{MFT}
20 @y
21 \def\title{MFT changes for C and METAPOST}
22 @z
23
24 @x [0] WEAVE: print changes only.
25 \pageno=\contentspagenumber \advance\pageno by 1
26 @y
27 \pageno=\contentspagenumber \advance\pageno by 1
28 \let\maybe=\iffalse
29 @z
30
31 @x [1]
32 This program converts a \MF\ source file to a \TeX\ file. It was written
33 @y
34 This program converts a \MF\ or \MP\ source file to a \TeX\ file.
35 It was written
36 @z
37 @x [1]
38 @^Knuth, Donald Ervin@>
39 been developed in January, 1980.
40 @y
41 @^Knuth, Donald Ervin@>
42 been developed in January, 1980.
43 @^Bzyl, Wlodek@>
44 Changes for \MP\ by W.~Bzyl in July, 2001.
45 @z
46
47 @x [2] Define my_name
48 @d banner=='This is MFT, Version 2.1'
49 @y
50 @d my_name=='mft'
51 @d banner=='This is MFT, Version 2.1'
52 @z
53
54 % [3] No need for the final label in C.
55 % AIX defines `class' in <math.h>, so let's take this opportunity to
56 % define that away.
57 @x [3]
58 calls the `|jump_out|' procedure, which goes to the label |end_of_MFT|.
59
60 @d end_of_MFT = 9999 {go here to wrap it up}
61 @y
62 calls the `|jump_out|' procedure.
63
64 @d class == class_var
65 @z
66
67 @x [3] No global labels.
68 label end_of_MFT; {go here to finish}
69 @y
70 @z
71
72 @x [3]
73 procedure initialize;
74 var @<Local variables for initialization@>@/
75 begin @<Set initial values@>@/
76 @y
77 @<Define \(|parse_arguments|@>
78 procedure initialize;
79 var @<Local variables for initialization@>@/
80 begin
81 kpse_set_program_name (argv[0], my_name);
82 parse_arguments;
83 @<Set initial values@>;
84 @z
85
86 @x [8] Increase constants.
87 @!max_bytes=10000; {the number of bytes in tokens; must be less than 65536}
88 @!max_names=1000; {number of tokens}
89 @y
90 @!max_bytes=60000; {the number of bytes in tokens; must be less than 65536}
91 @!max_names=6000; {number of tokens}
92 @z
93 @x [8]
94 @!buf_size=100; {maximum length of input line}
95 @!line_length=80; {lines of \TeX\ output have at most this many characters,
96 @y
97 @!buf_size=3000; {maximum length of input line}
98 @!line_length=79; {lines of \TeX\ output have at most this many characters,
99 @z
100
101 % [13] The text_char type is used as an array index into xord. The
102 % default type `char' produces signed integers, which are bad array
103 % indices in C.
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 @x [13]
106 @d text_char == char {the data type of characters in text files}
107 @y
108 @d text_char == ASCII_code {the data type of characters in text files}
109 @z
110
111 @x [17] Allow any input character.
112 for i:=0 to @'37 do xchr[i]:=' ';
113 for i:=@'177 to @'377 do xchr[i]:=' ';
114 @y
115 for i:=1 to @'37 do xchr[i]:=chr(i);
116 for i:=@'177 to @'377 do xchr[i]:=chr(i);
117 @z
118
119 @x [20] Terminal I/O.
120 @d print(#)==write(term_out,#) {`|print|' means write on the terminal}
121 @y
122 @d term_out==stdout
123 @d print(#)==write(term_out,#) {`|print|' means write on the terminal}
124 @z
125
126 @x [20] Remove term_out.
127 @<Globals...@>=
128 @!term_out:text_file; {the terminal as an output file}
129 @y
130 @z
131
132 @x [21] Don't initialize the terminal.
133 @ Different systems have different ways of specifying that the output on a
134 certain file will appear on the user's terminal. Here is one way to do this
135 on the \PASCAL\ system that was used in \.{WEAVE}'s initial development:
136 @^system dependencies@>
137
138 @<Set init...@>=
139 rewrite(term_out,'TTY:'); {send |term_out| output to the terminal}
140 @y
141 @ Different systems have different ways of specifying that the output on a
142 certain file will appear on the user's terminal.
143 @^system dependencies@>
144
145 @<Set init...@>=
146 {nothing need be done}
147 @z
148
149 @x [22] `break' is `fflush'.
150 @d update_terminal == break(term_out) {empty the terminal output buffer}
151 @y
152 @d update_terminal == fflush(term_out) {empty the terminal output buffer}
153 @z
154
155 @x [24] Open input files.
156 @ The following code opens the input files. Since these files were listed
157 in the program header, we assume that the \PASCAL\ runtime system has
158 already checked that suitable file names have been given; therefore no
159 additional error checking needs to be done.
160 @^system dependencies@>
161
162 @p procedure open_input; {prepare to read the inputs}
163 begin reset(mf_file); reset(change_file); reset(style_file);
164 end;
165 @y
166 @ The following code opens the input files.
167 @^system dependencies@>
168
169 @p procedure open_input; {prepare to read inputs}
170 begin
171 if metapost then
172 mf_file := kpse_open_file (cmdline (optind), kpse_mp_format)
173 else
174 mf_file := kpse_open_file (cmdline (optind), kpse_mf_format);
175 if change_name then begin
176 if metapost then
177 change_file := kpse_open_file (change_name, kpse_mp_format)
178 else
179 change_file := kpse_open_file (change_name, kpse_mf_format);
180 end;
181 style_file := kpse_open_file (style_name[0], kpse_mft_format);
182 i_style_name := 1;
183 end;
184 @z
185
186 @x [26] Opening the .tex output file.
187 rewrite(tex_file);
188 @y
189 rewrite (tex_file, tex_name);
190 @z
191
192 @x [28] Fix f^.
193 begin buffer[limit]:=xord[f^]; get(f);
194 incr(limit);
195 if buffer[limit-1]<>" " then final_limit:=limit;
196 if limit=buf_size then
197 begin while not eoln(f) do get(f);
198 @y
199 begin buffer[limit]:=xord[getc(f)];
200 incr(limit);
201 if buffer[limit-1]<>" " then final_limit:=limit;
202 if limit=buf_size then
203 begin while not eoln(f) do vgetc(f);
204 @z
205
206 @x [31] Fix jump_out.
207 @ The |jump_out| procedure just cuts across all active procedure levels
208 and jumps out of the program. This is the only non-local \&{goto} statement
209 in \.{MFT}. It is used when no recovery from a particular error has
210 been provided.
211
212 Some \PASCAL\ compilers do not implement non-local |goto| statements.
213 @^system dependencies@>
214 In such cases the code that appears at label |end_of_MFT| should be
215 copied into the |jump_out| procedure, followed by a call to a system procedure
216 that terminates the program.
217
218 @d fatal_error(#)==begin new_line; print(#); error; mark_fatal; jump_out;
219 end
220
221 @<Error handling...@>=
222 procedure jump_out;
223 begin goto end_of_MFT;
224 end;
225 @y
226 @ The |jump_out| procedure cleans up, prints appropriate messages,
227 and exits back to the operating system.
228
229 @d fatal_error(#)==begin new_line; print(#); error; mark_fatal; jump_out;
230 end
231
232 @<Error handling...@>=
233 procedure jump_out;
234 begin
235 {here files should be closed if the operating system requires it}
236 @<Print the job |history|@>;
237 new_line;
238 if (history <> spotless) and (history <> harmless_message) then
239 uexit(1)
240 else
241 uexit(0);
242 end;
243 @z
244
245 @x [47] -- allow for multiple style files
246 @ @<Read from |style_file|...@>=
247 begin incr(line);
248 if not input_ln(style_file) then
249 begin styling:=false; line:=0;
250 end;
251 end
252 @y
253 @ @<Read from |style_file|...@>=
254 begin incr(line);
255 if not input_ln(style_file) then begin
256 if i_style_name <> n_style_name then begin
257 xfclose(style_file,style_name[i_style_name-1]);
258 style_file := kpse_open_file (style_name[i_style_name], kpse_mft_format);
259 i_style_name := i_style_name + 1;
260 end
261 else begin
262 styling:=false;
263 end;
264 line:=0;
265 end;
266 end
267 @z
268
269 % MFT incorrectly handles TeX code contained in groups:
270 %
271 % btex <TeX material> etex
272 % verbatimtex <TeX material> etex
273 %
274 % Ulrik Vieth (using ideas of Andreas Scherer) developed a Unix
275 % shell script which tries to correct errors made by MFT when
276 % prettyprinting TeX material.
277 % His script converts TeX material to a `TeXnical MFT comment',
278 % which means that it is extracted and prettyprinted as string.
279 % Unfortunately, his script assumes that these groups may not
280 % extend across line breaks and there may be only one such
281 % group per line, which is sometimes hard to obey and
282 % makes prettyprinted code harder to read.
283 % Moreover, any synonym for btex/verbatimtex/etex would not be
284 % recognized. So, if we introduce a change in MFT's formatting
285 % rules with
286 % %%% btex my_btex
287 % i.e. we instruct MFT to format token `my_btex' according the
288 % current convention for `btex' token,
289 % then this new convention would not be obeyed. It is so,
290 % because the script has hardcoded btex/verbatimtex/etex names.
291
292 @x [63]
293 @d input_command=31 {internal code for tokens like `\.{input}'}
294 @d special_tag=32 {internal code for tags that take at most one subscript}
295 @d tag=33 {internal code for nonprimitive tokens}
296 @y
297 @d input_command=31 {internal code for tokens like `\.{input}'}
298 @d btex_code=32 {begin \TeX\ material (\.{btex})}
299 @d verbatim_code=33 {begin \TeX\ material (\.{verbatimtex})}
300 @d etex_marker=34 {end \TeX\ material (\.{etex})}
301 @d special_tag=35 {internal code for tags that take at most one subscript}
302 @d tag=36 {internal code for nonprimitive tokens}
303 @z
304
305 % Now follows the simplest change -- although the bigest one.
306 % The primitives of \MF\ and \MP\ are reshuffled into
307 % three categories:
308 % -- primitives common for \MF\ and \MP
309 % -- primitives specific for \MF
310 % -- primitives specific for \MP
311
312 @x [65]
313 @ The intended use of the macros above might not be immediately obvious,
314 but the riddle is answered by the following:
315
316 @<Store all the primitives@>=
317 id_loc:=18;@/
318 pr2(".")(".")(path_join);@/
319 pr1("[")(as_is);@/
320 pr1("]")(as_is);@/
321 pr1("}")(as_is);@/
322 pr1("{")(as_is);@/
323 pr1(":")(colon);@/
324 pr2(":")(":")(colon);@/
325 pr3("|")("|")(":")(colon);@/
326 pr2(":")("=")(as_is);@/
327 pr1(",")(as_is);@/
328 pr1(";")(semicolon);@/
329 pr1("\")(backslash);@/
330 pr2("\")("\")(double_back);@/
331 pr5("a")("d")("d")("t")("o")(command);@/
332 pr2("a")("t")(bbinary);@/
333 pr7("a")("t")("l")("e")("a")("s")("t")(op);@/
334 pr10("b")("e")("g")("i")("n")("g")("r")("o")("u")("p")(command);
335 pr8("c")("o")("n")("t")("r")("o")("l")("s")(op);@/
336 pr4("c")("u")("l")("l")(command);@/
337 pr4("c")("u")("r")("l")(op);@/
338 pr10("d")("e")("l")("i")("m")("i")("t")("e")("r")("s")(command);@/
339 pr7("d")("i")("s")("p")("l")("a")("y")(command);@/
340 pr8("e")("n")("d")("g")("r")("o")("u")("p")(endit);@/
341 pr8("e")("v")("e")("r")("y")("j")("o")("b")(command);@/
342 pr6("e")("x")("i")("t")("i")("f")(command);@/
343 pr11("e")("x")("p")("a")("n")("d")("a")("f")("t")("e")("r")(command);@/
344 pr4("f")("r")("o")("m")(bbinary);@/
345 pr8("i")("n")("w")("i")("n")("d")("o")("w")(bbinary);@/
346 pr7("i")("n")("t")("e")("r")("i")("m")(command);@/
347 pr3("l")("e")("t")(command);@/
348 pr11("n")("e")("w")("i")("n")("t")("e")("r")("n")("a")("l")(command);@/
349 pr2("o")("f")(command);@/
350 pr10("o")("p")("e")("n")("w")("i")("n")("d")("o")("w")(command);@/
351 pr10("r")("a")("n")("d")("o")("m")("s")("e")("e")("d")(command);@/
352 pr4("s")("a")("v")("e")(command);@/
353 pr10("s")("c")("a")("n")("t")("o")("k")("e")("n")("s")(command);@/
354 pr7("s")("h")("i")("p")("o")("u")("t")(command);@/
355 pr4("s")("t")("e")("p")(bbinary);@/
356 pr3("s")("t")("r")(command);@/
357 pr7("t")("e")("n")("s")("i")("o")("n")(op);@/
358 pr2("t")("o")(bbinary);@/
359 pr5("u")("n")("t")("i")("l")(bbinary);@/
360 pr3("d")("e")("f")(command);@/
361 pr6("v")("a")("r")("d")("e")("f")(command);@/
362
363 @ (There are so many primitives, it's necessary to break this long
364 initialization code up into pieces so as not to overflow \.{WEAVE}'s capacity.)
365
366 @<Store all the primitives@>=
367 pr10("p")("r")("i")("m")("a")("r")("y")("d")("e")("f")(command);@/
368 pr12("s")("e")("c")("o")("n")("d")("a")("r")("y")("d")("e")("f")(command);@/
369 pr11("t")("e")("r")("t")("i")("a")("r")("y")("d")("e")("f")(command);@/
370 pr6("e")("n")("d")("d")("e")("f")(endit);@/
371 pr3("f")("o")("r")(command);@/
372 pr11("f")("o")("r")("s")("u")("f")("f")("i")("x")("e")("s")(command);@/
373 pr7("f")("o")("r")("e")("v")("e")("r")(command);@/
374 pr6("e")("n")("d")("f")("o")("r")(endit);@/
375 pr5("q")("u")("o")("t")("e")(command);@/
376 pr4("e")("x")("p")("r")(command);@/
377 pr6("s")("u")("f")("f")("i")("x")(command);@/
378 pr4("t")("e")("x")("t")(command);@/
379 pr7("p")("r")("i")("m")("a")("r")("y")(command);@/
380 pr9("s")("e")("c")("o")("n")("d")("a")("r")("y")(command);@/
381 pr8("t")("e")("r")("t")("i")("a")("r")("y")(command);@/
382 pr5("i")("n")("p")("u")("t")(input_command);@/
383 pr8("e")("n")("d")("i")("n")("p")("u")("t")(bold);@/
384 pr2("i")("f")(command);@/
385 pr2("f")("i")(endit);@/
386 pr4("e")("l")("s")("e")(command);@/
387 pr6("e")("l")("s")("e")("i")("f")(command);@/
388 pr4("t")("r")("u")("e")(bold);@/
389 pr5("f")("a")("l")("s")("e")(bold);@/
390 pr11("n")("u")("l")("l")("p")("i")("c")("t")("u")("r")("e")(bold);@/
391 pr7("n")("u")("l")("l")("p")("e")("n")(bold);@/
392 pr7("j")("o")("b")("n")("a")("m")("e")(bold);@/
393 pr10("r")("e")("a")("d")("s")("t")("r")("i")("n")("g")(bold);@/
394 pr9("p")("e")("n")("c")("i")("r")("c")("l")("e")(bold);@/
395 pr4("g")("o")("o")("d")(special_tag);@/
396 pr2("=")(":")(as_is);@/
397 pr3("=")(":")("|")(as_is);@/
398 pr4("=")(":")("|")(">")(as_is);@/
399 pr3("|")("=")(":")(as_is);@/
400 pr4("|")("=")(":")(">")(as_is);@/
401 pr4("|")("=")(":")("|")(as_is);@/
402 pr5("|")("=")(":")("|")(">")(as_is);@/
403 pr6("|")("=")(":")("|")(">")(">")(as_is);@/
404 pr4("k")("e")("r")("n")(binary);
405 pr6("s")("k")("i")("p")("t")("o")(command);@/
406
407 @ (Does anybody out there remember the commercials that went \.{LS-MFT}?)
408
409 @<Store all the prim...@>=
410 pr13("n")("o")("r")("m")("a")("l")("d")("e")("v")("i")("a")("t")("e")(op);@/
411 pr3("o")("d")("d")(op);@/
412 pr5("k")("n")("o")("w")("n")(op);@/
413 pr7("u")("n")("k")("n")("o")("w")("n")(op);@/
414 pr3("n")("o")("t")(op);@/
415 pr7("d")("e")("c")("i")("m")("a")("l")(op);@/
416 pr7("r")("e")("v")("e")("r")("s")("e")(op);@/
417 pr8("m")("a")("k")("e")("p")("a")("t")("h")(op);@/
418 pr7("m")("a")("k")("e")("p")("e")("n")(op);@/
419 pr11("t")("o")("t")("a")("l")("w")("e")("i")("g")("h")("t")(op);@/
420 pr3("o")("c")("t")(op);@/
421 pr3("h")("e")("x")(op);@/
422 pr5("A")("S")("C")("I")("I")(op);@/
423 pr4("c")("h")("a")("r")(op);@/
424 pr6("l")("e")("n")("g")("t")("h")(op);@/
425 pr13("t")("u")("r")("n")("i")("n")("g")("n")("u")("m")("b")("e")("r")(op);@/
426 pr5("x")("p")("a")("r")("t")(op);@/
427 pr5("y")("p")("a")("r")("t")(op);@/
428 pr6("x")("x")("p")("a")("r")("t")(op);@/
429 pr6("x")("y")("p")("a")("r")("t")(op);@/
430 pr6("y")("x")("p")("a")("r")("t")(op);@/
431 pr6("y")("y")("p")("a")("r")("t")(op);@/
432 pr4("s")("q")("r")("t")(op);@/
433 pr4("m")("e")("x")("p")(op);@/
434 pr4("m")("l")("o")("g")(op);@/
435 pr4("s")("i")("n")("d")(op);@/
436 pr4("c")("o")("s")("d")(op);@/
437 pr5("f")("l")("o")("o")("r")(op);@/
438 pr14("u")("n")("i")("f")("o")("r")("m")("d")("e")("v")("i")("a")("t")("e")(op);
439 @/
440 pr10("c")("h")("a")("r")("e")("x")("i")("s")("t")("s")(op);@/
441 pr5("a")("n")("g")("l")("e")(op);@/
442 pr5("c")("y")("c")("l")("e")(op);@/
443
444 @ (If you think this \.{WEB} code is ugly, you should see the Pascal code
445 it produces.)
446
447 @<Store all the primitives@>=
448 pr13("t")("r")("a")("c")("i")("n")("g")
449 ("t")("i")("t")("l")("e")("s")(internal);@/
450 pr16("t")("r")("a")("c")("i")("n")("g")
451 ("e")("q")("u")("a")("t")("i")("o")("n")("s")(internal);@/
452 pr15("t")("r")("a")("c")("i")("n")("g")
453 ("c")("a")("p")("s")("u")("l")("e")("s")(internal);@/
454 pr14("t")("r")("a")("c")("i")("n")("g")
455 ("c")("h")("o")("i")("c")("e")("s")(internal);@/
456 pr12("t")("r")("a")("c")("i")("n")("g")
457 ("s")("p")("e")("c")("s")(internal);@/
458 pr11("t")("r")("a")("c")("i")("n")("g")
459 ("p")("e")("n")("s")(internal);@/
460 pr15("t")("r")("a")("c")("i")("n")("g")
461 ("c")("o")("m")("m")("a")("n")("d")("s")(internal);@/
462 pr13("t")("r")("a")("c")("i")("n")("g")
463 ("m")("a")("c")("r")("o")("s")(internal);@/
464 pr12("t")("r")("a")("c")("i")("n")("g")
465 ("e")("d")("g")("e")("s")(internal);@/
466 pr13("t")("r")("a")("c")("i")("n")("g")
467 ("o")("u")("t")("p")("u")("t")(internal);@/
468 pr12("t")("r")("a")("c")("i")("n")("g")
469 ("s")("t")("a")("t")("s")(internal);@/
470 pr13("t")("r")("a")("c")("i")("n")("g")
471 ("o")("n")("l")("i")("n")("e")(internal);@/
472 pr15("t")("r")("a")("c")("i")("n")("g")
473 ("r")("e")("s")("t")("o")("r")("e")("s")(internal);@/
474
475 @ @<Store all the primitives@>=
476 pr4("y")("e")("a")("r")(internal);@/
477 pr5("m")("o")("n")("t")("h")(internal);@/
478 pr3("d")("a")("y")(internal);@/
479 pr4("t")("i")("m")("e")(internal);@/
480 pr8("c")("h")("a")("r")("c")("o")("d")("e")(internal);@/
481 pr7("c")("h")("a")("r")("e")("x")("t")(internal);@/
482 pr6("c")("h")("a")("r")("w")("d")(internal);@/
483 pr6("c")("h")("a")("r")("h")("t")(internal);@/
484 pr6("c")("h")("a")("r")("d")("p")(internal);@/
485 pr6("c")("h")("a")("r")("i")("c")(internal);@/
486 pr6("c")("h")("a")("r")("d")("x")(internal);@/
487 pr6("c")("h")("a")("r")("d")("y")(internal);@/
488 pr10("d")("e")("s")("i")("g")("n")("s")("i")("z")("e")(internal);@/
489 pr4("h")("p")("p")("p")(internal);@/
490 pr4("v")("p")("p")("p")(internal);@/
491 pr7("x")("o")("f")("f")("s")("e")("t")(internal);@/
492 pr7("y")("o")("f")("f")("s")("e")("t")(internal);@/
493 pr7("p")("a")("u")("s")("i")("n")("g")(internal);@/
494 pr12("s")("h")("o")("w")
495 ("s")("t")("o")("p")("p")("i")("n")("g")(internal);@/
496 pr10("f")("o")("n")("t")("m")("a")("k")("i")("n")("g")(internal);@/
497 pr8("p")("r")("o")("o")("f")("i")("n")("g")(internal);@/
498 pr9("s")("m")("o")("o")("t")("h")("i")("n")("g")(internal);@/
499 pr12("a")("u")("t")("o")("r")("o")("u")("n")("d")("i")("n")("g")(internal);@/
500 pr11("g")("r")("a")("n")("u")("l")("a")("r")("i")("t")("y")(internal);@/
501 pr6("f")("i")("l")("l")("i")("n")(internal);@/
502 pr12("t")("u")("r")("n")("i")("n")("g")("c")("h")("e")("c")("k")(internal);@/
503 pr12("w")("a")("r")("n")("i")("n")("g")("c")("h")("e")("c")("k")(internal);@/
504 pr12("b")("o")("u")("n")("d")("a")("r")("y")("c")("h")("a")("r")(internal);@/
505
506 @ Still more.
507
508 @<Store all the prim...@>=
509 pr1("+")(abinary);@/
510 pr1("-")(abinary);@/
511 pr1("*")(abinary);@/
512 pr1("/")(as_is);@/
513 pr2("+")("+")(binary);@/
514 pr3("+")("-")("+")(pyth_sub);@/
515 pr3("a")("n")("d")(binary);@/
516 pr2("o")("r")(binary);@/
517 pr1("<")(as_is);@/
518 pr2("<")("=")(less_or_equal);@/
519 pr1(">")(as_is);@/
520 pr2(">")("=")(greater_or_equal);@/
521 pr1("=")(as_is);@/
522 pr2("<")(">")(not_equal);@/
523 pr9("s")("u")("b")("s")("t")("r")("i")("n")("g")(command);@/
524 pr7("s")("u")("b")("p")("a")("t")("h")(command);@/
525 pr13("d")("i")("r")("e")("c")("t")("i")("o")("n")@|
526 ("t")("i")("m")("e")(command);@/
527 pr5("p")("o")("i")("n")("t")(command);@/
528 pr10("p")("r")("e")("c")("o")("n")("t")("r")("o")("l")(command);@/
529 pr11("p")("o")("s")("t")("c")("o")("n")("t")("r")("o")("l")(command);@/
530 pr9("p")("e")("n")("o")("f")("f")("s")("e")("t")(command);@/
531 pr1("&")(ampersand);@/
532 pr7("r")("o")("t")("a")("t")("e")("d")(binary);@/
533 pr7("s")("l")("a")("n")("t")("e")("d")(binary);@/
534 pr6("s")("c")("a")("l")("e")("d")(binary);@/
535 pr7("s")("h")("i")("f")("t")("e")("d")(binary);@/
536 pr11("t")("r")("a")("n")("s")("f")("o")("r")("m")("e")("d")(binary);@/
537 pr7("x")("s")("c")("a")("l")("e")("d")(binary);@/
538 pr7("y")("s")("c")("a")("l")("e")("d")(binary);@/
539 pr7("z")("s")("c")("a")("l")("e")("d")(binary);@/
540 pr17("i")("n")("t")("e")("r")("s")("e")("c")("t")("i")("o")("n")@|
541 ("t")("i")("m")("e")("s")(binary);@/
542 pr7("n")("u")("m")("e")("r")("i")("c")(type_name);@/
543 pr6("s")("t")("r")("i")("n")("g")(type_name);@/
544 pr7("b")("o")("o")("l")("e")("a")("n")(type_name);@/
545 pr4("p")("a")("t")("h")(type_name);@/
546 pr3("p")("e")("n")(type_name);@/
547 pr7("p")("i")("c")("t")("u")("r")("e")(type_name);@/
548 pr9("t")("r")("a")("n")("s")("f")("o")("r")("m")(type_name);@/
549 pr4("p")("a")("i")("r")(type_name);@/
550
551 @ At last we are done with the tedious initialization of primitives.
552
553 @<Store all the prim...@>=
554 pr3("e")("n")("d")(endit);@/
555 pr4("d")("u")("m")("p")(endit);@/
556 pr9("b")("a")("t")("c")("h")("m")("o")("d")("e")(bold);
557 pr11("n")("o")("n")("s")("t")("o")("p")("m")("o")("d")("e")(bold);
558 pr10("s")("c")("r")("o")("l")("l")("m")("o")("d")("e")(bold);
559 pr13("e")("r")("r")("o")("r")("s")("t")("o")("p")@|
560 ("m")("o")("d")("e")(bold);
561 pr5("i")("n")("n")("e")("r")(command);@/
562 pr5("o")("u")("t")("e")("r")(command);@/
563 pr9("s")("h")("o")("w")("t")("o")("k")("e")("n")(command);@/
564 pr9("s")("h")("o")("w")("s")("t")("a")("t")("s")(bold);@/
565 pr4("s")("h")("o")("w")(command);@/
566 pr12("s")("h")("o")("w")("v")("a")("r")("i")("a")("b")("l")("e")(command);@/
567 pr16("s")("h")("o")("w")@|
568 ("d")("e")("p")("e")("n")("d")("e")("n")("c")("i")("e")("s")(bold);@/
569 pr7("c")("o")("n")("t")("o")("u")("r")(command);@/
570 pr10("d")("o")("u")("b")("l")("e")("p")("a")("t")("h")(command);@/
571 pr4("a")("l")("s")("o")(command);@/
572 pr7("w")("i")("t")("h")("p")("e")("n")(command);@/
573 pr10("w")("i")("t")("h")("w")("e")("i")("g")("h")("t")(command);@/
574 pr8("d")("r")("o")("p")("p")("i")("n")("g")(command);@/
575 pr7("k")("e")("e")("p")("i")("n")("g")(command);@/
576 pr7("m")("e")("s")("s")("a")("g")("e")(command);@/
577 pr10("e")("r")("r")("m")("e")("s")("s")("a")("g")("e")(command);@/
578 pr7("e")("r")("r")("h")("e")("l")("p")(command);@/
579 pr8("c")("h")("a")("r")("l")("i")("s")("t")(command);@/
580 pr8("l")("i")("g")("t")("a")("b")("l")("e")(command);@/
581 pr10("e")("x")("t")("e")("n")("s")("i")("b")("l")("e")(command);@/
582 pr10("h")("e")("a")("d")("e")("r")("b")("y")("t")("e")(command);@/
583 pr9("f")("o")("n")("t")("d")("i")("m")("e")("n")(command);@/
584 pr7("s")("p")("e")("c")("i")("a")("l")(command);@/
585 pr10("n")("u")("m")("s")("p")("e")("c")("i")("a")("l")(command);@/
586 pr1("%")(comment);@/
587 pr2("%")("%")(verbatim);@/
588 pr3("%")("%")("%")(set_format);@/
589 pr4("%")("%")("%")("%")(mft_comment);@/
590 pr1("#")(sharp);@/
591 @y
592 @ We begin with primitives common to \MF\ and \MP.
593
594 The intended use of the macros above might not be immediately obvious,
595 but the riddle is answered by the following:
596
597 @<Store all the primitives@>=
598 id_loc:=18;@/
599 pr2(".")(".")(path_join);@/
600 pr1("[")(as_is);@/
601 pr1("]")(as_is);@/
602 pr1("}")(as_is);@/
603 pr1("{")(as_is);@/
604 pr1(":")(colon);@/
605 pr2(":")(":")(colon);@/
606 pr3("|")("|")(":")(colon);@/
607 pr2(":")("=")(as_is);@/
608 pr1(",")(as_is);@/
609 pr1(";")(semicolon);@/
610 pr1("\")(backslash);@/
611 pr2("\")("\")(double_back);@/
612 pr5("a")("d")("d")("t")("o")(command);@/
613 pr2("a")("t")(bbinary);@/
614 pr7("a")("t")("l")("e")("a")("s")("t")(op);@/
615 pr10("b")("e")("g")("i")("n")("g")("r")("o")("u")("p")(command);
616 pr8("c")("o")("n")("t")("r")("o")("l")("s")(op);@/
617 pr4("c")("u")("l")("l")(command);@/
618 pr4("c")("u")("r")("l")(op);@/
619 pr10("d")("e")("l")("i")("m")("i")("t")("e")("r")("s")(command);@/
620 pr8("e")("n")("d")("g")("r")("o")("u")("p")(endit);@/
621 pr8("e")("v")("e")("r")("y")("j")("o")("b")(command);@/
622 pr6("e")("x")("i")("t")("i")("f")(command);@/
623 pr11("e")("x")("p")("a")("n")("d")("a")("f")("t")("e")("r")(command);@/
624 pr4("f")("r")("o")("m")(bbinary);@/
625 pr7("i")("n")("t")("e")("r")("i")("m")(command);@/
626 pr3("l")("e")("t")(command);@/
627 pr11("n")("e")("w")("i")("n")("t")("e")("r")("n")("a")("l")(command);@/
628 pr2("o")("f")(command);@/
629 pr10("r")("a")("n")("d")("o")("m")("s")("e")("e")("d")(command);@/
630 pr4("s")("a")("v")("e")(command);@/
631 pr10("s")("c")("a")("n")("t")("o")("k")("e")("n")("s")(command);@/
632 pr7("s")("h")("i")("p")("o")("u")("t")(command);@/
633 pr4("s")("t")("e")("p")(bbinary);@/
634 pr3("s")("t")("r")(command);@/
635 pr7("t")("e")("n")("s")("i")("o")("n")(op);@/
636 pr2("t")("o")(bbinary);@/
637 pr5("u")("n")("t")("i")("l")(bbinary);@/
638 pr3("d")("e")("f")(command);@/
639 pr6("v")("a")("r")("d")("e")("f")(command);@/
640
641 @ (There are so many primitives, it's necessary to break this long
642 initialization code up into pieces so as not to overflow \.{WEAVE}'s capacity.)
643
644 @<Store all the primitives@>=
645 pr10("p")("r")("i")("m")("a")("r")("y")("d")("e")("f")(command);@/
646 pr12("s")("e")("c")("o")("n")("d")("a")("r")("y")("d")("e")("f")(command);@/
647 pr11("t")("e")("r")("t")("i")("a")("r")("y")("d")("e")("f")(command);@/
648 pr6("e")("n")("d")("d")("e")("f")(endit);@/
649 pr3("f")("o")("r")(command);@/
650 pr11("f")("o")("r")("s")("u")("f")("f")("i")("x")("e")("s")(command);@/
651 pr7("f")("o")("r")("e")("v")("e")("r")(command);@/
652 pr6("e")("n")("d")("f")("o")("r")(endit);@/
653 pr5("q")("u")("o")("t")("e")(command);@/
654 pr4("e")("x")("p")("r")(command);@/
655 pr6("s")("u")("f")("f")("i")("x")(command);@/
656 pr4("t")("e")("x")("t")(command);@/
657 pr7("p")("r")("i")("m")("a")("r")("y")(command);@/
658 pr9("s")("e")("c")("o")("n")("d")("a")("r")("y")(command);@/
659 pr8("t")("e")("r")("t")("i")("a")("r")("y")(command);@/
660 pr5("i")("n")("p")("u")("t")(input_command);@/
661 pr8("e")("n")("d")("i")("n")("p")("u")("t")(bold);@/
662 pr2("i")("f")(command);@/
663 pr2("f")("i")(endit);@/
664 pr4("e")("l")("s")("e")(command);@/
665 pr6("e")("l")("s")("e")("i")("f")(command);@/
666 pr4("t")("r")("u")("e")(bold);@/
667 pr5("f")("a")("l")("s")("e")(bold);@/
668 pr11("n")("u")("l")("l")("p")("i")("c")("t")("u")("r")("e")(bold);@/
669 pr7("n")("u")("l")("l")("p")("e")("n")(bold);@/
670 pr7("j")("o")("b")("n")("a")("m")("e")(bold);@/
671 pr10("r")("e")("a")("d")("s")("t")("r")("i")("n")("g")(bold);@/
672 pr9("p")("e")("n")("c")("i")("r")("c")("l")("e")(bold);@/
673 pr2("=")(":")(as_is);@/
674 pr3("=")(":")("|")(as_is);@/
675 pr4("=")(":")("|")(">")(as_is);@/
676 pr3("|")("=")(":")(as_is);@/
677 pr4("|")("=")(":")(">")(as_is);@/
678 pr4("|")("=")(":")("|")(as_is);@/
679 pr5("|")("=")(":")("|")(">")(as_is);@/
680 pr6("|")("=")(":")("|")(">")(">")(as_is);@/
681 pr4("k")("e")("r")("n")(binary);
682 pr6("s")("k")("i")("p")("t")("o")(command);@/
683
684 @ (Does anybody out there remember the commercials that went \.{LS-MFT}?)
685
686 @<Store all the prim...@>=
687 pr13("n")("o")("r")("m")("a")("l")("d")("e")("v")("i")("a")("t")("e")(op);@/
688 pr3("o")("d")("d")(op);@/
689 pr5("k")("n")("o")("w")("n")(op);@/
690 pr7("u")("n")("k")("n")("o")("w")("n")(op);@/
691 pr3("n")("o")("t")(op);@/
692 pr7("d")("e")("c")("i")("m")("a")("l")(op);@/
693 pr7("r")("e")("v")("e")("r")("s")("e")(op);@/
694 pr8("m")("a")("k")("e")("p")("a")("t")("h")(op);@/
695 pr7("m")("a")("k")("e")("p")("e")("n")(op);@/
696 pr3("o")("c")("t")(op);@/
697 pr3("h")("e")("x")(op);@/
698 pr5("A")("S")("C")("I")("I")(op);@/
699 pr4("c")("h")("a")("r")(op);@/
700 pr6("l")("e")("n")("g")("t")("h")(op);@/
701 pr13("t")("u")("r")("n")("i")("n")("g")("n")("u")("m")("b")("e")("r")(op);@/
702 pr5("x")("p")("a")("r")("t")(op);@/
703 pr5("y")("p")("a")("r")("t")(op);@/
704 pr6("x")("x")("p")("a")("r")("t")(op);@/
705 pr6("x")("y")("p")("a")("r")("t")(op);@/
706 pr6("y")("x")("p")("a")("r")("t")(op);@/
707 pr6("y")("y")("p")("a")("r")("t")(op);@/
708 pr4("s")("q")("r")("t")(op);@/
709 pr4("m")("e")("x")("p")(op);@/
710 pr4("m")("l")("o")("g")(op);@/
711 pr4("s")("i")("n")("d")(op);@/
712 pr4("c")("o")("s")("d")(op);@/
713 pr5("f")("l")("o")("o")("r")(op);@/
714 pr14("u")("n")("i")("f")("o")("r")("m")("d")("e")("v")("i")("a")("t")("e")(op);
715 @/
716 pr10("c")("h")("a")("r")("e")("x")("i")("s")("t")("s")(op);@/
717 pr5("a")("n")("g")("l")("e")(op);@/
718 pr5("c")("y")("c")("l")("e")(op);@/
719
720 @ (If you think this \.{WEB} code is ugly, you should see the Pascal code
721 it produces.)
722
723 @<Store all the primitives@>=
724 pr13("t")("r")("a")("c")("i")("n")("g")
725 ("t")("i")("t")("l")("e")("s")(internal);@/
726 pr16("t")("r")("a")("c")("i")("n")("g")
727 ("e")("q")("u")("a")("t")("i")("o")("n")("s")(internal);@/
728 pr15("t")("r")("a")("c")("i")("n")("g")
729 ("c")("a")("p")("s")("u")("l")("e")("s")(internal);@/
730 pr14("t")("r")("a")("c")("i")("n")("g")
731 ("c")("h")("o")("i")("c")("e")("s")(internal);@/
732 pr12("t")("r")("a")("c")("i")("n")("g")
733 ("s")("p")("e")("c")("s")(internal);@/
734 pr11("t")("r")("a")("c")("i")("n")("g")
735 ("p")("e")("n")("s")(internal);@/
736 pr15("t")("r")("a")("c")("i")("n")("g")
737 ("c")("o")("m")("m")("a")("n")("d")("s")(internal);@/
738 pr13("t")("r")("a")("c")("i")("n")("g")
739 ("m")("a")("c")("r")("o")("s")(internal);@/
740 pr13("t")("r")("a")("c")("i")("n")("g")
741 ("o")("u")("t")("p")("u")("t")(internal);@/
742 pr12("t")("r")("a")("c")("i")("n")("g")
743 ("s")("t")("a")("t")("s")(internal);@/
744 pr13("t")("r")("a")("c")("i")("n")("g")
745 ("o")("n")("l")("i")("n")("e")(internal);@/
746 pr15("t")("r")("a")("c")("i")("n")("g")
747 ("r")("e")("s")("t")("o")("r")("e")("s")(internal);@/
748
749 @ @<Store all the primitives@>=
750 pr4("y")("e")("a")("r")(internal);@/
751 pr5("m")("o")("n")("t")("h")(internal);@/
752 pr3("d")("a")("y")(internal);@/
753 pr4("t")("i")("m")("e")(internal);@/
754 pr8("c")("h")("a")("r")("c")("o")("d")("e")(internal);@/
755 pr7("c")("h")("a")("r")("e")("x")("t")(internal);@/
756 pr6("c")("h")("a")("r")("w")("d")(internal);@/
757 pr6("c")("h")("a")("r")("h")("t")(internal);@/
758 pr6("c")("h")("a")("r")("d")("p")(internal);@/
759 pr6("c")("h")("a")("r")("i")("c")(internal);@/
760 pr6("c")("h")("a")("r")("d")("x")(internal);@/
761 pr6("c")("h")("a")("r")("d")("y")(internal);@/
762 pr10("d")("e")("s")("i")("g")("n")("s")("i")("z")("e")(internal);@/
763 pr7("x")("o")("f")("f")("s")("e")("t")(internal);@/
764 pr7("y")("o")("f")("f")("s")("e")("t")(internal);@/
765 pr7("p")("a")("u")("s")("i")("n")("g")(internal);@/
766 pr12("s")("h")("o")("w")
767 ("s")("t")("o")("p")("p")("i")("n")("g")(internal);@/
768 pr10("f")("o")("n")("t")("m")("a")("k")("i")("n")("g")(internal);@/
769 pr8("p")("r")("o")("o")("f")("i")("n")("g")(internal);@/
770 pr12("t")("u")("r")("n")("i")("n")("g")("c")("h")("e")("c")("k")(internal);@/
771 pr12("w")("a")("r")("n")("i")("n")("g")("c")("h")("e")("c")("k")(internal);@/
772 pr12("b")("o")("u")("n")("d")("a")("r")("y")("c")("h")("a")("r")(internal);@/
773
774 @ Still more.
775
776 @<Store all the prim...@>=
777 pr1("+")(abinary);@/
778 pr1("-")(abinary);@/
779 pr1("*")(abinary);@/
780 pr1("/")(as_is);@/
781 pr2("+")("+")(binary);@/
782 pr3("+")("-")("+")(pyth_sub);@/
783 pr3("a")("n")("d")(binary);@/
784 pr2("o")("r")(binary);@/
785 pr1("<")(as_is);@/
786 pr2("<")("=")(less_or_equal);@/
787 pr1(">")(as_is);@/
788 pr2(">")("=")(greater_or_equal);@/
789 pr1("=")(as_is);@/
790 pr2("<")(">")(not_equal);@/
791 pr9("s")("u")("b")("s")("t")("r")("i")("n")("g")(command);@/
792 pr7("s")("u")("b")("p")("a")("t")("h")(command);@/
793 pr13("d")("i")("r")("e")("c")("t")("i")("o")("n")@|
794 ("t")("i")("m")("e")(command);@/
795 pr5("p")("o")("i")("n")("t")(command);@/
796 pr10("p")("r")("e")("c")("o")("n")("t")("r")("o")("l")(command);@/
797 pr11("p")("o")("s")("t")("c")("o")("n")("t")("r")("o")("l")(command);@/
798 pr9("p")("e")("n")("o")("f")("f")("s")("e")("t")(command);@/
799 pr1("&")(ampersand);@/
800 pr7("r")("o")("t")("a")("t")("e")("d")(binary);@/
801 pr7("s")("l")("a")("n")("t")("e")("d")(binary);@/
802 pr6("s")("c")("a")("l")("e")("d")(binary);@/
803 pr7("s")("h")("i")("f")("t")("e")("d")(binary);@/
804 pr11("t")("r")("a")("n")("s")("f")("o")("r")("m")("e")("d")(binary);@/
805 pr7("x")("s")("c")("a")("l")("e")("d")(binary);@/
806 pr7("y")("s")("c")("a")("l")("e")("d")(binary);@/
807 pr7("z")("s")("c")("a")("l")("e")("d")(binary);@/
808 pr17("i")("n")("t")("e")("r")("s")("e")("c")("t")("i")("o")("n")@|
809 ("t")("i")("m")("e")("s")(binary);@/
810 pr7("n")("u")("m")("e")("r")("i")("c")(type_name);@/
811 pr6("s")("t")("r")("i")("n")("g")(type_name);@/
812 pr7("b")("o")("o")("l")("e")("a")("n")(type_name);@/
813 pr4("p")("a")("t")("h")(type_name);@/
814 pr3("p")("e")("n")(type_name);@/
815 pr7("p")("i")("c")("t")("u")("r")("e")(type_name);@/
816 pr9("t")("r")("a")("n")("s")("f")("o")("r")("m")(type_name);@/
817 pr4("p")("a")("i")("r")(type_name);@/
818
819 @ At last we are done with the tedious initialization of primitives.
820
821 @<Store all the prim...@>=
822 pr3("e")("n")("d")(endit);@/
823 pr4("d")("u")("m")("p")(endit);@/
824 pr9("b")("a")("t")("c")("h")("m")("o")("d")("e")(bold);
825 pr11("n")("o")("n")("s")("t")("o")("p")("m")("o")("d")("e")(bold);
826 pr10("s")("c")("r")("o")("l")("l")("m")("o")("d")("e")(bold);
827 pr13("e")("r")("r")("o")("r")("s")("t")("o")("p")@|
828 ("m")("o")("d")("e")(bold);
829 pr5("i")("n")("n")("e")("r")(command);@/
830 pr5("o")("u")("t")("e")("r")(command);@/
831 pr9("s")("h")("o")("w")("t")("o")("k")("e")("n")(command);@/
832 pr9("s")("h")("o")("w")("s")("t")("a")("t")("s")(bold);@/
833 pr4("s")("h")("o")("w")(command);@/
834 pr12("s")("h")("o")("w")("v")("a")("r")("i")("a")("b")("l")("e")(command);@/
835 pr16("s")("h")("o")("w")@|
836 ("d")("e")("p")("e")("n")("d")("e")("n")("c")("i")("e")("s")(bold);@/
837 pr7("c")("o")("n")("t")("o")("u")("r")(command);@/
838 pr10("d")("o")("u")("b")("l")("e")("p")("a")("t")("h")(command);@/
839 pr4("a")("l")("s")("o")(command);@/
840 pr7("w")("i")("t")("h")("p")("e")("n")(command);@/
841 pr7("m")("e")("s")("s")("a")("g")("e")(command);@/
842 pr10("e")("r")("r")("m")("e")("s")("s")("a")("g")("e")(command);@/
843 pr7("e")("r")("r")("h")("e")("l")("p")(command);@/
844 pr8("c")("h")("a")("r")("l")("i")("s")("t")(command);@/
845 pr8("l")("i")("g")("t")("a")("b")("l")("e")(command);@/
846 pr10("e")("x")("t")("e")("n")("s")("i")("b")("l")("e")(command);@/
847 pr10("h")("e")("a")("d")("e")("r")("b")("y")("t")("e")(command);@/
848 pr9("f")("o")("n")("t")("d")("i")("m")("e")("n")(command);@/
849 pr7("s")("p")("e")("c")("i")("a")("l")(command);@/
850 pr1("%")(comment);@/
851 pr2("%")("%")(verbatim);@/
852 pr3("%")("%")("%")(set_format);@/
853 pr4("%")("%")("%")("%")(mft_comment);@/
854 pr1("#")(sharp);@/
855 pr4("g")("o")("o")("d")(special_tag);@/
856 @z
857
858 @x [75] The code below follows ideas from the section 646 of `mp.web'.
859 two global variables, |cur_type| and |cur_tok|.
860 @y
861 two global variables, |cur_type| and |cur_tok|.
862
863 The \&{btex}$\,\ldots\,$\&{etex} and \&{verbatimtex}$\,\ldots\,$\&{etex}
864 features need to be implemented at a low level in the scanning
865 process. This is implemented by changing the behavior of the
866 scanner via |scanner_status| global variable.
867
868 @d normal=0 {|scanner_status| at ``quiet times''}
869 @d verbatimtex_flushing=1 {|scanner_status| when moving verbatim \TeX\ material}
870 @d btex_flushing=2 {|scanner_status| when moving \TeX\ code}
871 @z
872
873 @x [75]
874 @!prev_tok:integer; {previous value of |cur_tok|}
875 @y
876 @!prev_tok:integer; {previous value of |cur_tok|}
877 @!scanner_status:normal..btex_flushing; {are we scanning at high speed?}
878 @z
879
880 @x [79] Allow any 8 bit character in input.
881 for i:=0 to " "-1 do char_class[i]:=invalid_class;
882 char_class[carriage_return]:=end_line_class;@/
883 for i:=127 to 255 do char_class[i]:=invalid_class;
884 @y
885 for i:=0 to " "-1 do char_class[i]:=letter_class;
886 for i:=127 to 255 do char_class[i]:=letter_class;
887 char_class[carriage_return]:=end_line_class;
888 char_class[@'11]:=space_class; {tab}
889 char_class[@'14]:=space_class; {form feed}
890 @z
891
892 @x [81] When dealing with a TeX material we must copy spaces to output.
893 space_class:if start_of_line then emit(indentation)
894 else goto switch;
895 @y
896 space_class:if start_of_line or scanner_status>normal then emit(indentation)
897 else goto switch;
898 @z
899
900 @x [88] Set the default set of macros for \MP.
901 so that the first line of the output file will be `\.{\\input mftmac}'.
902 @.\\input mftmac@>
903 @.mftmac@>
904
905 @<Set init...@>=
906 out_ptr:=1; out_buf[1]:=" "; out_line:=1; write(tex_file,'\input mftmac');
907 @y
908 so that the first line of the output file will be `\.{\\input mftmac}'
909 or `\.{\\input mptmac}' if a \MP\ file is converted.
910 @.\\input mftmac@>
911 @.mftmac@>
912 @.\\input mptmac@>
913 @.mptmac@>
914 @<Set init...@>=
915 out_ptr:=1; out_buf[1]:=" "; out_line:=1;
916 if metapost then begin write(tex_file,'\input mptmac'); end
917 else write(tex_file,'\input mftmac');
918 @z
919
920 @x [97]
921 string_token:@<Translate a string token@>;
922 @y
923 string_token:@<Translate a string token@>;
924 verbatim_code,btex_code:@<Copy \TeX\ material@>;
925 @z
926
927 % [112] Print newline at end of run, exit based upon value of history,
928 % and remove the end_of_MFT label.
929 @x [112]
930 print_ln(banner); {print a ``banner line''}
931 @y
932 print (banner); {print a ``banner line''}
933 print_ln (version_string);
934 @z
935
936 @x [112]
937 end_of_MFT:{here files should be closed if the operating system requires it}
938 @<Print the job |history|@>;
939 end.
940 @y
941 @<Print the job |history|@>;
942 new_line;
943 if (history <> spotless) and (history <> harmless_message)
944 then uexit (1)
945 else uexit (0);
946 end.
947 @z
948
949 @x [114] System-dependent changes.
950 This module should be replaced, if necessary, by changes to the program
951 that are necessary to make \.{MFT} work at a particular installation.
952 It is usually best to design your change file so that all changes to
953 previous modules preserve the module numbering; then everybody's version
954 will be consistent with the printed program. More extensive changes,
955 which introduce new modules, can be inserted here; then only the index
956 itself will get a new module number.
957 @^system dependencies@>
958 @y
959 The user calls \.{MFT} with arguments on the command line. These are
960 either filenames or flags (beginning with `\.-'). The following globals
961 are for communicating the user's desires to the rest of the program. The
962 various |name| variables contain strings with the full names of those
963 files, as UNIX knows them.
964
965 @d max_style_name = 32
966
967 @<Globals...@>=
968 @!change_name,@!tex_name:const_c_string;
969 @!style_name:array[0..max_style_name-1] of const_c_string;
970 @!n_style_name:c_int_type; {Number of values in |style_name| array.}
971 @!i_style_name:c_int_type; {The next |style_name|.}
972 @!metapost:c_int_type; {|true| for \MP, |false| for \MF}
973
974 @ Look at the command line arguments and set the |name| variables accordingly.
975
976 At least one file name must be present as the first argument: the \.{mf}
977 file. It may have an extension, or it may omit it to get |'.mf'| added.
978 If there is only one file name, the output file name is formed by
979 replacing the \.{mf} file name extension by |'.tex'|. Thus, the command
980 line \.{mf foo} implies the use of the \MF\ input file \.{foo.mf}
981 and the output file \.{foo.tex}. If this style of command line, with
982 only one argument, is used, the default style file, |plain.mft|, will be
983 used to provide basic formatting.
984
985 @d argument_is (#) == (strcmp (long_options[option_index].name, #) = 0)
986
987 @<Define \(|parse_arguments|@> =
988 procedure parse_arguments;
989 const n_options = 5; {Pascal won't count array lengths for us.}
990 var @!long_options: array[0..n_options] of getopt_struct;
991 @!getopt_return_val: integer;
992 @!option_index: c_int_type;
993 @!current_option: 0..n_options;
994 @!suffix: const_c_string;
995 begin
996 @<Initialize the option variables@>;
997 @<Define the option table@>;
998 n_style_name := 0;
999 repeat
1000 getopt_return_val := getopt_long_only (argc, argv, '', long_options,
1001 address_of (option_index));
1002 if getopt_return_val = -1 then begin
1003 do_nothing; {End of arguments; we exit the loop below.}
1004
1005 end else if getopt_return_val = "?" then begin
1006 usage (my_name);
1007
1008 end else if argument_is ('help') then begin
1009 usage_help (MFT_HELP, nil);
1010
1011 end else if argument_is ('version') then begin
1012 print_version_and_exit (banner, nil,
1013 'D.E. Knuth (MP changes by W. Bzyl)',
1014 nil);
1015
1016 end else if argument_is ('change') then begin
1017 change_name := extend_filename (optarg, 'ch');
1018
1019 end else if argument_is ('style') then begin
1020 if (n_style_name = max_style_name) then begin
1021 fatal_error ('Too many style files specified.');
1022 usage (my_name);
1023 end;
1024 style_name[n_style_name] := extend_filename (optarg, 'mft');
1025 n_style_name := n_style_name + 1;
1026
1027 end; {Else it was a flag; |getopt| has already done the assignment.}
1028 until getopt_return_val = -1;
1029
1030 {Now |optind| is the index of first non-option on the command line.
1031 We must have exactly one remaining argument.}
1032 if (optind + 1 <> argc) then begin
1033 write_ln (stderr, my_name, ': Need exactly one file argument.');
1034 usage (my_name);
1035 end;
1036
1037 suffix := find_suffix (cmdline (optind));
1038 if suffix and (strcmp (suffix, 'mp') = 0) then begin
1039 metapost := true;
1040 tex_name := basename_change_suffix (cmdline (optind), '.mp', '.tex');
1041 end else begin
1042 tex_name := basename_change_suffix (cmdline (optind), '.mf', '.tex');
1043 end;
1044
1045 if (n_style_name = 0) then begin
1046 if metapost then
1047 style_name[0] := 'mplain.mft'
1048 else
1049 style_name[0] := 'plain.mft';
1050 n_style_name := 1;
1051 end;
1052 end;
1053
1054 @ Here are the options we allow. The first is one of the standard GNU options.
1055 @.-help@>
1056
1057 @<Define the option...@> =
1058 current_option := 0;
1059 long_options[current_option].name := 'help';
1060 long_options[current_option].has_arg := 0;
1061 long_options[current_option].flag := 0;
1062 long_options[current_option].val := 0;
1063 incr (current_option);
1064
1065 @ Another of the standard options.
1066 @.-version@>
1067
1068 @<Define the option...@> =
1069 long_options[current_option].name := 'version';
1070 long_options[current_option].has_arg := 0;
1071 long_options[current_option].flag := 0;
1072 long_options[current_option].val := 0;
1073 incr (current_option);
1074
1075 @ Here is the option to set a change file.
1076 @.-change@>
1077
1078 @<Define the option...@> =
1079 long_options[current_option].name := 'change';
1080 long_options[current_option].has_arg := 1;
1081 long_options[current_option].flag := 0;
1082 long_options[current_option].val := 0;
1083 incr (current_option);
1084
1085 @ Here is the option to set the style file.
1086 @.-style@>
1087
1088 @<Define the option...@> =
1089 long_options[current_option].name := 'style';
1090 long_options[current_option].has_arg := 1;
1091 long_options[current_option].flag := 0;
1092 long_options[current_option].val := 0;
1093 incr (current_option);
1094
1095 @ The option to set a \MP\ file processing.
1096
1097 @<Define the option...@> =
1098 long_options[current_option].name := 'metapost';
1099 long_options[current_option].has_arg := 0;
1100 long_options[current_option].flag := address_of (metapost);
1101 long_options[current_option].val := 1;
1102 incr (current_option);
1103
1104 @ |metapost| defaults to |false|; will become |true| for \MP.
1105
1106 @<Initialize the option...@> =
1107 metapost:=false;
1108
1109 @ An element with all zeros always ends the list of options.
1110
1111 @<Define the option...@> =
1112 long_options[current_option].name := 0;
1113 long_options[current_option].has_arg := 0;
1114 long_options[current_option].flag := 0;
1115 long_options[current_option].val := 0;
1116
1117 @ Store primitives specific for \MF.
1118
1119 @<Store all the prim...@>=
1120 if not metapost then begin
1121 pr12("a")("u")("t")("o")("r")("o")("u")("n")("d")("i")("n")("g")(internal);@/
1122 pr7("c")("h")("a")("r")("f")("a")("m")(internal);@/
1123 pr8("d")("r")("o")("p")("p")("i")("n")("g")(command);@/
1124 pr7("d")("i")("s")("p")("l")("a")("y")(command);@/
1125 pr6("f")("i")("l")("l")("i")("n")(internal);@/
1126 pr11("g")("r")("a")("n")("u")("l")("a")("r")("i")("t")("y")(internal);@/
1127 pr8("i")("n")("w")("i")("n")("d")("o")("w")(bbinary);@/
1128 pr4("h")("p")("p")("p")(internal);@/
1129 pr7("k")("e")("e")("p")("i")("n")("g")(command);@/
1130 pr10("n")("u")("m")("s")("p")("e")("c")("i")("a")("l")(command);@/
1131 pr10("o")("p")("e")("n")("w")("i")("n")("d")("o")("w")(command);@/
1132 pr9("s")("m")("o")("o")("t")("h")("i")("n")("g")(internal);@/
1133 pr4("v")("p")("p")("p")(internal);@/
1134 pr11("t")("o")("t")("a")("l")("w")("e")("i")("g")("h")("t")(op);@/
1135 pr12("t")("r")("a")("c")("i")("n")("g")("e")("d")("g")("e")("s")(internal);@/
1136 pr10("w")("i")("t")("h")("w")("e")("i")("g")("h")("t")(command);@/
1137 end;
1138
1139 @ Store primitives specific for \MP.
1140
1141 @<Store all the prim...@>=
1142 if metapost then begin
1143 pr9("a")("r")("c")("l")("e")("n")("g")("t")("h")(op);@/
1144 pr7("a")("r")("c")("t")("i")("m")("e")(command);@/
1145 pr8("b")("l")("u")("e")("p")("a")("r")("t")(op);@/
1146 pr7("b")("o")("u")("n")("d")("e")("d")(op);@/
1147 pr4("b")("t")("e")("x")(btex_code);@/
1148 pr4("c")("l")("i")("p")(command);@/
1149 pr7("c")("l")("i")("p")("p")("e")("d")(op);@/
1150 pr9("c")("l")("o")("s")("e")("f")("r")("o")("m")(input_command);@/
1151 pr5("c")("o")("l")("o")("r")(type_name);@/
1152 pr6("d")("a")("s")("h")("e")("d")(command);@/
1153 pr8("d")("a")("s")("h")("p")("a")("r")("t")(op);@/
1154 pr4("e")("t")("e")("x")(etex_marker);@/
1155 pr6("f")("i")("l")("l")("e")("d")(op);@/
1156 pr8("f")("o")("n")("t")("p")("a")("r")("t")(op);@/
1157 pr8("f")("o")("n")("t")("s")("i")("z")("e")(op);@/
1158 pr9("g")("r")("e")("e")("n")("p")("a")("r")("t")(op);@/
1159 pr6("i")("n")("f")("o")("n")("t")(binary);@/
1160 pr8("l")("i")("n")("e")("j")("o")("i")("n")(internal);@/
1161 pr7("l")("i")("n")("e")("c")("a")("p")(internal);@/
1162 pr8("l")("l")("c")("o")("r")("n")("e")("r")(op);@/
1163 pr8("l")("r")("c")("o")("r")("n")("e")("r")(op);@/
1164 pr10("m")("i")("t")("e")("r")("l")("i")("m")("i")("t")(internal);@/
1165 pr8("m")("p")("x")("b")("r")("e")("a")("k")(bold);@/
1166 pr8("p")("a")("t")("h")("p")("a")("r")("t")(op);@/
1167 pr7("p")("e")("n")("p")("a")("r")("t")(op);@/
1168 pr9("p")("r")("o")("l")("o")("g")("u")("e")("s")(internal);@/
1169 pr7("r")("e")("d")("p")("a")("r")("t")(op);@/
1170 pr8("r")("e")("a")("d")("f")("r")("o")("m")(input_command);@/
1171 pr9("s")("e")("t")("b")("o")("u")("n")("d")("s")(command);@/
1172 pr7("s")("t")("r")("o")("k")("e")("d")(op);@/
1173 pr8("t")("e")("x")("t")("p")("a")("r")("t")(op);@/
1174 pr7("t")("e")("x")("t")("u")("a")("l")(op);@/
1175 pr16("t")("r")("a")("c")("i")("n")("g")
1176 ("l")("o")("s")("t")("c")("h")("a")("r")("s")(internal);@/
1177 pr11("t")("r")("u")("e")("c")("o")("r")("n")("e")("r")("s")(internal);@/
1178 pr8("u")("l")("c")("o")("r")("n")("e")("r")(op);@/
1179 pr8("u")("r")("c")("o")("r")("n")("e")("r")(op);@/
1180 pr11("v")("e")("r")("b")("a")("t")("i")("m")("t")("e")("x")(verbatim_code);@/
1181 pr6("w")("i")("t")("h")("i")("n")(bbinary);@/
1182 pr9("w")("i")("t")("h")("c")("o")("l")("o")("r")(command);@/
1183 pr5("w")("r")("i")("t")("e")(command);@/
1184 end;
1185
1186 @ Here an extra section is added.
1187 `\.{btex}' token is translated to `\.{\\mftbeginB}' and
1188 `\.{verbatimtex}' to `\.{\\mftbeginV}'.
1189 `\.{etex}' is translated to `\.{\\mftend}'.
1190 These \TeX\ macros are defined in \.{mptmac.tex}.
1191 @.mptmac@>
1192 @<Copy \TeX\ material@>=
1193 begin out4("\")("m")("f")("t"); out5("b")("e")("g")("i")("n");
1194 if cur_type=verbatim_code then begin
1195 out("V");
1196 scanner_status:=verbatimtex_flushing;
1197 end else if cur_type=btex_code then begin
1198 out("B");
1199 scanner_status:=btex_flushing;
1200 end;
1201 out("{"); out_name(cur_tok); out("}");
1202 get_next;
1203 while cur_type<>etex_marker do begin
1204 if cur_type=indentation then begin out(" "); end
1205 else if cur_type=end_of_line then begin
1206 flush_buffer(out_ptr,false);
1207 empty_buffer:=true;
1208 end
1209 else copy(id_first);
1210 get_next;
1211 end;
1212 out4("\")("m")("f")("t"); out3("e")("n")("d");
1213 out("{"); out_name(cur_tok); out("}");
1214 if scanner_status=verbatimtex_flushing then out("$");
1215 scanner_status:=normal;
1216 end
1217 @z