summaryrefslogtreecommitdiffstats
path: root/source/ap/vim/patches/7.3.447
blob: 9c0af9f4d660c24458edf2201c3ae8777beb8202 (about) (plain) (blame)
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
To: vim_dev@googlegroups.com
Subject: Patch 7.3.447
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.447 (after 7.3.446)
Problem:    Win32: External commands with "start" do not work.
Solution:   Unescape part of the command. (Yasuhiro Matsumoto)
Files:	    src/os_win32.c


*** ../vim-7.3.446/src/os_win32.c	2012-02-19 18:19:24.000000000 +0100
--- src/os_win32.c	2012-02-21 20:56:51.000000000 +0100
***************
*** 259,264 ****
--- 259,287 ----
  }
  
  /*
+  * Unescape characters in "p" that appear in "escaped".
+  */
+     static void
+ unescape_shellxquote(char_u *p, char_u *escaped)
+ {
+     int	    l = STRLEN(p);
+     int	    n;
+ 
+     while (*p != NUL)
+     {
+ 	if (*p == '^' && vim_strchr(escaped, p[1]) != NULL)
+ 	    mch_memmove(p, p + 1, l--);
+ #ifdef FEAT_MBYTE
+ 	n = (*mb_ptr2len)(p);
+ #else
+ 	n = 1;
+ #endif
+ 	p += n;
+ 	l -= n;
+     }
+ }
+ 
+ /*
   * Load library "name".
   */
      HINSTANCE
***************
*** 3559,3564 ****
--- 3582,3588 ----
      garray_T	ga;
      int	    delay = 1;
      DWORD	buffer_off = 0;	/* valid bytes in buffer[] */
+     char	*p = NULL;
  
      SECURITY_ATTRIBUTES saAttr;
  
