summaryrefslogtreecommitdiff
path: root/Build/source
diff options
context:
space:
mode:
authorTakuji Tanaka <KXD02663@nifty.ne.jp>2014-01-03 14:00:00 +0000
committerTakuji Tanaka <KXD02663@nifty.ne.jp>2014-01-03 14:00:00 +0000
commit328323ed52ee920c9624ebac9eb9707e2d4d231e (patch)
tree933eb5eae5e977c533b08c1e1429f9482f9ce5f2 /Build/source
parentf6eb6c21d2b52f7713e59cbf9734f668489fd071 (diff)
Enable console input of Unicode characters in upTeX on Windows
git-svn-id: svn://tug.org/texlive/trunk@32557 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source')
-rw-r--r--Build/source/texk/ptexenc/ChangeLog5
-rw-r--r--Build/source/texk/ptexenc/ptexenc.c38
-rw-r--r--Build/source/texk/ptexenc/ptexenc/unicode.h3
3 files changed, 44 insertions, 2 deletions
diff --git a/Build/source/texk/ptexenc/ChangeLog b/Build/source/texk/ptexenc/ChangeLog
index e545a298f89..e3bd3168007 100644
--- a/Build/source/texk/ptexenc/ChangeLog
+++ b/Build/source/texk/ptexenc/ChangeLog
@@ -1,3 +1,8 @@
+2014-01-03 TANAKA Takuji <KXD02663@nifty.ne.jp>
+
+ * ptexenc.c, ptexenc/unicode.h: Enable console (keyboad) input
+ of Unicode characters in upTeX on Windows.
+
2013-08-17 Peter Breitenlohner <peb@mppmu.mpg.de>
* configure.ac (AH_TOP): Simplify the generation of c-auto.h.
diff --git a/Build/source/texk/ptexenc/ptexenc.c b/Build/source/texk/ptexenc/ptexenc.c
index fa680201542..497f634417f 100644
--- a/Build/source/texk/ptexenc/ptexenc.c
+++ b/Build/source/texk/ptexenc/ptexenc.c
@@ -455,7 +455,7 @@ static int put_multibyte(long c, FILE *fp) {
return EOF;
return BYTE4(c);
- }
+ }
}
#endif
@@ -557,7 +557,41 @@ static int getc4(FILE *fp)
{
struct unget_st *p = &ungetbuff[fileno(fp)];
- if (p->size == 0) return getc(fp);
+ if (p->size == 0)
+#ifdef WIN32
+ {
+ const int fd = fileno(fp);
+ HANDLE hStdin;
+ DWORD ret;
+ wint_t wc[2];
+ long c;
+
+ if (!(fd == fileno(stdin) && _isatty(fd) && is_internalUPTEX()))
+ return getc(fp);
+
+ hStdin = GetStdHandle(STD_INPUT_HANDLE);
+ 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)
+ return EOF;
+ if (0xdc00<=wc[1] && wc[1]<0xe000) {
+ c = UTF16StoUTF32(wc[0], wc[1]);
+ } else {
+ return EOF; /* illegal input */
+ }
+ } else {
+ c = wc[0];
+ }
+ c = UCStoUTF8(c);
+ /* always */ p->buff[p->size++]=BYTE4(c);
+ if (BYTE3(c) != 0) p->buff[p->size++]=BYTE3(c);
+ if (BYTE2(c) != 0) p->buff[p->size++]=BYTE2(c);
+ if (BYTE1(c) != 0) p->buff[p->size++]=BYTE1(c);
+ }
+#else
+ return getc(fp);
+#endif
return p->buff[--p->size];
}
diff --git a/Build/source/texk/ptexenc/ptexenc/unicode.h b/Build/source/texk/ptexenc/ptexenc/unicode.h
index 13e1567a714..c5f2826966d 100644
--- a/Build/source/texk/ptexenc/ptexenc/unicode.h
+++ b/Build/source/texk/ptexenc/ptexenc/unicode.h
@@ -51,4 +51,7 @@ extern long UPTEXtoUCS(long uptex);
#define UTF32toUTF16HS(x) (0xd800 + ((((x)-0x10000) >> 10) & 0x3ff))
#define UTF32toUTF16LS(x) (0xdc00 + ( (x) & 0x3ff))
+/* UTF-16 surrogate pair -> UTF-32 over U+FFFF */
+#define UTF16StoUTF32(x,y) ((((x) & 0x3ff) << 10) + ((y) & 0x3ff) +0x10000)
+
#endif /* PTEXENC_UNICODE_H */