@@ -208,6 +208,44 @@ static void extract_first_arg(LPWSTR command_line, LPWSTR exepath, LPWSTR buf)
208
208
LocalFree (wargv );
209
209
}
210
210
211
+ static LPWSTR expand_variables (LPWSTR buf , size_t alloc )
212
+ {
213
+ size_t len = wcslen (buf );
214
+
215
+ for (;;) {
216
+ LPWSTR atat = wcsstr (buf , L"@@" ), atat2 ;
217
+ WCHAR save ;
218
+ int env_len , delta ;
219
+
220
+ if (!atat )
221
+ break ;
222
+
223
+ atat2 = wcsstr (atat + 2 , L"@@" );
224
+ if (!atat2 )
225
+ break ;
226
+
227
+ * atat2 = L'\0' ;
228
+ env_len = GetEnvironmentVariable (atat + 2 , NULL , 0 );
229
+ delta = env_len - 1 - (atat2 + 2 - atat );
230
+ if (len + delta >= alloc ) {
231
+ fwprintf (stderr ,
232
+ L"Substituting '%s' results in too "
233
+ L"large a command-line\n" , atat + 2 );
234
+ exit (1 );
235
+ }
236
+ if (delta )
237
+ memmove (atat2 + 2 + delta , atat2 + 2 ,
238
+ sizeof (WCHAR ) * (len + 1
239
+ - (atat2 + 2 - buf )));
240
+ len += delta ;
241
+ save = atat [env_len - 1 ];
242
+ GetEnvironmentVariable (atat + 2 , atat , env_len );
243
+ atat [env_len - 1 ] = save ;
244
+ }
245
+
246
+ return buf ;
247
+ }
248
+
211
249
static int configure_via_resource (LPWSTR basename , LPWSTR exepath , LPWSTR exep ,
212
250
LPWSTR * prefix_args , int * prefix_args_len ,
213
251
int * is_git_command , LPWSTR * working_directory , int * full_path ,
@@ -218,6 +256,7 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
218
256
219
257
#define BUFSIZE 65536
220
258
static WCHAR buf [BUFSIZE ];
259
+ LPWSTR buf2 = buf ;
221
260
int len ;
222
261
223
262
for (id = 0 ; ; id ++ ) {
@@ -257,48 +296,19 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
257
296
if (!id )
258
297
SetEnvironmentVariable (L"EXEPATH" , exepath );
259
298
260
- for (;;) {
261
- LPWSTR atat = wcsstr (buf , L"@@" ), atat2 ;
262
- WCHAR save ;
263
- int env_len , delta ;
264
-
265
- if (!atat )
266
- break ;
267
-
268
- atat2 = wcsstr (atat + 2 , L"@@" );
269
- if (!atat2 )
270
- break ;
271
-
272
- * atat2 = L'\0' ;
273
- env_len = GetEnvironmentVariable (atat + 2 , NULL , 0 );
274
- delta = env_len - 1 - (atat2 + 2 - atat );
275
- if (len + delta >= BUFSIZE ) {
276
- fwprintf (stderr ,
277
- L"Substituting '%s' results in too "
278
- L"large a command-line\n" , atat + 2 );
279
- exit (1 );
280
- }
281
- if (delta )
282
- memmove (atat2 + 2 + delta , atat2 + 2 ,
283
- sizeof (WCHAR ) * (len + 1
284
- - (atat2 + 2 - buf )));
285
- len += delta ;
286
- save = atat [env_len - 1 ];
287
- GetEnvironmentVariable (atat + 2 , atat , env_len );
288
- atat [env_len - 1 ] = save ;
289
- }
299
+ buf2 = expand_variables (buf , BUFSIZE );
290
300
291
- extract_first_arg (buf , exepath , exep );
301
+ extract_first_arg (buf2 , exepath , exep );
292
302
293
303
if (_waccess (exep , 0 ) != -1 )
294
304
break ;
295
305
fwprintf (stderr ,
296
306
L"Skipping command-line '%s'\n('%s' not found)\n" ,
297
- buf , exep );
307
+ buf2 , exep );
298
308
}
299
309
300
- * prefix_args = buf ;
301
- * prefix_args_len = wcslen (buf );
310
+ * prefix_args = buf2 ;
311
+ * prefix_args_len = wcslen (buf2 );
302
312
303
313
* is_git_command = 0 ;
304
314
* working_directory = (LPWSTR ) 1 ;
0 commit comments