OSDN Git Service

updated Windows build.
[putex/putex.git] / src / texsourc / tex9.c
1 /* Copyright 2014 Clerk Ma\r
2 \r
3    This program is free software; you can redistribute it and/or modify\r
4    it under the terms of the GNU General Public License as published by\r
5    the Free Software Foundation; either version 2 of the License, or\r
6    (at your option) any later version.\r
7 \r
8    This program is distributed in the hope that it will be useful, but\r
9    WITHOUT ANY WARRANTY; without even the implied warranty of\r
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
11    General Public License for more details.\r
12 \r
13    You should have received a copy of the GNU General Public License\r
14    along with this program; if not, write to the Free Software\r
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\r
16    02110-1301 USA.  */\r
17 \r
18 #define EXTERN extern\r
19 \r
20 #include "dpx.h"\r
21 #include "yandytex.h"\r
22 \r
23 /* sec 1284 */\r
24 void give_err_help (void)\r
25 {\r
26   token_show(err_help);\r
27 }\r
28 /* sec 0524 */\r
29 boolean open_fmt_file (void)\r
30 {\r
31   integer j;\r
32 \r
33   j = loc;\r
34 \r
35   if (buffer[loc] == '&' || buffer[loc] == '+')\r
36   {\r
37     incr(loc);\r
38     j = loc;\r
39     buffer[last] = ' ';\r
40 \r
41     while (buffer[j] != ' ')\r
42       incr(j);\r
43 \r
44     pack_buffered_name(0, loc, j - 1);\r
45 \r
46     if (w_open_in(fmt_file))\r
47       goto found;\r
48   \r
49     if (knuth_flag)\r
50       printf("%s;%s\n", "Sorry, I can't find that format", " will try the default.");\r
51     else\r
52     {\r
53       name_of_file[name_length + 1] = '\0';\r
54       printf("%s (%s);%s\n", "Sorry, I can't find that format",\r
55         name_of_file + 1, " will try the default."); \r
56       name_of_file[name_length + 1] = ' ';\r
57       printf("(Perhaps your %s environment variable is not set correctly)\n",\r
58         "TEXFORMATS");\r
59     }\r
60 \r
61     update_terminal();\r
62   }\r
63 \r
64   pack_buffered_name(format_default_length - 4, 1, 0);\r
65 \r
66   if (!w_open_in(fmt_file))\r
67   {\r
68     if (knuth_flag)\r
69       printf("%s!\n", "I can't find the default format file");\r
70     else\r
71     {\r
72       name_of_file[name_length + 1] = '\0';\r
73       printf("%s (%s)!\n", "I can't find the default format file", name_of_file + 1);\r
74       name_of_file[name_length + 1] = ' ';\r
75       printf("(Perhaps your %s environment variable is not set correctly)\n", "TEXFORMATS");\r
76     }\r
77 \r
78     return false;\r
79   }\r
80 \r
81 found:\r
82   loc = j;\r
83 \r
84   return true;\r
85 }\r
86 /* sec 1333 */\r
87 void close_files_and_terminate (void)\r
88 {\r
89   integer k; \r
90 \r
91   if (trace_flag)\r
92     puts("\nclose_files_and_terminate() ");\r
93 \r
94   for (k = 0; k <= 15; k++)\r
95     if (write_open[k])\r
96       a_close(write_file[k]);\r
97 \r
98 #ifdef STAT\r
99   if (tracing_stats > 0 || verbose_flag != 0)\r
100     if (log_opened)\r
101     {\r
102       fprintf(log_file, "%c\n", ' ');\r
103       fprintf(log_file, "\n");\r
104       fprintf(log_file, "%s%s\n", "Here is how much of TeX's memory", " you used:");\r
105       fprintf(log_file, "%c%lld%s", ' ', (integer)(str_ptr - init_str_ptr), " string");\r
106 \r
107       if (str_ptr != init_str_ptr + 1)\r
108         putc('s', log_file);\r
109 \r
110 #ifdef ALLOCATESTRING\r
111       if (show_current)\r
112         fprintf(log_file, "%s%d\n", " out of ", (int)(current_max_strings - init_str_ptr));\r
113       else\r
114 #endif\r
115         fprintf(log_file, "%s%d\n", " out of ", (int)(max_strings - init_str_ptr));\r
116 \r
117 #ifdef ALLOCATESTRING\r
118       if (show_current)\r
119         fprintf(log_file, "%c%lld%s%lld\n", ' ', (integer)(pool_ptr - init_pool_ptr), " string characters out of ", current_pool_size - init_pool_ptr);\r
120       else\r
121 #endif\r
122         fprintf(log_file, "%c%lld%s%lld\n", ' ', (integer)(pool_ptr - init_pool_ptr), " string characters out of ", pool_size - init_pool_ptr);\r
123 \r
124 #ifdef ALLOCATEMAIN\r
125       if (show_current)\r
126         fprintf(log_file, "%c%lld%s%d\n", ' ', (integer)(lo_mem_max - mem_min + mem_end - hi_mem_min + 2), " words of memory out of ", current_mem_size);\r
127       else\r
128 #endif\r
129         fprintf(log_file, "%c%lld%s%lld\n", ' ', (integer)(lo_mem_max - mem_min + mem_end - hi_mem_min + 2), " words of memory out of ", mem_end + 1 - mem_min);\r
130 \r
131       fprintf(log_file, "%c%lld%s%d\n", ' ', (cs_count), " multiletter control sequences out of ", (hash_size + hash_extra));\r
132       fprintf(log_file, "%c%lld%s%lld%s", ' ', (fmem_ptr), " words of font info for ", (font_ptr - font_base), " font");\r
133 \r
134       if (font_ptr != 1)\r
135         wlog('s');\r
136 \r
137 #ifdef ALLOCATEFONT\r
138       if (show_current)\r
139         fprintf(log_file, "%s%d%s%d\n", ", out of ", current_font_mem_size, " for ", font_max - font_base);\r
140       else\r
141 #endif\r
142         fprintf(log_file, "%s%lu%s%d\n", ", out of ", font_mem_size, " for ", font_max - font_base);\r
143 \r
144       fprintf(log_file, "%c%lld%s", ' ', hyph_count, " hyphenation exception");\r
145 \r
146       if (hyph_count != 1)\r
147         wlog('s');\r
148 \r
149       fprintf(log_file, "%s%lld\n", " out of ", hyphen_prime);\r
150       fprintf(log_file, " ");\r
151       fprintf(log_file, "%d%s", (int) max_in_stack, "i,");\r
152       fprintf(log_file, "%d%s", (int) max_nest_stack, "n,");\r
153       fprintf(log_file, "%d%s", (int) max_param_stack, "p,");\r
154       fprintf(log_file, "%d%s", (int) max_buf_stack + 1, "b,");\r
155       fprintf(log_file, "%d%s", (int) max_save_stack + 6, "s");\r
156       fprintf(log_file, " stack positions out of ");\r
157 \r
158 #ifdef ALLOCATESAVESTACK\r
159       if (show_current)\r
160         fprintf(log_file, "%d%s", current_stack_size, "i,");\r
161       else\r
162 #endif\r
163         fprintf(log_file, "%d%s", stack_size, "i,");\r
164 \r
165 #ifdef ALLOCATENESTSTACK\r
166       if (show_current)\r
167         fprintf(log_file, "%d%s", current_nest_size, "n,");\r
168       else\r
169 #endif\r
170         fprintf(log_file, "%d%s", nest_size, "n,");\r
171 \r
172 #ifdef ALLOCATEPARAMSTACK\r
173       if (show_current)\r
174         fprintf(log_file, "%d%s", current_param_size, "p,");\r
175       else\r
176 #endif\r
177         fprintf(log_file, "%d%s", param_size, "p,");\r
178 \r
179 #ifdef ALLOCATEBUFFER\r
180       if (show_current)\r
181         fprintf(log_file, "%d%s", current_buf_size, "b,");\r
182       else\r
183 #endif\r
184         fprintf(log_file, "%ld%s", buf_size, "b,");\r
185 \r
186 #ifdef ALLOCATESAVESTACK\r
187       if (show_current)\r
188         fprintf(log_file, "%d%s", current_save_size, "s");\r
189       else\r
190 #endif\r
191         fprintf(log_file, "%d%s", save_size, "s");\r
192 \r
193       fprintf(log_file, "\n");\r
194 \r
195       if (!knuth_flag)\r
196         fprintf(log_file, " (i = in_stack, n = nest_stack, p = param_stack, b = buf_stack, s = save_stack)\n");\r
197 \r
198       if (!knuth_flag)\r
199         fprintf(log_file, " %lld inputs open max out of %d\n", high_in_open, max_in_open);\r
200 \r
201       if (show_line_break_stats && first_pass_count > 0)\r
202       {\r
203         int first_count, second_count, third_count;\r
204 \r
205         fprintf(log_file, "\nSuccess at breaking %d paragraph%s:", first_pass_count, (first_pass_count == 1) ? "" : "s");\r
206 \r
207         if (single_line > 0)\r
208           fprintf(log_file, "\n %d single line `paragraph%s'", single_line, (single_line == 1) ? "" : "s");\r
209 \r
210         first_count = first_pass_count - single_line - second_pass_count;\r
211 \r
212         if (first_count < 0)\r
213           first_count = 0;\r
214 \r
215         second_count = second_pass_count - final_pass_count;\r
216         third_count = final_pass_count - paragraph_failed;\r
217 \r
218         if (first_pass_count > 0)\r
219           fprintf(log_file, "\n %d first pass (\\pretolerance = %lld)", first_pass_count, pretolerance);\r
220 \r
221         if (second_pass_count > 0)\r
222           fprintf(log_file, "\n %d second pass (\\tolerance = %lld)", second_pass_count, tolerance);\r
223 \r
224         if (final_pass_count > 0 || emergency_stretch > 0)\r
225           fprintf(log_file, "\n %d third pass (\\emergencystretch = %lgpt)",\r
226             final_pass_count, (double) emergency_stretch / 65536.0);\r
227 \r
228         if (paragraph_failed > 0)\r
229           fprintf(log_file, "\n %d failed", paragraph_failed);\r
230 \r
231         putc('\n', log_file);\r
232 \r
233         if (overfull_hbox > 0)\r
234           fprintf(log_file, "\n %d overfull \\hbox%s", overfull_hbox, (overfull_hbox > 1) ? "es" : "");\r
235 \r
236         if (underfull_hbox > 0)\r
237           fprintf(log_file, "\n %d underfull \\hbox%s", underfull_hbox, (underfull_hbox > 1) ? "es" : "");\r
238 \r
239         if (overfull_vbox > 0)\r
240           fprintf(log_file, "\n %d overfull \\vbox%s", overfull_vbox, (overfull_vbox > 1) ? "es" : "");\r
241 \r
242         if (underfull_vbox > 0)\r
243           fprintf(log_file, "\n %d underfull \\vbox%s", underfull_vbox, (underfull_vbox > 1) ? "es" : "");\r
244 \r
245         if (overfull_hbox || underfull_hbox || overfull_vbox || underfull_vbox)\r
246           putc('\n', log_file);\r
247       }\r
248   }\r
249 #endif\r
250 \r
251   {\r
252     spc_exec_at_end_document();\r
253     pdf_close_document();\r
254     pdf_close_device();\r
255     pdf_files_close();\r
256     pdf_close_fontmaps();\r
257 \r
258     if (total_pages == 0)\r
259       print_nl("No pages of output.");\r
260     else\r
261     {\r
262       if (total_pages >= 65536)\r
263       {\r
264         sprintf(log_line, "\nWARNING: page count (dvi_t) in DVI file will be %lld not %lld\n",\r
265           (total_pages % 65536), total_pages);\r
266 \r
267         if (log_opened)\r
268           fputs(log_line, log_file);\r
269 \r
270         show_line(log_line, 1);\r
271       }\r
272 \r
273       print_nl("Output written on ");\r
274 \r
275       if (full_file_name_flag && pdf_file_name != NULL)\r
276         prints(pdf_file_name);\r
277       else\r
278         slow_print(output_file_name);\r
279 \r
280       prints(" (");\r
281       print_int(total_pages);\r
282       prints(" page");\r
283 \r
284       if (total_pages != 1)\r
285         print_char('s');\r
286 \r
287       prints(", ");\r
288       print_int(pdf_output_stats());\r
289       prints(" bytes).");\r
290       b_close(pdf_file);\r
291     }\r
292   }\r
293 \r
294 /*\r
295   switch (shipout_flag)\r
296   {\r
297     case out_dvi_flag:\r
298     case out_xdv_flag:\r
299       {\r
300         while (cur_s > -1)\r
301         {\r
302           if (cur_s > 0) \r
303             dvi_out(pop);\r
304           else\r
305           {\r
306             dvi_out(eop);\r
307             incr(total_pages);\r
308           }\r
309 \r
310           decr(cur_s);\r
311         }\r
312 \r
313         if (total_pages == 0)\r
314           print_nl("No pages of output.");\r
315         else\r
316         {\r
317           dvi_out(post);\r
318           dvi_four(last_bop);\r
319           last_bop = dvi_offset + dvi_ptr - 5;\r
320           dvi_four(25400000L);\r
321           dvi_four(473628672L);\r
322           prepare_mag();\r
323           dvi_four(mag);\r
324           dvi_four(max_v);\r
325           dvi_four(max_h);\r
326           dvi_out(max_push / 256);\r
327           dvi_out(max_push % 256);\r
328 \r
329           if (total_pages >= 65536)\r
330           {\r
331             sprintf(log_line, "\nWARNING: page count (dvi_t) in DVI file will be %lld not %lld\n",\r
332               (total_pages % 65536), total_pages);\r
333 \r
334             if (log_opened)\r
335               fputs(log_line, log_file);\r
336 \r
337             show_line(log_line, 1);\r
338           }\r
339 \r
340           dvi_out((total_pages / 256) % 256);\r
341           dvi_out(total_pages % 256);\r
342 \r
343           if (show_fonts_used && log_opened)\r
344             show_font_info();\r
345 \r
346           while (font_ptr > 0)\r
347           {\r
348             if (font_used[font_ptr])\r
349               dvi_font_def(font_ptr);\r
350 \r
351             decr(font_ptr);\r
352           }\r
353 \r
354           dvi_out(post_post);\r
355           dvi_four(last_bop);\r
356           dvi_out(id_byte);\r
357           k = 4 + ((dvi_buf_size - dvi_ptr) % 4);\r
358 \r
359           while (k > 0)\r
360           {\r
361             dvi_out(223);\r
362             decr(k);\r
363           }\r
364 \r
365           if (trace_flag)\r
366             printf("\ndvi_write %lld", dvi_gone);\r
367 \r
368           if (dvi_limit == half_buf)\r
369             write_dvi(half_buf, dvi_buf_size - 1);\r
370 \r
371           if (dvi_ptr > 0)\r
372             write_dvi(0, dvi_ptr - 1); \r
373 \r
374           print_nl("Output written on ");\r
375 \r
376           if (full_file_name_flag && dvi_file_name != NULL)\r
377             prints(dvi_file_name);\r
378           else\r
379             slow_print(output_file_name);\r
380 \r
381           prints(" (");\r
382           print_int(total_pages);\r
383           prints(" page");\r
384 \r
385           if (total_pages != 1)\r
386             print_char('s');\r
387 \r
388           prints(", ");\r
389           print_int(dvi_offset + dvi_ptr);\r
390           prints(" bytes).");\r
391           b_close(dvi_file);\r
392         }\r
393       }\r
394       break;\r
395   }\r
396 */\r
397   if (log_opened)\r
398   {\r
399     wlog_cr();\r
400     a_close(log_file);\r
401     selector = selector - 2;\r
402 \r
403     if (selector == term_only)\r
404     {\r
405       print_nl("Transcript written on ");\r
406 \r
407       if (full_file_name_flag && log_file_name != NULL)\r
408         prints(log_file_name);\r
409       else\r
410         slow_print(log_name);\r
411 \r
412       print_char('.');\r
413     }\r
414   }\r
415 \r
416   print_ln();\r
417 \r
418   if ((edit_name_start != 0) && (interaction > 0))\r
419     call_edit(str_pool, edit_name_start, edit_name_length, edit_line);\r
420 }\r
421 #ifdef DEBUG\r
422 /* sec 1338 */\r
423 void debug_help (void) \r
424 {\r
425   integer k, l, m, n;\r
426 \r
427   while (true)\r
428   { \r
429     print_nl(" debug # (-1 to exit):");\r
430 \r
431 #ifndef _WINDOWS\r
432     fflush(stdout); \r
433 #endif\r
434 \r
435     read(stdin, m);  // ???\r
436 \r
437     if (m < 0)\r
438       return;\r
439     else if (m == 0)\r
440       dumpcore();\r
441     else\r
442     {\r
443       read(stdin, n);\r
444 \r
445       switch (m)\r
446       {\r
447         case 1:\r
448           print_word(mem[n]);\r
449           break;\r
450 \r
451         case 2:\r
452           print_int(mem[n].hh.lh);\r
453           break;\r
454           \r
455         case 3:\r
456           print_int(mem[n].hh.rh);\r
457           break;\r
458         \r
459         case 4:\r
460           print_word(eqtb[n]);\r
461           break;\r
462 \r
463         case 5:\r
464 #ifdef SHORTFONTINFO\r
465           print_scaled(font_info[n].sc);\r
466           print_char(' ');\r
467           print_int(font_info[n].b0);\r
468           print_char(':');\r
469           print_int(font_info[n].b1);\r
470           print_char(':');\r
471           print_int(font_info[n].b2);\r
472           print_char(':');\r
473           print_int(font_info[n].b3);\r
474 #else\r
475           print_word(font_info[n]); \r
476 #endif\r
477           break;\r
478         \r
479         case 6:\r
480           print_word(save_stack[n]);\r
481           break;\r
482           \r
483         case 7:\r
484           show_box(n);\r
485           break;\r
486         \r
487         case 8:\r
488           {\r
489             breadth_max = 10000;\r
490 #ifdef ALLOCATESTRING\r
491             if (pool_ptr + 32000 > current_pool_size)\r
492               str_pool = realloc_str_pool (increment_pool_size);\r
493 #endif\r
494 #ifdef ALLOCATESTRING\r
495             depth_threshold = current_pool_size - pool_ptr - 10;\r
496 #else\r
497             depth_threshold = pool_size - pool_ptr - 10;\r
498 #endif\r
499             show_node_list(n);\r
500           }\r
501           break;\r
502         \r
503         case 9:\r
504           show_token_list(n, 0, 1000);\r
505           break;\r
506         \r
507         case 10:\r
508           slow_print(n);\r
509           break;\r
510         \r
511         case 11:\r
512           check_mem(n > 0);\r
513           break;\r
514         \r
515         case 12:\r
516           search_mem(n);\r
517           break;\r
518         \r
519         case 13:\r
520           {\r
521             read(stdin, l);\r
522             print_cmd_chr(n, l);\r
523           }\r
524           break;\r
525         \r
526         case 14:\r
527           {\r
528             for (k = 0; k <= n; k++)\r
529               print(buffer[k]);\r
530           }\r
531           break;\r
532         \r
533         case 15:\r
534           {\r
535             font_in_short_display = 0;\r
536             short_display(n);\r
537           }\r
538           break;\r
539         \r
540         case 16:\r
541           panicking = !panicking;\r
542           break;\r
543         \r
544         default:\r
545           print('?');\r
546           break;\r
547       }\r
548     }\r
549   }\r
550 }\r
551 #endif\r