1 /* Copyright 2014 Clerk Ma
\r
3 This program is free software; you can redistribute it and/or modify
\r
4 it under the terms of the GNU General Public License as published by
\r
5 the Free Software Foundation; either version 2 of the License, or
\r
6 (at your option) any later version.
\r
8 This program is distributed in the hope that it will be useful, but
\r
9 WITHOUT ANY WARRANTY; without even the implied warranty of
\r
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
11 General Public License for more details.
\r
13 You should have received a copy of the GNU General Public License
\r
14 along with this program; if not, write to the Free Software
\r
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
\r
18 #define EXTERN extern
\r
20 #include "yandytex.h"
\r
22 extern void pdf_init_fontmaps(void);
\r
23 extern void pdf_close_fontmaps(void);
\r
25 extern void pdf_doc_set_creator(const char * creator);
\r
27 // primitive \pdfminorversion
\r
28 extern void pdf_set_version(unsigned version);
\r
30 extern void pdf_set_compression(int level);
\r
31 extern void pdf_files_init(void);
\r
32 extern void pdf_files_close(void);
\r
34 extern void pdf_init_device(double dvi2pts, int precision, int black_and_white);
\r
35 extern void pdf_close_device(void);
\r
37 extern void pdf_open_document(const char *filename,
\r
39 double media_width, double media_height,
\r
40 double annot_grow_amount, int bookmark_open_depth,
\r
42 extern void pdf_close_document(void);
\r
43 extern void pdf_doc_begin_page(double scale, double x_origin, double y_origin);
\r
44 extern void pdf_doc_end_page(void);
\r
45 extern int spc_exec_at_begin_document(void);
\r
46 extern int spc_exec_at_end_document(void);
\r
47 extern int spc_exec_at_begin_page(void);
\r
48 extern int spc_exec_at_end_page(void);
\r
50 typedef signed long spt_t;
\r
51 extern int pdf_dev_locate_font(const char *font_name, spt_t ptsize);
\r
52 extern void pdf_dev_set_rule(spt_t xpos, spt_t ypos, spt_t width, spt_t height);
\r
53 extern void pdf_dev_set_string(spt_t xpos, spt_t ypos,
\r
54 const void *instr_ptr, int instr_len,
\r
56 int font_id, int ctype);
\r
59 void give_err_help (void)
\r
61 token_show(err_help);
\r
64 boolean open_fmt_file (void)
\r
70 if (buffer[loc] == '&' || buffer[loc] == '+')
\r
76 while (buffer[j] != ' ')
\r
79 pack_buffered_name(0, loc, j - 1);
\r
81 if (w_open_in(fmt_file))
\r
85 printf("%s;%s\n", "Sorry, I can't find that format", " will try the default.");
\r
88 name_of_file[name_length + 1] = '\0';
\r
89 printf("%s (%s);%s\n", "Sorry, I can't find that format",
\r
90 name_of_file + 1, " will try the default.");
\r
91 name_of_file[name_length + 1] = ' ';
\r
92 printf("(Perhaps your %s environment variable is not set correctly)\n",
\r
99 pack_buffered_name(format_default_length - 4, 1, 0);
\r
101 if (!w_open_in(fmt_file))
\r
104 printf("%s!\n", "I can't find the default format file");
\r
107 name_of_file[name_length + 1] = '\0';
\r
108 printf("%s (%s)!\n", "I can't find the default format file", name_of_file + 1);
\r
109 name_of_file[name_length + 1] = ' ';
\r
110 printf("(Perhaps your %s environment variable is not set correctly)\n", "TEXFORMATS");
\r
122 void close_files_and_terminate (void)
\r
127 puts("\nclose_files_and_terminate() ");
\r
129 for (k = 0; k <= 15; k++)
\r
131 a_close(write_file[k]);
\r
134 if (tracing_stats > 0 || verbose_flag != 0)
\r
137 fprintf(log_file, "%c\n", ' ');
\r
138 fprintf(log_file, "\n");
\r
139 fprintf(log_file, "%s%s\n", "Here is how much of TeX's memory", " you used:");
\r
140 fprintf(log_file, "%c%lld%s", ' ', (integer)(str_ptr - init_str_ptr), " string");
\r
142 if (str_ptr != init_str_ptr + 1)
\r
143 putc('s', log_file);
\r
145 #ifdef ALLOCATESTRING
\r
147 fprintf(log_file, "%s%d\n", " out of ", (int)(current_max_strings - init_str_ptr));
\r
150 fprintf(log_file, "%s%d\n", " out of ", (int)(max_strings - init_str_ptr));
\r
152 #ifdef ALLOCATESTRING
\r
154 fprintf(log_file, "%c%lld%s%lld\n", ' ', (integer)(pool_ptr - init_pool_ptr), " string characters out of ", current_pool_size - init_pool_ptr);
\r
157 fprintf(log_file, "%c%lld%s%lld\n", ' ', (integer)(pool_ptr - init_pool_ptr), " string characters out of ", pool_size - init_pool_ptr);
\r
159 #ifdef ALLOCATEMAIN
\r
161 fprintf(log_file, "%c%lld%s%d\n", ' ', (integer)(lo_mem_max - mem_min + mem_end - hi_mem_min + 2), " words of memory out of ", current_mem_size);
\r
164 fprintf(log_file, "%c%lld%s%lld\n", ' ', (integer)(lo_mem_max - mem_min + mem_end - hi_mem_min + 2), " words of memory out of ", mem_end + 1 - mem_min);
\r
166 fprintf(log_file, "%c%lld%s%d\n", ' ', (cs_count), " multiletter control sequences out of ", (hash_size + hash_extra));
\r
167 fprintf(log_file, "%c%lld%s%lld%s", ' ', (fmem_ptr), " words of font info for ", (font_ptr - font_base), " font");
\r
172 #ifdef ALLOCATEFONT
\r
174 fprintf(log_file, "%s%d%s%d\n", ", out of ", current_font_mem_size, " for ", font_max - font_base);
\r
177 fprintf(log_file, "%s%lu%s%d\n", ", out of ", font_mem_size, " for ", font_max - font_base);
\r
179 fprintf(log_file, "%c%lld%s", ' ', hyph_count, " hyphenation exception");
\r
181 if (hyph_count != 1)
\r
184 fprintf(log_file, "%s%lld\n", " out of ", hyphen_prime);
\r
185 fprintf(log_file, " ");
\r
186 fprintf(log_file, "%d%s", (int) max_in_stack, "i,");
\r
187 fprintf(log_file, "%d%s", (int) max_nest_stack, "n,");
\r
188 fprintf(log_file, "%d%s", (int) max_param_stack, "p,");
\r
189 fprintf(log_file, "%d%s", (int) max_buf_stack + 1, "b,");
\r
190 fprintf(log_file, "%d%s", (int) max_save_stack + 6, "s");
\r
191 fprintf(log_file, " stack positions out of ");
\r
193 #ifdef ALLOCATESAVESTACK
\r
195 fprintf(log_file, "%d%s", current_stack_size, "i,");
\r
198 fprintf(log_file, "%d%s", stack_size, "i,");
\r
200 #ifdef ALLOCATENESTSTACK
\r
202 fprintf(log_file, "%d%s", current_nest_size, "n,");
\r
205 fprintf(log_file, "%d%s", nest_size, "n,");
\r
207 #ifdef ALLOCATEPARAMSTACK
\r
209 fprintf(log_file, "%d%s", current_param_size, "p,");
\r
212 fprintf(log_file, "%d%s", param_size, "p,");
\r
214 #ifdef ALLOCATEBUFFER
\r
216 fprintf(log_file, "%d%s", current_buf_size, "b,");
\r
219 fprintf(log_file, "%ld%s", buf_size, "b,");
\r
221 #ifdef ALLOCATESAVESTACK
\r
223 fprintf(log_file, "%d%s", current_save_size, "s");
\r
226 fprintf(log_file, "%d%s", save_size, "s");
\r
228 fprintf(log_file, "\n");
\r
231 fprintf(log_file, " (i = in_stack, n = nest_stack, p = param_stack, b = buf_stack, s = save_stack)\n");
\r
234 fprintf(log_file, " %lld inputs open max out of %d\n", high_in_open, max_in_open);
\r
236 if (show_line_break_stats && first_pass_count > 0)
\r
238 int first_count, second_count, third_count;
\r
240 fprintf(log_file, "\nSuccess at breaking %d paragraph%s:", first_pass_count, (first_pass_count == 1) ? "" : "s");
\r
242 if (single_line > 0)
\r
243 fprintf(log_file, "\n %d single line `paragraph%s'", single_line, (single_line == 1) ? "" : "s");
\r
245 first_count = first_pass_count - single_line - second_pass_count;
\r
247 if (first_count < 0)
\r
250 second_count = second_pass_count - final_pass_count;
\r
251 third_count = final_pass_count - paragraph_failed;
\r
253 if (first_pass_count > 0)
\r
254 fprintf(log_file, "\n %d first pass (\\pretolerance = %lld)", first_pass_count, pretolerance);
\r
256 if (second_pass_count > 0)
\r
257 fprintf(log_file, "\n %d second pass (\\tolerance = %lld)", second_pass_count, tolerance);
\r
259 if (final_pass_count > 0 || emergency_stretch > 0)
\r
260 fprintf(log_file, "\n %d third pass (\\emergencystretch = %lgpt)",
\r
261 final_pass_count, (double) emergency_stretch / 65536.0);
\r
263 if (paragraph_failed > 0)
\r
264 fprintf(log_file, "\n %d failed", paragraph_failed);
\r
266 putc('\n', log_file);
\r
268 if (overfull_hbox > 0)
\r
269 fprintf(log_file, "\n %d overfull \\hbox%s", overfull_hbox, (overfull_hbox > 1) ? "es" : "");
\r
271 if (underfull_hbox > 0)
\r
272 fprintf(log_file, "\n %d underfull \\hbox%s", underfull_hbox, (underfull_hbox > 1) ? "es" : "");
\r
274 if (overfull_vbox > 0)
\r
275 fprintf(log_file, "\n %d overfull \\vbox%s", overfull_vbox, (overfull_vbox > 1) ? "es" : "");
\r
277 if (underfull_vbox > 0)
\r
278 fprintf(log_file, "\n %d underfull \\vbox%s", underfull_vbox, (underfull_vbox > 1) ? "es" : "");
\r
280 if (overfull_hbox || underfull_hbox || overfull_vbox || underfull_vbox)
\r
281 putc('\n', log_file);
\r
287 spc_exec_at_end_document();
\r
288 pdf_close_document();
\r
289 pdf_close_device();
\r
291 pdf_close_fontmaps();
\r
293 if (total_pages == 0)
\r
294 print_nl("No pages of output.");
\r
297 if (total_pages >= 65536)
\r
299 sprintf(log_line, "\nWARNING: page count (dvi_t) in DVI file will be %lld not %lld\n",
\r
300 (total_pages % 65536), total_pages);
\r
303 fputs(log_line, log_file);
\r
305 show_line(log_line, 1);
\r
308 print_nl("Output written on ");
\r
310 if (full_file_name_flag && pdf_file_name != NULL)
\r
311 prints(pdf_file_name);
\r
313 slow_print(output_file_name);
\r
316 print_int(total_pages);
\r
319 if (total_pages != 1)
\r
323 print_int(pdf_output_stats());
\r
324 prints(" bytes).");
\r
331 pdf_set_version(5);
\r
332 pdf_set_compression(0);
\r
333 pdf_doc_set_creator("Y&Y TeX 2.3.0");
\r
335 pdf_init_device(1, 2, 0);
\r
336 pdf_open_document("test.pdf", 0, 595.0, 842.0, 0, 0, (1 << 4));
\r
337 pdf_doc_begin_page(1, 0, 0);
\r
338 spc_exec_at_begin_page();
\r
339 spc_exec_at_end_page();
\r
340 pdf_doc_end_page();
\r
341 pdf_close_document(); // bytes written
\r
342 pdf_close_device();
\r
347 switch (shipout_flag)
\r
365 if (total_pages == 0)
\r
366 print_nl("No pages of output.");
\r
370 dvi_four(last_bop);
\r
371 last_bop = dvi_offset + dvi_ptr - 5;
\r
372 dvi_four(25400000L);
\r
373 dvi_four(473628672L);
\r
378 dvi_out(max_push / 256);
\r
379 dvi_out(max_push % 256);
\r
381 if (total_pages >= 65536)
\r
383 sprintf(log_line, "\nWARNING: page count (dvi_t) in DVI file will be %lld not %lld\n",
\r
384 (total_pages % 65536), total_pages);
\r
387 fputs(log_line, log_file);
\r
389 show_line(log_line, 1);
\r
392 dvi_out((total_pages / 256) % 256);
\r
393 dvi_out(total_pages % 256);
\r
395 if (show_fonts_used && log_opened)
\r
398 while (font_ptr > 0)
\r
400 if (font_used[font_ptr])
\r
401 dvi_font_def(font_ptr);
\r
406 dvi_out(post_post);
\r
407 dvi_four(last_bop);
\r
409 k = 4 + ((dvi_buf_size - dvi_ptr) % 4);
\r
418 printf("\ndvi_write %lld", dvi_gone);
\r
420 if (dvi_limit == half_buf)
\r
421 write_dvi(half_buf, dvi_buf_size - 1);
\r
424 write_dvi(0, dvi_ptr - 1);
\r
426 print_nl("Output written on ");
\r
428 if (full_file_name_flag && dvi_file_name != NULL)
\r
429 prints(dvi_file_name);
\r
431 slow_print(output_file_name);
\r
434 print_int(total_pages);
\r
437 if (total_pages != 1)
\r
441 print_int(dvi_offset + dvi_ptr);
\r
442 prints(" bytes).");
\r
453 selector = selector - 2;
\r
455 if (selector == term_only)
\r
457 print_nl("Transcript written on ");
\r
459 if (full_file_name_flag && log_file_name != NULL)
\r
460 prints(log_file_name);
\r
462 slow_print(log_name);
\r
470 if ((edit_name_start != 0) && (interaction > 0))
\r
471 call_edit(str_pool, edit_name_start, edit_name_length, edit_line);
\r
475 void debug_help (void)
\r
477 integer k, l, m, n;
\r
481 print_nl(" debug # (-1 to exit):");
\r
487 read(stdin, m); // ???
\r
500 print_word(mem[n]);
\r
504 print_int(mem[n].hh.lh);
\r
508 print_int(mem[n].hh.rh);
\r
512 print_word(eqtb[n]);
\r
516 #ifdef SHORTFONTINFO
\r
517 print_scaled(font_info[n].sc);
\r
519 print_int(font_info[n].b0);
\r
521 print_int(font_info[n].b1);
\r
523 print_int(font_info[n].b2);
\r
525 print_int(font_info[n].b3);
\r
527 print_word(font_info[n]);
\r
532 print_word(save_stack[n]);
\r
541 breadth_max = 10000;
\r
542 #ifdef ALLOCATESTRING
\r
543 if (pool_ptr + 32000 > current_pool_size)
\r
544 str_pool = realloc_str_pool (increment_pool_size);
\r
546 #ifdef ALLOCATESTRING
\r
547 depth_threshold = current_pool_size - pool_ptr - 10;
\r
549 depth_threshold = pool_size - pool_ptr - 10;
\r
556 show_token_list(n, 0, 1000);
\r
574 print_cmd_chr(n, l);
\r
580 for (k = 0; k <= n; k++)
\r
587 font_in_short_display = 0;
\r
593 panicking = !panicking;
\r