OSDN Git Service

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