summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0534
blob: 9071561d658f4930944a70e76c272a37783fc86e (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0534
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.0534
Problem:    MS-Windows installer uses different $HOME than Vim.
Solution:   Use the Vim logic also in the MS-Windows installer. (Ken Takata,
            closes #3564)
Files:	    src/dosinst.c, src/misc1.c


*** ../vim-8.1.0533/src/dosinst.c	2018-10-13 17:25:24.112718312 +0200
--- src/dosinst.c	2018-11-16 19:39:24.551085683 +0100
***************
*** 115,128 ****
      vimfiles_dir_vim,
      vimfiles_dir_home
  };
! static char    *(vimfiles_dir_choices[]) =
  {
      "\nCreate plugin directories:",
      "No",
      "In the VIM directory",
      "In your HOME directory",
  };
- static int     vimfiles_dir_choice;
  
  /* non-zero when selected to install the popup menu entry. */
  static int	install_popup = 0;
--- 115,127 ----
      vimfiles_dir_vim,
      vimfiles_dir_home
  };
! static char *(vimfiles_dir_choices[]) =
  {
      "\nCreate plugin directories:",
      "No",
      "In the VIM directory",
      "In your HOME directory",
  };
  
  /* non-zero when selected to install the popup menu entry. */
  static int	install_popup = 0;
***************
*** 741,747 ****
      choices[choice_count].installfunc = NULL;
      choices[choice_count].active = 0;
      choices[choice_count].changefunc = NULL;
!     choices[choice_count].installfunc = NULL;
      ++choice_count;
  }
  
--- 740,747 ----
      choices[choice_count].installfunc = NULL;
      choices[choice_count].active = 0;
      choices[choice_count].changefunc = NULL;
!     choices[choice_count].text = NULL;
!     choices[choice_count].arg = 0;
      ++choice_count;
  }
  
***************
*** 2089,2094 ****
--- 2089,2096 ----
      static void
  set_directories_text(int idx)
  {
+     int vimfiles_dir_choice = choices[idx].arg;
+ 
      if (vimfiles_dir_choice == (int)vimfiles_dir_none)
  	alloc_text(idx, "Do NOT create plugin directories%s", "");
      else
***************
*** 2097,2102 ****
--- 2099,2189 ----
  }
  
  /*
+  * To get the "real" home directory:
+  * - get value of $HOME
+  * - if not found, get value of $HOMEDRIVE$HOMEPATH
+  * - if not found, get value of $USERPROFILE
+  *
+  * This code is based on init_homedir() in misc1.c, keep in sync!
+  */
+ static char *homedir = NULL;
+ 
+     void
+ init_homedir(void)
+ {
+     char    *var;
+     char    buf[MAX_PATH];
+ 
+     if (homedir != NULL)
+     {
+ 	free(homedir);
+ 	homedir = NULL;
+     }
+ 
+     var = getenv("HOME");
+ 
+     /*
+      * Typically, $HOME is not defined on Windows, unless the user has
+      * specifically defined it for Vim's sake.  However, on Windows NT
+      * platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for
+      * each user.  Try constructing $HOME from these.
+      */
+     if (var == NULL || *var == NUL)
+     {
+ 	char	*homedrive, *homepath;
+ 
+ 	homedrive = getenv("HOMEDRIVE");
+ 	homepath = getenv("HOMEPATH");
+ 	if (homepath == NULL || *homepath == NUL)
+ 	    homepath = "\\";
+ 	if (homedrive != NULL
+ 			   && strlen(homedrive) + strlen(homepath) < MAX_PATH)
+ 	{
+ 	    sprintf(buf, "%s%s", homedrive, homepath);
+ 	    if (buf[0] != NUL)
+ 		var = buf;
+ 	}
+     }
+ 
+     if (var == NULL)
+ 	var = getenv("USERPROFILE");
+ 
+     /*
+      * Weird but true: $HOME may contain an indirect reference to another
+      * variable, esp. "%USERPROFILE%".  Happens when $USERPROFILE isn't set
+      * when $HOME is being set.
+      */
+     if (var != NULL && *var == '%')
+     {
+ 	char	*p;
+ 	char	*exp;
+ 
+ 	p = strchr(var + 1, '%');
+ 	if (p != NULL)
+ 	{
+ 	    strncpy(buf, var + 1, p - (var + 1));
+ 	    buf[p - (var + 1)] = NUL;
+ 	    exp = getenv(buf);
+ 	    if (exp != NULL && *exp != NUL
+ 					&& strlen(exp) + strlen(p) < MAX_PATH)
+ 	    {
+ 		_snprintf(buf, MAX_PATH, "%s%s", exp, p + 1);
+ 		buf[MAX_PATH - 1] = NUL;
+ 		var = buf;
+ 	    }
+ 	}
+     }
+ 
+     if (var != NULL && *var == NUL)	// empty is same as not set
+ 	var = NULL;
+ 
+     if (var == NULL)
+ 	homedir = NULL;
+     else
+ 	homedir = _strdup(var);
+ }
+ 
+ /*
   * Change the directory that the vim plugin directories will be created in:
   * $HOME, $VIM or nowhere.
   */
