summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea/knj.c
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2013-12-01 15:05:15 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2013-12-01 15:05:15 +0000
commitb91ea14a043007a08ec25199870aa0a3a3fbbc1f (patch)
tree9e4607d05889e3ab457a8f3c137598907b413b25 /Build/source/texk/kpathsea/knj.c
parent2fdc70b46aa72675253c5d8b51fcab18d509af38 (diff)
Support KANJI file name in (e)up-TeX on Windows (T. Tanaka)
git-svn-id: svn://tug.org/texlive/trunk@32288 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea/knj.c')
-rw-r--r--Build/source/texk/kpathsea/knj.c81
1 files changed, 80 insertions, 1 deletions
diff --git a/Build/source/texk/kpathsea/knj.c b/Build/source/texk/kpathsea/knj.c
index bdf7d5cbf75..e4f9639d1c6 100644
--- a/Build/source/texk/kpathsea/knj.c
+++ b/Build/source/texk/kpathsea/knj.c
@@ -1,6 +1,7 @@
/* knj.c: check for 2-Byte Kanji (CP 932, SJIS) codes.
Copyright 2010, 2011 Akira Kakuto.
+ Copyright 2013 TANAKA Takuji.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -16,8 +17,9 @@
along with this library; if not, see <http://www.gnu.org/licenses/>. */
#include <kpathsea/config.h>
+#include <kpathsea/debug.h>
-int is_cp932_system;
+int is_cp932_system, file_system_codepage;
int isknj(int c)
{
@@ -48,3 +50,80 @@ int isknj2(int c)
return(0);
}
}
+
+/*
+ Get wide string from multibyte string.
+*/
+wchar_t *
+get_wstring_from_mbstring(int cp, const char *mbstr, wchar_t *wstr)
+{
+ int len;
+
+ len = MultiByteToWideChar(cp, 0, mbstr, -1, wstr, 0);
+ if (len==0) {
+ FATAL("cannot convert string to wide string");
+ }
+ if (wstr==NULL) {
+ wstr = xmalloc(sizeof(wchar_t)*(len+1));
+ }
+ len = MultiByteToWideChar(cp, 0, mbstr, -1, wstr, len+1);
+ if (len==0) {
+ FATAL("cannot convert multibyte string to wide string");
+ }
+ return wstr;
+}
+
+/*
+ Get multibyte string from wide string.
+*/
+char *
+get_mbstring_from_wstring(int cp, const wchar_t *wstr, char *mbstr)
+{
+ int len;
+
+ len = WideCharToMultiByte(cp, 0, wstr, -1, mbstr, 0, NULL, NULL);
+ if (len==0) {
+ FATAL("cannot convert string to wide string");
+ }
+ if (mbstr==NULL) {
+ mbstr = xmalloc(len+1);
+ }
+ len = WideCharToMultiByte(cp, 0, wstr, -1, mbstr, len+1, NULL, NULL);
+ if (len==0) {
+ FATAL("cannot convert wide string to multibyte string");
+ }
+ return mbstr;
+}
+
+/*
+ xfopen by file system codepage
+*/
+FILE *
+fsyscp_xfopen (const char *filename, const char *mode)
+{
+ FILE *f;
+ wchar_t *fnamew, modew[4];
+#if defined (KPSE_COMPAT_API)
+ kpathsea kpse = kpse_def;
+#endif
+
+ assert(filename && mode);
+
+ fnamew = get_wstring_from_fsyscp(filename, fnamew=NULL);
+ get_wstring_from_fsyscp(mode, modew);
+ f = _wfopen(fnamew, modew);
+ if (f == NULL)
+ FATAL_PERROR(filename);
+#if defined (KPSE_COMPAT_API)
+ if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) {
+ DEBUGF_START ();
+ fprintf (stderr, "fsyscp_xfopen(%s [", filename);
+ WriteConsoleW( GetStdHandle( STD_ERROR_HANDLE ), fnamew, wcslen( fnamew ), NULL, NULL );
+ fprintf (stderr, "], %s) => 0x%lx\n", mode, (unsigned long) f);
+ DEBUGF_END ();
+ }
+#endif
+ free(fnamew);
+
+ return f;
+}