summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea
diff options
context:
space:
mode:
authorTakuji Tanaka <KXD02663@nifty.ne.jp>2014-08-22 12:57:28 +0000
committerTakuji Tanaka <KXD02663@nifty.ne.jp>2014-08-22 12:57:28 +0000
commit0ed6b8327b488c58909c010a33811773293610af (patch)
tree34b279b97d86e67a2239008742e5f9724877144f /Build/source/texk/kpathsea
parent02a9cd9e5aa4f87b2c06d053175ef76751f5ab98 (diff)
texk/kpathsea [WIN32]: Add a new function win32_vfprintf()
git-svn-id: svn://tug.org/texlive/trunk@35012 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea')
-rw-r--r--Build/source/texk/kpathsea/ChangeLog5
-rw-r--r--Build/source/texk/kpathsea/c-std.h1
-rw-r--r--Build/source/texk/kpathsea/config.h1
-rw-r--r--Build/source/texk/kpathsea/knj.c41
-rw-r--r--Build/source/texk/kpathsea/knj.h1
5 files changed, 43 insertions, 6 deletions
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 <KXD02663@nifty.ne.jp>
+
+ * knj.[ch], c-std.h, config.h: Add a new function win32_vfprintf()
+ (Windows only)
+
2014-07-22 Karl Berry <karl@tug.org>
* 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 <stdio.h>
+#include <stdarg.h>
/* Be sure we have constants from <unistd.h>. */
#include <kpathsea/c-unistd.h>
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 <stdarg.h>
#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