***************
*** 2106,2114 ****
      int	    choice_count = TABLE_SIZE(vimfiles_dir_choices);
  
      /* Don't offer the $HOME choice if $HOME isn't set. */
!     if (getenv("HOME") == NULL)
  	--choice_count;
!     vimfiles_dir_choice = get_choice(vimfiles_dir_choices, choice_count);
      set_directories_text(idx);
  }
  
--- 2193,2201 ----
      int	    choice_count = TABLE_SIZE(vimfiles_dir_choices);
  
      /* Don't offer the $HOME choice if $HOME isn't set. */
!     if (homedir == NULL)
  	--choice_count;
!     choices[idx].arg = get_choice(vimfiles_dir_choices, choice_count);
      set_directories_text(idx);
  }
  
***************
*** 2120,2125 ****
--- 2207,2213 ----
  install_vimfilesdir(int idx)
  {
      int i;
+     int vimfiles_dir_choice = choices[idx].arg;
      char *p;
      char vimdir_path[BUFSIZE];
      char vimfiles_path[BUFSIZE];
***************
*** 2144,2151 ****
  	}
  	case vimfiles_dir_home:
  	{
! 	    /* Find the $HOME directory.  Its existence was already checked. */
! 	    p = getenv("HOME");
  	    if (p == NULL)
  	    {
  		printf("Internal error: $HOME is NULL\n");
--- 2232,2239 ----
  	}
  	case vimfiles_dir_home:
  	{
! 	    // Find the $HOME directory.  Its existence was already checked.
! 	    p = homedir;
  	    if (p == NULL)
  	    {
  		printf("Internal error: $HOME is NULL\n");
***************
*** 2156,2162 ****
  	}
  	case vimfiles_dir_none:
  	{
! 	    /* Do not create vim plugin directory */
  	    return;
  	}
      }
--- 2244,2250 ----
  	}
  	case vimfiles_dir_none:
  	{
! 	    // Do not create vim plugin directory.
  	    return;
  	}
      }
***************
*** 2185,2198 ****
      struct stat	st;
      char	tmp_dirname[BUFSIZE];
      char	*p;
  
      choices[choice_count].text = alloc(150);
      choices[choice_count].changefunc = change_directories_choice;
      choices[choice_count].installfunc = install_vimfilesdir;
      choices[choice_count].active = 1;
  
