diff -ur dvi2tty-5.3.1.orig/commands.h dvi2tty-5.3.1/commands.h --- dvi2tty-5.3.1.orig/commands.h 2010-10-19 11:34:16.000000000 +0200 +++ dvi2tty-5.3.1/commands.h 2010-10-20 11:34:16.000000000 +0200 @@ -85,3 +85,12 @@ #define TRAILER 223 /* trailer bytes in dvi file */ /* undefined_commands 250,251,252,253,254,255 */ + +/* additional DVI commands for XeTeX extensions */ +#define PIC_FILE 251 +#define NAT_FNT 252 /* define a native font */ +#define SET_GL_AR 253 +#define SET_GL_ST 254 + +/* additional DVI command for pTeX extensions */ +#define DVI_DIR 255 /* set direction */ diff -ur dvi2tty-5.3.1.orig/disdvi.1 dvi2tty-5.3.1/disdvi.1 --- dvi2tty-5.3.1.orig/disdvi.1 2010-10-20 14:21:13.000000000 +0200 +++ dvi2tty-5.3.1/disdvi.1 2010-10-23 13:10:17.000000000 +0200 @@ -1,17 +1,25 @@ -.TH DISDVI 1 "20 October 2010" "TeX Live" +.TH DISDVI 1 "23 October 2010" "TeX Live" .SH NAME -disdvi \- `disassemble' a TeX DVI file +disdvi \- `disassemble' a (p)TeX DVI or XeTeX XDV file .SH SYNOPSIS .B disdvi -dvi\-file +.RB [ \-p ] +.RI [ dvi_file [ \fB.dvi\fP ]] +.br +.B disdvi \-x +.RI [ xdv_file [ \fB.xdv\fP ]] +.br +.B disdvi \-h .SH DESCRIPTION .I disdvi interprets the contents of -.IR dvi\-file , +.IR dvi_file +or +.IR xdv_file , printing the DVI commands and text in a human-readable ASCII format on the standard output. .SH "SEE ALSO" -dvi2tty(SIPB) +.BR dvi2tty (1) .SH AUTHOR Marcel J.E. Mol, Delft University of Technology, The Netherlands .br diff -ur dvi2tty-5.3.1.orig/disdvi.c dvi2tty-5.3.1/disdvi.c --- dvi2tty-5.3.1.orig/disdvi.c 2010-10-22 09:15:58.000000000 +0200 +++ dvi2tty-5.3.1/disdvi.c 2010-10-22 09:17:28.000000000 +0200 @@ -107,6 +107,9 @@ char * progname; +int is_ptex = 0; +int is_xetex = 0; +const char * dvi_ext = ".dvi"; /* * Function declarations @@ -130,6 +133,11 @@ unsigned long num (int size); long snum (int size); void usage (void); +void picfile (int opcode); +void natfontdef (int opcode); +void glyphs (int opcode); +void dvidir (int opcode); +void invalid (int opcode); @@ -155,6 +163,25 @@ progname = *argv++; + if ((argc > 1) && (*argv[0] == '-')) { + if (!strcmp(*argv, "-h")) { + usage(); + exit(0); + } + if (!strcmp(*argv, "-p")) + is_ptex = 1; + else if (!strcmp(*argv, "-x")) { + is_xetex = 1; + dvi_ext = ".xdv"; + } else { + fprintf(stderr, "Invalid option `%s'\n", *argv); + usage(); + exit(3); + } + argv++; + argc--; + } + if (argc > 2) { fprintf(stderr, "To many arguments\n"); usage(); @@ -162,21 +189,17 @@ } if (argc == 2) { - if (!strcmp(*argv, "-h")) { - usage(); - exit(0); - } if ((i = strlen(*argv)) == 0) { fprintf(stderr, "Illegal empty filename\n"); usage(); exit(2); } - if ((i >= 5) && (!strcmp(*argv+i-4, ".dvi"))) + if ((i >= 5) && (!strcmp(*argv+i-4, dvi_ext))) dvi_name = *argv; else { dvi_name = malloc((i+5) * sizeof(char)); strcpy(dvi_name, *argv); - strcat(dvi_name, ".dvi"); + strcat(dvi_name, dvi_ext); } if ((dvifp = fopen(dvi_name, "r")) == NULL) { perror(dvi_name); @@ -293,6 +316,12 @@ case PRE : preamble(); break; case POST : postamble(); break; case POST_POST: postpostamble(); break; + case PIC_FILE : picfile(opcode); break; + case NAT_FNT : natfontdef(opcode); break; + case SET_GL_AR: + case SET_GL_ST: glyphs(opcode); break; + case DVI_DIR : dvidir(opcode); break; + default : invalid(opcode); } } @@ -616,9 +645,157 @@ { fprintf(stderr, "\n%s\n\n", disdvi); - fprintf(stderr, " disassembles TeX dvi files\n"); - fprintf(stderr, "Usage: %s [-h | [.dvi]]\n", progname); + fprintf(stderr, " disassembles (p)TeX dvi and XeTeX xdv files\n"); + fprintf(stderr, "Usage: %s [-h | [-p] [dvi_file[.dvi]]\n", progname); + fprintf(stderr, " | -x [xdv_file[.xdv]]]\n"); return; } /* usage */ + + + +void picfile(int opcode) +{ + int i; + + if (!is_xetex) { + invalid(opcode); + return; + } + + printf("PIC_FILE flags : %ld\n", get1()); + printf("%06ld: trans :", pc); + for (i=0; i<6; i++) + printf(" %ld", sget4()); + printf("\n%06ld: ", pc); + printf(" page : %ld\n", get2()); + printf("%06ld: ", pc); + i = (int) get1(); + printf(" path name (%3d) :", i); + while (i-- > 0) + putchar((int) get1()); + putchar('\n'); +} /* picfile */ + + + +void natfontdef(int opcode) +{ + register int i; + char * name; + font * fnt; + int flags, namelen, famlen, stylen; + long fntnum; + int new = 0; + + if (!is_xetex) { + invalid(opcode); + return; + } + + fntnum = num(4); + printf("NAT_FNT: %ld\n", fntnum); + printf("%06ld: ", pc); + printf(" scale : %ld\n", get4()); + printf("%06ld: ", pc); + flags = get2(); + printf(" flags : %d\n", flags); + printf("%06ld: ", pc); + printf(" name : "); + namelen = (int) get1(); + famlen = (int) get1(); + stylen = (int) get1(); + fnt = fonts; + while (fnt != NULL && fnt->num != fntnum) + fnt = fnt->next; + if (fnt == NULL) { + if ((fnt = (font *) malloc(sizeof(font))) == NULL) { + perror("fontdef"); + exit(1); + } + fnt->num = fntnum; + new = 1; + } + else + free(fnt->name); /* free old name */ + if ((name = (char *) malloc((namelen+1) * sizeof(char))) == NULL) { + perror("fontdef"); + exit(1); + } + + for (i = 0; i < namelen; i++) + name[i] = get1(); + name[namelen] = '\0'; + fnt->name = name; + if (new) { + fnt->next = fonts; + fonts = fnt; + } + + printf("%s\n", name); + + if (famlen) { + printf(" family : "); + while (famlen-- > 0) + putchar((int) get1()); + putchar('\n'); + } + + if (stylen) { + printf(" style : "); + while (stylen-- > 0) + putchar((int) get1()); + putchar('\n'); + } +} /* fontdef */ + + + +void glyphs(int opcode) +{ + long width; + int x, n, i, j; + long * xy; + + if (!is_xetex) { + invalid(opcode); + return; + } + + x = SET_GL_ST - opcode + 1; + width = sget4(); + n = get2(); + printf("GLYPH_%s width : %ld\n", x == 2 ? "ARR" : "STR", width); + if ((xy = (long *) malloc(n * x * sizeof(long))) == NULL) { + perror("glyphs"); + exit(1); + } + for (j=0; j < n * x; j++) + xy[j] = sget4(); + for (i=0, j=0; i < n; i++) { + printf(" x: %ld", xy[j++]); + if (x == 2) + printf(" y: %ld", xy[j++]); + printf(" g: %ld\n", get2()); + } +} /* glyphs */ + + + +void dvidir(int opcode) +{ + if (!is_ptex) { + invalid(opcode); + return; + } + + printf("DVI_DIR: %ld\n", get1()); +} /* dvidir */ + + + +void invalid(int opcode) +{ + printf("INVALID %d\n", opcode); +} /* invalid */