OSDN Git Service

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