***************
*** 3599,3607 ****
      if (options & SHELL_READ)
  	ga_init2(&ga, 1, BUFLEN);
  
      /* Now, run the command */
      CreateProcess(NULL,			/* Executable name */
! 		  cmd,			/* Command to execute */
  		  NULL,			/* Process security attributes */
  		  NULL,			/* Thread security attributes */
  
--- 3623,3640 ----
      if (options & SHELL_READ)
  	ga_init2(&ga, 1, BUFLEN);
  
+     if (cmd != NULL)
+     {
+ 	p = (char *)vim_strsave((char_u *)cmd);
+ 	if (p != NULL)
+ 	    unescape_shellxquote((char_u *)p, p_sxe);
+ 	else
+ 	    p = cmd;
+     }
+ 
      /* Now, run the command */
      CreateProcess(NULL,			/* Executable name */
! 		  p,			/* Command to execute */
  		  NULL,			/* Process security attributes */
  		  NULL,			/* Thread security attributes */
  
***************
*** 3616,3621 ****
--- 3649,3656 ----
  		  &si,			/* Startup information */
  		  &pi);			/* Process information */
  
+     if (p != cmd)
+ 	vim_free(p);
  
      /* Close our unused side of the pipes */
      CloseHandle(g_hChildStd_IN_Rd);
***************
*** 3898,4018 ****
      else
      {
  	/* we use "command" or "cmd" to start the shell; slow but easy */
! 	char_u *newcmd;
! 	long_u cmdlen =  (
! #ifdef FEAT_GUI_W32
! 		(allowPiping && !p_stmp ? 0 : STRLEN(vimrun_path)) +
! #endif
! 		STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10);
! 
! 	newcmd = lalloc(cmdlen, TRUE);
! 	if (newcmd != NULL)
! 	{
! 	    char_u *cmdbase = cmd;
! 
! 	    /* Skip a leading ", ( and "(. */
! 	    if (*cmdbase == '"' )
! 		++cmdbase;
! 	    if (*cmdbase == '(')
! 		++cmdbase;
! 	    if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5]))
! 	    {
! 		STARTUPINFO		si;
! 		PROCESS_INFORMATION	pi;
! 		DWORD			flags = CREATE_NEW_CONSOLE;
! 
! 		si.cb = sizeof(si);
! 		si.lpReserved = NULL;
! 		si.lpDesktop = NULL;
! 		si.lpTitle = NULL;
! 		si.dwFlags = 0;
! 		si.cbReserved2 = 0;
! 		si.lpReserved2 = NULL;
! 
! 		cmdbase = skipwhite(cmdbase + 5);
! 		if ((STRNICMP(cmdbase, "/min", 4) == 0)
! 			&& vim_iswhite(cmdbase[4]))
! 		{
! 		    cmdbase = skipwhite(cmdbase + 4);
! 		    si.dwFlags = STARTF_USESHOWWINDOW;
! 		    si.wShowWindow = SW_SHOWMINNOACTIVE;
! 		}
! 		else if ((STRNICMP(cmdbase, "/b", 2) == 0)
! 			&& vim_iswhite(cmdbase[2]))
! 		{
! 		    cmdbase = skipwhite(cmdbase + 2);
! 		    flags = CREATE_NO_WINDOW;
! 		    si.dwFlags = STARTF_USESTDHANDLES;
! 		    si.hStdInput = CreateFile("\\\\.\\NUL",	// File name
! 			GENERIC_READ,				// Access flags
! 			0,					// Share flags
! 			NULL,					// Security att.
! 			OPEN_EXISTING,				// Open flags
! 			FILE_ATTRIBUTE_NORMAL,			// File att.
! 			NULL);					// Temp file
! 		    si.hStdOutput = si.hStdInput;
! 		    si.hStdError = si.hStdInput;
! 		}
  
! 		/* When the command is in double quotes, but 'shellxquote' is
! 		 * empty, keep the double quotes around the command.
! 		 * Otherwise remove the double quotes, they aren't needed
! 		 * here, because we don't use a shell to run the command. */
! 		if (cmdbase > cmd)
! 		{
! 		    if (STRNCMP(cmd, p_sxq, cmd - cmdbase) != 0)
! 		    {
! 			STRCPY(newcmd, cmd);
! 		    }
! 		    else
! 		    {
! 			char_u *p;
  
! 			STRCPY(newcmd, cmdbase);
! 			/* Remove a trailing ", ) and )" if they have a match
! 			 * at the start of the command. */
! 			p = newcmd + STRLEN(newcmd);
! 			if (p > newcmd && p[-1] == '"' && *cmd == '"')
! 			    *--p = NUL;
! 			if (p > newcmd && p[-1] == ')'
! 					     && (*cmd =='(' || cmd[1] == '('))
! 			    *--p = NUL;
! 		    }
! 		}
  
! 		/*
! 		 * Now, start the command as a process, so that it doesn't
! 		 * inherit our handles which causes unpleasant dangling swap
! 		 * files if we exit before the spawned process
! 		 */
! 		if (CreateProcess(NULL,		// Executable name
! 			newcmd,			// Command to execute
! 			NULL,			// Process security attributes
! 			NULL,			// Thread security attributes
! 			FALSE,			// Inherit handles
! 			flags,			// Creation flags
! 			NULL,			// Environment
! 			NULL,			// Current directory
! 			&si,			// Startup information
! 			&pi))			// Process information
! 		    x = 0;
! 		else
! 		{
! 		    x = -1;
  #ifdef FEAT_GUI_W32
! 		    EMSG(_("E371: Command not found"));
  #endif
- 		}
- 		if (si.hStdInput != NULL)
- 		{
- 		    /* Close the handle to \\.\NUL */
- 		    CloseHandle(si.hStdInput);
- 		}
- 		/* Close the handles to the subprocess, so that it goes away */
- 		CloseHandle(pi.hThread);
- 		CloseHandle(pi.hProcess);
  	    }
