Debian Codegraph @

texk/dvi2tty/dvi2tty-src/disdvi.c

raw
1 /*****************************************************************************/
2 /* */
3 /* disdvi --- disassembles TeX dvi files. */
4 /* */
5 /* */
6 /* 2.27 30apr2022 TexLive support multibyte output for SET[23] */
7 /* in pTeX dvi with PTEXENC library */
8 /* 2.26 23oct2010 TexLive support pTeX and XeTeX */
9 /* 2.25 23jan2003 M.J.E. Mol fixed bug in copying font name (name[i]) */
10 /* 2.24 27may96 M.J.E. Mol A few typecasts added */
11 /* 2.23 23jul95 M.J.E. Mol Cleanups from [email protected] */
12 /* 2.22 13dec90 M.J.E. Mol Fixed bug in num(). Cleaned up code. */
13 /* 2.21 03may90 M.J.E. Mol Created usage(). */
14 /* 2.2 02may90 M.J.E. Mol Included port to VAX/VMS VAXC by */
15 /* Robert Schneider. */
16 /* 2.1 19jan90 M.J.E. Mol Maintain a list of fonts and */
17 /* show fontnames in font changes. */
18 /* Show character code when printing ligatures */
19 /* 2.0 23jan89 M.J.E. Mol (c) 1989 */
20 /* [email protected] */
21 /* */
22 /*****************************************************************************/
23
24 /*
25 * dvi2tty
26 * Copyright (C) 2003 Marcel J.E. Mol <[email protected]>
27 *
28 * This program is free software; you can redistribute it and/or
29 * modify it under the terms of the GNU General Public License
30 * as published by the Free Software Foundation; either version 2
31 * of the License, or (at your option) any later version.
32 *
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
37 *
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 *
42 */
43
44 const char *disdvi = "@(#) disdvi.c 2.27 20220501 M.J.E. Mol (c) 1989-2010, [email protected]";
45
46 /*
47 * Include files
48 */
49
50 #if defined(KPATHSEA)
51 # define NO_DEBUG 1
52 # include <kpathsea/config.h>
53 # include <kpathsea/lib.h>
54 #if defined(WIN32)
55 # include <kpathsea/variable.h>
56 #endif
57 #endif
58
59 #include <stdio.h>
60 #include <stdlib.h>
61 #if defined(WIN32)
62 # include <fcntl.h>
63 #else
64 # include <unistd.h>
65 #endif
66 #include <ctype.h>
67 #include <string.h>
68 #include "commands.h"
69 #if defined(WIN32) && defined(KPATHSEA)
70 #undef fopen
71 #define fopen fsyscp_fopen
72 #endif
73
74 #if defined(PTEXENC)
75 #include <kpathsea/config.h>
76 #include <kpathsea/readable.h>
77 #include <ptexenc/ptexenc.h>
78 #include <ptexenc/unicode.h>
79
80 /* internal encoding for ASCII pTeX : "euc" or "sjis" */
81 #define PTEX_INTERNAL_ENC "euc"
82
83 /* internal encoding for upTeX : "uptex" */
84 #define UPTEX_INTERNAL_ENC "uptex"
85 #endif
86
87 /*
88 * Constant definitions
89 */
90
91 #define LASTCHAR 127 /* max dvi character, above are commands */
92
93 #define get1() num(1)
94 #define get2() num(2)
95 #define get3() num(3)
96 #define get4() num(4)
97 #define sget1() snum(1)
98 #define sget2() snum(2)
99 #define sget3() snum(3)
100 #define sget4() snum(4)
101
102
103
104 /*
105 * Type definitions
106 */
107
108 typedef struct _font {
109 long num;
110 struct _font * next;
111 char * name;
112 } font;
113
114
115
116 /*
117 * Variable declarations
118 */
119
120 font * fonts = NULL;
121 FILE * dvifp;
122 char * dvi_name;
123 long pc = 0;
124
125 char * progname;
126
127 int is_ptex = 0;
128 #if defined(PTEXENC)
129 int is_uptex = 0;
130 int with_ptexenc = 0;
131 #endif
132 int is_xetex = 0;
133 const char * dvi_ext = ".dvi";
134
135 /*
136 * Function declarations
137 */
138
139 void bop (void);
140 void preamble (void);
141 void postamble (void);
142 void postpostamble (void);
143 void fontdef (int x);
144 const char * fontname (unsigned long fntnum);
145 void special (int x);
146 void printnonprint (int ch);
147 unsigned long num (int size);
148 long snum (int size);
149 void usage (void);
150 void picfile (int opcode);
151 void natfontdef (int opcode);
152 void glyphs (int opcode);
153 void dvidir (int opcode);
154 void invalid (int opcode);
155
156 #if defined(PTEXENC)
157 int printch(int code, unsigned long ch0)
158 {
159 int ch1;
160 if (with_ptexenc) {
161 printf("\"%lX", ch0);
162 if (code>1) {
163 ch1 = toBUFF(fromDVI(ch0));
164 printf(" ");
165 putc2('(', stdout);
166 if (BYTE1(ch1) != 0) putc2(BYTE1(ch1), stdout);
167 if (BYTE2(ch1) != 0) putc2(BYTE2(ch1), stdout);
168 if (BYTE3(ch1) != 0) putc2(BYTE3(ch1), stdout);
169 /* always */ putc2(BYTE4(ch1), stdout);
170 putc2(')', stdout);
171 }
172 } else {
173 printf("%ld", ch0);
174 }
175 return ch0;
176 } /* main */
177 #endif
178
179
180 /*
181 * MAIN --
182 */
183
184 int main(int argc, char **argv)
185 {
186 register int opcode; /* dvi opcode */
187 register int i;
188 unsigned long fontnum;
189 #if defined(PTEXENC)
190 int code;
191 #endif
192
193 #if defined(WIN32) && defined(KPATHSEA)
194 char **av, *enc;
195 int ac;
196 kpse_set_program_name(argv[0], "disdvi");
197 enc = kpse_var_value("command_line_encoding");
198 if (get_command_line_args_utf8(enc, &ac, &av)) {
199 argv = av;
200 argc = ac;
201 }
202 _setmode (fileno(stdout), _O_BINARY);
203 #endif
204
205 progname = *argv++;
206
207 #if defined(PTEXENC)
208 while ((argc > 1) && (*argv[0] == '-')) {
209 #else
210 if ((argc > 1) && (*argv[0] == '-')) {
211 #endif
212 if (!strcmp(*argv, "-h")) {
213 usage();
214 exit(0);
215 }
216 if (!strcmp(*argv, "-p")) {
217 is_ptex = 1;
218 #if defined(PTEXENC)
219 set_enc_string (NULL, PTEX_INTERNAL_ENC);
220 #endif
221 }
222 #if defined(PTEXENC)
223 else if (!strcmp(*argv, "-u")) {
224 is_uptex = 1;
225 enable_UPTEX(true);
226 set_enc_string (NULL, UPTEX_INTERNAL_ENC);
227 }
228 else if (!strncmp(*argv, "-E", 2)) {
229 with_ptexenc = 1;
230 set_prior_file_enc();
231 if (!strcmp(*argv, "-Ee")) set_enc_string ("euc", NULL);
232 if (!strcmp(*argv, "-Es")) set_enc_string ("sjis", NULL);
233 if (!strcmp(*argv, "-Ej")) set_enc_string ("jis", NULL);
234 if (!strcmp(*argv, "-Eu")) set_enc_string ("utf8", NULL);
235 }
236 #endif
237 else if (!strcmp(*argv, "-x")) {
238 is_xetex = 1;
239 dvi_ext = ".xdv";
240 } else {
241 fprintf(stderr, "Invalid option `%s'\n", *argv);
242 usage();
243 exit(3);
244 }
245 argv++;
246 argc--;
247 }
248
249 if (argc > 2) {
250 fprintf(stderr, "Too many arguments\n");
251 usage();
252 exit(1);
253 }
254
255 if (argc == 2) {
256 if ((i = strlen(*argv)) == 0) {
257 fprintf(stderr, "Illegal empty filename\n");
258 usage();
259 exit(2);
260 }
261 if ((i >= 5) && (!strcmp(*argv+i-4, dvi_ext)))
262 dvi_name = *argv;
263 else {
264 if ((dvi_name = malloc((i+5) * sizeof(char))) == NULL) {
265 perror("dvi_name");
266 exit(1);
267 }
268 strcpy(dvi_name, *argv);
269 strcat(dvi_name, dvi_ext);
270 }
271 if ((dvifp = fopen(dvi_name, "r")) == NULL) {
272 perror(dvi_name);
273 exit(3);
274 }
275 }
276 else
277 dvifp = stdin;
278
279 #if defined(WIN32)
280 setmode(fileno(dvifp), _O_BINARY);
281 #endif
282
283 while ((opcode = (int) get1()) != EOF) { /* process until end of file */
284 printf("%06ld: ", pc - 1);
285 if ((opcode <= LASTCHAR) && isprint(opcode)) {
286 printf("Char: ");
287 while ((opcode <= LASTCHAR) && isprint(opcode)) {
288 putchar(opcode);
289 opcode = (int) get1();
290 }
291 putchar('\n');
292 printf("%06ld: ", pc - 1);
293 }
294
295 if (opcode <= LASTCHAR)
296 printnonprint(opcode); /* it must be a non-printable */
297 else if ((opcode >= FONT_00) && (opcode <= FONT_63))
298 printf("FONT_%02d /* %s */\n", opcode - FONT_00,
299 fontname((unsigned long) opcode - FONT_00));
300 else
301 switch (opcode) {
302 case SET1 :
303 case SET2 :
304 case SET3 :
305 case SET4 :
306 #if defined(PTEXENC)
307 code = opcode - SET1 + 1;
308 printf("SET%d: ", code);
309 printch(code, num(code));
310 printf("\n");
311 #else
312 printf("SET%d: %ld\n", opcode - SET1 + 1,
313 num(opcode - SET1 + 1));
314 #endif
315 break;
316 case SET_RULE : printf("SET_RULE: height: %ld\n", sget4());
317 printf("%06ld: ", pc);
318 printf(" length: %ld\n", sget4());
319 break;
320 case PUT1 :
321 case PUT2 :
322 case PUT3 :
323 case PUT4 :
324 #if defined(PTEXENC)
325 code = opcode - PUT1 + 1;
326 printf("PUT%d: ", code);
327 printch(code, num(code));
328 printf("\n");
329 #else
330 printf("PUT%d: %ld\n", opcode - PUT1 + 1,
331 num(opcode - PUT1 + 1));
332 #endif
333 break;
334 case PUT_RULE : printf("PUT_RULE: height: %ld\n", sget4());
335 printf("%06ld: ", pc);
336 printf(" length: %ld\n", sget4());
337 break;
338 case NOP : printf("NOP\n"); break;
339 case BOP : bop(); break;
340 case EOP : printf("EOP\n"); break;
341 case PUSH : printf("PUSH\n"); break;
342 case POP : printf("POP\n"); break;
343 case RIGHT1 :
344 case RIGHT2 :
345 case RIGHT3 :
346 case RIGHT4 : printf("RIGHT%d: %ld\n", opcode - RIGHT1 + 1,
347 snum(opcode - RIGHT1 + 1));
348 break;
349 case W0 : printf("W0\n"); break;
350 case W1 :
351 case W2 :
352 case W3 :
353 case W4 : printf("W%d: %ld\n", opcode - W0,
354 snum(opcode - W0));
355 break;
356 case X0 : printf("X0\n"); break;
357 case X1 :
358 case X2 :
359 case X3 :
360 case X4 : printf("X%d: %ld\n", opcode - X0,
361 snum(opcode - X0));
362 break;
363 case DOWN1 :
364 case DOWN2 :
365 case DOWN3 :
366 case DOWN4 : printf("DOWN%d: %ld\n", opcode - DOWN1 + 1,
367 snum(opcode - DOWN1 + 1));
368 break;
369 case Y0 : printf("Y0\n"); break;
370 case Y1 :
371 case Y2 :
372 case Y3 :
373 case Y4 : printf("Y%d: %ld\n", opcode - Y0,
374 snum(opcode - Y0));
375 break;
376 case Z0 : printf("Z0\n"); break;
377 case Z1 :
378 case Z2 :
379 case Z3 :
380 case Z4 : printf("Z%d: %ld\n", opcode - Z0,
381 snum(opcode - Z0));
382 break;
383 case FNT1 :
384 case FNT2 :
385 case FNT3 :
386 case FNT4 : fontnum = num(opcode -FNT1 + 1);
387 printf("FNT%d: %ld /* %s */\n",
388 opcode - FNT1 + 1, fontnum,
389 fontname(fontnum));
390 break;
391 case XXX1 :
392 case XXX2 :
393 case XXX3 :
394 case XXX4 : special(opcode - XXX1 + 1); break;
395 case FNT_DEF1 :
396 case FNT_DEF2 :
397 case FNT_DEF3 :
398 case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1); break;
399 case PRE : preamble(); break;
400 case POST : postamble(); break;
401 case POST_POST: postpostamble(); break;
402 case PIC_FILE : picfile(opcode); break;
403 case NAT_FNT : natfontdef(opcode); break;
404 case SET_GL_AR:
405 case SET_GL_ST: glyphs(opcode); break;
406 case DVI_DIR : dvidir(opcode); break;
407 default : invalid(opcode);
408 }
409 }
410
411 exit(0);
412
413 } /* main */
414
415
416
417 /*
418 * BOP -- Process beginning of page.
419 */
420
421 void bop(void)
422 {
423 int i;
424
425 printf("BOP page number : %ld", sget4());
426 for (i=9; i > 0; i--) {
427 if (i % 3 == 0)
428 printf("\n%06ld: ", pc);
429 printf(" %6ld", sget4());
430 }
431 printf("\n%06ld: ", pc);
432 printf(" prev page offset : %06ld\n", sget4());
433
434 return;
435
436 } /* bop */
437
438
439
440 /*
441 * POSTAMBLE -- Process post amble.
442 */
443
444 void postamble(void)
445 {
446
447 printf("POST last page offset : %06ld\n", sget4());
448 printf("%06ld: ", pc);
449 printf(" numerator : %lu\n", get4());
450 printf("%06ld: ", pc);
451 printf(" denominator : %lu\n", get4());
452 printf("%06ld: ", pc);
453 printf(" magnification : %lu\n", get4());
454 printf("%06ld: ", pc);
455 printf(" max page height : %lu\n", get4());
456 printf("%06ld: ", pc);
457 printf(" max page width : %lu\n", get4());
458 printf("%06ld: ", pc);
459 printf(" stack size needed: %d\n", (int) get2());
460 printf("%06ld: ", pc);
461 printf(" number of pages : %d\n", (int) get2());
462
463 return;
464
465 } /* postamble */
466
467
468
469 /*
470 * PREAMBLE -- Process pre amble.
471 */
472
473 void preamble(void)
474 {
475 register int i;
476
477 printf("PRE version : %d\n", (int) get1());
478 printf("%06ld: ", pc);
479 printf(" numerator : %lu\n", get4());
480 printf("%06ld: ", pc);
481 printf(" denominator : %lu\n", get4());
482 printf("%06ld: ", pc);
483 printf(" magnification : %lu\n", get4());
484 printf("%06ld: ", pc);
485 i = (int) get1();
486 printf(" job name (%3d) :", i);
487 while (i-- > 0)
488 putchar((int) get1());
489 putchar('\n');
490
491 return;
492
493 } /* preamble */
494
495
496
497 /*
498 * POSTPOSTAMBLE -- Process post post amble.
499 */
500
501 void postpostamble(void)
502 {
503 register int i;
504
505 printf("POSTPOST postamble offset : %06lu\n", get4());
506 printf("%06ld: ", pc);
507 printf(" version : %d\n", (int) get1());
508 while ((i = (int) get1()) == TRAILER) {
509 printf("%06ld: ", pc - 1);
510 printf("TRAILER\n");
511 }
512 while (i != EOF) {
513 printf("%06ld: ", pc - 1);
514 printf("BAD DVI FILE END: 0x%02X\n", i);
515 i = (int) get1();
516 }
517
518 return;
519
520 } /* postpostamble */
521
522
523
524 /*
525 * SPECIAL -- Process special opcode.
526 */
527
528 void special(int x)
529 {
530 register long len;
531
532 len = num(x);
533 printf("XXX%d: %ld bytes\n", x, len);
534 printf("%06ld: ", pc);
535 for (; len>0; len--) /* a bit dangerous ... */
536 putchar((int) get1()); /* can be non-printables */
537 putchar('\n');
538
539 return;
540
541 } /* special */
542
543
544
545 /*
546 * FONTDEF -- Process a font definition.
547 */
548
549 void fontdef(int x)
550 {
551 register int i;
552 char * name;
553 font * fnt;
554 int namelen;
555 unsigned long fntnum;
556 int new = 0;
557
558 fntnum = num(x);
559 printf("FNT_DEF%d: %ld\n", x, fntnum);
560 printf("%06ld: ", pc); /* avoid side-effect on pc in get4() */
561 printf(" checksum : %lu\n", get4());
562 printf("%06ld: ", pc);
563 printf(" scale : %lu\n", get4());
564 printf("%06ld: ", pc);
565 printf(" design : %lu\n", get4());
566 printf("%06ld: ", pc);
567 printf(" name : ");
568 namelen = (int) get1() + (int) get1();
569 fnt = fonts;
570 while (fnt != NULL && fnt->num != fntnum)
571 fnt = fnt->next;
572 if (fnt == NULL) {
573 if ((fnt = (font *) malloc(sizeof(font))) == NULL) {
574 perror("fontdef");
575 exit(1);
576 }
577 fnt->num = fntnum;
578 new = 1;
579 }
580 else
581 free(fnt->name); /* free old name */
582 if ((name = (char *) malloc((namelen+1) * sizeof(char))) == NULL) {
583 perror("fontdef");
584 exit(1);
585 }
586
587 for (i = 0; i < namelen; i++)
588 name[i] = get1();
589 name[i] = '\0';
590 fnt->name = name;
591 if (new) {
592 fnt->next = fonts;
593 fonts = fnt;
594 }
595
596 printf("%s\n", name);
597
598 return;
599
600 } /* fontdef */
601
602
603
604 /*
605 * FONTNAME -- Return font name.
606 */
607
608 const char * fontname(unsigned long fntnum)
609 {
610 font * fnt;
611
612 fnt = fonts;
613 while (fnt != NULL && fnt->num != fntnum)
614 fnt = fnt->next;
615 if (fnt != NULL)
616 return fnt->name;
617
618 return "unknown fontname";
619
620 } /* fontname */
621
622
623
624 /*
625 * PRINTNONPRINT -- Translate non-printable characters.
626 */
627
628 void printnonprint(int ch)
629 {
630
631 printf("Char: ");
632 switch (ch) {
633 case 11 : printf("ff /* ligature (non-printing) 0x%02X */",
634 ch);
635 break;
636 case 12 : printf("fi /* ligature (non-printing) 0x%02X */",
637 ch);
638 break;
639 case 13 : printf("fl /* ligature (non-printing) 0x%02X */",
640 ch);
641 break;
642 case 14 : printf("ffi /* ligature (non-printing) 0x%02X */",
643 ch);
644 break;
645 case 15 : printf("ffl /* ligature (non-printing) 0x%02X */",
646 ch);
647 break;
648 case 16 : printf("i /* (non-printing) 0x%02X */", ch);
649 break;
650 case 17 : printf("j /* (non-printing) 0x%02X */", ch);
651 break;
652 case 25 : printf("ss /* german (non-printing) 0x%02X */", ch);
653 break;
654 case 26 : printf("ae /* scandinavian (non-printing) 0x%02X */",
655 ch);
656 break;
657 case 27 : printf("oe /* scandinavian (non-printing) 0x%02X */",
658 ch);
659 break;
660 case 28 : printf("o /* scandinavian (non-printing) 0x%02X */",
661 ch);
662 break;
663 case 29 : printf("AE /* scandinavian (non-printing) 0x%02X */",
664 ch);
665 break;
666 case 30 : printf("OE /* scandinavian (non-printing) 0x%02X */",
667 ch);
668 break;
669 case 31 : printf("O /* scandinavian (non-printing) 0x%02X */",
670 ch);
671 break;
672 default : printf("0x%02X", ch); break;
673 }
674 putchar('\n');
675
676 return;
677
678 } /* printnonprint */
679
680
681
682 /*
683 * NUM --
684 */
685
686 unsigned long num(int size)
687 {
688 register int i;
689 register unsigned long x = 0;
690
691 pc += size;
692 for (i = size; i > 0; i--)
693 x = (x << 8) + (unsigned) getc(dvifp);
694
695 return x;
696
697 } /* num */
698
699
700
701 /*
702 * SNUM --
703 */
704
705 long snum(int size)
706 {
707 register int i;
708 register long x;
709
710 pc += size;
711 x = getc(dvifp);
712 if (x & 0x80)
713 x -= 0x100;
714 for (i = size - 1; i > 0; i--)
715 x = (x << 8) + (unsigned) getc(dvifp);
716
717 return x;
718
719 } /* snum */
720
721
722
723 /*
724 * USAGE --
725 */
726
727 void usage(void)
728 {
729
730 fprintf(stderr, "\n%s\n\n", disdvi);
731 fprintf(stderr, " disassembles (p)TeX dvi and XeTeX xdv files\n");
732 #if defined(PTEXENC)
733 fprintf(stderr, "Usage: %s [-h | [-p] [-u] [-Eenc] [dvi_file[.dvi]]\n", progname);
734 #else
735 fprintf(stderr, "Usage: %s [-h | [-p] [dvi_file[.dvi]]\n", progname);
736 #endif
737 fprintf(stderr, " | -x [xdv_file[.xdv]]]\n");
738 fprintf(stderr, "Options:\n");
739 #if defined(PTEXENC)
740 fprintf(stderr, " -p Support ASCII pTeX dvi\n");
741 fprintf(stderr, " -u Support upTeX dvi\n");
742 fprintf(stderr, " -x Support XeTeX xdv\n");
743 fprintf(stderr, " -Eenc Output multibyte encoding. The enc argument denotes u:UTF8 e:EUC-JP s:Shift_JIS j:JIS\n");
744 #else
745 fprintf(stderr, " -p Support ASCII pTeX dvi\n");
746 fprintf(stderr, " -x Support XeTeX xdv\n");
747 #endif
748 fprintf(stderr, " -h This help message.\n");
749 fprintf(stderr, "\n If you like this code and want to support is feel free\n to donate at Paypal [email protected]. Thanks.\n\n");
750
751
752 return;
753
754 } /* usage */
755
756
757
758 void picfile(int opcode)
759 {
760 int i;
761
762 if (!is_xetex) {
763 invalid(opcode);
764 return;
765 }
766
767 printf("PIC_FILE flags : %ld\n", get1());
768 printf("%06ld: trans :", pc);
769 for (i=0; i<6; i++)
770 printf(" %ld", sget4());
771 printf("\n%06ld: ", pc);
772 printf(" page : %ld\n", get2());
773 printf("%06ld: ", pc);
774 i = (int) get1();
775 printf(" path name (%3d) :", i);
776 while (i-- > 0)
777 putchar((int) get1());
778 putchar('\n');
779 } /* picfile */
780
781
782
783 void natfontdef(int opcode)
784 {
785 register int i;
786 char * name;
787 font * fnt;
788 int flags, namelen, famlen, stylen;
789 long fntnum;
790 int new = 0;
791
792 if (!is_xetex) {
793 invalid(opcode);
794 return;
795 }
796
797 fntnum = num(4);
798 printf("NAT_FNT: %ld\n", fntnum);
799 printf("%06ld: ", pc);
800 printf(" scale : %lu\n", get4());
801 printf("%06ld: ", pc);
802 flags = get2();
803 printf(" flags : %d\n", flags);
804 printf("%06ld: ", pc);
805 printf(" name : ");
806 namelen = (int) get1();
807 famlen = (int) get1();
808 stylen = (int) get1();
809 fnt = fonts;
810 while (fnt != NULL && fnt->num != fntnum)
811 fnt = fnt->next;
812 if (fnt == NULL) {
813 if ((fnt = (font *) malloc(sizeof(font))) == NULL) {
814 perror("fontdef");
815 exit(1);
816 }
817 fnt->num = fntnum;
818 new = 1;
819 }
820 else
821 free(fnt->name); /* free old name */
822 if ((name = (char *) malloc((namelen+1) * sizeof(char))) == NULL) {
823 perror("fontdef");
824 exit(1);
825 }
826
827 for (i = 0; i < namelen; i++)
828 name[i] = get1();
829 name[namelen] = '\0';
830 fnt->name = name;
831 if (new) {
832 fnt->next = fonts;
833 fonts = fnt;
834 }
835
836 printf("%s\n", name);
837
838 if (famlen) {
839 printf(" family : ");
840 while (famlen-- > 0)
841 putchar((int) get1());
842 putchar('\n');
843 }
844
845 if (stylen) {
846 printf(" style : ");
847 while (stylen-- > 0)
848 putchar((int) get1());
849 putchar('\n');
850 }
851 } /* fontdef */
852
853
854
855 void glyphs(int opcode)
856 {
857 long width;
858 int x, n, i, j;
859 long * xy;
860
861 if (!is_xetex) {
862 invalid(opcode);
863 return;
864 }
865
866 x = SET_GL_ST - opcode + 1;
867 width = sget4();
868 n = get2();
869 printf("GLYPH_%s width : %ld\n", x == 2 ? "ARR" : "STR", width);
870 if ((xy = (long *) malloc(n * x * sizeof(long))) == NULL) {
871 perror("glyphs");
872 exit(1);
873 }
874 for (j=0; j < n * x; j++)
875 xy[j] = sget4();
876 for (i=0, j=0; i < n; i++) {
877 printf(" x: %ld", xy[j++]);
878 if (x == 2)
879 printf(" y: %ld", xy[j++]);
880 printf(" g: %ld\n", get2());
881 }
882 } /* glyphs */
883
884
885
886 void dvidir(int opcode)
887 {
888 #if defined(PTEXENC)
889 if (!is_ptex && !is_uptex) {
890 #else
891 if (!is_ptex) {
892 #endif
893 invalid(opcode);
894 return;
895 }
896
897 printf("DVI_DIR: %ld\n", get1());
898 } /* dvidir */
899
900
901
902 void invalid(int opcode)
903 {
904 printf("INVALID %d\n", opcode);
905 } /* invalid */