[PATCH 2/5] [cmd] Identify the program name using more appropriate parsing
Ann and Jason Edmeades
jason at edmeades.me.uk
Mon Oct 15 18:53:28 CDT 2012
Since the changes to WCMD_Parameter made a single, more accurate
routine for parsing tokens, use it for extracting the program name
from the command line when running a program.
[Fixes a lot of the todo's in the new tests added last week]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20121016/bb3c24dd/attachment.html>
-------------- next part --------------
From b17ec8a17b0cbc17757aaaa647b914fe4c6363f8 Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Sat, 13 Oct 2012 22:11:03 +0100
Subject: [PATCH 2/5] [cmd] Identify the program name using more appropriate parsing
Since the changes to WCMD_Parameter made a single, more accurate
routine for parsing tokens, use it for extracting the program name
from the command line when running a program.
[Fixes a lot of the todo's in the new tests added last week]
---
programs/cmd/tests/test_cmdline.cmd.exp | 32 +++++++++++++++----------------
programs/cmd/wcmdmain.c | 23 ++++++++++------------
2 files changed, 26 insertions(+), 29 deletions(-)
diff --git a/programs/cmd/tests/test_cmdline.cmd.exp b/programs/cmd/tests/test_cmdline.cmd.exp
index 61deff6..4ea4ce0 100644
--- a/programs/cmd/tests/test_cmdline.cmd.exp
+++ b/programs/cmd/tests/test_cmdline.cmd.exp
@@ -48,37 +48,37 @@ var=33 at space@
------ Testing invocation of batch files ----------
0 at space@
1 at space@
- at todo_wine@1 at space@
1 at space@
- at todo_wine@1 at space@
+1 at space@
+1 at space@
0 at space@
- at todo_wine@1 at space@
- at todo_wine@2 at space@
+1 at space@
+2 at space@
0 at space@
3 at space@
- at todo_wine@3 at space@
+3 at space@
@todo_wine at 4@space@
------ Testing invocation with CMD /C -------------
0 at space@
1 at space@
- at todo_wine@0 at space@
0 at space@
- at todo_wine@1 at space@
0 at space@
- at todo_wine@1 at space@
- at todo_wine@2 at space@
+1 at space@
+0 at space@
+1 at space@
+2 at space@
0 at space@
- at todo_wine@3 at space@
+3 at space@
@todo_wine at 4@space@
---------- Testing CMD /C quoting -----------------
"hi"
- at todo_wine@1 at space@
+1 at space@
"\"\\"\\\"\\\\"@space@"\"\\"\\\"\\\\"
1 at space@
0 at space@
1 at space@
0 at space@
- at todo_wine@0 at space@
+0 at space@
0 at space@@or_broken at 3@space@
3 at space@
2 at space@
@@ -100,7 +100,7 @@ THIS FAILS: cmd ignoreme/c say one
{@space@
}@space@
0 at space@
- at todo_wine@0 at space@
+0 at space@
!@space@
@todo_wine at 0@space@@or_broken@!@space@
@todo_wine at 0@space@
@@ -117,8 +117,8 @@ THIS FAILS: cmd ignoreme/c say one
@todo_wine at 1:((1)),2:@space@
@todo_wine at 1:(1)(2),2:@space@
@todo_wine at 1:(1),2:(2)@space@
- at todo_wine@1:1,2:2 at space@
- at todo_wine@1:1,2:2 at space@
- at todo_wine@1:1,2:2 at space@
+1:1,2:2 at space@
+1:1,2:2 at space@
+1:1,2:2 at space@
1:"p at space@"1,2:p"@space@"2 at space@
1:p"1 at space@p",2:2 at space@
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 2aa116c..eb0897a 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -1008,6 +1008,7 @@ void WCMD_run_program (WCHAR *command, BOOL called)
MAX_PATH, including null character */
WCHAR *lastSlash;
WCHAR pathext[MAXSTRING];
+ WCHAR *firstParam;
BOOL extensionsupplied = FALSE;
BOOL launched = FALSE;
BOOL status;
@@ -1016,17 +1017,13 @@ void WCMD_run_program (WCHAR *command, BOOL called)
static const WCHAR envPath[] = {'P','A','T','H','\0'};
static const WCHAR delims[] = {'/','\\',':','\0'};
- /* Quick way to get the filename
- * (but handle leading / as part of program name, not qualifier)
- */
- for (len = 0; command[len] == '/'; len++) param1[len] = '/';
- WCMD_parse (command + len, quals, param1 + len, param2);
-
- if (!(*param1) && !(*param2))
- return;
+ /* Quick way to get the filename is to extract the first argument. */
+ WINE_TRACE("Running '%s' (%d)\n", wine_dbgstr_w(command), called);
+ firstParam = WCMD_parameter(command, 0, NULL, NULL, FALSE);
+ if (!firstParam) return;
/* Calculate the search path and stem to search for */
- if (strpbrkW (param1, delims) == NULL) { /* No explicit path given, search path */
+ if (strpbrkW (firstParam, delims) == NULL) { /* No explicit path given, search path */
static const WCHAR curDir[] = {'.',';','\0'};
strcpyW(pathtosearch, curDir);
len = GetEnvironmentVariableW(envPath, &pathtosearch[2], (sizeof(pathtosearch)/sizeof(WCHAR))-2);
@@ -1034,19 +1031,19 @@ void WCMD_run_program (WCHAR *command, BOOL called)
static const WCHAR curDir[] = {'.','\0'};
strcpyW (pathtosearch, curDir);
}
- if (strchrW(param1, '.') != NULL) extensionsupplied = TRUE;
- if (strlenW(param1) >= MAX_PATH)
+ if (strchrW(firstParam, '.') != NULL) extensionsupplied = TRUE;
+ if (strlenW(firstParam) >= MAX_PATH)
{
WCMD_output_asis_stderr(WCMD_LoadMessage(WCMD_LINETOOLONG));
return;
}
- strcpyW(stemofsearch, param1);
+ strcpyW(stemofsearch, firstParam);
} else {
/* Convert eg. ..\fred to include a directory by removing file part */
- GetFullPathNameW(param1, sizeof(pathtosearch)/sizeof(WCHAR), pathtosearch, NULL);
+ GetFullPathNameW(firstParam, sizeof(pathtosearch)/sizeof(WCHAR), pathtosearch, NULL);
lastSlash = strrchrW(pathtosearch, '\\');
if (lastSlash && strchrW(lastSlash, '.') != NULL) extensionsupplied = TRUE;
strcpyW(stemofsearch, lastSlash+1);
--
1.7.9.5
More information about the wine-patches
mailing list