! 	    else
  	    {
  #if defined(FEAT_GUI_W32)
  		if (need_vimrun_warning)
--- 3933,4048 ----
      else
      {
  	/* we use "command" or "cmd" to start the shell; slow but easy */
! 	char_u *cmdbase = cmd;
  
! 	/* Skip a leading ", ( and "(. */
! 	if (*cmdbase == '"' )
! 	    ++cmdbase;
! 	if (*cmdbase == '(')
! 	    ++cmdbase;
! 
! 	if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5]))
! 	{
! 	    STARTUPINFO		si;
! 	    PROCESS_INFORMATION	pi;
! 	    DWORD		flags = CREATE_NEW_CONSOLE;
! 	    char_u		*p;
! 
! 	    si.cb = sizeof(si);
! 	    si.lpReserved = NULL;
! 	    si.lpDesktop = NULL;
! 	    si.lpTitle = NULL;
! 	    si.dwFlags = 0;
! 	    si.cbReserved2 = 0;
! 	    si.lpReserved2 = NULL;
! 
! 	    cmdbase = skipwhite(cmdbase + 5);
! 	    if ((STRNICMP(cmdbase, "/min", 4) == 0)
! 		    && vim_iswhite(cmdbase[4]))
! 	    {
! 		cmdbase = skipwhite(cmdbase + 4);
! 		si.dwFlags = STARTF_USESHOWWINDOW;
! 		si.wShowWindow = SW_SHOWMINNOACTIVE;
! 	    }
! 	    else if ((STRNICMP(cmdbase, "/b", 2) == 0)
! 		    && vim_iswhite(cmdbase[2]))
! 	    {
! 		cmdbase = skipwhite(cmdbase + 2);
! 		flags = CREATE_NO_WINDOW;
! 		si.dwFlags = STARTF_USESTDHANDLES;
! 		si.hStdInput = CreateFile("\\\\.\\NUL",	// File name
! 		    GENERIC_READ,				// Access flags
! 		    0,					// Share flags
! 		    NULL,					// Security att.
! 		    OPEN_EXISTING,				// Open flags
! 		    FILE_ATTRIBUTE_NORMAL,			// File att.
! 		    NULL);					// Temp file
! 		si.hStdOutput = si.hStdInput;
! 		si.hStdError = si.hStdInput;
! 	    }
! 
! 	    /* Remove a trailing ", ) and )" if they have a match
! 	     * at the start of the command. */
! 	    if (cmdbase > cmd)
! 	    {
! 		p = cmdbase + STRLEN(cmdbase);
! 		if (p > cmdbase && p[-1] == '"' && *cmd == '"')
! 		    *--p = NUL;
! 		if (p > cmdbase && p[-1] == ')'
! 			&& (*cmd =='(' || cmd[1] == '('))
! 		    *--p = NUL;
! 	    }
  
! 	    /*
! 	     * Unescape characters in shellxescape. This is workaround for
! 	     * /b option. Only redirect character should be unescaped.
! 	     */
! 	    unescape_shellxquote(cmdbase,
! 			(flags & CREATE_NEW_CONSOLE) ? p_sxe : "<>");
  
! 	    /*
! 	     * Now, start the command as a process, so that it doesn't
! 	     * inherit our handles which causes unpleasant dangling swap
! 	     * files if we exit before the spawned process
! 	     */
! 	    if (CreateProcess(NULL,		// Executable name
! 		    cmdbase,			// Command to execute
! 		    NULL,			// Process security attributes
! 		    NULL,			// Thread security attributes
! 		    FALSE,			// Inherit handles
! 		    flags,			// Creation flags
! 		    NULL,			// Environment
! 		    NULL,			// Current directory
! 		    &si,			// Startup information
! 		    &pi))			// Process information
! 		x = 0;
! 	    else
! 	    {
! 		x = -1;
  #ifdef FEAT_GUI_W32
! 		EMSG(_("E371: Command not found"));
  #endif
  	    }
! 	    if (si.hStdInput != NULL)
! 	    {
! 		/* Close the handle to \\.\NUL */
! 		CloseHandle(si.hStdInput);
! 	    }
! 	    /* Close the handles to the subprocess, so that it goes away */
! 	    CloseHandle(pi.hThread);
! 	    CloseHandle(pi.hProcess);
! 	}
! 	else
! 	{
! 	    char_u *newcmd;
! 	    long_u cmdlen =  (
! #ifdef FEAT_GUI_W32
! 		(allowPiping && !p_stmp ? 0 : STRLEN(vimrun_path)) +
! #endif
! 		STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10);
! 
! 	    newcmd = lalloc(cmdlen, TRUE);
! 	    if (newcmd != NULL)
  	    {
  #if defined(FEAT_GUI_W32)
  		if (need_vimrun_warning)
***************
*** 4038,4045 ****
  		    vim_snprintf((char *)newcmd, cmdlen, "%s %s %s",
  							   p_sh, p_shcf, cmd);
  		x = mch_system((char *)newcmd, options);
  	    }
- 	    vim_free(newcmd);
  	}
      }
  
--- 4068,4075 ----
  		    vim_snprintf((char *)newcmd, cmdlen, "%s %s %s",
  							   p_sh, p_shcf, cmd);
  		x = mch_system((char *)newcmd, options);
+ 		vim_free(newcmd);
  	    }
  	}
      }
  
*** ../vim-7.3.446/src/version.c	2012-02-20 22:18:23.000000000 +0100
--- src/version.c	2012-02-21 21:20:05.000000000 +0100
***************
*** 716,717 ****
--- 716,719 ----
  {   /* Add new patch number below this line */
+ /**/
+     447,
  /**/

-- 
From "know your smileys":
 :----}  You lie like Pinocchio

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