OSDN Git Service

1604054036c1c0b39774e4e14fedd6ce8aa4a282
[putex/putex.git] / src / texsourc / tex3.c
1 /* Copyright 2014 Clerk Ma
2
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2 of the License, or
6    (at your option) any later version.
7
8    This program is distributed in the hope that it will be useful, but
9    WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11    General Public License for more details.
12
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16    02110-1301 USA.  */
17
18 #define EXTERN extern
19
20 #include "texd.h"
21
22 /* sec 0440 */
23 void scan_int (void)
24 {
25   boolean negative;
26   integer m;
27   small_number d;
28   boolean vacuous;
29   boolean OKsofar;
30
31   radix = 0;
32   OKsofar = true;
33   negative = false;
34
35   do
36     {
37       do 
38         {
39           get_x_token();
40         }
41       while (!(cur_cmd != spacer));
42
43       if (cur_tok == other_token + '-')
44       {
45         negative = !negative;
46         cur_tok = other_token + '+';
47       }
48     }
49   while (!(cur_tok != other_token + '+'));
50
51   if (cur_tok == alpha_token)
52   {
53     get_token();
54
55     if (cur_tok < cs_token_flag)
56     {
57       cur_val = cur_chr;
58
59       if (cur_cmd <= right_brace)
60         if (cur_cmd == right_brace)
61           incr(align_state);
62         else
63           decr(align_state);
64     }
65     else if (cur_tok < cs_token_flag + single_base)
66       cur_val = cur_tok - cs_token_flag - active_base;
67     else
68       cur_val = cur_tok - cs_token_flag - single_base;
69
70     if (cur_val > 255)
71     {
72       print_err("Improper alphabetic constant");
73       help2("A one-character control sequence belongs after a ` mark.",
74         "So I'm essentially inserting \\0 here.");
75       cur_val = '0';
76       back_error();
77     }
78     else
79     {
80       get_x_token();
81
82       if (cur_cmd != spacer)
83         back_input();
84     }
85   }
86   else if ((cur_cmd >= min_internal) && (cur_cmd <= max_internal))
87   {
88     scan_something_internal(int_val, false);
89   }
90   else
91   {
92     radix = 10;
93     m = 214748364L;   /* 7FFFFFFF hex */
94
95     if (cur_tok == octal_token)
96     {
97       radix = 8;
98       m = 268435456L;   /* 2^28 */
99       get_x_token();
100     }
101     else if (cur_tok == hex_token)
102     {
103       radix = 16;
104       m = 134217728L;   /* 2^27 8000000 hex */
105       get_x_token();
106     }
107
108     vacuous = true;
109     cur_val = 0;
110
111     while (true)
112     {
113       if ((cur_tok < zero_token + radix) && (cur_tok >= zero_token) && (cur_tok <= zero_token + 9))
114         d = cur_tok - zero_token;
115       else if (radix == 16)
116         if ((cur_tok <= A_token + 5) && (cur_tok >= A_token))
117           d = cur_tok - A_token + 10;
118         else if ((cur_tok <= other_A_token + 5) && (cur_tok >= other_A_token))
119           d = cur_tok - other_A_token;
120         else
121           goto done;
122       else
123         goto done;
124
125       vacuous = false;
126
127       if ((cur_val >= m) && ((cur_val > m) || (d > 7) || (radix != 10)))
128       {
129         if (OKsofar)
130         {
131           print_err("Number too big");
132           help2("I can only go up to 2147483647='17777777777=\"7FFFFFFF,",
133             "so I'm using that number instead of yours.");
134           error();
135           cur_val = 2147483647L;    /* 7FFFFFFF hex */
136           OKsofar = false;
137         }
138       }
139       else
140         cur_val = cur_val * radix + d;
141       get_x_token();
142     }
143 done:;
144
145     if (vacuous)
146     {
147       print_err("Missing number, treated as zero");
148       help3("A number should have been here; I inserted `0'.",
149         "(If you can't figure out why I needed to see a number,",
150         "look up `weird error' in the index to The TeXbook.)");
151       back_error();
152     } 
153     else if (cur_cmd != spacer)
154       back_input();
155   }
156
157   if (negative)
158     cur_val = - (integer) cur_val;
159 }
160 /* sec 0448 */
161 void scan_dimen_(boolean mu, boolean inf, boolean shortcut)
162 {
163   boolean negative;
164   integer f;
165   integer num, denom;
166   small_number k, kk;
167   halfword p, q;
168   scaled v;
169   integer savecurval;
170
171   f = 0;
172   arith_error = false;
173   cur_order = 0;
174   negative = false;
175
176   if (!shortcut)
177   {
178     negative = false;
179
180     do
181       {
182         do
183           {
184             get_x_token();
185           }
186         while (!(cur_cmd != spacer));
187
188         if (cur_tok == other_token + '-')
189         {
190           negative = ! negative;
191           cur_tok = other_token + '+';
192         }
193       }
194     while (!(cur_tok != other_token + '+'));
195
196     if ((cur_cmd >= min_internal) && (cur_cmd <= max_internal))
197     {
198       if (mu)
199       {
200         scan_something_internal(mu_val, false);
201
202         if (cur_val_level >= glue_val)
203         {
204           v = width(cur_val);
205           delete_glue_ref(cur_val);
206           cur_val = v;
207         }
208
209         if (cur_val_level == mu_val)
210           goto attach_sign;
211
212         if (cur_val_level != int_val)
213           mu_error();
214       }
215       else
216       {
217         scan_something_internal(dimen_val, false);
218
219         if (cur_val_level == dimen_val)
220           goto attach_sign;
221       }
222     }
223     else
224     {
225       back_input();
226
227       if (cur_tok == continental_point_token)
228         cur_tok = point_token;
229
230       if (cur_tok != point_token)
231       {
232         scan_int();
233       }
234       else
235       {
236         radix = 10;
237         cur_val = 0;
238       }
239
240       if (cur_tok == continental_point_token)
241         cur_tok = point_token;
242
243       if ((radix == 10) && (cur_tok == point_token))
244       {
245         k = 0;
246         p = 0;      /* p:=null l.8883 */
247         get_token();
248
249         while (true)
250         {
251           get_x_token();
252
253           if ((cur_tok > zero_token + 9) || (cur_tok < zero_token))
254             goto done1;
255
256           if (k < 17)
257           {
258             q = get_avail();
259             link(q) = p;
260             info(q) = cur_tok - zero_token;
261             p = q;
262             incr(k);
263           }
264         }
265 done1:
266         for (kk = k; kk >= 1; kk--)
267         {
268           dig[kk - 1] = info(p);
269           q = p;
270           p = link(p);
271           free_avail(q);
272         }
273
274         f = round_decimals(k);
275
276         if (cur_cmd != spacer)
277           back_input();
278         }
279       }
280   }
281
282   if (cur_val < 0)
283   {
284     negative = !negative;
285     cur_val = - (integer) cur_val;
286   }
287
288   if (inf)
289   {
290     if (scan_keyword("fil"))
291     {
292       cur_order = fil;
293
294       while (scan_keyword("l"))
295       {
296         if (cur_order == filll)
297         {
298           print_err("Illegal unit of measure (");
299           print_string("replaced by filll)");
300           help1("I dddon't go any higher than filll.");
301           error();
302         }
303         else
304           incr(cur_order);
305       }
306       goto attach_fraction;
307     }
308   }
309
310   savecurval = cur_val;
311
312   do
313     {
314       get_x_token();
315     }
316   while (!(cur_cmd != spacer));
317
318   if ((cur_cmd < min_internal) || (cur_cmd > max_internal))
319     back_input();
320   else
321   {
322     if (mu)
323     {
324       scan_something_internal(mu_val, false);
325
326       if (cur_val_level >= glue_val)
327       {
328         v = width(cur_val);
329         delete_glue_ref(cur_val);
330         cur_val = v;
331       }
332
333       if (cur_val_level != mu_val)
334       {
335         mu_error();
336       }
337     }
338     else
339     {
340       scan_something_internal(dimen_val, false);
341     }
342
343     v = cur_val;
344     goto found;
345   }
346
347   if (mu)
348     goto not_found;
349
350   if (scan_keyword("em"))
351     v = quad(cur_font);
352   else if (scan_keyword("ex"))
353     v = x_height(cur_font);
354   else
355     goto not_found;
356
357   {
358     get_x_token();
359
360     if (cur_cmd != spacer)
361       back_input();
362   }
363
364 found:
365   cur_val = mult_and_add(savecurval, v, xn_over_d(v, f, 65536L), 1073741823L);   /* 2^30 - 1 */
366   goto attach_sign;
367
368 not_found:
369   if (mu)
370   {
371     if (scan_keyword("mu"))
372       goto attach_fraction;
373     else
374     {
375       print_err("Illegal unit of measure (");
376       print_string("mu inserted)");
377       help4("The unit of measurement in math glue must be mu.",
378           "To recover gracefully from this error, it's best to",
379           "delete the erroneous units; e.g., type `2' to delete",
380           "two letters. (See Chapter 27 of The TeXbook.)");
381       error();
382       goto attach_fraction;
383     }
384   }
385
386   if (scan_keyword("true"))
387   {
388     prepare_mag();
389
390     if (mag != 1000)
391     {
392       cur_val = xn_over_d(cur_val, 1000, mag);
393       f = (1000 * f + 65536L * tex_remainder) / mag;
394       cur_val = cur_val + (f / 65536L);
395       f = f % 65536L;
396     }
397   }
398
399   if (scan_keyword("pt"))
400     goto attach_fraction;
401
402   if (scan_keyword("in"))
403     set_conversion(7227, 100);
404   else if (scan_keyword("pc"))
405     set_conversion(12, 1);
406   else if (scan_keyword("cm"))
407     set_conversion(7227, 254);
408   else if (scan_keyword("mm"))
409     set_conversion(7227, 2540);
410   else if (scan_keyword("bp"))
411     set_conversion(7227, 7200);
412   else if (scan_keyword("dd"))
413     set_conversion(1238, 1157);
414   else if (scan_keyword("cc"))
415     set_conversion(14856, 1157);
416   else if (scan_keyword("Q"))
417     set_conversion(7227, 10160);
418   else if (scan_keyword("H"))
419     set_conversion(7227, 10160);
420   else if (scan_keyword("sp"))
421     goto done;
422   else
423   {
424     print_err("Illegal unit of measure (");
425     print_string("pt inserted)");
426     help6("Dimensions can be in units of em, ex, in, pt, pc,",
427       "cm, mm, dd, cc, bp, or sp; but yours is a new one!",
428       "I'll assume that you meant to say pt, for printer's points.",
429       "To recover gracefully from this error, it's best to",
430       "delete the erroneous units; e.g., type `2' to delete",
431       "two letters. (See Chapter 27 of The TeXbook.)");
432     error();
433     goto done2;
434   }
435
436   cur_val = xn_over_d(cur_val, num, denom);
437   f = (num * f + 65536L * tex_remainder) / denom;
438   cur_val = cur_val +(f / 65536L);
439   f = f % 65536L;
440
441 done2:
442 attach_fraction:
443   if (cur_val >= 16384)     /* 2^14 */
444     arith_error = true;
445   else
446     cur_val = cur_val * unity + f;
447
448 done:
449   {
450     get_x_token();
451
452     if (cur_cmd != spacer)
453       back_input();
454   }
455
456 attach_sign:
457   if (arith_error || (abs(cur_val) >= 1073741824L)) /* 2^30 */
458   {
459     print_err("Dimension too large");
460     help2("I can't work with sizes bigger than about 19 feet.",
461         "Continue and I'll use the largest value I can.");
462     error();
463     cur_val = max_dimen;
464     arith_error = false;
465   }
466
467   if (negative)
468     cur_val = - (integer) cur_val;
469 }
470 /* sec 0461 */
471 void scan_glue_(small_number level)
472 {
473   boolean negative;
474   halfword q;
475   boolean mu;
476
477   mu = (level == mu_val);
478   negative = false;
479
480   do
481     {
482       do
483         {
484           get_x_token();
485         }
486       while (!(cur_cmd != spacer));
487
488       if (cur_tok == other_token + '-')
489       {
490         negative = !negative;
491         cur_tok = other_token + '+';
492       }
493     }
494   while (!(cur_tok != other_token + '+'));
495
496   if ((cur_cmd >= min_internal) && (cur_cmd <= max_internal))
497   {
498     scan_something_internal(level, negative);
499
500     if (cur_val_level >= glue_val)
501     {
502       if (cur_val_level != level)
503       {
504         mu_error();
505       }
506       return;
507     }
508
509     if (cur_val_level == int_val)
510     {
511       scan_dimen(mu, false, true);
512     }
513     else if (level == mu_val)
514     {
515       mu_error();
516     }
517   }
518   else
519   {
520     back_input();
521     scan_dimen(mu, false, false);
522
523     if (negative)
524       cur_val = - (integer) cur_val;
525   }
526   q = new_spec(zero_glue);
527   width(q) = cur_val;
528
529   if (scan_keyword("plus"))
530   {
531     scan_dimen(mu, true, false);
532     stretch(q) = cur_val;
533     stretch_order(q) = cur_order;
534   }
535
536   if (scan_keyword("minus"))
537   {
538     scan_dimen(mu, true, false);
539     shrink(q) = cur_val;
540     shrink_order(q) = cur_order;
541   }
542
543   cur_val = q;
544 }
545 /* sec 0463 */
546 halfword scan_rule_spec (void)
547 {
548   halfword q;
549
550   q = new_rule();
551
552   if (cur_cmd == vrule)
553     width(q) = default_rule;
554   else
555   {
556     height(q) = default_rule;
557     depth(q) = 0;
558   }
559
560 reswitch:
561
562   if (scan_keyword("width"))
563   {
564     scan_dimen(false, false, false);
565     width(q) = cur_val;
566     goto reswitch;
567   }
568
569   if (scan_keyword("height"))
570   {
571     scan_dimen(false, false, false);
572     height(q) = cur_val;
573     goto reswitch;
574   }
575
576   if (scan_keyword("depth"))
577   {
578     scan_dimen(false, false, false);
579     depth(q) = cur_val;
580     goto reswitch;
581   }
582
583   return q;
584 }
585 /* sec 0464 */
586 halfword str_toks_(pool_pointer b)
587 {
588   halfword p;
589   halfword q;
590   halfword t;
591   pool_pointer k;
592
593   str_room(1);
594   p = temp_head;
595   link(p) = 0;
596   k = b;
597
598   while (k < pool_ptr)
599   {
600     t = str_pool[k];
601
602     if (t == ' ')
603       t = space_token;
604     else
605       t = other_token + t;
606
607     fast_store_new_token(t);
608     incr(k);
609   }
610
611   pool_ptr = b;
612
613   return p;
614 }
615 /* sec 0465 */
616 halfword the_toks (void)
617 {
618   register halfword Result;
619   char old_setting;
620   halfword p, q, r;
621   pool_pointer b;
622
623   get_x_token();
624   scan_something_internal(tok_val, false);
625
626   if (cur_val_level >= ident_val)
627   {
628     p = temp_head;
629     link(p) = 0;
630
631     if (cur_val_level == ident_val)
632       store_new_token(cs_token_flag + cur_val);
633     else if (cur_val != 0)
634     {
635       r = link(cur_val);
636
637       while (r != 0)
638       {
639         fast_store_new_token(info(r));
640         r = link(r);
641       }
642     }
643
644     Result = p;
645   }
646   else
647   {
648     old_setting = selector;
649     selector = new_string;
650     b = pool_ptr;
651
652     switch (cur_val_level)
653     {
654       case int_val:
655         print_int(cur_val);
656         break;
657       case dimen_val:
658         {
659           print_scaled(cur_val);
660           print_string("pt");
661         }
662         break;
663       case glue_val:
664         {
665           print_spec(cur_val, "pt");
666           delete_glue_ref(cur_val);
667         }
668         break;
669       case mu_val:
670         {
671           print_spec(cur_val, "mu");
672           delete_glue_ref(cur_val);
673         }
674         break;
675     }
676     selector = old_setting;
677     Result = str_toks(b);
678   }
679
680   return Result;
681 }
682 /* sec 0467 */
683 void ins_the_toks (void) 
684
685   link(garbage) = the_toks();
686   begin_token_list(link(temp_head), 4);
687 }
688 /* sec 0470 */
689 void conv_toks (void)
690 {
691   char old_setting;
692   char c;
693   small_number save_scanner_status;
694   pool_pointer b;
695
696   c = cur_chr;
697
698   switch (c)
699   {
700     case number_code:
701     case roman_numeral_code:
702       scan_int();
703       break;
704
705     case string_code:
706     case meaning_code:
707       save_scanner_status = scanner_status;
708       scanner_status = 0;
709       get_token();
710       scanner_status = save_scanner_status;
711       break;
712
713     case font_name_code:
714       scan_font_ident();
715       break;
716
717     case job_name_code:
718       if (job_name == 0)
719         open_log_file();
720       break;
721   }
722
723   old_setting = selector;
724   selector = new_string;
725   b = pool_ptr;
726
727   switch (c)
728   {
729     case number_code:
730       print_int(cur_val);
731       break;
732
733     case roman_numeral_code:
734       print_roman_int(cur_val);
735       break;
736
737     case string_code:
738       if (cur_cs != 0)
739         sprint_cs(cur_cs);
740       else
741         print_char(cur_chr);
742       break;
743
744     case meaning_code:
745       print_meaning();
746       break;
747
748     case font_name_code:
749       print(font_name[cur_val]);
750
751       if (font_size[cur_val] != font_dsize[cur_val])
752       {
753         print_string(" at ");
754         print_scaled(font_size[cur_val]);
755         print_string("pt");
756       }
757       break;
758
759     case job_name_code:
760       print(job_name);
761       break;
762   }
763
764   selector = old_setting;
765   link(garbage) = str_toks(b);
766   begin_token_list(link(temp_head), 4);
767 }
768 /* sec 0473 */
769 halfword scan_toks_(boolean macrodef, boolean xpand)
770 {
771   register halfword Result;
772   halfword t;
773   halfword s;
774   halfword p;
775   halfword q;
776   halfword unbalance;
777   halfword hashbrace;
778
779   if (macrodef)
780     scanner_status = defining;
781   else
782     scanner_status = absorbing;
783
784   warning_index = cur_cs;
785   def_ref = get_avail();
786   token_ref_count(def_ref) = 0;
787   p = def_ref;
788   hashbrace = 0;
789   t = zero_token;
790
791   if (macrodef)
792   {
793     while (true)
794     {
795       get_token();
796
797       if (cur_tok < right_brace_limit)
798         goto done1;
799
800       if (cur_cmd == mac_param)
801       {
802         s = match_token + cur_chr;
803         get_token();
804
805         if (cur_cmd == left_brace)
806         {
807           hashbrace = cur_tok;
808           store_new_token(cur_tok);
809           store_new_token(end_match_token);
810           goto done;
811         }
812
813         if (t == zero_token + 9)
814         {
815           print_err("You already have nine parameters");
816           help1("I'm going to ignore the # sign you just used.");
817           error();
818         }
819         else
820         {
821           incr(t);
822
823           if (cur_tok != t)
824           {
825             print_err("Parameters must be numbered consecutively");
826             help2("I've inserted the digit you should have used after the #.",
827                 "Type `1' to delete what you did use.");
828             back_error();
829           }
830           cur_tok = s;
831         }
832       }
833
834       store_new_token(cur_tok);
835     }
836
837 done1:
838     store_new_token(end_match_token);
839
840     if (cur_cmd == right_brace)
841     {
842       print_err("Missing { inserted");
843       incr(align_state);
844       help2("Where was the left brace? You said something like `\\def\\a}',",
845           "which I'm going to interpret as `\\def\\a{}'.");
846       error();
847       goto found;
848     }
849 done:;
850   }
851   else
852   {
853     scan_left_brace();
854   }
855
856   unbalance = 1;
857
858   while (true)
859   {
860     if (xpand)
861     {
862       while (true)
863       {
864         get_next();
865
866         if (cur_cmd <= max_command)
867           goto done2;
868
869         if (cur_cmd != the)
870         {
871           expand();
872         }
873         else
874         {
875           q = the_toks();
876
877           if (link(temp_head) != 0)
878           {
879             link(p) = link(temp_head);
880             p = q;
881           }
882         }
883       }
884 done2:
885       x_token();
886     }
887     else
888       get_token();
889
890     if (cur_tok < right_brace_limit)
891       if (cur_cmd < right_brace)
892         incr(unbalance);
893       else
894       {
895         decr(unbalance);
896
897         if (unbalance == 0)
898           goto found;
899       }
900     else if (cur_cmd == mac_param)
901       if (macrodef)
902       {
903         s = cur_tok;
904
905         if (xpand)
906           get_x_token();
907         else
908           get_token();
909
910         if (cur_cmd != mac_param)
911           if ((cur_tok <= zero_token) || (cur_tok > t))
912           {
913             print_err("Illegal parameter number in definition of ");
914             sprint_cs(warning_index);
915             help3("You meant to type ## instead of #, right?",
916                 "Or maybe a } was forgotten somewhere earlier, and things",
917                 "are all screwed up? I'm going to assume that you meant ##.");
918             back_error();
919             cur_tok = s;
920           }
921           else
922             cur_tok = out_param_token - '0' + cur_chr;
923       }
924
925     store_new_token(cur_tok);
926   }
927 found:
928   scanner_status = 0;
929
930   if (hashbrace != 0)
931     store_new_token(hashbrace);
932
933   Result = p;
934   return Result;
935 }
936 /* used only in ITEX.C */
937 /* sec 0482 */
938 void read_toks_(integer n, halfword r)
939 {
940   halfword p;
941   halfword q;
942   integer s;
943 /*  small_number m;  */
944   int m; /* 95/Jan/7 */
945
946   scanner_status = defining;
947   warning_index = r;
948   def_ref = get_avail();
949   token_ref_count(def_ref) = 0;
950   p = def_ref;
951   store_new_token(end_match_token);
952
953   if ((n < 0) || (n > 15))
954     m = 16;
955   else
956     m = n;
957
958   s = align_state;
959   align_state = 1000000L;
960
961   do
962     {
963       begin_file_reading();
964       cur_input.name_field = m + 1;
965
966       if (read_open[m] == closed)
967         if (interaction > nonstop_mode)
968           if (n < 0)
969             prompt_input("");
970           else
971           {
972             print_ln();
973             sprint_cs(r);
974             prompt_input("=");
975             n = -1;
976           }
977         else
978         {
979           fatal_error("*** (cannot \\read from terminal in nonstop modes)");
980           return;
981         }
982       else if (read_open[m] == 1)
983         if (input_ln(read_file[m], false))
984           read_open[m] = 0;
985         else
986         {
987           (void) a_close(read_file[m]);
988           read_open[m] = 2;
989         }
990       else
991       {
992         if (!input_ln(read_file[m], true))
993         {
994           (void) a_close(read_file[m]);
995           read_open[m] = 2;
996
997           if (align_state != 1000000L)
998           {
999             runaway();
1000             print_err("File ended within ");
1001             print_esc("read");
1002             help1("This \\read has unbalanced braces.");
1003             align_state = 1000000L;
1004             error();
1005           }
1006         }
1007       }
1008
1009       limit = last;
1010
1011       if (end_line_char_inactive())
1012         decr(limit);
1013       else
1014         buffer[limit] = end_line_char;
1015
1016       first = limit + 1;
1017       loc = start;
1018       state = new_line;
1019
1020       while (true)
1021       {
1022         get_token();
1023
1024         if (cur_tok == 0)
1025           goto done;
1026
1027         if (align_state < 1000000L)
1028         {
1029           do
1030             {
1031               get_token();
1032             }
1033           while (!(cur_tok == 0));
1034
1035           align_state = 1000000L;
1036           goto done;
1037         }
1038
1039         store_new_token(cur_tok);
1040       }
1041 done:
1042       end_file_reading();
1043     }
1044   while (!(align_state == 1000000L));
1045
1046   cur_val = def_ref;
1047   scanner_status = normal;
1048   align_state = s;
1049 }
1050 /* sec 0494 */
1051 void pass_text (void)
1052 {
1053   integer l;
1054   small_number save_scanner_status;
1055
1056   save_scanner_status = scanner_status;
1057   scanner_status = skipping;
1058   l = 0;
1059   skip_line = line;
1060
1061   while (true)
1062   {
1063     get_next();
1064
1065     if (cur_cmd == fi_or_else)
1066     {
1067       if (l == 0)
1068         goto done;
1069
1070       if (cur_chr == 2)
1071         decr(l);
1072     }
1073     else if (cur_cmd == if_test)
1074       incr(l);
1075   }
1076 done:
1077   scanner_status = save_scanner_status;
1078 }
1079 /* sec 0497 */
1080 void change_if_limit_(small_number l, halfword p)
1081 {
1082   halfword q;
1083
1084   if (p == cond_ptr)
1085     if_limit = l;
1086   else
1087   {
1088     q = cond_ptr;
1089
1090     while (true)
1091     {
1092       if (q == 0)
1093       {
1094         confusion("if");
1095         return;
1096       }
1097
1098       if (link(q) == p)
1099       {
1100         type(p) = l;
1101         return;
1102       }
1103
1104       q = link(q);
1105     }
1106   }
1107 }
1108 /* called from tex2.c */
1109 /* sec 0498 */
1110 void conditional (void)
1111 {
1112   boolean b;
1113   char r;
1114   integer m, n;
1115   halfword p, q;
1116   small_number save_scanner_status;
1117   halfword savecondptr;
1118   small_number thisif;
1119
1120   {
1121     p = get_node(if_node_size);
1122     link(p) = cond_ptr;
1123     type(p) = if_limit;
1124     subtype(p) = cur_if;
1125     if_line_field(p) = if_line;
1126     cond_ptr = p;
1127     cur_if = cur_chr;
1128     if_limit = if_code;
1129     if_line = line;
1130   }
1131
1132   savecondptr = cond_ptr;
1133   thisif = cur_chr;
1134
1135   switch (thisif)
1136   {
1137     case if_char_code:
1138     case if_cat_code:
1139       {
1140         {
1141           get_x_token();
1142
1143           if (cur_cmd == relax)
1144             if (cur_chr == no_expand_flag)
1145             {
1146               cur_cmd = active_char;
1147               cur_chr = cur_tok - cs_token_flag - active_base;
1148             }
1149         }
1150
1151         if ((cur_cmd > active_char) || (cur_chr > 255))
1152         {
1153           m = relax;
1154           n = 256;
1155         }
1156         else
1157         {
1158           m = cur_cmd;
1159           n = cur_chr;
1160         }
1161         {
1162           get_x_token();
1163
1164           if (cur_cmd == relax)
1165             if (cur_chr == no_expand_flag)
1166             {
1167               cur_cmd = active_char;
1168               cur_chr = cur_tok - cs_token_flag - active_base;
1169             }
1170         }
1171
1172         if ((cur_cmd > active_char) || (cur_chr > 255))
1173         {
1174           cur_cmd = relax;
1175           cur_chr = 256;
1176         }
1177
1178         if (thisif == if_char_code)
1179           b = (n == cur_chr); 
1180         else
1181           b = (m == cur_cmd);
1182       }
1183       break;
1184
1185     case if_int_code:
1186     case if_dim_code:
1187       {
1188         if (thisif == if_int_code)
1189           scan_int();
1190         else
1191           scan_dimen(false, false, false);
1192
1193         n = cur_val;
1194         
1195         do
1196           {
1197             get_x_token();
1198           }
1199         while (!(cur_cmd != spacer));
1200
1201         if ((cur_tok >= other_token + '<') && (cur_tok <= other_token + '>'))
1202           r = cur_tok - other_token;
1203         else
1204         {
1205           print_err("Missing = inserted for ");
1206           print_cmd_chr(if_test, thisif);
1207           help1("I was expecting to see `<', `=', or `>'. Didn't.");
1208           back_error();
1209           r = '=';
1210         }
1211
1212         if (thisif == if_int_code)
1213           scan_int();
1214         else 
1215           scan_dimen(false, false, false);
1216
1217         switch (r)
1218         {
1219           case '<':
1220             b = (n < cur_val);
1221             break;
1222
1223           case '=':
1224             b = (n == cur_val);
1225             break;
1226
1227           case '>':
1228             b = (n > cur_val);
1229             break;
1230         }
1231       }
1232       break;
1233
1234     case if_odd_code:
1235       scan_int();
1236       b = odd(cur_val);
1237       break;
1238
1239     case if_vmode_code:
1240       b = (abs(mode) == 1);
1241       break;
1242
1243     case if_hmode_code:
1244       b = (abs(mode) == 102);
1245       break;
1246
1247     case if_mmode_code:
1248       b = (abs(mode) == 203);
1249       break;
1250
1251     case if_inner_code:
1252       b = (mode < 0);
1253       break;
1254
1255     case if_void_code:
1256     case if_hbox_code:
1257     case if_vbox_code:
1258       {
1259         scan_eight_bit_int();
1260         p = box(cur_val);
1261
1262         if (thisif == if_void_code)
1263           b = (p == 0);
1264         else if (p == 0)
1265           b = false;
1266         else if (thisif == if_hbox_code)
1267           b = (type(p) == hlist_node);
1268         else
1269           b = (type(p) == vlist_node);
1270       }
1271       break;
1272
1273     case ifx_code:
1274       {
1275         save_scanner_status = scanner_status;
1276         scanner_status = 0;
1277         get_next();
1278         n = cur_cs;
1279         p = cur_cmd;
1280         q = cur_chr;
1281         get_next();
1282
1283         if (cur_cmd != p)
1284           b = false;
1285         else if (cur_cmd < call)
1286           b = (cur_chr == q);
1287         else
1288         {
1289           p = link(cur_chr);
1290           q = link(equiv(n));
1291
1292           if (p == q)
1293             b = true;
1294           else
1295           {
1296             while ((p != 0) && (q != 0))
1297               if (info(p) != info(q))
1298                 p = 0;
1299               else
1300               {
1301                 p = link(p);
1302                 q = link(q);
1303               }
1304
1305             b = ((p == 0) && (q == 0));
1306           }
1307         }
1308
1309         scanner_status = save_scanner_status;
1310       }
1311       break;
1312
1313     case if_eof_code:
1314       {
1315         scan_four_bit_int();
1316         b = (read_open[cur_val] == closed);
1317       }
1318       break;
1319
1320     case if_true_code:
1321       b = true;
1322       break;
1323
1324     case if_false_code:
1325       b = false;
1326       break;
1327
1328     case if_case_code:
1329       {
1330         scan_int();
1331         n = cur_val;
1332
1333         if (tracing_commands > 1)
1334         {
1335           begin_diagnostic();
1336           print_string("{case ");
1337           print_int(n); 
1338           print_char('}');
1339           end_diagnostic(false);
1340         }
1341
1342         while (n != 0)
1343         {
1344           pass_text();
1345
1346           if (cond_ptr == savecondptr)
1347             if (cur_chr == or_code)
1348               decr(n);
1349             else 
1350               goto common_ending;
1351           else if (cur_chr == fi_code)
1352           {
1353             p = cond_ptr;
1354             if_line = if_line_field(p);
1355             cur_if = subtype(p);
1356             if_limit = type(p);
1357             cond_ptr = link(p);
1358             free_node(p, if_node_size);
1359           }
1360         }
1361
1362         change_if_limit(or_code, savecondptr);
1363         return;
1364       }
1365       break;
1366   }
1367
1368   if (tracing_commands > 1)
1369   {
1370     begin_diagnostic();
1371
1372     if (b)
1373       print_string("{true}");
1374     else
1375       print_string("{false}");
1376
1377     end_diagnostic(false);
1378   }
1379
1380   if (b)     /* b may be used without ... */
1381   {
1382     change_if_limit(else_code, savecondptr);
1383     return;
1384   }
1385
1386   while (true)
1387   {
1388     pass_text();
1389
1390     if (cond_ptr == savecondptr)
1391     {
1392       if (cur_chr != or_code)
1393         goto common_ending;
1394
1395       print_err("Extra ");
1396       print_esc("or");
1397       help1("I'm ignoring this; it doesn't match any \\if.");
1398       error();
1399     }
1400     else if (cur_chr == fi_code)
1401     {
1402       p = cond_ptr;
1403       if_line = if_line_field(p);
1404       cur_if = subtype(p);
1405       if_limit = type(p);
1406       cond_ptr = link(p);
1407       free_node(p, if_node_size);
1408     }
1409   }
1410
1411 common_ending:
1412   if (cur_chr == fi_code)
1413   {
1414     p = cond_ptr;
1415     if_line = if_line_field(p);
1416     cur_if = subtype(p);
1417     if_limit = type(p);
1418     cond_ptr = link(p);
1419     free_node(p, if_node_size);
1420   }
1421   else
1422     if_limit = fi_code;
1423 }
1424 /* sec 0515 */
1425 void begin_name (void)
1426 {
1427   area_delimiter = 0;
1428   ext_delimiter = 0;
1429 }
1430 /* This gathers up a file name and makes a string of it */
1431 /* Also tries to break it into `file area' `file name' and `file extension' */
1432 /* Used by scan_file_name and prompt_file_name */
1433 /* We assume tilde has been converted to pseudo_tilde and space to pseudo_space */
1434 /* returns false if it is given a space character - end of file name */
1435 /* sec 0516 */
1436 boolean more_name_(ASCII_code c)
1437 {
1438   if (quoted_file_name == 0 && c == ' ')
1439     return false;
1440   else if (quoted_file_name != 0 && c == '"')
1441   {
1442     quoted_file_name = 0; /* catch next space character */
1443     return true;    /* accept ending quote, but throw away */
1444   }
1445   else
1446   {   
1447     str_room(1);
1448     append_char(c);
1449     //  for DOS/Windows
1450     if ((c == '/' || c == '\\' || c == ':')) 
1451     {
1452       area_delimiter = cur_length;
1453       ext_delimiter = 0;
1454     } 
1455     else if (c == '.')
1456       ext_delimiter = cur_length;
1457
1458     return true;
1459   }
1460 }
1461
1462 /* sec 0517 */
1463 void end_name (void) 
1464 {
1465 #ifdef ALLOCATESTRING
1466   if (str_ptr + 3 > current_max_strings)
1467     str_start = realloc_str_start(increment_max_strings + 3);
1468
1469   if (str_ptr + 3 > current_max_strings)
1470   {
1471     overflow("number of strings", current_max_strings - init_str_ptr);
1472     return;
1473   }
1474 #else
1475   if (str_ptr + 3 > max_strings)
1476   {
1477     overflow("number of strings", max_strings - init_str_ptr);
1478     return;
1479   }
1480 #endif
1481
1482   if (area_delimiter == 0)   // no area delimiter ':' '/' or '\' found
1483     cur_area = 335;     // "" default area 
1484   else
1485   {
1486     cur_area = str_ptr;
1487     str_start[str_ptr + 1] = str_start[str_ptr] + area_delimiter;
1488     incr(str_ptr);
1489   }
1490
1491   if (ext_delimiter == 0) // no extension delimiter '.' found
1492   {
1493     cur_ext = 335;        // "" default extension 
1494     cur_name = make_string();
1495   } 
1496   else            // did find an extension
1497   {
1498     cur_name = str_ptr;
1499     str_start[str_ptr + 1] = str_start[str_ptr]+ ext_delimiter - area_delimiter - 1;
1500     incr(str_ptr);
1501     cur_ext = make_string();
1502   }
1503 }
1504
1505 /* n current name, a current area, e current extension */
1506 /* result in name_of_file[] */
1507 /* sec 0519 */
1508 void pack_file_name_(str_number n, str_number a, str_number e)
1509 {
1510   integer k;
1511   ASCII_code c;
1512   pool_pointer j;
1513
1514   k = 0;
1515
1516   for (j = str_start[a]; j <= str_start[a + 1] - 1; j++)
1517   {
1518     c = str_pool[j];
1519     incr(k);
1520
1521     if (k <= file_name_size)
1522       name_of_file[k] = xchr[c];
1523   }
1524
1525   for (j = str_start[n]; j <= str_start[n + 1] - 1; j++)
1526   {
1527     c = str_pool[j];
1528     incr(k);
1529
1530     if (k <= file_name_size)
1531       name_of_file[k] = xchr[c];
1532   }
1533
1534   for (j = str_start[e]; j <= str_start[e + 1] - 1; j++)
1535   {
1536     c = str_pool[j];
1537     incr(k);
1538
1539     if (k <= file_name_size)
1540       name_of_file[k] = xchr[c];
1541   }
1542
1543   if (k < file_name_size)
1544     name_length = k;
1545   else
1546     name_length = file_name_size - 1;
1547
1548 /*  pad it out with spaces ... what for ? in case we modify and forget  ? */
1549   for (k = name_length + 1; k <= file_name_size; k++)
1550     name_of_file[k] = ' ';
1551
1552   name_of_file[file_name_size] = '\0';    /* paranoia 94/Mar/24 */
1553
1554   {
1555     name_of_file [name_length+1] = '\0';
1556
1557     if (trace_flag)
1558     {
1559       sprintf(log_line, " pack_file_name `%s' (%d) ", name_of_file + 1, name_length); /* debugging */
1560       show_line(log_line, 0);
1561     }
1562
1563     name_of_file [name_length + 1] = ' ';
1564   }
1565 }
1566 /* Called only from two places tex9.c for format name - specified and default */
1567 /* for specified format name args are 0, a, b name in buffer[a] --- buffer[b] */
1568 /* for default args are format_default_length-4, 1, 0 */
1569 /* sec 0523 */
1570 void pack_buffered_name_(small_number n, integer a, integer b)
1571 {
1572   integer k;
1573   ASCII_code c;
1574   integer j;
1575
1576   if (n + b - a + 5 > file_name_size)
1577     b = a + file_name_size - n - 5;
1578
1579   k = 0;
1580
1581 /*  This loop kicks in when we want the default format name */
1582   for (j = 1; j <= n; j++)
1583   {
1584     c = xord[TEX_format_default[j]];
1585     incr(k);
1586
1587     if (k <= file_name_size)
1588       name_of_file[k] = xchr[c];
1589   }
1590 /*  This loop kicks in when we want a specififed format name */
1591   for (j = a; j <= b; j++)
1592   {
1593     c = buffer[j];
1594     incr(k);
1595
1596     if (k <= file_name_size)
1597       name_of_file[k] = xchr[c];
1598   }
1599
1600 /*  This adds the extension from the default format name */
1601   for (j = format_default_length - 3; j <= format_default_length; j++)
1602   {
1603     c = xord[TEX_format_default[j]];
1604     incr(k);
1605
1606     if (k <= file_name_size)
1607       name_of_file[k] = xchr[c];
1608   }
1609
1610   if (k < file_name_size)
1611     name_length = k;
1612   else
1613     name_length = file_name_size - 1;
1614
1615  /*  pad it out with spaces ... what for ? */
1616   for (k = name_length + 1; k <= file_name_size; k++)
1617     name_of_file[k]= ' ';
1618
1619   name_of_file[file_name_size] = '\0';    /* paranoia 94/Mar/24 */
1620 }
1621 /* sec 0525 */
1622 str_number make_name_string (void)
1623 {
1624   integer k;
1625
1626 #ifdef ALLOCATESTRING
1627   if (pool_ptr + name_length > current_pool_size)
1628     str_pool = realloc_str_pool(increment_pool_size + name_length);
1629
1630   if (str_ptr == current_max_strings)
1631     str_start = realloc_str_start(increment_max_strings);
1632
1633   if ((pool_ptr + name_length > current_pool_size) || (str_ptr == current_max_strings) || (cur_length > 0))
1634 #else
1635   if ((pool_ptr + name_length > pool_size) || (str_ptr == max_strings) || (cur_length > 0))
1636 #endif
1637   {
1638     return '?';
1639   }
1640   else
1641   {
1642     for (k = 1; k <= name_length; k++)
1643       append_char(xord[name_of_file[k]]);
1644
1645     return make_string();
1646   }
1647 }
1648 /* sec 0525 */
1649 //str_number a_make_name_string_(alpha_file * f)
1650 str_number a_make_name_string_(void)
1651 {
1652   return make_name_string();
1653 }
1654 /* sec 0525 */
1655 //str_number b_make_name_string_(byte_file * f)
1656 str_number b_make_name_string_(void)
1657 {
1658   return make_name_string(); 
1659 }
1660 /* sec 0525 */
1661 //str_number w_make_name_string_(word_file * f)
1662 str_number w_make_name_string_(void)
1663 {
1664   return make_name_string();
1665 }
1666
1667 /* Used by start_input to scan file name on command line */
1668 /* Also in tex8.c new_font_, open_or_close_in, and do_extension */
1669 /* sec 0526 */
1670 void scan_file_name (void)
1671 {
1672   name_in_progress = true;
1673   begin_name();
1674
1675   do
1676     {
1677       get_x_token(); 
1678     }
1679   while (!(cur_cmd != spacer));
1680
1681   quoted_file_name = false;
1682
1683   if (allow_quoted_names)
1684   {
1685     if (cur_chr == '"')
1686     {
1687       quoted_file_name = 1;
1688       get_x_token();
1689     }
1690   }
1691
1692   while (true)
1693   {
1694     if ((cur_cmd > other_char) || (cur_chr > 255)) 
1695     {
1696       back_input();
1697       goto done; 
1698     } 
1699
1700     if (!more_name(cur_chr))    /* up to next white space */
1701       goto done;
1702
1703     get_x_token();
1704   }
1705
1706 done:
1707   end_name();
1708   name_in_progress = false;
1709 }
1710 /* argument is string .fmt, .log, or .dvi */
1711 /* sec 0529 */
1712 void pack_job_name_(str_number s)
1713 {
1714   cur_area = 335;       /* "" */
1715   cur_ext  = s;
1716   cur_name = job_name;
1717   pack_file_name(cur_name, cur_area, cur_ext);
1718 }
1719
1720 /**********************************************************************/
1721 /* sec 0530 */
1722 /* s - what can't be found, e - default */
1723 void prompt_file_name_(char * s, str_number e) 
1724 {
1725   integer k;
1726
1727   if (interaction == scroll_mode);
1728
1729   if (!strcmp("input file name", s))
1730     print_err("I can't find file `");
1731   else
1732     print_err("I can't write on file `");
1733
1734   print_file_name(cur_name, cur_area, cur_ext);
1735   print_string("'.");
1736
1737   if (e == 785)    /* .tex */
1738     show_context();
1739
1740   print_nl("Please type another ");
1741   print_string(s); 
1742
1743   if (interaction < 2)
1744   {
1745     fatal_error("*** (job aborted, file error in nonstop mode)");
1746     return;
1747   }
1748
1749   if (!knuth_flag)
1750 #ifdef _WINDOWS
1751     show_line(" (or ^z to exit)", 0);
1752 #else
1753     show_line(" (or Ctrl-Z to exit)", 0);
1754 #endif
1755   prompt_input(": ");
1756
1757 /*  should we deal with tilde and space in file name here ??? */
1758   {
1759     begin_name();
1760     k = first;
1761
1762     while ((buffer[k] == ' ') && (k < last))
1763       incr(k);
1764 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1765     quoted_file_name = 0;         /* 98/March/15 */
1766
1767     if (allow_quoted_names && k < last) /* check whether quoted name */
1768     {
1769       if (buffer[k]== '"')
1770       {
1771         quoted_file_name = 1;
1772         incr(k);
1773       }
1774     }
1775
1776     while (true)
1777     {
1778       if (k == last)
1779         goto done;
1780 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1781 /*  convert tilde '~' to pseudo tilde */
1782       if (pseudo_tilde != 0 && buffer[k]== '~')
1783         buffer[k] = pseudo_tilde;
1784 /*  convert space ' ' to pseudo space */
1785       if (pseudo_space != 0 && buffer[k]== ' ')
1786         buffer[k] = pseudo_space;
1787 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1788       if (!more_name(buffer[k]))
1789         goto done;
1790
1791       incr(k);
1792     }
1793 done:
1794     end_name();
1795   }
1796
1797   if (cur_ext == 335)    /* "" */
1798     cur_ext = e;      /* use default extension */
1799
1800   pack_file_name(cur_name, cur_area, cur_ext);
1801 }
1802 /* sec 0534 */
1803 void open_log_file (void)
1804 {
1805   char old_setting;
1806   integer k;
1807   integer l;
1808   char * months;
1809
1810   old_setting = selector;
1811
1812   if (job_name == 0)
1813     job_name = 790;
1814
1815   pack_job_name(".log");
1816
1817   while (!a_open_out(log_file))
1818   {
1819     selector = term_only;
1820     prompt_file_name("transcript file name", ".log");
1821   }
1822
1823   texmf_log_name = a_make_name_string(log_file);
1824   selector = log_only;
1825   log_opened = true;
1826
1827   {
1828     if (want_version)
1829     {
1830       stamp_it(log_line);
1831       strcat(log_line, "\n");
1832       (void) fputs(log_line, log_file);
1833       stampcopy(log_line);
1834       strcat(log_line, "\n");
1835       (void) fputs(log_line, log_file);
1836     }
1837     
1838     fprintf(log_file, "%s (%s %s)", tex_version, application, yandyversion);
1839
1840     if (format_ident > 0)
1841       slow_print(format_ident);
1842
1843     print_string("  ");
1844
1845     if (civilize_flag)
1846       print_int(year);
1847     else
1848       print_int(day);
1849
1850     print_char(' ');
1851     months = " JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
1852
1853     for (k = 3 * month - 2; k <= 3 * month; k++)
1854       (void) putc(months[k],  log_file);
1855
1856     print_char(' ');
1857
1858     if (civilize_flag)
1859       print_int(day);
1860     else
1861       print_int(year);
1862
1863     print_char(' ');
1864     print_two(tex_time / 60);
1865     print_char(':');
1866     print_two(tex_time % 60);
1867   }
1868
1869   input_stack[input_ptr] = cur_input;
1870   print_nl("**");
1871   l = input_stack[0].limit_field;
1872
1873   if (buffer[l] == end_line_char)
1874     decr(l);
1875
1876   for (k = 1; k <= l; k++)
1877     print(buffer[k]);
1878
1879   print_ln(); 
1880
1881   if (show_fmt_flag)
1882   {
1883     if (format_file != NULL)
1884     {
1885       fprintf(log_file, "(%s)\n", format_file);
1886       free(format_file);
1887       format_file = NULL;
1888     }
1889   }
1890
1891   selector = old_setting + 2;
1892 }
1893
1894 // Attempt to deal with foo.bar.tex given as foo.bar on command line
1895 // Makes copy of job_name with extension
1896
1897 void more_name_copy(ASCII_code c)
1898 {
1899 #ifdef ALLOCATESTRING
1900   if (pool_ptr + 1 > current_pool_size)
1901     str_pool = realloc_str_pool (increment_pool_size);
1902
1903   if (pool_ptr + 1 > current_pool_size)
1904   {
1905     overflow("pool size", current_pool_size - init_pool_ptr);
1906     return;
1907   }
1908 #else
1909   if (pool_ptr + 1 > pool_size)
1910   {
1911     overflow("pool size", pool_size - init_pool_ptr);
1912     return;
1913   }
1914 #endif
1915
1916   str_pool[pool_ptr] = c; 
1917   incr(pool_ptr);
1918 }
1919
1920 int end_name_copy(void)
1921 {
1922 #ifdef ALLOCATESTRING
1923   if (str_ptr + 1 > current_max_strings)
1924     str_start = realloc_str_start(increment_max_strings + 1);
1925
1926   if (str_ptr + 1 > current_max_strings)
1927   {
1928     overflow("number of strings", current_max_strings - init_str_ptr);
1929     return 0;
1930   }
1931 #else
1932   if (str_ptr + 1 > max_strings)
1933   {
1934     overflow("number of strings", max_strings - init_str_ptr);
1935     return 0;
1936   }
1937 #endif
1938
1939   return make_string();
1940 }
1941
1942 void job_name_append (void)
1943
1944   int k, n;
1945
1946   k = str_start[job_name];
1947   n = str_start[job_name + 1];
1948
1949   while (k < n)
1950     more_name_copy(str_pool[k++]);
1951
1952   k = str_start[cur_ext];
1953   n = str_start[cur_ext + 1];
1954
1955   while (k < n)
1956     more_name_copy(str_pool[k++]);
1957
1958   job_name = end_name_copy();
1959 }
1960
1961 /* sec 0537 */
1962 void start_input(void)
1963 {
1964   scan_file_name();
1965   pack_file_name(cur_name, cur_area, cur_ext); 
1966
1967   while (true)
1968   {
1969     begin_file_reading();
1970     
1971     if (a_open_in(cur_file, TEXINPUTPATH))
1972       goto done;
1973
1974     end_file_reading();
1975     prompt_file_name("input file name", ".tex");
1976   }
1977
1978 done: 
1979   cur_input.name_field = a_make_name_string(cur_file);
1980
1981   if (job_name == 0)
1982   {
1983     job_name = cur_name;
1984     open_log_file();
1985   }
1986
1987   if (term_offset + length(cur_input.name_field) > max_print_line - 2)
1988     print_ln();
1989   else if ((term_offset > 0) || (file_offset > 0))
1990     print_char(' ');
1991
1992   print_char('(');
1993   incr(open_parens);
1994
1995   if (open_parens > max_open_parens)
1996     max_open_parens = open_parens;
1997
1998   slow_print(cur_input.name_field);
1999   update_terminal();
2000   state = new_line;
2001
2002   {
2003     line = 1;
2004
2005     if (input_ln(cur_file, false));
2006
2007     firm_up_the_line();
2008
2009     if (end_line_char_inactive())
2010       decr(limit);
2011     else
2012       buffer[limit] = end_line_char;
2013
2014     first = limit + 1;
2015     loc = start;
2016   }
2017 }
2018 /* sec 0560 */
2019 internal_font_number read_font_info_(halfword u, str_number nom, str_number aire, scaled s)
2020 {
2021   font_index k;
2022   boolean file_opened;
2023   halfword lf, lh, nw, nh, nd, ni, nl, nk, ne, np;
2024   int bc, ec;
2025   internal_font_number f;
2026   internal_font_number g;
2027   eight_bits a, b, c, d;
2028   four_quarters qw;
2029   scaled sw;
2030   integer bch_label;
2031   short bchar;
2032   scaled z;
2033   integer alpha;
2034   char beta;
2035
2036   g = 0;
2037   file_opened = false;
2038   pack_file_name(nom, aire, 805); /* .tfm */
2039
2040   if (!b_open_in(tfm_file))
2041   {
2042     goto bad_tfm;
2043   } 
2044
2045   file_opened = true; 
2046
2047   {
2048     read_sixteen(lf);
2049     tfm_temp = getc(tfm_file);
2050     read_sixteen(lh);
2051     tfm_temp = getc(tfm_file);
2052     read_sixteen(bc);
2053     tfm_temp = getc(tfm_file);
2054     read_sixteen(ec);
2055
2056     if ((bc > ec + 1) || (ec > 255))
2057       goto bad_tfm;
2058
2059     if (bc > 255)
2060     {
2061       bc = 1;
2062       ec = 0;
2063     }
2064
2065     tfm_temp = getc(tfm_file);
2066     read_sixteen(nw);
2067     tfm_temp = getc(tfm_file);
2068     read_sixteen(nh);
2069     tfm_temp = getc(tfm_file);
2070     read_sixteen(nd);
2071     tfm_temp = getc(tfm_file);
2072     read_sixteen(ni);
2073     tfm_temp = getc(tfm_file);
2074     read_sixteen(nl);
2075     tfm_temp = getc(tfm_file);
2076     read_sixteen(nk);
2077     tfm_temp = getc(tfm_file);
2078     read_sixteen(ne);
2079     tfm_temp = getc(tfm_file);
2080     read_sixteen(np);
2081
2082     if (lf != 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np)
2083       goto bad_tfm;
2084
2085     if ((nw == 0) || (nh == 0) || (nd == 0) || (ni == 0))
2086       goto bad_tfm;
2087   }
2088
2089   lf = lf - 6 - lh;
2090
2091   if (np < 7)
2092     lf = lf + 7 - np;
2093
2094 #ifdef ALLOCATEFONT
2095   if ((fmem_ptr + lf > current_font_mem_size))
2096     font_info = realloc_font_info (increment_font_mem_size + lf);
2097
2098   if ((font_ptr == font_max) || (fmem_ptr + lf > current_font_mem_size))
2099 #else
2100   if ((font_ptr == font_max) || (fmem_ptr + lf > font_mem_size))
2101 #endif
2102   {
2103     if (trace_flag)
2104     {
2105       sprintf(log_line, "font_ptr %d font_max %d fmem_ptr %d lf %d font_mem_size %d\n",
2106           font_ptr, font_max, fmem_ptr, lf, font_mem_size);
2107       show_line(log_line, 0);
2108     }
2109
2110     print_err("Font ");
2111     sprint_cs(u);
2112     print_char('=');
2113     print_file_name(nom, aire, 335); /* "" */
2114
2115     if (s >= 0)
2116     {
2117       print_string(" at ");
2118       print_scaled(s);
2119       print_string("pt");
2120     }
2121     else if (s != -1000)
2122     {
2123       print_string(" scaled ");
2124       print_int(- (integer) s);
2125     }
2126
2127     print_string(" not loaded: Not enough room left");
2128     help4("I'm afraid I won't be able to make use of this font,",
2129         "because my memory for character-size data is too small.",
2130         "If you're really stuck, ask a wizard to enlarge me.",
2131         "Or maybe try `I\\font<same font id>=<name of loaded font>'.");
2132     error();
2133     goto done;
2134   }
2135
2136   f = font_ptr + 1;
2137   char_base[f] = fmem_ptr - bc;
2138   width_base[f] = char_base[f] + ec + 1;
2139   height_base[f] = width_base[f] + nw;
2140   depth_base[f] = height_base[f] + nh;
2141   italic_base[f] = depth_base[f] + nd;
2142   lig_kern_base[f] = italic_base[f] + ni;
2143   kern_base[f] = lig_kern_base[f] + nl - 256 * (128);
2144   exten_base[f] = kern_base[f] + 256 * (128) + nk;
2145   param_base[f] = exten_base[f] + ne;
2146
2147   {
2148     if (lh < 2)
2149       goto bad_tfm;
2150     
2151     store_four_quarters(font_check[f]);
2152     tfm_temp = getc(tfm_file);
2153     read_sixteen(z);
2154     tfm_temp = getc(tfm_file);
2155     z = z * 256 + tfm_temp;
2156     tfm_temp = getc(tfm_file);
2157     z =(z * 16) + (tfm_temp / 16);
2158
2159     if (z < unity)
2160       goto bad_tfm; 
2161
2162     while (lh > 2)
2163     {
2164       tfm_temp = getc(tfm_file);
2165       tfm_temp = getc(tfm_file);
2166       tfm_temp = getc(tfm_file);
2167       tfm_temp = getc(tfm_file);
2168       decr(lh);
2169     }
2170
2171     font_dsize[f] = z;
2172
2173     if (s != -1000)
2174       if (s >= 0)
2175         z = s;
2176       else
2177         z = xn_over_d(z, - (integer) s, 1000);
2178
2179     font_size[f] = z;
2180   }
2181
2182   for (k = fmem_ptr; k <= width_base[f] - 1; k++)
2183   {
2184     store_four_quarters(font_info[k].qqqq);
2185
2186     if ((a >= nw) || (b / 16 >= nh) || (b % 16 >= nd) || (c / 4 >= ni))
2187       goto bad_tfm;
2188
2189     switch (c % 4)
2190     {
2191       case lig_tag:
2192         if (d >= nl)
2193           goto bad_tfm;
2194         break;
2195
2196       case ext_tag:
2197         if (d >= ne)
2198           goto bad_tfm;
2199         break;
2200
2201       case list_tag:
2202         {
2203           {
2204             if ((d < bc) || (d > ec))
2205               goto bad_tfm;
2206           }
2207
2208           while (d < k + bc - fmem_ptr)
2209           {
2210             qw = char_info(f, d);
2211  
2212             if (char_tag(qw) != list_tag)
2213               goto not_found;
2214
2215             d = rem_byte(qw);
2216           }
2217
2218           if (d == k + bc - fmem_ptr)
2219             goto bad_tfm;
2220 not_found:; 
2221         }
2222         break;
2223
2224       default:
2225         break;
2226     }
2227   }
2228
2229   {
2230     {
2231       alpha = 16;
2232
2233       while (z >= 8388608L)   /* 2^23 */
2234       {
2235         z = z / 2;
2236         alpha = alpha + alpha;
2237       }
2238
2239       beta = (char) (256 / alpha);
2240       alpha = alpha * z;
2241     }
2242
2243     for (k = width_base[f]; k <= lig_kern_base[f] - 1; k++)
2244     {
2245       tfm_temp = getc(tfm_file);
2246       a = tfm_temp;
2247       tfm_temp = getc(tfm_file);
2248       b = tfm_temp;
2249       tfm_temp = getc(tfm_file);
2250       c = tfm_temp;
2251       tfm_temp = getc(tfm_file);
2252       d = tfm_temp;
2253       sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2254
2255       if (a == 0)
2256         font_info[k].cint = sw;
2257       else if (a == 255)
2258         font_info[k].cint = sw - alpha;
2259       else
2260         goto bad_tfm;
2261     }
2262
2263     if (font_info[width_base[f]].cint != 0)
2264       goto bad_tfm;
2265
2266     if (font_info[height_base[f]].cint != 0)
2267       goto bad_tfm;
2268
2269     if (font_info[depth_base[f]].cint != 0)
2270       goto bad_tfm;
2271
2272     if (font_info[italic_base[f]].cint != 0)
2273       goto bad_tfm;
2274   }
2275
2276   bch_label = 32767;     /* '77777 */
2277   bchar = 256;
2278
2279   if (nl > 0)
2280   {
2281     for (k = lig_kern_base[f]; k <= kern_base[f] + 256 * (128) - 1; k++)
2282     {
2283       store_four_quarters(font_info[k].qqqq);
2284
2285       if (a > 128)
2286       {
2287         if (256 * c + d >= nl)
2288           goto bad_tfm;
2289
2290         if (a == 255)
2291           if (k == lig_kern_base[f])
2292             bchar = b;
2293       }
2294       else
2295       {
2296         if (b != bchar)
2297         {
2298           {
2299             if ((b < bc) || (b > ec))  /* check-existence(b) */
2300               goto bad_tfm;
2301           }
2302
2303           qw = font_info[char_base[f] + b].qqqq;
2304
2305           if (!(qw.b0 > 0))
2306             goto bad_tfm;
2307         }
2308
2309         if (c < 128)
2310         {
2311           {
2312             if ((d < bc) || (d > ec))  /* check-existence(d) */
2313               goto bad_tfm;
2314           }
2315
2316           qw = font_info[char_base[f] + d].qqqq;
2317
2318           if (!(qw.b0 > 0))
2319             goto bad_tfm;
2320         }
2321         else if (256 * (c - 128) + d >= nk)
2322           goto bad_tfm;
2323
2324         if (a < 128)
2325           if (k - lig_kern_base[f] + a + 1 >= nl)
2326             goto bad_tfm;
2327       }
2328     }
2329
2330     if (a == 255)
2331       bch_label = 256 * c + d;
2332   }
2333
2334   for (k = kern_base[f] + 256 * (128); k <= exten_base[f] - 1; k++)
2335   {
2336     tfm_temp = getc(tfm_file);
2337     a = tfm_temp;
2338     tfm_temp = getc(tfm_file);
2339     b = tfm_temp;
2340     tfm_temp = getc(tfm_file);
2341     c = tfm_temp;
2342     tfm_temp = getc(tfm_file);
2343     d = tfm_temp;
2344     sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2345
2346     if (a == 0)
2347       font_info[k].cint = sw;
2348     else if (a == 255)
2349       font_info[k].cint = sw - alpha;
2350     else
2351       goto bad_tfm;
2352   }
2353
2354   for (k = exten_base[f]; k <= param_base[f] - 1; k++)
2355   {
2356     store_four_quarters(font_info[k].qqqq);
2357
2358     if (a != 0)
2359     {
2360       {
2361         if ((a < bc) || (a > ec))
2362           goto bad_tfm;
2363       }
2364
2365       qw = font_info[char_base[f] + a].qqqq;
2366
2367       if (!(qw.b0 > 0))
2368         goto bad_tfm;
2369     }
2370
2371     if (b != 0)
2372     {
2373       {
2374         if ((b < bc) || (b > ec))
2375           goto bad_tfm;
2376       }
2377
2378       qw = font_info[char_base[f] + b].qqqq;
2379
2380       if (!(qw.b0 > 0))
2381         goto bad_tfm;
2382     }
2383
2384     if (c != 0)
2385     {
2386       {
2387         if ((c < bc) || (c > ec))
2388           goto bad_tfm;
2389       }
2390
2391       qw = font_info[char_base[f] + c].qqqq;
2392
2393       if (!(qw.b0 > 0))
2394         goto bad_tfm;
2395     }
2396
2397     {
2398       {
2399         if ((d < bc) || (d > ec))
2400           goto bad_tfm;
2401       }
2402
2403       qw = font_info[char_base[f] + d].qqqq;
2404
2405       if (!(qw.b0 > 0))
2406         goto bad_tfm;
2407     }
2408   }
2409
2410   {
2411     for (k = 1; k <= np; k++)
2412       if (k == 1)
2413       {
2414         tfm_temp = getc(tfm_file);
2415         sw = tfm_temp;
2416
2417         if (sw > 127)
2418           sw = sw - 256;
2419
2420         tfm_temp = getc(tfm_file);
2421         sw = sw * 256 + tfm_temp;
2422         tfm_temp = getc(tfm_file);
2423         sw = sw * 256 + tfm_temp;
2424         tfm_temp = getc(tfm_file);
2425         font_info[param_base[f]].cint = (sw * 16) + (tfm_temp / 16);
2426       }
2427       else
2428       {
2429         tfm_temp = getc(tfm_file);
2430         a = tfm_temp;
2431         tfm_temp = getc(tfm_file);
2432         b = tfm_temp;
2433         tfm_temp = getc(tfm_file);
2434         c = tfm_temp;
2435         tfm_temp = getc(tfm_file);
2436         d = tfm_temp;
2437         sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2438
2439         if (a == 0)
2440           font_info[param_base[f] + k - 1].cint = sw;
2441         else if (a == 255)
2442           font_info[param_base[f] + k - 1].cint = sw - alpha;
2443         else goto bad_tfm;
2444       }
2445
2446     if (feof(tfm_file))
2447       goto bad_tfm;
2448
2449     for (k = np + 1; k <= 7; k++)
2450       font_info[param_base[f] + k - 1].cint = 0;
2451   }
2452
2453   if (np >= 7)
2454     font_params[f] = np;
2455   else
2456     font_params[f] = 7;
2457
2458   hyphen_char[f] = default_hyphen_char;
2459   skew_char[f] = default_skew_char;
2460
2461   if (bch_label < nl)
2462     bchar_label[f] = bch_label + lig_kern_base[f];
2463   else
2464     bchar_label[f] = non_address;
2465
2466   font_bchar[f] = bchar;
2467   font_false_bchar[f] = bchar;
2468
2469   if (bchar <= ec)
2470     if (bchar >= bc)
2471     {
2472       qw = font_info[char_base[f] + bchar].qqqq;
2473
2474       if ((qw.b0 > 0))
2475         font_false_bchar[f] = 256;
2476     }
2477
2478   font_name[f] = nom;
2479   font_area[f] = aire;
2480   font_bc[f] = bc;
2481   font_ec[f] = ec;
2482   font_glue[f] = 0;
2483   char_base[f] = char_base[f];
2484   width_base[f] = width_base[f];
2485   lig_kern_base[f] = lig_kern_base[f];
2486   kern_base[f] = kern_base[f];
2487   exten_base[f] = exten_base[f];
2488   decr(param_base[f]);
2489   fmem_ptr = fmem_ptr + lf;
2490   font_ptr = f;
2491   g = f;
2492   goto done;
2493
2494 bad_tfm:
2495   print_err("Font ");
2496   sprint_cs(u); 
2497   print_char('=');
2498   print_file_name(nom, aire, 335);
2499
2500   if (s >= 0)
2501   {
2502     print_string(" at ");
2503     print_scaled(s);
2504     print_string("pt");
2505   }
2506   else if (s != -1000)
2507   {
2508     print_string("scaled");
2509     print_int(- (integer) s);
2510   } 
2511
2512   if (file_opened)
2513     print_string(" not loadable: Bad metric (TFM) file");
2514   else
2515     print_string(" not loadable: Metric (TFM) file not found");
2516
2517   help5("I wasn't able to read the size data for this font,",
2518       "so I will ignore the font specification.",
2519       "[Wizards can fix TFM files using TFtoPL/PLtoTF.]",
2520       "You might try inserting a different font spec;",
2521       "e.g., type `I\\font<same font id>=<substitute font name>'.");
2522   error();
2523
2524 done:
2525   if (file_opened)
2526     b_close(tfm_file);
2527
2528   return g;
2529 }