OSDN Git Service

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