OSDN Git Service

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