OSDN Git Service

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