Jason Edmeades : cmd: Identify the program name using more appropriate parsing.

Alexandre Julliard julliard at winehq.org
Tue Oct 16 15:27:46 CDT 2012


Module: wine
Branch: master
Commit: 4236c2007df8267b4bbfdc00f5f26e86f71ddc99
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4236c2007df8267b4bbfdc00f5f26e86f71ddc99

Author: Jason Edmeades <jason at edmeades.me.uk>
Date:   Sat Oct 13 22:11:03 2012 +0100

cmd: Identify the program name using more appropriate parsing.

---

 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);




More information about the wine-cvs mailing list