!     /* Check if the "compiler" directory already exists.  That's a good
!      * indication that the plugin directories were already created. */
      if (getenv("HOME") != NULL)
      {
  	vimfiles_dir_choice = (int)vimfiles_dir_home;
--- 2273,2287 ----
      struct stat	st;
      char	tmp_dirname[BUFSIZE];
      char	*p;
+     int		vimfiles_dir_choice;
  
      choices[choice_count].text = alloc(150);
      choices[choice_count].changefunc = change_directories_choice;
      choices[choice_count].installfunc = install_vimfilesdir;
      choices[choice_count].active = 1;
  
!     // Check if the "compiler" directory already exists.  That's a good
!     // indication that the plugin directories were already created.
      if (getenv("HOME") != NULL)
      {
  	vimfiles_dir_choice = (int)vimfiles_dir_home;
***************
*** 2204,2210 ****
      {
  	vimfiles_dir_choice = (int)vimfiles_dir_vim;
  	p = getenv("VIM");
! 	if (p == NULL) /* No $VIM in path, use the install dir */
  	    dir_remove_last(installdir, tmp_dirname);
  	else
  	    strcpy(tmp_dirname, p);
--- 2293,2299 ----
      {
  	vimfiles_dir_choice = (int)vimfiles_dir_vim;
  	p = getenv("VIM");
! 	if (p == NULL)  // No $VIM in path, use the install dir.
  	    dir_remove_last(installdir, tmp_dirname);
  	else
  	    strcpy(tmp_dirname, p);
***************
*** 2213,2218 ****
--- 2302,2308 ----
  	    vimfiles_dir_choice = (int)vimfiles_dir_none;
      }
  
+     choices[choice_count].arg = vimfiles_dir_choice;
      set_directories_text(choice_count);
      ++choice_count;
  }
***************
*** 2369,2374 ****
--- 2459,2466 ----
  	}
  	else if (strcmp(argv[i], "-create-directories") == 0)
  	{
+ 	    int vimfiles_dir_choice;
+ 
  	    init_directories_choice();
  	    if (argv[i + 1][0] != '-')
  	    {
***************
*** 2377,2384 ****
  		    vimfiles_dir_choice = (int)vimfiles_dir_vim;
  		else if (strcmp(argv[i], "home") == 0)
  		{
! 		    if (getenv("HOME") == NULL) /* No $HOME in environment */
! 			vimfiles_dir_choice = (int)vimfiles_dir_vim;
  		    else
  			vimfiles_dir_choice = (int)vimfiles_dir_home;
  		}
--- 2469,2476 ----
  		    vimfiles_dir_choice = (int)vimfiles_dir_vim;
  		else if (strcmp(argv[i], "home") == 0)
  		{
! 		    if (homedir == NULL)  // No $HOME in environment
! 			vimfiles_dir_choice = (int)vimfiles_dir_none;
  		    else
  			vimfiles_dir_choice = (int)vimfiles_dir_home;
  		}
***************
*** 2391,2396 ****
--- 2483,2489 ----
  	    }
  	    else /* No choice specified, default to vim directory */
  		vimfiles_dir_choice = (int)vimfiles_dir_vim;
+ 	    choices[choice_count - 1].arg = vimfiles_dir_choice;
  	}
  	else if (strcmp(argv[i], "-register-OLE") == 0)
  	{
***************
*** 2589,2594 ****
--- 2682,2688 ----
  
      /* Initialize this program. */
      do_inits(argv);
+     init_homedir();
  
      if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0)
      {
*** ../vim-8.1.0533/src/misc1.c	2018-10-07 23:16:33.138616197 +0200
--- src/misc1.c	2018-11-16 19:37:57.095655169 +0100
***************
*** 3905,3910 ****
--- 3905,3912 ----
   *  - do mch_dirname() to get the real name of that directory.
   *  This also works with mounts and links.
   *  Don't do this for MS-DOS, it will change the "current dir" for a drive.
+  * For Windows:
+  *  This code is duplicated in init_homedir() in dosinst.c.  Keep in sync!
   */
  static char_u	*homedir = NULL;
  
*** ../vim-8.1.0533/src/version.c	2018-11-16 18:50:13.346534543 +0100
--- src/version.c	2018-11-16 19:33:13.893507996 +0100
***************
*** 794,795 ****
--- 794,797 ----
  {   /* Add new patch number below this line */
+ /**/
+     534,
  /**/

-- 
Two cows are standing together in a field.  One asks the other:
"So what do you think about this Mad Cow Disease?"
The other replies: "That doesn't concern me. I'm a helicopter."

 /// 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    ///