summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakuji Tanaka <KXD02663@nifty.ne.jp>2014-01-24 22:32:29 +0000
committerTakuji Tanaka <KXD02663@nifty.ne.jp>2014-01-24 22:32:29 +0000
commitdd0c82897b36b06b83de60b7f3633664f486496a (patch)
tree4fb8ee674b9e25f2d771d48465b3fd6478c0b478
parent46896d1e3c31bffc43794701ec710b6c38916bba (diff)
ptexenc, uptex [win32]: return U+FFFD for illegal surrogate pair in console input
git-svn-id: svn://tug.org/texlive/trunk@32777 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Build/source/texk/ptexenc/ChangeLog6
-rw-r--r--Build/source/texk/ptexenc/ptexenc.c14
2 files changed, 17 insertions, 3 deletions
diff --git a/Build/source/texk/ptexenc/ChangeLog b/Build/source/texk/ptexenc/ChangeLog
index e3bd3168007..1fe32913bce 100644
--- a/Build/source/texk/ptexenc/ChangeLog
+++ b/Build/source/texk/ptexenc/ChangeLog
@@ -1,3 +1,9 @@
+2014-01-25 TANAKA Takuji <KXD02663@nifty.ne.jp>
+
+ * ptexenc.c: Return replacement character U+FFFD
+ for illegal surrogate pair in console (keyboad) input
+ in upTeX on Windows.
+
2014-01-03 TANAKA Takuji <KXD02663@nifty.ne.jp>
* ptexenc.c, ptexenc/unicode.h: Enable console (keyboad) input
diff --git a/Build/source/texk/ptexenc/ptexenc.c b/Build/source/texk/ptexenc/ptexenc.c
index 497f634417f..bde9b9450c3 100644
--- a/Build/source/texk/ptexenc/ptexenc.c
+++ b/Build/source/texk/ptexenc/ptexenc.c
@@ -563,14 +563,19 @@ static int getc4(FILE *fp)
const int fd = fileno(fp);
HANDLE hStdin;
DWORD ret;
- wint_t wc[2];
+ wchar_t wc[2];
long c;
+ static wchar_t wcbuf = L'\0';
if (!(fd == fileno(stdin) && _isatty(fd) && is_internalUPTEX()))
return getc(fp);
hStdin = GetStdHandle(STD_INPUT_HANDLE);
- if (ReadConsoleW(hStdin, wc, 1, &ret, NULL) == 0)
+ if (wcbuf) {
+ wc[0] = wcbuf;
+ wcbuf = L'\0';
+ }
+ else if (ReadConsoleW(hStdin, wc, 1, &ret, NULL) == 0)
return EOF;
if (0xd800<=wc[0] && wc[0]<0xdc00) {
if (ReadConsoleW(hStdin, wc+1, 1, &ret, NULL) == 0)
@@ -578,8 +583,11 @@ static int getc4(FILE *fp)
if (0xdc00<=wc[1] && wc[1]<0xe000) {
c = UTF16StoUTF32(wc[0], wc[1]);
} else {
- return EOF; /* illegal input */
+ wcbuf = wc[1];
+ c = U_REPLACEMENT_CHARACTER; /* illegal upper surrogate pair */
}
+ } else if (0xdc00<=wc[0] && wc[0]<0xe000) {
+ c = U_REPLACEMENT_CHARACTER; /* illegal lower surrogate pair */
} else {
c = wc[0];
}