From eb9445db98a1eb9dc1f627045a9a3a51ec90b5a1 Mon Sep 17 00:00:00 2001 From: Takuji Tanaka Date: Sat, 8 Feb 2014 02:44:01 +0000 Subject: kpathsearch [win32]: Add a new function win32_putc() git-svn-id: svn://tug.org/texlive/trunk@32915 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/kpathsea/ChangeLog | 5 ++++ Build/source/texk/kpathsea/knj.c | 48 ++++++++++++++++++++++++++++++++++++ Build/source/texk/kpathsea/knj.h | 1 + 3 files changed, 54 insertions(+) (limited to 'Build') diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog index 20ea2e6aca4..c72db005d9a 100644 --- a/Build/source/texk/kpathsea/ChangeLog +++ b/Build/source/texk/kpathsea/ChangeLog @@ -1,3 +1,8 @@ +2014-02-08 TANAKA Takuji + + * knj.[ch]: Add a new function win32_putc(). + (Windows only) + 2014-01-25 Akira Kakuto * kpsewhich.c : [WIN32 only] progname should be kpse->program_name diff --git a/Build/source/texk/kpathsea/knj.c b/Build/source/texk/kpathsea/knj.c index 0f52d55f256..92116c0f64b 100644 --- a/Build/source/texk/kpathsea/knj.c +++ b/Build/source/texk/kpathsea/knj.c @@ -427,3 +427,51 @@ int win32_puts(const char *str) } return puts(""); } + +int win32_putc(int c, FILE *fp) +{ + const int fd = fileno(fp); + HANDLE hStdout; + DWORD ret; + wchar_t wstr[3]; + static int len = 0; + static char buff[5], *str; + + if (!((fd == fileno(stdout) || fd == fileno(stderr)) && _isatty(fd) + && file_system_codepage == CP_UTF8)) + return putc(c, fp); + + hStdout = (fd == fileno(stdout)) ? + GetStdHandle(STD_OUTPUT_HANDLE) : GetStdHandle(STD_ERROR_HANDLE); + + c &= 0xff; + + if (c < 0x80) { + str = buff; + len = 1; + } + if (c < 0xc0) { /* ASCII or trailer */ + *str++ = c; + len--; + if (len == 0) { + *str = '\0'; + get_wstring_from_utf8(buff, wstr); + if (WriteConsoleW(hStdout, wstr, wcslen(wstr), &ret, NULL) == 0) { + len = 0; + return EOF; + } + } + else if (len < 0) return EOF; + return c; + } + else if (c < 0xc2) { len = 0; return EOF; } /* illegal */ + else if (c < 0xe0) len = 2; + else if (c < 0xf0) len = 3; + else if (c < 0xf5) len = 4; + else { len = 0; return EOF; } + + str = buff; + *str++ = c; + len--; + return c; +} diff --git a/Build/source/texk/kpathsea/knj.h b/Build/source/texk/kpathsea/knj.h index df73074b8ad..d7dad8eae12 100644 --- a/Build/source/texk/kpathsea/knj.h +++ b/Build/source/texk/kpathsea/knj.h @@ -41,6 +41,7 @@ extern KPSEDLL int win32_getc(FILE *fp); extern KPSEDLL int win32_ungetc(int c, FILE *fp); extern KPSEDLL int win32_fputs(const char *str, FILE *fp); extern KPSEDLL int win32_puts(const char *str); +extern KPSEDLL int win32_putc(int c, FILE *fp); #ifdef __cplusplus } -- cgit v1.2.3