OSDN Git Service

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