From 0ed6b8327b488c58909c010a33811773293610af Mon Sep 17 00:00:00 2001 From: Takuji Tanaka Date: Fri, 22 Aug 2014 12:57:28 +0000 Subject: texk/kpathsea [WIN32]: Add a new function win32_vfprintf() git-svn-id: svn://tug.org/texlive/trunk@35012 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/kpathsea/ChangeLog | 5 +++++ Build/source/texk/kpathsea/c-std.h | 1 + Build/source/texk/kpathsea/config.h | 1 - Build/source/texk/kpathsea/knj.c | 41 +++++++++++++++++++++++++++++++----- Build/source/texk/kpathsea/knj.h | 1 + 5 files changed, 43 insertions(+), 6 deletions(-) (limited to 'Build') diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog index 512c1dc666f..36e2f76d574 100644 --- a/Build/source/texk/kpathsea/ChangeLog +++ b/Build/source/texk/kpathsea/ChangeLog @@ -1,3 +1,8 @@ +2014-08-22 TANAKA Takuji + + * knj.[ch], c-std.h, config.h: Add a new function win32_vfprintf() + (Windows only) + 2014-07-22 Karl Berry * tex-file.h, diff --git a/Build/source/texk/kpathsea/c-std.h b/Build/source/texk/kpathsea/c-std.h index 2ebacf6accd..6d65d150802 100644 --- a/Build/source/texk/kpathsea/c-std.h +++ b/Build/source/texk/kpathsea/c-std.h @@ -32,6 +32,7 @@ #endif #endif #include +#include /* Be sure we have constants from . */ #include diff --git a/Build/source/texk/kpathsea/config.h b/Build/source/texk/kpathsea/config.h index d9a1948b66a..293558a5eb7 100644 --- a/Build/source/texk/kpathsea/config.h +++ b/Build/source/texk/kpathsea/config.h @@ -137,7 +137,6 @@ A violation of (1) is handled here through static inline wrapper functions. */ -#include #undef snprintf #undef vsnprintf diff --git a/Build/source/texk/kpathsea/knj.c b/Build/source/texk/kpathsea/knj.c index 3cc8b3ff428..7270d9f5788 100644 --- a/Build/source/texk/kpathsea/knj.c +++ b/Build/source/texk/kpathsea/knj.c @@ -407,6 +407,22 @@ int win32_ungetc(int c, FILE *fp) return getc_buff[getc_len++] = c; } +static int __win32_fputs(const char *str, HANDLE hStdout) +{ + DWORD ret; + wchar_t *wstr; + + wstr = get_wstring_from_utf8(str, wstr=NULL); + + if (WriteConsoleW(hStdout, wstr, wcslen(wstr), &ret, NULL) == 0) { + free(wstr); + return EOF; + } + + free(wstr); + return ret; +} + int win32_fputs(const char *str, FILE *fp) { const int fd = fileno(fp); @@ -421,14 +437,29 @@ int win32_fputs(const char *str, FILE *fp) hStdout = (fd == fileno(stdout)) ? GetStdHandle(STD_OUTPUT_HANDLE) : GetStdHandle(STD_ERROR_HANDLE); - wstr = get_wstring_from_utf8(str, wstr=NULL); + return __win32_fputs(str, hStdout); +} - if (WriteConsoleW(hStdout, wstr, wcslen(wstr), &ret, NULL) == 0) { - free(wstr); +#define MAX_PROMPT_STR_SIZE 8192 + +int win32_vfprintf(FILE *fp, const char *format, va_list argp) +{ + const int fd = fileno(fp); + HANDLE hStdout; + char buff[MAX_PROMPT_STR_SIZE]; + int ret; + + if (!((fd == fileno(stdout) || fd == fileno(stderr)) && _isatty(fd) + && file_system_codepage == CP_UTF8)) + return vfprintf(fp, format, argp); + + hStdout = (fd == fileno(stdout)) ? + GetStdHandle(STD_OUTPUT_HANDLE) : GetStdHandle(STD_ERROR_HANDLE); + + ret = _vsnprintf(buff, sizeof(buff), format, argp); + if (__win32_fputs(buff, hStdout)==EOF) { return EOF; } - - free(wstr); return ret; } diff --git a/Build/source/texk/kpathsea/knj.h b/Build/source/texk/kpathsea/knj.h index d7dad8eae12..fc1b808b231 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_vfprintf(FILE *fp, const char *format, va_list argp); extern KPSEDLL int win32_putc(int c, FILE *fp); #ifdef __cplusplus -- cgit v1.2.3