diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2011-09-05 08:12:47 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2011-09-05 08:12:47 +0000 |
commit | 3684bb53c9f68827e1b7f387354053d75a99b961 (patch) | |
tree | 989948983921352c24149561e23f01a58a5ba433 | |
parent | 46319c0a4c44b4d4811810819fd2d8b57b9809a3 (diff) |
Apply patches by Takuji Tanaka.
git-svn-id: svn://tug.org/texlive/trunk@23825 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Build/source/texk/ptexenc/ChangeLog | 4 | ||||
-rw-r--r-- | Build/source/texk/ptexenc/ptexenc.c | 52 |
2 files changed, 43 insertions, 13 deletions
diff --git a/Build/source/texk/ptexenc/ChangeLog b/Build/source/texk/ptexenc/ChangeLog index 5b5600ad162..fec17c87fbb 100644 --- a/Build/source/texk/ptexenc/ChangeLog +++ b/Build/source/texk/ptexenc/ChangeLog @@ -1,3 +1,7 @@ +2011-09-05 Takuji Tanaka <KXD02663@nifty.ne.jp> + + * ptexenc.c: Fix putc2() to output right unicode characters. + 2011-08-29 Peter Breitenlohner <peb@mppmu.mpg.de> * unicode.c (UTF8length, UCStoUPTEX, UPTEXtoUCS), diff --git a/Build/source/texk/ptexenc/ptexenc.c b/Build/source/texk/ptexenc/ptexenc.c index e4663cedb42..c32d75b434d 100644 --- a/Build/source/texk/ptexenc/ptexenc.c +++ b/Build/source/texk/ptexenc/ptexenc.c @@ -413,34 +413,60 @@ static int put_multibyte(long c, FILE *fp) { /* always */ return putc(BYTE4(c), fp); } +static int flush (unsigned char *buff, int num, FILE *fp) +{ + int i, ret = EOF; + + /* fprintf(stderr, "putc2: unexpected chars. ( "); + for (i=0; i<num; i++) fprintf(stderr, "%02X ", buff[i]); + fprintf(stderr, ")\n"); + */ + for (i=0; i<num; i++) ret = putc(buff[i], fp); + return ret; +} + /* putc() with code conversion */ int putc2(int c, FILE *fp) { - static int inkanji[NOFILE]; /* 0: not in Kanji - 1: in JIS Kanji and first byte is in c1[] - -1: in JIS Kanji and c1[] is empty */ - static unsigned char c1[NOFILE]; + static int num[NOFILE]; + /* 0 : not in Kanji + 1..4 : in JIS Kanji and num[] bytes are in store[][] + -1 : in JIS Kanji and store[][] is empty */ + static unsigned char store[NOFILE][4]; const int fd = fileno(fp); int ret = c, output_enc; if (fp == stdout || fp == stderr) output_enc = get_terminal_enc(); else output_enc = get_file_enc(); - if (inkanji[fd] > 0) { /* KANJI 2nd */ - ret = put_multibyte(toENC(HILO(c1[fd], c), output_enc), fp); - inkanji[fd] = -1; - } else if (iskanji1(c)) { /* KANJI 1st */ - if (inkanji[fd] == 0 && output_enc == ENC_JIS) { + if (num[fd] > 0) { /* multi-byte char */ + if (is_internalUPTEX() && iskanji1(c)) { /* error */ + ret = flush(store[fd], num[fd], fp); + num[fd] = 0; + } + store[fd][num[fd]] = c; + num[fd]++; + if (multistrlen(store[fd], num[fd], 0) == num[fd]) { + long i = fromBUFF(store[fd], num[fd], 0); + ret = put_multibyte(toENC(i, output_enc), fp); + num[fd] = -1; + } else if ((is_internalUPTEX() && num[fd] == 4) || + (!is_internalUPTEX() && num[fd] == 2)) { /* error */ + ret = flush(store[fd], num[fd], fp); + num[fd] = -1; + } + } else if (iskanji1(c)) { /* first multi-byte char */ + if (num[fd] == 0 && output_enc == ENC_JIS) { ret = put_multibyte(KANJI_IN, fp); } - c1[fd] = c; - inkanji[fd] = 1; + store[fd][0] = c; + num[fd] = 1; } else { /* ASCII */ - if (inkanji[fd] < 0 && output_enc == ENC_JIS) { + if (num[fd] < 0 && output_enc == ENC_JIS) { put_multibyte(KANJI_OUT, fp); } ret = putc(c, fp); - inkanji[fd] = 0; + num[fd] = 0; } return ret; } |