OSDN Git Service

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