diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2014-01-14 05:31:31 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2014-01-14 05:31:31 +0000 |
commit | 5fef6cd2ed2fb4cd1e9a49bf995a935a73facf96 (patch) | |
tree | 90ff2a76aa3957c70c9f59d507de5ae3385cca9b | |
parent | 5246edbdec2f76e72de771908d6c75131190432e (diff) |
Add new functions (Windows only).
git-svn-id: svn://tug.org/texlive/trunk@32668 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Build/source/texk/kpathsea/ChangeLog | 5 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/knj.c | 105 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/knj.h | 4 |
3 files changed, 112 insertions, 2 deletions
diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog index d0d9b46c209..19af64518d9 100644 --- a/Build/source/texk/kpathsea/ChangeLog +++ b/Build/source/texk/kpathsea/ChangeLog @@ -1,3 +1,8 @@ +2014-01-14 Akira Kakuto <kakuto@fuk.kindai.ac.jp> + + * knj.[ch]: Add new functions fsyscp_spawnvp(), and fsyscp_system(). + (Windows only) + 2014-01-13 TANAKA Takuji <KXD02663@nifty.ne.jp> * knj.[ch]: Add a new function fsyscp_popen(). (Windows only) diff --git a/Build/source/texk/kpathsea/knj.c b/Build/source/texk/kpathsea/knj.c index 2f38500f005..0d3eb0ec04e 100644 --- a/Build/source/texk/kpathsea/knj.c +++ b/Build/source/texk/kpathsea/knj.c @@ -1,6 +1,6 @@ /* knj.c: check for 2-Byte Kanji (CP 932, SJIS) codes. - Copyright 2010, 2011 Akira Kakuto. + Copyright 2010, 2014 Akira Kakuto. Copyright 2013, 2014 TANAKA Takuji. This library is free software; you can redistribute it and/or @@ -238,3 +238,106 @@ get_command_line_args_utf8 (const_string enc, int *p_ac, char ***p_av) WARNING1("kpathsea: Ignoring unknown encoding `%s'", enc); } } + +/* + spawnvp by file system codepage +*/ +int +fsyscp_spawnvp (int mode, const char *command, const char* const *argv) +{ + int ret; + wchar_t *commandw, **argvw, **pw; + int i; + const char* const *p; +#if defined (KPSE_COMPAT_API) + kpathsea kpse; +#endif + assert(command && argv); + for (i = 0, p = argv; *p; p++) + i++; + argvw = xcalloc (i + 3, sizeof (wchar_t *)); + commandw = get_wstring_from_fsyscp(command, commandw=NULL); + p = argv; + pw = argvw; + while (*p) { + *pw = get_wstring_from_fsyscp(*p, *pw=NULL); + p++; + pw++; + } + *pw = NULL; + ret = _wspawnvp (mode, (const wchar_t *)commandw, (const wchar_t* const*) argvw); +#if defined (KPSE_COMPAT_API) + if (ret == -1) { + kpse = kpse_def; + if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) { + DEBUGF_START (); + fprintf (stderr, "fsyscp_spawnvp(%s [", command); + WriteConsoleW( GetStdHandle( STD_ERROR_HANDLE ), commandw, wcslen( commandw ), NULL, NULL ); + fprintf (stderr, "]\n"); + DEBUGF_END (); + } + } +#endif + if(commandw) free(commandw); + if (argvw) { + pw = argvw; + while (*pw) { + free (*pw); + pw++; + } + free (argvw); + } + + return ret; +} + +static int is_include_space (const char *s) +{ + char *p; + p = strchr (s, ' '); + if (p) return 1; + p = strchr (s, '\t'); + if (p) return 1; + return 0; +} + +/* + system by file system codepage +*/ +int +fsyscp_system (const char *cmd) +{ + const char *p; + char *q; + char *av[4]; + int len, ret; + int spacep = 0; + + if (cmd == NULL) + return 1; + + av[0] = xstrdup ("cmd.exe"); + av[1] = xstrdup ("/c"); + + len = strlen (cmd) + 3; + spacep = is_include_space (cmd); + av[2] = xmalloc (len); + q = av[2]; + if (spacep) + *q++ = '"'; + for (p = cmd; *p; p++, q++) { + if (*p == '\'') + *q = '"'; + else + *q = *p; + } + if (spacep) + *q++ = '"'; + *q = '\0'; + av[3] = NULL; + ret = fsyscp_spawnvp (_P_WAIT, av[0], av); + free (av[0]); + free (av[1]); + free (av[2]); + return ret; +} diff --git a/Build/source/texk/kpathsea/knj.h b/Build/source/texk/kpathsea/knj.h index 8bfe7df290e..0e942d518d6 100644 --- a/Build/source/texk/kpathsea/knj.h +++ b/Build/source/texk/kpathsea/knj.h @@ -1,6 +1,6 @@ /* knj.h: check for 2-Byte Kanji (CP 932, SJIS) codes. - Copyright 2010, 2011 Akira Kakuto. + Copyright 2010, 2014 Akira Kakuto. Copyright 2013, 2014 TANAKA Takuji. This library is free software; you can redistribute it and/or @@ -34,6 +34,8 @@ extern KPSEDLL char* get_mbstring_from_wstring(int cp, const wchar_t *wstr, char extern KPSEDLL FILE* fsyscp_xfopen(const char *filename, const char *mode); extern KPSEDLL FILE* fsyscp_fopen(const char *filename, const char *mode); extern KPSEDLL FILE* fsyscp_popen(const char *command, const char *mode); +extern KPSEDLL int fsyscp_spawnvp(int mode, const char *command, const char* const *argv); +extern KPSEDLL int fsyscp_system(const char *cmd); extern KPSEDLL void get_command_line_args_utf8(const char *enc, int *p_ac, char ***p_av); #ifdef __cplusplus |