diff options
author | Takuji Tanaka <KXD02663@nifty.ne.jp> | 2013-12-31 00:52:54 +0000 |
---|---|---|
committer | Takuji Tanaka <KXD02663@nifty.ne.jp> | 2013-12-31 00:52:54 +0000 |
commit | 1aae882b478be67d401b4d94e2c7b607dd23f10e (patch) | |
tree | f2ed9f77c21d7e770dc8f1b6360566768ec40764 /Build/source/texk/kpathsea | |
parent | bd344bcd4173e2f20b56a41f894f0354d05ddc4d (diff) |
bug fix about error check when fopen (Windows only)
git-svn-id: svn://tug.org/texlive/trunk@32519 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea')
-rw-r--r-- | Build/source/texk/kpathsea/ChangeLog | 6 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/knj.c | 72 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/knj.h | 5 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/progname.c | 5 |
4 files changed, 86 insertions, 2 deletions
diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog index 9ffda1014e1..874e0405a6f 100644 --- a/Build/source/texk/kpathsea/ChangeLog +++ b/Build/source/texk/kpathsea/ChangeLog @@ -1,3 +1,9 @@ +2013-12-31 TANAKA Takuji <KXD02663@nifty.ne.jp> + + * knj.c, knj.h: Add new functions fsyscp_fopen() and + get_command_line_args_utf8() (Windows only) + * progname.c: Refine initialization for KANJI (Windows only) + 2013-12-03 TANAKA Takuji <KXD02663@nifty.ne.jp> * elt-dirs.c, knj.c, knj.h, progname.c, readable.c: Support KANJI diff --git a/Build/source/texk/kpathsea/knj.c b/Build/source/texk/kpathsea/knj.c index eeb1120e913..efdaaeabe33 100644 --- a/Build/source/texk/kpathsea/knj.c +++ b/Build/source/texk/kpathsea/knj.c @@ -127,3 +127,75 @@ fsyscp_xfopen (const char *filename, const char *mode) return f; } + +/* + fopen by file system codepage +*/ +FILE * +fsyscp_fopen (const char *filename, const char *mode) +{ + FILE *f; + wchar_t *fnamew, modew[4]; +#if defined (KPSE_COMPAT_API) + kpathsea kpse; +#endif + assert(filename && mode); + + fnamew = get_wstring_from_fsyscp(filename, fnamew=NULL); + get_wstring_from_fsyscp(mode, modew); + f = _wfopen(fnamew, modew); +#if defined (KPSE_COMPAT_API) + if (f != NULL) { + kpse = kpse_def; + if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) { + DEBUGF_START (); + fprintf (stderr, "fsyscp_fopen(%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; +} + +void +get_command_line_args_utf8 (const_string enc, int *p_ac, string **p_av) +{ + int argc; + string *argv; + + if (!enc) return; +#ifdef DEBUG + fprintf(stderr, "command_line_encoding (%s)\n", enc); +#endif /* DEBUG */ + if (!(strncmp(enc,"utf8",5) && strncmp(enc,"utf-8",6))) { + DWORD ret; + LPWSTR *argvw; + INT argcw, i; + string s; +#ifdef DEBUG + HANDLE hStderr; + hStderr = GetStdHandle( STD_ERROR_HANDLE ); +#endif /* DEBUG */ + file_system_codepage = CP_UTF8; + is_cp932_system = 0; + argvw = CommandLineToArgvW(GetCommandLineW(), &argcw); + argc = argcw; + argv = xmalloc(sizeof(char *)*(argcw+1)); + for (i=0; i<argcw; i++) { + s = get_utf8_from_wstring(argvw[i], s=NULL); + argv[i] = s; +#ifdef DEBUG + fprintf(stderr, "Commandline arguments %d:(%s) [", i, argv[i]); + WriteConsoleW( hStderr, argvw[i], wcslen(argvw[i]), &ret, NULL); + fprintf(stderr, "]\n"); +#endif /* DEBUG */ + } + argv[argcw] = NULL; + } + *p_ac = argc; + *p_av = argv; +} diff --git a/Build/source/texk/kpathsea/knj.h b/Build/source/texk/kpathsea/knj.h index 0629213a309..00db79c5e24 100644 --- a/Build/source/texk/kpathsea/knj.h +++ b/Build/source/texk/kpathsea/knj.h @@ -19,6 +19,9 @@ #ifndef KPATHSEA_KNJ_H #define KPATHSEA_KNJ_H +#include <kpathsea/c-proto.h> +#include <kpathsea/types.h> + #ifdef __cplusplus extern "C" { #endif @@ -32,6 +35,8 @@ extern KPSEDLL int isknj2(int c); extern KPSEDLL wchar_t* get_wstring_from_mbstring(int cp, const char *mbstr, wchar_t *wstr); extern KPSEDLL char* get_mbstring_from_wstring(int cp, const wchar_t *wstr, char *mbstr); extern KPSEDLL FILE* fsyscp_xfopen(const char *filename, const char *mode); +extern KPSEDLL FILE* fsyscp_fopen(const char *filename, const char *mode); +extern KPSEDLL void get_command_line_args_utf8(const_string enc, int *p_ac, string **p_av); #ifdef __cplusplus } diff --git a/Build/source/texk/kpathsea/progname.c b/Build/source/texk/kpathsea/progname.c index 5952936579b..c4fe781011c 100644 --- a/Build/source/texk/kpathsea/progname.c +++ b/Build/source/texk/kpathsea/progname.c @@ -501,13 +501,14 @@ kpathsea_set_program_name (kpathsea kpse, const_string argv0, } #if defined(WIN32) - cp = GetACP(); + if (!file_system_codepage) + file_system_codepage = AreFileApisANSI() ? GetACP() : GetOEMCP(); + cp = file_system_codepage; if (cp == 932 || cp == 936 || cp == 950) { is_cp932_system = cp; } else is_cp932_system = 0; - file_system_codepage = AreFileApisANSI() ? GetACP() : GetOEMCP(); #if defined(__MINGW32__) /* Set various info about user. Among many things, |