Hi,
Setting environment variable with multibyte strings doesn't work well when
enc=utf-8. E.g.:
> vim --cmd "set enc=utf-8"
:let $FOO='こんにちは'
:echo $FOO
縺薙s縺ォ縺。縺ッ
Attached patch fixes the problem.
This patch was originally written by Taro Muraoka, and updated for v8.0.0175
and later by me.
Regards,
Ken Takata
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
# HG changeset patch
# Parent 544b47b05b3abf8086f15c4e28d1b77d29afc87a
diff --git a/src/misc1.c b/src/misc1.c
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -4453,9 +4453,6 @@ vim_setenv(char_u *name, char_u *val)
{
sprintf((char *)envbuf, "%s=%s", name, val);
putenv((char *)envbuf);
-# ifdef libintl_putenv
- libintl_putenv((char *)envbuf);
-# endif
}
#endif
#ifdef FEAT_GETTEXT
diff --git a/src/os_win32.c b/src/os_win32.c
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -516,6 +516,7 @@ static char *null_libintl_textdomain(con
static char *null_libintl_bindtextdomain(const char *, const char *);
static char *null_libintl_bind_textdomain_codeset(const char *, const char *);
static int null_libintl_putenv(const char *);
+static int null_libintl_wputenv(const wchar_t *);
static HINSTANCE hLibintlDLL = NULL;
char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
@@ -527,6 +528,7 @@ char *(*dyn_libintl_bindtextdomain)(cons
char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *)
= null_libintl_bind_textdomain_codeset;
int (*dyn_libintl_putenv)(const char *) = null_libintl_putenv;
+int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv;
int
dyn_libintl_init(void)
@@ -596,9 +598,14 @@ dyn_libintl_init(void)
/* _putenv() function for the libintl.dll is optional. */
hmsvcrt = find_imported_module_by_funcname(hLibintlDLL, "getenv");
if (hmsvcrt != NULL)
+ {
dyn_libintl_putenv = (void *)GetProcAddress(hmsvcrt, "_putenv");
- if (dyn_libintl_putenv == NULL || dyn_libintl_putenv == putenv)
+ dyn_libintl_wputenv = (void *)GetProcAddress(hmsvcrt, "_wputenv");
+ }
+ if (dyn_libintl_putenv == NULL || dyn_libintl_putenv == _putenv)
dyn_libintl_putenv = null_libintl_putenv;
+ if (dyn_libintl_wputenv == NULL || dyn_libintl_wputenv == _wputenv)
+ dyn_libintl_wputenv = null_libintl_wputenv;
return 1;
}
@@ -615,6 +622,7 @@ dyn_libintl_end(void)
dyn_libintl_bindtextdomain = null_libintl_bindtextdomain;
dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset;
dyn_libintl_putenv = null_libintl_putenv;
+ dyn_libintl_wputenv = null_libintl_wputenv;
}
/*ARGSUSED*/
@@ -663,6 +671,13 @@ null_libintl_putenv(const char *envstrin
return 0;
}
+/*ARGSUSED*/
+ int
+null_libintl_wputenv(const wchar_t *envstring)
+{
+ return 0;
+}
+
#endif /* DYNAMIC_GETTEXT */
/* This symbol is not defined in older versions of the SDK or Visual C++ */
@@ -7023,3 +7038,43 @@ fix_arg_enc(void)
set_alist_count();
}
#endif
+
+ int
+mch_setenv(char *var, char *value, int x)
+{
+ char_u *envbuf;
+
+ envbuf = alloc((unsigned)(STRLEN(var) + STRLEN(value) + 2));
+ if (envbuf == NULL)
+ return -1;
+
+ sprintf((char *)envbuf, "%s=%s", var, value);
+
+#ifdef FEAT_MBYTE
+ if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
+ {
+ WCHAR *p = enc_to_utf16(envbuf, NULL);
+
+ vim_free(envbuf);
+ if (p == NULL)
+ return -1;
+ _wputenv(p);
+# ifdef libintl_wputenv
+ libintl_wputenv(p);
+# endif
+ /* Unlike Un*x systems, we can free the string for _wputenv(). */
+ vim_free(p);
+ }
+ else
+#endif
+ {
+ _putenv((char *)envbuf);
+# ifdef libintl_putenv
+ libintl_putenv((char *)envbuf);
+# endif
+ /* Unlike Un*x systems, we can free the string for _putenv(). */
+ vim_free(envbuf);
+ }
+
+ return 0;
+}
diff --git a/src/os_win32.h b/src/os_win32.h
--- a/src/os_win32.h
+++ b/src/os_win32.h
@@ -201,7 +201,9 @@ Trace(char *pszFormat, ...);
#define ASSERT_NULL_OR_POINTER(p, type) \
ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
-#define mch_setenv(name, val, x) setenv(name, val, x)
+#ifndef HAVE_SETENV
+# define HAVE_SETENV
+#endif
#define mch_getenv(x) (char_u *)getenv((char *)(x))
#ifdef __BORLANDC__
# define vim_mkdir(x, y) mkdir(x)
diff --git a/src/proto/os_win32.pro b/src/proto/os_win32.pro
--- a/src/proto/os_win32.pro
+++ b/src/proto/os_win32.pro
@@ -65,4 +65,5 @@ void free_cmd_argsW(void);
void used_file_arg(char *name, int literal, int full_path, int diff_mode);
void set_alist_count(void);
void fix_arg_enc(void);
+int mch_setenv(char *var, char *value, int x);
/* vim: set ft=c : */
diff --git a/src/vim.h b/src/vim.h
--- a/src/vim.h
+++ b/src/vim.h
@@ -602,6 +602,7 @@ extern int (*dyn_libintl_putenv)(const c
# endif
# define textdomain(domain) (*dyn_libintl_textdomain)(domain)
# define libintl_putenv(envstring) (*dyn_libintl_putenv)(envstring)
+# define libintl_wputenv(envstring) (*dyn_libintl_wputenv)(envstring)
# else
# include <libintl.h>
# define _(x) gettext((char *)(x))