[1/2] wcmd: change strip function to return the string.
André Hentschel
nerv at dawncrow.de
Tue Aug 25 10:47:27 CDT 2009
---
programs/cmd/wcmd.h | 1 +
programs/cmd/wcmdmain.c | 29 +++++++++++++----------------
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index 667b3b9..21c3dcf 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);
+WCHAR *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..8eff794 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -453,25 +453,22 @@ 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;
- while((*dest=*src) != '\0') {
- if (*src=='\"')
- lastq=dest;
- dest++, src++;
- }
- if (lastq) {
- dest=lastq++;
- while ((*dest++=*lastq++) != 0)
- ;
- }
+WCHAR *WCMD_strip_quotes(WCHAR *s) {
+ UINT len=0;
+
+ if (!s) return NULL;
+ len = strlenW(s);
+ if (len>=2 && *s=='\"' && s[len-1]=='\"') {
+ s[len-1]='\0';
+ s++;
+ }
+ return s;
}
-
/*************************************************************************
* WCMD_expand_envvar
*
@@ -1148,7 +1145,7 @@ void WCMD_run_program (WCHAR *command, int called) {
if ((opt_c || opt_k) && !opt_s && !status
&& GetLastError()==ERROR_FILE_NOT_FOUND && command[0]=='\"') {
/* strip first and last quote WCHARacters and try again */
- WCMD_opt_s_strip_quotes(command);
+ command=WCMD_strip_quotes(command);
opt_s=1;
WCMD_run_program(command, called);
return;
@@ -2339,7 +2336,7 @@ 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);
+ cmd=WCMD_strip_quotes(cmd);
}
if (opt_c) {
--
Best Regards, André Hentschel
More information about the wine-patches
mailing list