OSDN Git Service

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