OSDN Git Service

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