wcmd: ignore start and end quotes (try 4)
André Hentschel
nerv at dawncrow.de
Thu Aug 27 11:44:23 CDT 2009
in cmd tested with:
>set foo=bar
>set foo
bar
>set "foo=test"
>set foo
test
>set "foo"
test
strip function tested with:
wine cmd /c "net help"
wine cmd /c /s "net help"
wine cmd /k "net help"
wine cmd /k /s "net help"
wine cmd /c "net "help""
wine cmd /c /s "net "help""
wine cmd /k "net "help""
wine cmd /k /s "net "help""
and the results stay the same
---
programs/cmd/builtins.c | 3 +++
programs/cmd/wcmd.h | 1 +
programs/cmd/wcmdmain.c | 18 +++++++++++-------
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index b544a37..5e42da2 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -2072,6 +2072,7 @@ void WCMD_setshow_env (WCHAR *s) {
s += 2;
while (*s && *s==' ') s++;
+ WCMD_strip_quotes(s);
/* If no parameter, or no '=' sign, return an error */
if (!(*s) || ((p = strchrW (s, '=')) == NULL )) {
@@ -2096,6 +2097,8 @@ void WCMD_setshow_env (WCHAR *s) {
} else {
DWORD gle;
+
+ WCMD_strip_quotes(s);
p = strchrW (s, '=');
if (p == NULL) {
env = GetEnvironmentStrings ();
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index 667b3b9..c19ea82 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -100,6 +100,7 @@ WCHAR *WCMD_strtrim_leading_spaces (WCHAR *string);
void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable, WCHAR *forValue, BOOL justFors);
void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
+void WCMD_strip_quotes(WCHAR *s);
WCHAR *WCMD_LoadMessage(UINT id);
WCHAR *WCMD_strdupW(WCHAR *input);
void WCMD_strsubstW(WCHAR *start, WCHAR* next, WCHAR* insert, int len);
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index d3aea6d..6856f4c 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -453,12 +453,16 @@ WCHAR *WCMD_strtrim_leading_spaces (WCHAR *string) {
}
/*************************************************************************
- * WCMD_opt_s_strip_quotes
+ * WCMD_strip_quotes
*
* Remove first and last quote WCHARacters, preserving all other text
*/
-static void WCMD_opt_s_strip_quotes(WCHAR *cmd) {
- WCHAR *src = cmd + 1, *dest = cmd, *lastq = NULL;
+void WCMD_strip_quotes(WCHAR *s) {
+ WCHAR *src = s, *dest = s, *lastq = NULL;
+ if (*src=='\"')
+ src++;
+ else
+ return;
while((*dest=*src) != '\0') {
if (*src=='\"')
lastq=dest;
@@ -1146,9 +1150,9 @@ void WCMD_run_program (WCHAR *command, int called) {
status = CreateProcess (assumeInternal?NULL : thisDir,
command, NULL, NULL, TRUE, 0, NULL, NULL, &st, &pe);
if ((opt_c || opt_k) && !opt_s && !status
- && GetLastError()==ERROR_FILE_NOT_FOUND && command[0]=='\"') {
+ && GetLastError()==ERROR_FILE_NOT_FOUND) {
/* strip first and last quote WCHARacters and try again */
- WCMD_opt_s_strip_quotes(command);
+ WCMD_strip_quotes(command);
opt_s=1;
WCMD_run_program(command, called);
return;
@@ -2338,8 +2342,8 @@ int wmain (int argc, WCHAR *argvW[])
/* strip first and last quote characters if opt_s; check for invalid
* executable is done later */
- if (opt_s && *cmd=='\"')
- WCMD_opt_s_strip_quotes(cmd);
+ if (opt_s)
+ WCMD_strip_quotes(cmd);
}
if (opt_c) {
--
Best Regards, André Hentschel
More information about the wine-patches
mailing list