summaryrefslogtreecommitdiff
path: root/Build/source/texk
diff options
context:
space:
mode:
authorTakuji Tanaka <KXD02663@nifty.ne.jp>2014-02-08 02:44:01 +0000
committerTakuji Tanaka <KXD02663@nifty.ne.jp>2014-02-08 02:44:01 +0000
commiteb9445db98a1eb9dc1f627045a9a3a51ec90b5a1 (patch)
tree7f792a6e0b926736dd6897d681aa6c08eec800b3 /Build/source/texk
parent8c20c8374675eead07b58ed8f35a643d7ee200b6 (diff)
kpathsearch [win32]: Add a new function win32_putc()
git-svn-id: svn://tug.org/texlive/trunk@32915 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk')
-rw-r--r--Build/source/texk/kpathsea/ChangeLog5
-rw-r--r--Build/source/texk/kpathsea/knj.c48
-rw-r--r--Build/source/texk/kpathsea/knj.h1
3 files changed, 54 insertions, 0 deletions
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 <KXD02663@nifty.ne.jp>
+
+ * knj.[ch]: Add a new function win32_putc().
+ (Windows only)
+
2014-01-25 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
* 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
}