File dvi2tty-japanese.patch of Package dvi2tty
--- dvi2tty.c
+++ dvi2tty.c
@@ -186,10 +186,10 @@
#define MAXLEN 100 /* size of char-arrays for strings */
#if defined(MSDOS) || defined(VMS) || defined(AMIGA)
-#define OPTSET "haJwepPousltvbc" /* legal options */
+#define OPTSET "haJwepPousltvbcAN" /* legal options */
#define OPTWARG "wepPovb" /* options with argument */
#else
-#define OPTSET "haJwepPousqlfFtvbc"/* legal options */
+#define OPTSET "haJwepPousqlfFtvbcAN"/* legal options */
#define OPTWARG "wepPoFvb" /* options with argument */
#endif
@@ -209,6 +209,8 @@
#if defined(THINK_C)
#define nored 10 /* if no input file, redirect stdin */
#endif
+#define confl 11 /* -N and -A conflict */
+#define confj 12 /* -J conflicts -N and -A */
@@ -512,7 +514,9 @@
j = strlen(optarg);
break;
#endif
- case 'J' : japan = TRUE; break;
+ case 'J' : jautodetect = TRUE; break;
+ case 'A' : asciip = TRUE; break; /* ASCII pTeX */
+ case 'N' : japan = TRUE; break; /* NTT jTeX */
case 't' : ttfont = TRUE; break;
case 'l' : noffd = TRUE; break;
case 's' : scascii = TRUE; break;
@@ -554,6 +558,15 @@
break;
default : usage(bdopt);
}
+
+ /* Option conflicts */
+ if (japan && asciip) {
+ usage(confl);
+ }
+
+ if (jautodetect && (japan || asciip)) {
+ usage(confj);
+ }
if ((optch = optarg[j++]) == '\0')
break;
if ( (optarg[j] == '\0') && (strchr(OPTWARG, optch) != NULL) ) {
@@ -855,6 +868,10 @@
command string,\n\Standard Input must be redirected with the radio button.");
break;
#endif
+ case confl : fprintf(stderr, "-N and -A conflict");
+ break;
+ case confj : fprintf(stderr, "-J conflicts -N and -A");
+ break;
default : fprintf(stderr, "unknown usage error");
break;
}
@@ -906,7 +923,11 @@
fprintf(stderr,
" -s National Swedish/Finnish characters printed as }{|][\\ (default %s).\n", DEFSCAND ? "on" : "off");
fprintf(stderr,
- " -J Allow processing of japanese fonts\n");
+ " -J Enable auto detect for NTT jTeX and ASCII pTeX.\n");
+ fprintf(stderr,
+ " -N Support NTT jTeX dvi.\n");
+ fprintf(stderr,
+ " -A Support ASCII pTeX dvi.\n");
fprintf(stderr,
" -c Override -a -u -s and print all characters 0-255.\n");
fprintf(stderr,
--- dvi2tty.h
+++ dvi2tty.h
@@ -96,8 +96,10 @@
extern bool scascii; /* Scand. nat. chars (dvistuff.c) */
extern bool accent; /* Output accent stuff(dvistuff.c) */
extern bool ttfont; /* tt font assumed (dvistuff.c) */
-extern bool japan; /* japanes font support (dvistuff.c) */
-extern bool noffd; /* output ^L or formfeed (dvistuff.c) */
+extern bool jautodetect; /* Auto detect jTeX / ASCII pTeX */
+extern bool japan; /* jTeX font support (dvistuff.c) */
+extern bool asciip; /* pTeX font support (dvistuff.c) */
+extern bool noffd; /* output ^L or formneed (dvistuff.c) */
extern bool printfont; /* include font switches (dvistuff.c) */
extern bool allchar; /* output all characters (dvistuff.c */
--- dvistuff.c
+++ dvistuff.c
@@ -24,6 +24,13 @@
#include "dvi2tty.h"
+#if !defined(JIS)
+#define JIS 1 /* if 0 then EUC/SJIS */
+#endif
+#if !defined(SJIS)
+#define SJIS 0 /* if !JIS, 0 then EUC */
+#endif
+
#if defined(VMS)
# include types.h
# include stat
@@ -126,7 +133,10 @@
bool accent; /* if true output accents etc: \'{e} etc. */
bool ttfont = FALSE; /* if true we assumed ttfonts, not cmr */
bool symbolfont = FALSE; /* true if font is a symbol font */
-bool japan = FALSE; /* switch to japanese fonts ... */
+bool japan = FALSE; /* switch to NTT japanese fonts ... */
+bool asciip = FALSE; /* switch to ASCII japanese fonts ... */
+bool jautodetect = FALSE;/* Japanese autodetect */
+bool jdetect = FALSE; /* switch if Japanese TeX detection is done */
bool mifont = FALSE;
bool T1font = FALSE; /* DC/EC encoding used ? */
int jfontnum = 0;
@@ -161,6 +171,14 @@
font * fonts = NULL; /* List of fontnames defined */
+#if JIS
+#define SJIS 0
+int inkanji = 0; /* is in kanji sequence */
+#define KANJIIN "\033$B"
+#define KANJIOUT "\033(J"
+#endif
+int kanji1 = 0; /* is first kanji character */
+int kanji2 = 0; /* is second kanji character */
/*
@@ -194,6 +212,7 @@
void setfont (long);
void jischar (long);
int compute_jis (int, int, int *, int *);
+void dokanji (int);
int getjsubfont (char *);
#else
@@ -223,6 +242,7 @@
void setfont (long fntnum);
void jischar (long charnr);
void compute_jis (int f, int c, int * ku, int * ten);
+void dokanji (int);
int getjsubfont (char * s);
#if defined(VMS)
long vmsseek ();
@@ -424,7 +444,7 @@
else
switch (opcode) {
case SET1 : japan ? jischar(get1()) : setchar(get1());break;
- case SET2 : setchar(get2()); break;
+ case SET2 : asciip ? dokanji(get2()) : setchar(get2()); break;
case SET3 : setchar(get3()); break;
case SET4 : setchar(get4()); break;
case SET_RULE : { long height = sget4();
@@ -610,18 +630,83 @@
for (i = firstcolumn, j = 1; i <= currentline->charactercount;
i++, j++) {
ch = currentline->text[i - leftmargin];
+ if (asciip) {
+ if (kanji1) {
+#if !JIS && !SJIS
+ ch |= 0x80;
+#endif
+ kanji2 = 1;
+ kanji1 = 0;
+ }
+ if (!kanji2 && ch > 127) {
+ kanji1 = 1;
+#if JIS
+ if (!inkanji) {
+ inkanji = 1;
+ fprintf(output, KANJIIN);
+ }
+ ch &= 0x7f;
+#endif
+ }
+#if JIS
+ if (!kanji1 && !kanji2 && inkanji) {
+ fprintf(output, KANJIOUT);
+ inkanji = 0;
+ }
+#endif
+ if (kanji1 && (j >= (int) foo) &&
+ (currentline->charactercount > i + 1)) {
+#if JIS
+ if (inkanji) {
+ fprintf(output, KANJIOUT);
+ }
+#endif
+ fprintf(output, "*\n"); /* if line too large */
+ fprintf(output, " *"); /* output mark */
+#if JIS
+ if (inkanji) {
+ fprintf(output, KANJIIN);
+ }
+#endif
+ j = 2;
+ }
+ }
+
if (ch >= SPACE || allchar)
putc(ch, output);
if ((j > (int) foo) && (currentline->charactercount > i+1)) {
- fprintf(output, "*\n"); /* if line to large */
- fprintf(output, " *"); /* mark output */
- j = 2;
+ if (asciip) {
+#if JIS
+ if (inkanji) {
+ fprintf(output, KANJIOUT);
+ }
+#endif
+ }
+ fprintf(output, "*\n"); /* if line too large */
+ fprintf(output, " *"); /* output mark */
+ if (asciip) {
+#if JIS
+ if (inkanji) {
+ fprintf(output, KANJIIN);
+ }
+#endif
+ }
+ j = 2;
}
+ if (asciip) kanji2 = 0;
}
}
putc('\n', output);
}
+ if (asciip) {
+#if JIS
+ if (!kanji1 && !kanji2 && inkanji) {
+ fprintf(output, KANJIOUT);
+ inkanji = 0;
+ }
+#endif
+ }
currentline = firstline;
while (currentline->next != nil) {
currentline = currentline->next;
@@ -1177,7 +1262,8 @@
if (foo == leftmargin-1)
- while ((currentline->text[j - leftmargin] != SPACE)
+ while (((currentline->text[j - leftmargin] != SPACE)
+ || kanji1 && (currentline->text[j + 1 - leftmargin] != SPACE))
&& (j < rightmargin)) {
j++;
h += charwidth;
@@ -1300,6 +1386,19 @@
name[i] = get1();
name[i] = '\0'; /* just to be sure */
fnt->name = name;
+ if ((asciip == FALSE && japan == FALSE) && (!jdetect) && jautodetect) {
+ if (strncmp("min", name, 3) == 0 || strncmp("got", name, 3) == 0) {
+ /* Detect as ASCII pTeX */
+ asciip = TRUE;
+ japan = FALSE;
+ jdetect = TRUE;
+ } else if (strncmp("dmj", name, 3) == 0 || strncmp("dgj", name, 3) == 0) {
+ /* Detect as NTT jTeX */
+ asciip = FALSE;
+ japan = TRUE;
+ jdetect = TRUE;
+ }
+ }
if (new) {
fnt->next = fonts;
fonts = fnt;
@@ -1583,3 +1682,28 @@
} /*vms_ungetc */
#endif
+
+/*
+* DOKANJI -- Process a kanji character opcode.
+*/
+
+void dokanji(ch)
+register int ch;
+{
+#if SJIS
+ register int c1, c2;
+ c1 = (ch >> 8) & 0xff;
+ c2 = ch & 0xff;
+ kanji1 = 1;
+ outchar((((c1 - 1) >> 1) + ((c1 <= 0x5e) ? 0x71 : 0xb1)));
+ kanji1 = 0;
+ outchar((c2 + ((c1 & 1) ? ((c2 < 0x60) ? 0x1f : 0x20) : 0x7e)));
+#else
+ kanji1 = 1;
+ outchar(0x80 | ( ch >> 8 ));
+ kanji1 = 0;
+ outchar(ch & 0xff);
+#endif
+
+ return;
+} /* dokanji */