summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.1091
blob: 28fb9cdb5db843c9399c87401d7964497a47e8ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
To: vim_dev@googlegroups.com
Subject: Patch 8.1.1091
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.1091
Problem:    MS-Windows: cannot use multi-byte chars in environment var.
Solution:   Use the wide API. (Ken Takata, closes #4008)
Files:	    src/misc1.c, src/testdir/test_let.vim


*** ../vim-8.1.1090/src/misc1.c	2019-03-30 18:46:57.356077354 +0100
--- src/misc1.c	2019-03-30 20:10:00.966173750 +0100
***************
*** 4301,4341 ****
      char_u *
  vim_getenv(char_u *name, int *mustfree)
  {
!     char_u	*p;
      char_u	*pend;
      int		vimruntime;
  
! #if defined(MSWIN)
!     /* use "C:/" when $HOME is not set */
      if (STRCMP(name, "HOME") == 0)
  	return homedir;
- #endif
  
!     p = mch_getenv(name);
!     if (p != NULL && *p == NUL)	    /* empty is the same as not set */
! 	p = NULL;
  
!     if (p != NULL)
      {
! #if defined(MSWIN)
! 	if (enc_utf8)
! 	{
! 	    int	    len;
! 	    char_u  *pp = NULL;
  
! 	    /* Convert from active codepage to UTF-8.  Other conversions are
! 	     * not done, because they would fail for non-ASCII characters. */
! 	    acp_to_enc(p, (int)STRLEN(p), &pp, &len);
! 	    if (pp != NULL)
! 	    {
! 		p = pp;
! 		*mustfree = TRUE;
! 	    }
! 	}
! #endif
  	return p;
      }
  
      vimruntime = (STRCMP(name, "VIMRUNTIME") == 0);
      if (!vimruntime && STRCMP(name, "VIM") != 0)
  	return NULL;
--- 4301,4346 ----
      char_u *
  vim_getenv(char_u *name, int *mustfree)
  {
!     char_u	*p = NULL;
      char_u	*pend;
      int		vimruntime;
+ #ifdef MSWIN
+     WCHAR	*wn, *wp;
  
!     // use "C:/" when $HOME is not set
      if (STRCMP(name, "HOME") == 0)
  	return homedir;
  
!     // Use Wide function
!     wn = enc_to_utf16(name, NULL);
!     if (wn == NULL)
! 	return NULL;
  
!     wp = _wgetenv(wn);
!     vim_free(wn);
! 
!     if (wp != NULL && *wp == NUL)   // empty is the same as not set
! 	wp = NULL;
! 
!     if (wp != NULL)
      {
! 	p = utf16_to_enc(wp, NULL);
! 	if (p == NULL)
! 	    return NULL;
  
! 	*mustfree = TRUE;
  	return p;
      }
+ #else
+     p = mch_getenv(name);
+     if (p != NULL && *p == NUL)	    // empty is the same as not set
+ 	p = NULL;
  
+     if (p != NULL)
+ 	return p;
+ #endif
+ 
+     // handling $VIMRUNTIME and $VIM is below, bail out if it's another name.
      vimruntime = (STRCMP(name, "VIMRUNTIME") == 0);
      if (!vimruntime && STRCMP(name, "VIM") != 0)
  	return NULL;
***************
*** 4350,4357 ****
  #endif
         )
      {
  	p = mch_getenv((char_u *)"VIM");
! 	if (p != NULL && *p == NUL)	    /* empty is the same as not set */
  	    p = NULL;
  	if (p != NULL)
  	{
--- 4355,4379 ----
  #endif
         )
      {
+ #ifdef MSWIN
+ 	// Use Wide function
+ 	wp = _wgetenv(L"VIM");
+ 	if (wp != NULL && *wp == NUL)	    // empty is the same as not set
+ 	    wp = NULL;
+ 	if (wp != NULL)
+ 	{
+ 	    char_u *q = utf16_to_enc(wp, NULL);
+ 	    if (q != NULL)
+ 	    {
+ 		p = vim_version_dir(q);
+ 		*mustfree = TRUE;
+ 		if (p == NULL)
+ 		    p = q;
+ 	    }
+ 	}
+ #else
  	p = mch_getenv((char_u *)"VIM");
! 	if (p != NULL && *p == NUL)	    // empty is the same as not set
  	    p = NULL;
  	if (p != NULL)
  	{
***************
*** 4360,4386 ****
  		*mustfree = TRUE;
  	    else
  		p = mch_getenv((char_u *)"VIM");
- 
- #if defined(MSWIN)
- 	    if (enc_utf8)
- 	    {
- 		int	len;
- 		char_u  *pp = NULL;
- 
- 		/* Convert from active codepage to UTF-8.  Other conversions
- 		 * are not done, because they would fail for non-ASCII
- 		 * characters. */
- 		acp_to_enc(p, (int)STRLEN(p), &pp, &len);
- 		if (pp != NULL)
- 		{
- 		    if (*mustfree)
- 			vim_free(p);
- 		    p = pp;
- 		    *mustfree = TRUE;
- 		}
- 	    }
- #endif
  	}
      }
  
      /*
--- 4382,4389 ----
  		*mustfree = TRUE;
  	    else
  		p = mch_getenv((char_u *)"VIM");
  	}
+ #endif
      }
  
      /*
*** ../vim-8.1.1090/src/testdir/test_let.vim	2019-02-11 22:00:07.671917613 +0100
--- src/testdir/test_let.vim	2019-03-30 20:07:06.947341962 +0100
***************
*** 146,148 ****
--- 146,153 ----
    call assert_fails('call s:set_varg8(1)', 'E742:')
    call s:set_varg9([0])
  endfunction
+ 
+ func Test_let_utf8_environment()
+   let $a = 'ĀĒĪŌŪあいうえお'
+   call assert_equal('ĀĒĪŌŪあいうえお', $a)
+ endfunc
*** ../vim-8.1.1090/src/version.c	2019-03-30 20:04:05.024567549 +0100
--- src/version.c	2019-03-30 20:07:53.131031588 +0100
***************
*** 777,778 ****
--- 777,780 ----
  {   /* Add new patch number below this line */
+ /**/
+     1091,
  /**/

-- 
Microsoft says that MS-Windows is much better for you than Linux.
That's like the Pope saying that catholicism is much better for
you than protestantism.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///