OSDN Git Service

font manager: libavl.
[putex/putex.git] / src / texsourc / tex9.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 #pragma warning(disable:4996)
12 #pragma warning(disable:4131) // old style declarator
13 #pragma warning(disable:4135) // conversion between different integral types 
14 #pragma warning(disable:4127) // conditional expression is constant
15
16 #include <setjmp.h>
17
18 #define EXTERN extern
19
20 #include "texd.h"
21
22 #pragma warning(disable:4244)       /* 96/Jan/10 */
23
24 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
25
26 /* end of the old tex8.c */
27 /* sec 1284 */
28 void give_err_help (void)
29 {
30   token_show(err_help);
31 }
32 /* sec 0524 */
33 bool open_fmt_file (void)
34 {
35   integer j;
36
37   j = cur_input.loc_field;
38
39 /* For Windows NT, lets allow + instead of & for format specification */
40 /*  User specified a format name on the command line                  */
41   if (buffer[cur_input.loc_field] == '&' || buffer[cur_input.loc_field] == '+')
42   {
43     incr(cur_input.loc_field);
44     j = cur_input.loc_field;
45     buffer[last] = ' ';
46
47     while (buffer[j] != ' ')
48       incr(j);
49
50     pack_buffered_name(0, cur_input.loc_field, j - 1);
51
52     if (w_open_in(fmt_file))
53       goto lab40;
54   
55     if (knuth_flag)
56     {
57       (void) sprintf(log_line, "%s;%s\n", "Sorry, I can't find that format",
58         " will try the default.");
59       show_line(log_line, 1);
60     }
61     else
62     {
63       char *s = log_line;
64
65       name_of_file[name_length + 1] = '\0';
66       (void) sprintf(s, "%s (%s);%s\n", "Sorry, I can't find that format",
67         name_of_file + 1, " will try the default."); 
68       name_of_file[name_length + 1] = ' ';
69       s += strlen(s);
70       (void) sprintf(s, "(Perhaps your %s environment variable is not set correctly)\n",
71         "TEXFORMATS");
72       s += strlen(s);
73       {
74         char *t;            /* extra info 97/June/13 */
75
76         if ((t = grabenv("TEXFORMATS")) != NULL)
77         {
78           sprintf(s, "(%s=%s)\n", "TEXFORMATS", t);
79         }
80         else
81         {
82           sprintf(s, "%s environment variable not set\n", "TEXFORMATS");
83         }
84       }
85       show_line(log_line, 1); // show all three lines at once
86     }
87
88 #ifndef _WINDOWS
89     fflush(stdout);
90 #endif
91   }
92
93 /* Try the default format (either because no format specified or failed) */
94   pack_buffered_name(format_default_length - 4, 1, 0);
95
96   if (!w_open_in(fmt_file))
97   {
98     if (knuth_flag)
99     {
100       (void) sprintf(log_line, "%s!\n", "I can't find the default format file");
101       show_line(log_line, 1);
102     }
103     else
104     {
105       char *s = log_line;
106
107       name_of_file[name_length + 1] = '\0';
108       (void) sprintf(s, "%s (%s)!\n", "I can't find the default format file", name_of_file + 1);
109       name_of_file[name_length + 1] = ' ';
110       s += strlen(s);
111       (void) sprintf(s, "(Perhaps your %s environment variable is not set correctly)\n", "TEXFORMATS");
112       s += strlen(s);
113       {
114         char *t;            /* extra info 97/June/13 */
115
116         if ((t = grabenv("TEXFORMATS")) != NULL)
117         {
118           sprintf(s, "(%s=%s)\n", "TEXFORMATS", t);
119         }
120         else
121         {
122           sprintf(s, "%s environment variable not set\n", "TEXFORMATS");
123         }
124       }
125       show_line(log_line, 1);   // show all three lines at once
126     }
127
128     return false;
129   }
130
131 lab40:
132   cur_input.loc_field = j;
133
134   return true;
135 }
136 /**************************************************************************/
137 void print_char_string (unsigned char *s)
138 {
139   while (*s > 0)
140     print_char(*s++);
141 }
142 void show_font_info (void);   // now in local.c
143 extern int closed_already;     // make sure we don't try this more than once
144 /* The following needs access to zdvibuf of ALLOCATEDVIBUF 94/Mar/24 */
145 /* done in closefilesandterminate_regmem  in coerce.h */
146 /* sec 1333 */
147 void close_files_and_terminate (void)
148 {
149   integer k; 
150
151   if (closed_already++)
152   {
153     show_line("close_files_and_terminated already ", 0);
154     return;     // sanity check
155   }
156
157   if (trace_flag)
158     show_line("\nclose_files_and_terminate ", 0);
159
160 /* close all open files */
161   for (k = 0; k <= 15; k++)
162     if (write_open[k])
163     {
164       (void) a_close(write_file[k]);
165     }
166
167 #ifdef STAT
168   if (tracing_stats > 0 || verbose_flag != 0)  /* 93/Nov/30 - bkph */
169     if (log_opened)
170     {
171 /* used to output paragraph breaking statistics here */
172       (void) fprintf(log_file, "%c\n", ' ');
173       (void) fprintf(log_file, "\n");
174       (void) fprintf(log_file, "%s%s\n", "Here is how much of TeX's memory", " you used:");
175       (void) fprintf(log_file, "%c%ld%s", ' ', (long)str_ptr - init_str_ptr, " string");
176       if (str_ptr != init_str_ptr + 1)
177         (void) putc('s',  log_file);
178 #ifdef ALLOCATESTRING
179       if (show_current)
180         (void) fprintf(log_file, "%s%ld\n", " out of ", (long) current_max_strings - init_str_ptr);
181       else
182 #endif
183         (void) fprintf(log_file, "%s%ld\n", " out of ", (long) max_strings - init_str_ptr);
184
185 #ifdef ALLOCATESTRING
186       if (show_current)
187         (void) fprintf(log_file, "%c%ld%s%ld\n", ' ', (long) pool_ptr - init_pool_ptr, " string characters out of ", (long) current_pool_size - init_pool_ptr);
188       else
189 #endif
190         (void) fprintf(log_file, "%c%ld%s%ld\n", ' ', (long) pool_ptr - init_pool_ptr, " string characters out of ", (long) pool_size - init_pool_ptr);
191
192 #ifdef ALLOCATEMAIN
193       if (show_current)
194         (void) fprintf(log_file, "%c%ld%s%ld\n", ' ', (long) lo_mem_max - mem_min + mem_end - hi_mem_min + 2, " words of memory out of ", (long)current_mem_size);
195       else
196 #endif
197         (void) fprintf(log_file, "%c%ld%s%ld\n", ' ', (long) lo_mem_max - mem_min + mem_end - hi_mem_min + 2, " words of memory out of ", (long)mem_end + 1 - mem_min);
198       (void) fprintf(log_file, "%c%ld%s%ld\n", ' ', (long) cs_count, " multiletter control sequences out of ", (long)(hash_size + hash_extra));
199       (void) fprintf(log_file, "%c%ld%s%ld%s", ' ', (long) fmem_ptr, " words of font info for ", (long) font_ptr - 0, " font");
200       if (font_ptr != 1)
201         (void) putc('s',  log_file);
202
203 #ifdef ALLOCATEFONT
204       if (show_current)
205         (void) fprintf(log_file, "%s%ld%s%ld\n", ", out of ", (long)current_font_mem_size, " for ", (long)font_max - 0);
206       else
207 #endif
208         (void) fprintf(log_file, "%s%ld%s%ld\n", ", out of ", (long)font_mem_size, " for ", (long)font_max - 0);
209       (void) fprintf(log_file, "%c%ld%s", ' ', (long)hyph_count, " hyphenation exception");
210       if (hyph_count != 1)
211         (void) putc('s',  log_file);
212
213       (void) fprintf(log_file, "%s%ld\n",  " out of ", (long) hyphen_prime);
214       (void) fprintf(log_file, " ");
215       (void) fprintf(log_file, "%ld%s", (long)max_in_stack, "i,");
216       (void) fprintf(log_file, "%ld%s", (long)max_nest_stack, "n,");
217       (void) fprintf(log_file, "%ld%s", (long)max_param_stack, "p,");
218       (void) fprintf(log_file, "%ld%s", (long)max_buf_stack + 1, "b,");
219       (void) fprintf(log_file, "%ld%s", (long)max_save_stack + 6, "s");
220       (void) fprintf(log_file, " stack positions out of ");
221
222 #ifdef ALLOCATESAVESTACK
223       if (show_current)
224         (void) fprintf(log_file, "%ld%s", (long)current_stack_size, "i,");
225       else
226 #endif
227         (void) fprintf(log_file, "%ld%s", (long)stack_size, "i,");
228
229 #ifdef ALLOCATENESTSTACK
230       if (show_current)
231         (void) fprintf(log_file, "%ld%s", (long)current_nest_size, "n,");
232       else
233 #endif
234         (void) fprintf(log_file, "%ld%s", (long)nest_size, "n,");
235
236 #ifdef ALLOCATEPARAMSTACK
237       if (show_current)
238         (void) fprintf(log_file, "%ld%s", (long)current_param_size, "p,");
239       else
240 #endif
241         (void) fprintf(log_file, "%ld%s", (long)param_size, "p,");
242
243 #ifdef ALLOCATEBUFFER
244       if (show_current)
245         (void) fprintf(log_file, "%ld%s", (long)current_buf_size, "b,");
246       else
247 #endif
248         (void) fprintf(log_file, "%ld%s", (long)buf_size, "b,");
249
250 #ifdef ALLOCATESAVESTACK
251       if (show_current)
252         (void) fprintf(log_file, "%ld%s", (long)current_save_size, "s");
253       else
254 #endif
255         (void) fprintf(log_file, "%ld%s", (long)save_size, "s");
256       (void) fprintf(log_file, "\n");
257
258       if (!knuth_flag)
259         fprintf(log_file, " (i = in_stack, n = nest_stack, p = param_stack, b = buf_stack, s = save_stack)\n");
260
261       if (!knuth_flag)
262         fprintf(log_file, " %d inputs open max out of %d\n", high_in_open, max_in_open);
263
264 /*  Modified 98/Jan/14 to leave out lines with zero counts */
265       if (show_line_break_stats && first_pass_count > 0) /* 96/Feb/8 */
266       {
267         int first_count, secondcount, thirdcount;
268
269         (void) fprintf(log_file, "\nSuccess at breaking %d paragraph%s:", first_pass_count, (first_pass_count == 1) ? "" : "s");
270
271         if (single_line > 0)
272           (void) fprintf(log_file, "\n %d single line `paragraph%s'", single_line, (single_line == 1) ? "" : "s");  /* 96/Apr/23 */
273
274         first_count = first_pass_count - single_line - second_pass_count;
275
276         if (first_count < 0)
277           first_count = 0;
278
279         secondcount = second_pass_count - final_pass_count;
280         thirdcount = final_pass_count - paragraph_failed;
281
282         if (first_pass_count > 0)
283           (void) fprintf(log_file, "\n %d first pass (\\pretolerance = %d)", first_pass_count, pretolerance);
284
285         if (second_pass_count > 0)
286           (void) fprintf(log_file, "\n %d second pass (\\tolerance = %d)", second_pass_count, tolerance);
287
288         if (final_pass_count > 0 || emergency_stretch > 0)
289         {
290           (void) fprintf(log_file, "\n %d third pass (\\emergencystretch = %lgpt)", final_pass_count, (double) emergency_stretch / 65536.0);
291         }
292
293         if (paragraph_failed > 0)
294           (void) fprintf(log_file, "\n %d failed", paragraph_failed);
295
296         (void) putc('\n', log_file);
297
298         if (overfull_hbox > 0)
299           (void) fprintf(log_file, "\n %d overfull \\hbox%s", overfull_hbox, (overfull_hbox > 1) ? "es" : "");
300
301         if (underfull_hbox > 0)
302           (void) fprintf(log_file, "\n %d underfull \\hbox%s", underfull_hbox, (underfull_hbox > 1) ? "es" : "");
303
304         if (overfull_vbox > 0)
305           (void) fprintf(log_file, "\n %d overfull \\vbox%s", overfull_vbox, (overfull_vbox > 1) ? "es" : "");
306
307         if (underfull_vbox > 0)
308           (void) fprintf(log_file, "\n %d underfull \\vbox%s", underfull_vbox, (underfull_vbox > 1) ? "es" : "");
309
310         if (overfull_hbox || underfull_hbox || overfull_vbox || underfull_vbox)
311           (void) putc('\n', log_file);
312       }
313   } /* end of if (log_opened) */ 
314 #endif /* STAT */
315
316   if (pdf_output_flag)
317   {
318     if (total_pages == 0)
319     {
320       print_nl("No pages of output.");
321     }
322     else
323     {
324       HPDF_SaveToFile(yandy_pdf, pdf_file_name);
325       
326       print_nl("Output written on ");
327
328       if (full_file_name_flag && dvi_file_name != NULL)
329         print_char_string((unsigned char *) pdf_file_name);
330       else
331         slow_print(output_file_name);
332
333       print_string(" (");
334       print_int(total_pages);
335       print_string(" page");
336
337       if (total_pages != 1)
338         print_char('s');
339
340       print_string(", ");
341       //print_int(dvi_offset + dvi_ptr);
342       print_int(yandy_pdf->sig_bytes);
343       print_string(" bytes).");
344       //print_string(").");
345       b_close(dvi_file);
346     }
347
348     HPDF_Free(yandy_pdf);
349     free_tfm_map();
350   }
351   else
352   {
353     while (cur_s > -1)
354     {
355       if (cur_s > 0) 
356         dvi_out(142);
357       else
358       {
359         dvi_out(eop);
360         incr(total_pages);
361       }
362
363       decr(cur_s);
364     }
365
366     if (total_pages == 0)
367       print_nl("No pages of output.");
368     else
369     {
370       dvi_out(post);
371       dvi_four(last_bop);
372       last_bop = dvi_offset + dvi_ptr - 5;
373       dvi_four(25400000L);
374       dvi_four(473628672L);
375       prepare_mag();
376       dvi_four(mag);
377       dvi_four(max_v);
378       dvi_four(max_h);
379       dvi_out(max_push / 256);
380       dvi_out(max_push % 256);
381
382       if (total_pages >= 65536)    // 99/Oct/10 dvi_t 16 bit problem
383       {
384         sprintf(log_line, "\nWARNING: page count (dvi_t) in DVI file will be %ld not %ld\n",
385           (total_pages % 65536), total_pages);
386
387         if (log_opened)
388           (void) fputs (log_line, log_file);
389
390         show_line(log_line, 1);
391       }
392
393       dvi_out((total_pages / 256) % 256);
394       dvi_out(total_pages % 256);
395
396       if (show_fonts_used && log_opened)     /* 97/Dec/24 */
397         show_font_info();           // now in local.c
398
399       while (font_ptr > 0)
400       {
401         if (font_used[font_ptr])
402           dvi_font_def(font_ptr);
403
404         decr(font_ptr);
405       }
406
407       dvi_out(post_post);
408       dvi_four(last_bop);
409       dvi_out(id_byte);
410       k = 4 + ((dvi_buf_size - dvi_ptr) % 4);
411
412       while (k > 0)
413       {
414         dvi_out(223);
415         decr(k);
416       }
417
418       if (trace_flag) /* 93/Dec/28 - bkph */
419       {
420         sprintf(log_line, "\ndviwrite %d", dvi_gone);
421         show_line(log_line, 0);
422       }
423
424       if (dvi_limit == half_buf)
425         write_dvi(half_buf, dvi_buf_size - 1);
426
427       if (dvi_ptr > 0)
428         write_dvi(0, dvi_ptr - 1); 
429
430       print_nl("Output written on ");
431
432       if (full_file_name_flag && dvi_file_name != NULL)
433         print_char_string((unsigned char *) dvi_file_name);
434       else
435         slow_print(output_file_name);
436
437       print_string(" (");
438       print_int(total_pages);
439       print_string(" page");
440
441       if (total_pages != 1)
442         print_char('s');
443
444       print_string(", ");
445       print_int(dvi_offset + dvi_ptr);
446       print_string(" bytes).");
447       b_close(dvi_file);
448     }
449   }
450
451   if (log_opened)
452   {
453     (void) putc('\n', log_file);
454     (void) a_close(log_file);
455     selector = selector - 2;
456
457     if (selector == term_only)
458     {
459       print_nl("Transcript written on ");
460
461       if (full_file_name_flag && log_file_name != NULL)
462         print_char_string((unsigned char *) log_file_name);
463       else
464         slow_print(texmf_log_name);
465
466       print_char('.');
467     }
468   }
469
470   print_ln();
471
472   if ((edit_name_start != 0) && (interaction > 0))
473   {
474     call_edit(str_pool, edit_name_start, edit_name_length, edit_line);
475   }
476 }
477 #ifdef DEBUG
478 /* sec 1338 */
479 void debug_help (void) 
480 {/* 888 10 */ 
481   integer k, l, m, n; 
482   while (true) {
483  ; 
484     print_nl(" debug # (-1 to exit):");
485 #ifndef _WINDOWS
486     fflush(stdout); 
487 #endif
488     read(stdin, m);  // ???
489     if (m < 0)return; 
490     else if (m == 0)
491     dumpcore(); 
492     else {
493       read(stdin, n);  // ???
494       switch(m)
495       {case 1 : 
496   print_word(mem[n]); 
497   break; 
498       case 2 : 
499   print_int(mem[n].hh.v.LH); 
500   break; 
501       case 3 : 
502   print_int(mem[n].hh.v.RH); 
503   break; 
504       case 4 : 
505   print_word(eqtb[n]); 
506   break; 
507       case 5 : 
508 #ifdef SHORTFONTINFO
509   print_scaled(font_info[n].sc);  print_char(' ');
510   print_int(font_info[n].qqq.b0);  print_char(':');
511   print_int(font_info[n].qqq.b1);  print_char(':');
512   print_int(font_info[n].qqq.b2);  print_char(':');
513   print_int(font_info[n].qqq.b3);  
514 #else
515   print_word(font_info[n]); 
516 #endif
517   break; 
518       case 6 : 
519   print_word(save_stack[n]); 
520   break; 
521       case 7 : 
522   show_box(n); 
523   break; 
524       case 8 : 
525   {
526     breadth_max = 10000; 
527 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
528 #ifdef ALLOCATESTRING
529 /* About to output node list make some space in string pool 97/Mar/9 */
530   if (pool_ptr + 32000 > current_pool_size)
531     str_pool = realloc_str_pool (increment_pool_size);
532 /* We don't bother to check whether this worked */
533 #endif
534 #ifdef ALLOCATESTRING
535     depth_threshold = current_pool_size - pool_ptr - 10; 
536 #else
537 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
538     depth_threshold = pool_size - pool_ptr - 10; 
539 #endif
540     show_node_list(n); 
541   } 
542   break; 
543       case 9 : 
544   show_token_list(n, 0, 1000); 
545   break; 
546       case 10 : 
547   slow_print(n); 
548   break; 
549       case 11 : 
550   check_mem(n > 0); 
551   break; 
552       case 12 : 
553   search_mem(n); 
554   break; 
555       case 13 : 
556   {
557     read(stdin, l);  // ???
558     print_cmd_chr(n, l); 
559   } 
560   break; 
561       case 14 : 
562   {
563     register integer for_end; 
564     k = 0; 
565     for_end = n; 
566     if (k <= for_end) 
567       do print(buffer[k]); 
568     while(k++ < for_end);
569   } 
570   break; 
571       case 15 : 
572   {
573     font_in_short_display = 0; 
574     short_display(n); 
575   } 
576   break; 
577       case 16 : 
578   panicking = !panicking; 
579   break; 
580   default: 
581   print(63);    /* ? */
582   break; 
583       } 
584     } 
585   } 
586
587 #endif /* DEBUG */