OSDN Git Service

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