OSDN Git Service

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