Debian Codegraph @

texmf-dist/doc/fonts/fontinst/test/comparemetrics.sty

raw
1 % We start by making some default catcode assignments, in case we are
2 % using ini\TeX{}.
3 % \begin{macrocode}
4 %<*pkg>
5 \catcode`\{=1
6 \catcode`\}=2
7 \catcode`\#=6
8 \catcode`\^=7
9 %</pkg>
10 % \end{macrocode}
11 %
12 % \package{fontinst} uses some unusual, but convenient, settings of
13 % |\catcode|. |@| and |_| are made letters, |~| is made a space, and
14 % space and newline are ignored. Before setting those however, we save
15 % the current values of the catcodes, so that they can be restored at
16 % the end of \texttt{fontinst.sty}.
17 %
18 % \begin{macrocode}
19 %<*pkg>
20 \edef\spacecatcode{\the\catcode`\ }
21 \edef\nlcatcode{\the\catcode`\^^M}
22 \edef\atcatcode{\the\catcode`\@}
23 \edef\underscorecatcode{\the\catcode`\_}
24 \edef\tildecatcode{\the\catcode`\~}
25 % \end{macrocode}
26 %
27 % \begin{macrocode}
28 \catcode`\ =9
29 \catcode`\^^M=9
30 \catcode`\@=11
31 \catcode`\_=11
32 \catcode`\~=10
33 %</pkg>
34 % \end{macrocode}
35 %
36
37
38 \newlinechar=`\^^J
39
40 % \begin{macro}{\a_read}
41 % \begin{macro}{\b_read}
42 % \begin{macro}{\a_filelineno}
43 % \begin{macro}{\b_filelineno}
44 % These control sequences are used for keeping track of the ``physical''
45 % side of the two input files. |\a_read| and |\b_read| are the stream
46 % numbers. |\a_filelineno| and |\b_filelineno| are the respective
47 % line numbers of the lines most recently read from these files.
48 % \begin{macrocode}
49 \newread\a_read
50 \newread\b_read
51 \newcount\a_filelineno
52 \newcount\b_filelineno
53 % \end{macrocode}
54 % \end{macro}\end{macro}\end{macro}\end{macro}
55 %
56 % \begin{macro}{\a_lineno}
57 % \begin{macro}{\b_lineno}
58 % \begin{macro}{\a_bufbase}
59 % \begin{macro}{\b_bufbase}
60 % \begin{macro}{\a_bufmid}
61 % \begin{macro}{\b_bufmid}
62 % \begin{macro}{\a_buftop}
63 % \begin{macro}{\b_buftop}
64 % These count registers are used for managing the buffert of lines
65 % that are read from the input files when a match between lines is
66 % being looked for. This buffert consists of lines which are saved in
67 % the macros
68 % \begin{quote}
69 % |\|\meta{letter}|_saved-|\meta{ofs}
70 % \end{quote}
71 % where \meta{letter} is |a| or |b| and \meta{ofs} is an integer,
72 % being the index into the buffert. |\a_bufbase| and |\b_bufbase|
73 % contain the \meta{ofs} of the first line currently in the buffert,
74 % whereas |\a_buftop| and |\b_buftop| contain the \meta{ofs} of the
75 % last such line. |\a_bufmid| and |\b_bufmid| hold the buffert
76 % positions of the lines which are currently considered the next by
77 % |\get_next_line|. If \(\mathtt{buftop}<\mathtt{bufmid}\) then the
78 % buffert is empty. |\a_lineno| and |\b_lineno| are the respective
79 % line numbers of the |\a_bufbase| and |\b_bufbase| lines.
80 %
81 % All these registers should be set globally.
82 % \begin{macrocode}
83 \newcount\a_lineno \newcount\b_lineno
84 \newcount\a_bufbase \newcount\b_bufbase
85 \newcount\a_bufmid \newcount\b_bufmid
86 \newcount\a_buftop \newcount\b_buftop
87 % \end{macrocode}
88 % \end{macro}\end{macro}\end{macro}\end{macro}\end{macro}\end{macro}
89 % \end{macro}\end{macro}
90
91
92 % \begin{macro}{\get_next_line}
93 % The |\get_next_line| macro is called as
94 % \begin{quote}
95 % |\get_next_line|\marg{letter}
96 % \end{quote}
97 % where \meta{letter} is |a| or |b|. This sets the
98 % |\|\meta{letter}|_line| macro to the next line of that file and
99 % updates the value of |\|\meta{letter}|_lineno|.
100 %
101 % The ``next line'' is normally read from input stream
102 % |\|\meta{letter}|_read|, but if a line mismatch recently occured
103 % then it might happen that the next line has already been read from
104 % the file, and in that case it is taken from one of the
105 % |\|\meta{letter}|_saved-|\meta{ofs} macros.
106 % \begin{macrocode}
107 \def\get_next_line#1{
108 \ifnum \csname#1_buftop\endcsname<\csname#1_bufmid\endcsname
109 \ifeof \csname#1_read\endcsname
110 \x_cs\let{#1_line}\end_of_file_line
111 \else
112 \read\csname#1_read\endcsname t\x_cs{o}{#1_line}
113 \global\advance \csname#1_filelineno\endcsname \@ne
114 \fi
115 \else
116 \expandafter\let \csname#1_line\expandafter\endcsname
117 \csname#1_saved-\the\csname#1_bufmid\endcsname\endcsname
118 \fi
119 }
120 % \end{macrocode}
121 % \end{macro}
122
123 % \begin{macro}{\end_of_file_line}
124 % This macro expands to the text \verb*|(ENDOFFILE) | with the
125 % catcodes it would have if read from an input file. It is used as an
126 % end-of-file marker.
127 % \begin{macrocode}
128 \begingroup
129 \catcode`\(=13
130 \catcode`\)=13
131 \gdef\end_of_file_line{(ENDOFFILE)~}
132 \endgroup
133 % \end{macrocode}
134 % \end{macro}
135
136 % \begin{macro}{\the_line}
137 % The |\the_line| macro is called as
138 % \begin{quote}
139 % |\the_line|\marg{letter}\marg{ofs}
140 % \end{quote}
141 % where \meta{letter} is |a| or |b|, and \meta{ofs} is a \TeX\ number.
142 % It expands to the control sequence |\|\meta{letter}|_saved-|^^A
143 % \meta{ofs}.
144 % \begin{macrocode}
145 \def\the_line#1#2{\csname#1_saved-\number#2\endcsname}
146 % \end{macrocode}
147 % \end{macro}
148
149 % \begin{macro}{\initialise_search}
150 % The |\initialise_search| macro sets everything up for a search for
151 % a match between lines.
152 %
153 % \begin{macrocode}
154 \def\initialise_search{
155 \global\a_bufbase=\a_bufmid
156 \global\b_bufbase=\b_bufmid
157 \add_to_buffert{a}
158 \add_to_buffert{b}
159 \global\advance \a_bufmid \@ne
160 \global\advance \b_bufmid \@ne
161 }
162 % \end{macrocode}
163 % \end{macro}
164
165 % \begin{macro}{\add_to_buffert}
166 % The |\add_to_buffert| macro is called as
167 % \begin{quote}
168 % |\add_to_buffert|\marg{letter}
169 % \end{quote}
170 % It adds the line returned by |\get_next_line| to the corresponding
171 % buffert (if it wasn't already there) and updates the counters for
172 % that buffert. After this, the line following the line being put into
173 % the buffert will be the line that |\get_next_line| returns.
174 % \begin{macrocode}
175 \def\add_to_buffert#1{
176 \ifnum \csname#1_buftop\endcsname<\csname#1_bufmid\endcsname
177 \expandafter\let
178 \csname#1_saved-\the\csname#1_bufmid\endcsname
179 \expandafter\endcsname
180 \csname#1_line\endcsname
181 \global\advance \csname#1_buftop\endcsname \@ne
182 \fi
183 }
184 % \end{macrocode}
185 % \end{macro}
186
187
188
189 \newcount\first_integer
190 \newcount\second_integer
191
192 % \begin{macro}{\match_lines}
193 % The |\match_lines| macro tests if two lines can be considered the
194 % same (up to metrics changes, which need not be small). It is called as
195 % \begin{quote}
196 % |\match_lines|\marg{line a}\marg{line b}
197 % \end{quote}
198 % \meta{line a} and \meta{line b} may be any amount of text which
199 % eventually expands to the lines in question. |\match_lines| returns
200 % its answer by setting the |_a_| switch to |false| (if the lines
201 % match) or |true| (if the lines don't match).
202 %
203 % |\match_lines| also causes the |\first_dimen| and |\second_dimen|
204 % registers, as well as the |_histogram_dimen_| switch to be updated,
205 % so it can be immediately followed by a test of the metrics.
206 % \begin{macrocode}
207 \def\match_lines#1#2{
208 \first_integer=\z@
209 \second_integer=\z@
210 \first_dimen=\z@
211 \second_dimen=\z@
212 \x_cs\let{string-+}\empty_command
213 \x_cs\let{string--}\empty_command
214 % \end{macrocode}
215 % \begin{macrocode}
216 \def\sign{+}
217 #1\line_stop
218 \def\sign{-}
219 #2\line_stop
220 % \end{macrocode}
221 % \begin{macrocode}
222 \_a_false
223 \expandafter\ifx \csname cmd-+ \expandafter\endcsname
224 \csname cmd--\endcsname
225 \else \_a_true \fi
226 \ifnum \first_integer=\z@ \else \_a_true \fi
227 \ifnum \second_integer=\z@ \else \_a_true \fi
228 \expandafter\ifx \csname string-+ \expandafter\endcsname
229 \csname string--\endcsname
230 \else \_a_true \fi
231 }
232 % \end{macrocode}
233 % \end{macro}
234
235 % \begin{macro}{\try_matching}
236 % \begin{macro}{\a_bufP}
237 % \begin{macro}{\b_bufP}
238 % The |\try_matching| descends through the buffert until the |_a_|
239 % switch gets |false| or it has tried the bottommost lines in the
240 % buffert. Since |\body| is already defined by the |\loop| in
241 % |\process_lines|, |\try_matching| uses an explicit end recursion to
242 % make the loop.
243 % \begin{macrocode}
244 \newcount\a_bufP
245 \newcount\b_bufP
246 \def\try_matching{
247 \global\advance \a_bufP \m@ne
248 \global\advance \b_bufP \m@ne
249 % % Begin debug
250 % \wlog{a_bufbase:~\the\a_bufbase\space\space\space
251 % b_bufbase:~\the\b_bufbase}
252 % \wlog{a_bufmid:~\the\a_bufmid\space\space\space
253 % b_bufmid:~\the\b_bufmid}
254 % \wlog{a_buftop:~\the\a_buftop\space\space\space
255 % b_buftop:~\the\b_buftop}
256 % \wlog{a_bufP:~\the\a_bufP\space\space\space
257 % b_bufP:~\the\b_bufP}
258 % \begingroup
259 % \def\do_left_paren{(}\def\do_right_paren{)}
260 % \wlog{a_line:~\a_line}
261 % \wlog{b_buf_line:~\the_line{b}{\b_bufP}}
262 % \wlog{b_line:~\b_line}
263 % \wlog{a_buf_line:~\the_line{a}{\a_bufP}^^J}
264 % \endgroup
265 % % End debug
266 \match_lines{\a_line}{\the_line{b}{\b_bufP}}
267 \if_a_
268 \match_lines{\the_line{a}{\a_bufP}}{\b_line}
269 \if_a_ \else
270 \global\a_bufmid=\a_bufP
271 \fi
272 \else
273 \global\b_bufmid=\b_bufP
274 \fi
275 \ifnum \a_bufP>\a_bufbase \if_a_
276 \expandafter\expandafter\expandafter\try_matching
277 \fi \fi
278 }
279 % \end{macrocode}
280 % \end{macro}
281
282 % \begin{macro}{\report_mismatch}
283 % The |\report_mismatch| macro does precisely what it says. It also increases
284 % the \texttt{bufbase} and \texttt{lineno} registers to point at the
285 % matching lines.
286 % \begin{macrocode}
287 \def\report_mismatch{
288 \begingroup
289 \def\do_left_paren{(}
290 \def\do_right_paren{)}
291 \wlog{Mismatch~in~first~file~(at~\the\a_lineno):}
292 \loop
293 \wlog{\the_line{a}{\a_bufbase}}
294 \ifnum \a_bufbase<\a_bufmid
295 \global\advance \a_bufbase \@ne
296 \global\advance \a_lineno \@ne
297 \repeat
298 \wlog{Match~found~at~line~\the\a_lineno.}
299 \wlog{Mismatch~in~second~file~(at~\the\b_lineno):}
300 \loop
301 \wlog{\the_line{b}{\b_bufbase}}
302 \ifnum \b_bufbase<\b_bufmid
303 \global\advance \b_bufbase \@ne
304 \global\advance \b_lineno \@ne
305 \repeat
306 \wlog{Match~found~at~line~\the\b_lineno.}
307 \endgroup
308 \glyphified_location
309 \ifnum 4>\compared_status
310 \global\chardef\compared_status=4
311 \fi
312 }
313 % \end{macrocode}
314 % \end{macro}
315
316 \def\glyphified_location{
317 \ifx \encoding_name\empty_command
318 \ifnum \m@ne<\last_character
319 \wlog{This~is~related~to~slot~\the\last_character.^^J}
320 \else
321 \wlog{This~is~in~the~header.^^J}
322 \fi
323 \else
324 \if_undefined{name-\encoding_name-\the\last_character}\then
325 \ifnum \last_character=\m@ne
326 \wlog{This~is~in~the~header.^^J}
327 \else
328 \wlog{This~is~related~to~slot~\the\last_character\space
329 (unencoded).^^J}
330 \fi
331 \else
332 \wlog{This~is~related~to~the~glyph~
333 \csname name-\encoding_name-\the\last_character\endcsname
334 .^^J}
335 \fi
336 \fi
337 }
338 % \begin{macro}{\compared_status}
339 % |\compared_status| is a \meta{chardef token} which stores the
340 % current status of the comparision, according to the following table
341 % \begin{enumerate}
342 % \item[0] The property lists are equal---there may be checksum
343 % differences, but nothing else.
344 % \item[1] The property lists are almost equal---there are
345 % differences in the metrics, but these are within the |\tolerance|
346 % level.
347 % \item[2] The property lists are essentially equal---there are
348 % differences in the metrics, but these are within the |\tolerance|
349 % level, with the exception of some \texttt{CHARHT},
350 % \texttt{CHARDP}, and \texttt{CHARIC} values.
351 % \item[3] The property lists have metric differences---there are
352 % metric differences not with category 2.
353 % \item[4] The property lists are not completely matched.
354 % \end{enumerate}
355 % \end{macro}
356
357 % \begin{macro}{\step_linenos}
358 % The |\step_linenos| macro increments the |_lineno| line numbers. If
359 % the current line was fetched from the buffert, then it also
360 % increments the |_bufmid| and |_bufbase| registers, and checks
361 % whether the buffert ended (in which case it is normalized to its
362 % starting position, to conserve hash table space).
363 % \begin{macrocode}
364 \def\step_linenos{
365 \global\advance \a_lineno \@ne
366 \ifnum \a_bufmid=\a_buftop
367 \global\a_bufbase=\z@
368 \global\a_bufmid=\z@
369 \global\a_buftop=\m@ne
370 \else\ifnum \a_bufmid<\a_buftop
371 \global\advance \a_bufmid \@ne
372 \global\advance \a_bufbase \@ne
373 \fi\fi
374 \global\advance \b_lineno \@ne
375 \ifnum \b_bufmid=\b_buftop
376 \global\b_bufbase=\z@
377 \global\b_bufmid=\z@
378 \global\b_buftop=\m@ne
379 \else\ifnum \b_bufmid<\b_buftop
380 \global\advance \b_bufmid \@ne
381 \global\advance \b_bufbase \@ne
382 \fi\fi
383 }
384 % \end{macrocode}
385 % \end{macro}
386
387
388 \newdimen\first_dimen
389 \newdimen\second_dimen
390 \newcount\ht_hist_i
391 \newcount\ht_hist_ii
392 \newcount\ht_hist_iii
393 \newcount\ht_hist_iv
394 \newcount\dp_hist_i
395 \newcount\dp_hist_ii
396 \newcount\dp_hist_iii
397 \newcount\dp_hist_iv
398 \newcount\ic_hist_i
399 \newcount\ic_hist_ii
400 \newcount\ic_hist_iii
401 \newcount\ic_hist_iv
402
403 % \begin{macro}{\clear_histograms}
404 % This macro clears all the histograms.
405 % \begin{macrocode}
406 \def\clear_histograms{
407 \global\ht_hist_i=\z@
408 \global\ht_hist_ii=\z@
409 \global\ht_hist_iii=\z@
410 \global\ht_hist_iv=\z@
411 \global\dp_hist_i=\z@
412 \global\dp_hist_ii=\z@
413 \global\dp_hist_iii=\z@
414 \global\dp_hist_iv=\z@
415 \global\ic_hist_i=\z@
416 \global\ic_hist_ii=\z@
417 \global\ic_hist_iii=\z@
418 \global\ic_hist_iv=\z@
419 }
420 % \enc{macrocode}
421 % \end{macro}
422
423 % \begin{macro}{\present_histograms}
424 % This macro writes the histogram data to the log file.
425 % \begin{macrocode}
426 \def\present_histograms{
427 \wlog{\string\tolerance*~\space CHARHT~\space CHARDP~\space CHARIC}
428 \wlog{~\space\space 1--~\space\space 10\hist_to_eight{ht}{i}
429 \hist_to_eight{dp}{i}\hist_to_eight{ic}{i}}
430 \wlog{~\space 10--~\space 100\hist_to_eight{ht}{ii}
431 \hist_to_eight{dp}{ii}\hist_to_eight{ic}{ii}}
432 \wlog{~100--~1000\hist_to_eight{ht}{iii}\hist_to_eight{dp}{iii}
433 \hist_to_eight{ic}{iii}}
434 \wlog{1000--10000\hist_to_eight{ht}{iv}\hist_to_eight{dp}{iv}
435 \hist_to_eight{ic}{iv}}
436 }
437 \def\hist_to_eight#1#2{\x_cs\hist_to_eight_i{#1_hist_#2}}
438 \def\hist_to_eight_i#1{
439 \ifnum #1<\@M
440 \four_spaces
441 \ifnum #1<\one_hundred
442 \space\space
443 \ifnum 10>#1 ~\fi
444 \else \ifnum #1<\one_thousand \space\fi \fi
445 \else
446 \ifnum 1000000>#1
447 \space\space
448 \ifnum 100000>#1 ~\fi
449 \else \ifnum 1000000>#1 ~\fi \fi
450 \fi
451 \the#1
452 }
453 % \end{macrocode}
454 % \end{macro}
455
456
457 % \begin{macro}{\metric_statistics}
458 % \begin{macro}{\metric_origin}
459 % The |\metric_statistics| macro takes care of comparing the metrics
460 % by inspecting the values of |\first_dimen| and |\second_dimen|. It
461 % has four classes of differences, which are represented by
462 % |\compared_status| values 0--3: no difference, tolerable (almost no)
463 % difference, histogrammed (essentially no) difference, and
464 % non-tolerable difference. If a non-tolerable difference is found,
465 % then the current lines are written to the log file. Histogrammed
466 % differences causes the corresponding
467 % |\|\meta{type}|_hist_|\meta{group} register to be incremented, and
468 % tolerable differences only affect the value of |\compared_status|.
469 %
470 % The |\metric_origin| macro contains the \meta{type} of the metric
471 % data. It is usually empty, but PL properties with metrics that have
472 % histograms set it so that the correct histogram is updated.
473 %
474 % \begin{macrocode}
475 \def\metric_statistics{
476 \_a_false
477 %
478 \ifdim \first_dimen<\z@ \first_dimen=-\first_dimen \fi
479 \ifdim \first_dimen=\z@
480 \else\ifdim \first_dimen<\tolerance
481 \ifnum 1>\compared_status
482 \global\chardef\compared_status=1
483 \fi
484 \else\ifx \metric_origin\empty_command
485 \_a_true
486 \else
487 \a_count=\@ne
488 \def\a_macro{10}
489 \loop\ifdim \a_macro\tolerance<\first_dimen
490 \edef\a_macro{\a_macro 0}
491 \advance \a_count \@ne
492 \repeat
493 \if_undefined{\metric_origin _hist_ \romannumeral\a_count}\then
494 \_a_true
495 \else
496 \global\advance \csname \metric_origin _hist_
497 \romannumeral\a_count \endcsname \@ne
498 \ifnum 2>\compared_status
499 \global\chardef\compared_status=2
500 \fi
501 \fi
502 \fi\fi\fi
503 %
504 \ifdim \second_dimen<\z@ \second_dimen=-\second_dimen \fi
505 \ifdim \second_dimen=\z@
506 \else\ifdim \second_dimen<\tolerance
507 \ifnum 1>\compared_status
508 \global\chardef\compared_status=1
509 \fi
510 \else\ifx \metric_origin\empty_command
511 \_a_true
512 \else
513 \a_count=\@ne
514 \def\a_macro{10}
515 \loop\ifdim \a_macro\tolerance<\second_dimen
516 \edef\a_macro{\a_macro 0}
517 \advance \a_count \@ne
518 \repeat
519 \if_undefined{\metric_origin _hist_ \romannumeral\a_count}\then
520 \_a_true
521 \else
522 \global\advance \csname \metric_origin _hist_
523 \romannumeral\a_count \endcsname \@ne
524 \ifnum 2>\compared_status
525 \global\chardef\compared_status=2
526 \fi
527 \fi
528 \fi\fi\fi
529 %
530 \if_a_
531 \ifnum 3>\compared_status
532 \global\chardef\compared_status=3
533 \fi
534 \begingroup
535 \def\do_left_paren{(}
536 \def\do_right_paren{)}
537 \wlog{Metric~differences~at~lines~\the\a_lineno\space
538 and~\the\b_lineno\space respectively:}
539 \wlog{\a_line}
540 \wlog{\b_line}
541 \endgroup
542 \glyphified_location
543 \fi
544 }
545 % \end{macrocode}
546 % \end{macro}\end{macro}
547
548
549
550
551 \newif\if_b_
552
553 % \begin{macro}{\process_lines}
554 % The |\process_lines| macro is the cheif executive in the comparision.
555 % Its normal mode of operation is to retrive the next two lines from
556 % the input files, match them, and update the metric differences
557 % statistics. If the lines do not match, however, it starts building a
558 % buffert of lines in which it searches for two matching lines. When
559 % these two lines are found the mismatching portions of the files are
560 % written to the log file, and the metric difference statistics are
561 % updated for the two lines that matched.
562 %
563 % \begin{macrocode}
564 \def\process_lines{
565 \get_next_line{a}
566 \get_next_line{b}
567 \match_lines{\a_line}{\b_line}
568 \if_a_
569 % \end{macrocode}
570 % Now the process of trying to find a match begins. At each step of
571 % the search for a match, it tries all possible matches with the
572 % lines read so far that haven't been tried at an earlier step.
573 % \begin{macrocode}
574 % \tracingmacros=\@ne\tracingcommands=\tw@ % DEBUG
575 \initialise_search
576 \loop
577 \get_next_line{a}
578 \get_next_line{b}
579 \add_to_buffert{a}
580 \add_to_buffert{b}
581 \match_lines{\a_line}{\b_line}
582 \if_a_
583 \global\a_bufP=\a_bufmid
584 \global\b_bufP=\b_bufmid
585 \try_matching
586 \fi
587 \if_a_
588 \global\advance \a_bufmid \@ne
589 \global\advance \b_bufmid \@ne
590 \ifnum \a_bufmid>\sixt@@n
591 \errmessage{Big~buffert.~\the\a_lineno[\the\a_filelineno]:
592 \the\b_lineno[\the\b_filelineno]}
593 \fi % DEBUG
594 \repeat
595 \report_mismatch
596 % \tracingcommands=\z@\tracingmacros=\z@ % DEBUG
597 % \end{macrocode}
598 % \begin{macrocode}
599 \fi
600 \metric_statistics
601 \step_linenos
602 \par % DEBUG
603 \if \ifx \a_line\end_of_file_line
604 \ifx \b_line\end_of_file_line 1\else 0\fi\else 0\fi 0
605 % then
606 \expandafter\process_lines
607 \fi
608 }
609 % \end{macrocode}
610 % \end{macro}
611
612 \def\loadencoding#1{{
613 \def\do_slot{\x_cs\xdef{name-#1-\the\slot_number}{\slot_name}}
614 \inputetx{#1}
615 }}
616
617 % \begin{macro}{\comparePLs}
618 % The |\comparePLs| command compares two property lists files. It is
619 % geared against verifying that two different such files are as good
620 % as equal, and it might take a very long time before it gives up on
621 % trying to find any resemblance between them. It is furthermore only
622 % meant to be used on (V)PL files generated by \package{TFtoPL} or
623 % \package{VFtoVP}, because it assumes the property lists follow a
624 % stricter syntax than \package{PLtoTF} and \package{VPtoVF} requires
625 % them to. Finally it needs to be said that the comparision is rather
626 % stupid in many respects, as it is completely line-oriented and
627 % takes no notice of what kind of property list it is reading. This
628 % may in some cases cause it to find ``matches'' between lines which
629 % for syntactical reasons alone cannot match.
630 %
631 % |\comparePLs| is called as
632 % \begin{quote}
633 % |\comparePLs|\marg{first PL}\marg{second PL}\marg{encoding}
634 % \end{quote}
635 % where \meta{first PL} and \meta{second PL} are the complete names
636 % (including extensions) of the files to compare. \meta{encoding} is
637 % the name of the encoding to use when translating slots to glyph
638 % names; leave it empty if you don't want to specify one. (One could
639 % use the \texttt{CODINGSCHEME} property to determine the encoding in
640 % that case, but this is not currently done). The slot to glyph
641 % translation is only done to make it easier to locate the position of
642 % some mismatch; it has not effect on the actual comparision.
643 % \begin{macrocode}
644 \newcount\last_character
645 \def\comparePLs#1#2#3{{
646 \def\encoding_name{#3}
647 \last_character=\m@ne
648 \openin\a_read=#1\x_relax
649 \openin\b_read=#2\x_relax
650 \immediate\write\sixt@@n{#1~and^^J #2}
651 \pl_catcodes
652 \let\do_left_paren=\do_property
653 \let\do_right_paren=\empty_command
654 \global\chardef\compared_status=\z@
655 \clear_histograms
656 \global\a_filelineno=\@ne
657 \global\b_filelineno=\@ne
658 \global\a_lineno=\@ne
659 \global\b_lineno=\@ne
660 \global\a_bufbase=\z@
661 \global\b_bufbase=\z@
662 \global\a_bufmid=\z@
663 \global\b_bufmid=\z@
664 \global\a_buftop=\m@ne
665 \global\b_buftop=\m@ne
666 \process_lines
667 \closein\a_read
668 \closein\b_read
669 \ifcase \compared_status
670 \immediate\write\sixt@@n{are~equal.^^J}
671 \or
672 \immediate\write\sixt@@n{are~almost~equal.^^J}
673 \or
674 \immediate\write\sixt@@n{are~essentially~equal.}
675 \or
676 \immediate\write\sixt@@n{have~non-tolerated~metric~differences.}
677 \or
678 \immediate\write\sixt@@n{do~not~completely~match.}
679 \else
680 \immediate\write\sixt@@n{could~not~be~matched!}
681 \fi
682 \ifnum 1<\compared_status
683 \immediate\write\sixt@@n{See~log~file~for~specification.}
684 \present_histograms
685 \immediate\write\sixt@@n{}
686 \fi
687 }}
688 % \end{macrocode}
689 % \end{macro}
690
691
692 \begingroup
693 \catcode`\(=13 \catcode`\)=13
694 \gdef\pl_catcodes{
695 \catcode`\(=13 \def({\do_left_paren}
696 \catcode`\)=13 \def){\do_right_paren}
697 }
698 \endgroup
699
700 \def\do_property#1~{
701 \x_cs\edef{cmd-\sign}{#1}
702 \let\metric_origin=\empty_command
703 \x_cs\ifx{pl-#1}\x_relax
704 \expandafter\ignore_parens
705 \else
706 \csname pl-#1 \expandafter\endcsname
707 \fi
708 }
709 \def\pl_def_s#1(#2){\x_cs\def{pl-#1}#2~}
710 \begingroup
711 \catcode`\!=13\lccode`\!=`\)
712 \lowercase{\endgroup
713 \def\pl_def_p#1(#2){\x_cs\def{pl-#1}#2!}
714 }
715 \def\pl_let#1#2{
716 \expandafter\let
717 \csname pl-#1 \expandafter\endcsname \csname pl-#2 \endcsname
718 }
719
720
721
722 \newdimen\tolerance \tolerance=110sp
723
724 % The following is for gobbling to the next unmatched right parenthesis.
725 % The |\catcode| trick used by the PL-to-MTX converter's
726 % |\ignore_parens| cannot be used since the characters are already
727 % tokenized, but one can do something similar with an |\edef| since one
728 % does not have to worry about the PL files containing material which
729 % expands in an undesirable way.
730 %
731 % The |\line_stop| is so that linebreaks in the parenthesis being
732 % gobbled will not cause total havok (although the parenthesis won't be
733 % gobbled completely). It inserts end-of-group tokens until the |\edef|
734 % is terminated, and then the |\afterassignment| token will close the
735 % group and restore the normal definition.
736
737 \def\ignore_parens{
738 \begingroup
739 \def\do_left_paren{{\iffalse}\fi}
740 \def\do_right_paren{\iffalse{\fi}}
741 \def\line_stop{\do_right_paren\line_stop}
742 \afterassignment\endgroup
743 \edef\a_macro{\iffalse}\fi
744 }
745 \def\line_stop{\x_relax}
746 % \end{macrocode}
747 %
748 \begingroup
749 \catcode`\(=1
750 \catcode`\)=2
751 \gdef\pl_string{
752 \begingroup
753 \def\do_left_paren{(\iffalse)\fi}
754 \def\do_right_paren{\iffalse(\fi)}
755 \def\line_stop{\iffalse{\fi}\line_stop}
756 \afterassignment\pl_string_i
757 \edef\a_macro{\iffalse}\fi
758 }
759 \endgroup
760 \def\pl_string_i{
761 \expandafter\endgroup \expandafter\def
762 \csname string-\sign \expandafter\endcsname
763 \expandafter{\a_macro}
764 }
765
766 \def\pl_real#1{\sign#1\hundred_pt}
767 \newdimen\hundred_pt \hundred_pt=100pt
768
769 % Convert a PL int to a \TeX{} int, assuming it's prefixed
770 % by |C|, |D|, |O|, or |H|.
771 %
772 % \begin{macrocode}
773 \def\pl_int#1#2{
774 \sign \ifx#1C `#2
775 \else\ifx#1D #2
776 \else\ifx#1O '#2
777 \else\ifx#1H "#2
778 \else -1\errmessage{Unknown~PL~number~prefix~`#1'}
779 \fi\fi\fi\fi
780 }
781 % \end{macrocode}
782
783
784 % \begin{macrocode}
785 \pl_def_p{NEXTLARGER}(#1~#2){\advance \first_integer \pl_int{#1}{#2}}
786 \pl_let{BOUNDARYCHAR}{NEXTLARGER}
787 % \end{macrocode}
788 %
789 %
790 % \begin{macrocode}
791 \x_cs\let{pl-VTITLE}=\pl_string
792 \pl_let{FONTNAME}{VTITLE}
793 \pl_let{FONTAREA}{VTITLE}
794 % \pl_let{CHECKSUM}{VTITLE}
795 % % Not really a string, but unsigned numbers can become too large for TeX.
796 % \pl_let{FONTCHECKSUM}{CHECKSUM}
797 % Commented out since checksums vary too much.
798 \pl_def_p{FONTAT}(R~#1){\advance \first_dimen \pl_real{#1}}
799 \pl_let{FONTDSIZE}{FONTAT}
800 \pl_let{SELECTFONT}{NEXTLARGER}
801 \pl_let{SETCHAR}{NEXTLARGER}
802 \pl_def_p{SETRULE}(R~#1~R~#2){
803 \advance \first_dimen \pl_real{#1}
804 \advance \second_dimen \pl_real{#2}
805 }
806 \x_cs\let{pl-POP}\empty_command
807 \pl_let{PUSH}{POP}
808 \pl_let{MOVERIGHT}{FONTAT}
809 \pl_let{MOVELEFT}{FONTAT}
810 \pl_let{MOVEUP}{FONTAT}
811 \pl_let{MOVEDOWN}{FONTAT}
812 \pl_let{SPECIAL}{VTITLE}
813 \pl_let{SPECIALHEX}{VTITLE}
814 % \end{macrocode}
815 %
816 %
817
818 \pl_let{CODINGSCHEME}{VTITLE}
819 \pl_let{DESIGNSIZE}{FONTAT}
820
821 \def\pl_parameter#1#2#3{
822 \advance \first_integer \pl_int{#1}{#2}
823 \advance \first_dimen \pl_real{#3}
824 }
825
826 \pl_def_p{PARAMETER}(#1~#2~R~#3){\pl_parameter{#1}{#2}{#3}}
827
828 \pl_def_p{SLANT}(R~#1){\pl_parameter{D}{1}{#1}}
829 \pl_def_p{SPACE}(R~#1){\pl_parameter{D}{2}{#1}}
830 \pl_def_p{STRETCH}(R~#1){\pl_parameter{D}{3}{#1}}
831 \pl_def_p{SHRINK}(R~#1){\pl_parameter{D}{4}{#1}}
832 \pl_def_p{XHEIGHT}(R~#1){\pl_parameter{D}{5}{#1}}
833 \pl_def_p{QUAD}(R~#1){\pl_parameter{D}{6}{#1}}
834 \pl_def_p{EXTRASPACE}(R~#1){\pl_parameter{D}{7}{#1}}
835
836 \pl_def_p{NUM1}(R~#1){\pl_parameter{D}{8}{#1}}
837 \pl_def_p{NUM2}(R~#1){\pl_parameter{D}{9}{#1}}
838 \pl_def_p{NUM3}(R~#1){\pl_parameter{D}{10}{#1}}
839 \pl_def_p{DENOM1}(R~#1){\pl_parameter{D}{11}{#1}}
840 \pl_def_p{DENOM2}(R~#1){\pl_parameter{D}{12}{#1}}
841 \pl_def_p{SUP1}(R~#1){\pl_parameter{D}{13}{#1}}
842 \pl_def_p{SUP2}(R~#1){\pl_parameter{D}{14}{#1}}
843 \pl_def_p{SUP3}(R~#1){\pl_parameter{D}{15}{#1}}
844 \pl_def_p{SUB1}(R~#1){\pl_parameter{D}{16}{#1}}
845 \pl_def_p{SUB2}(R~#1){\pl_parameter{D}{17}{#1}}
846 \pl_def_p{SUPDROP}(R~#1){\pl_parameter{D}{18}{#1}}
847 \pl_def_p{SUBDROP}(R~#1){\pl_parameter{D}{19}{#1}}
848 \pl_def_p{DELIM1}(R~#1){\pl_parameter{D}{20}{#1}}
849 \pl_def_p{DELIM2}(R~#1){\pl_parameter{D}{21}{#1}}
850 \pl_def_p{AXISHEIGHT}(R~#1){\pl_parameter{D}{22}{#1}}
851
852 \pl_let{DEFAULTRULETHICKNESS}{NUM1}
853 \pl_let{BIGOPSPACING1}{NUM2}
854 \pl_let{BIGOPSPACING2}{NUM3}
855 \pl_let{BIGOPSPACING3}{DENOM1}
856 \pl_let{BIGOPSPACING4}{DENOM2}
857 \pl_let{BIGOPSPACING5}{SUP1}
858
859 \def\boundarychar_name{BOUNDARYCHAR}
860 \pl_def_s{LABEL}(#1){
861 \def\a_macro{#1}
862 \ifx \a_macro\boundarychar_name
863 \x_cs\let{string-\sign}\a_macro
864 \else
865 \def\a_macro{\csname pl-LABEL(i\endcsname #1~}
866 \expandafter\a_macro
867 \fi
868 }
869 \pl_def_p{LABEL(i}(#1~#2){
870 \last_character=\first_integer
871 \advance \first_integer \pl_int{#1}{#2}
872 }
873 \pl_def_p{LIG}(#1~#2~#3~#4){
874 \advance \first_integer \pl_int{#1}{#2}
875 \advance \second_integer \pl_int{#3}{#4}
876 }
877 \pl_let{/LIG}{LIG}
878 \pl_let{/LIG>}{LIG}
879 \pl_let{LIG/}{LIG}
880 \pl_let{LIG/>}{LIG}
881 \pl_let{/LIG/}{LIG}
882 \pl_let{/LIG/>}{LIG}
883 \pl_let{/LIG/>>}{LIG}
884
885 \pl_let{HEADER}{LIG}
886
887 % \def\pl_lig#1~#2~#3~#4~#5~{
888 % \x_cs\def{string-\sign}{#1}
889 % \def\LIG#1~{
890 % \if\ifx #1C 0
891 % \else\ifx #1D 0
892 % \else\ifx #1H 0
893 % \else\ifx #1O 0 \else 1\fi\fi\fi\fi 0
894 % % then
895 % \expandafter\both_of_two
896 % \else
897 % \expandafter\first_of_two
898 % \fi{\pl_lig LIG}{~}#1~
899 % }
900 % \def\/{\pl_lig/}
901
902 \pl_let{KRN}{PARAMETER}
903 \pl_let{SKIP}{NEXTLARGER}
904
905 \pl_def_s{CHARACTER}(#1~#2){
906 \last_character=\first_integer
907 \advance \first_integer \pl_int{#1}{#2}
908 }
909 \pl_let{CHARWD}{FONTAT}
910 \pl_def_p{CHARHT}(R~#1){
911 \def\metric_origin{ht}
912 \advance \first_dimen \pl_real{#1}
913 }
914 \pl_def_p{CHARDP}(R~#1){
915 \def\metric_origin{dp}
916 \advance \first_dimen \pl_real{#1}
917 }
918 \pl_def_p{CHARIC}(R~#1){
919 \def\metric_origin{ic}
920 \advance \first_dimen \pl_real{#1}
921 }
922
923 \pl_let{TOP}{NEXTLARGER}
924 \pl_let{MID}{NEXTLARGER}
925 \pl_let{BOT}{NEXTLARGER}
926 \pl_let{REP}{NEXTLARGER}
927
928 \pl_let{FONTDIMEN}{POP}
929 \pl_let{LIGTABLE}{POP}
930 \pl_let{VARCHAR}{POP}
931 \pl_def_s{MAPFONT}(#1~#2){\advance \first_integer \pl_int{#1}{#2}}
932 \pl_let{MAP}{POP}
933
934
935 % \begin{macrocode}
936 \catcode`\@=\atcatcode
937 \catcode`\^^M=\nlcatcode
938 \catcode`\ =\spacecatcode
939 \catcode`\~=\tildecatcode
940 \catcode`\_=\underscorecatcode
941 % \end{macrocode}