[PATCH 1/4] [cmd] Convert wcmd_for to use WCMD_parameter
Ann and Jason Edmeades
jason at edmeades.me.uk
Mon Oct 1 06:38:18 CDT 2012
This patch is almost a noop other than it simplifies the wcmd_for
to remove all the manual walking of strings and uses the routine
designed for doing it in the first place (wcmd_parameter).
Note the two 'fixed todos' are not actually fixed but now pass as
the for command line is slightly better recognized. for /f just
isnt yet implemented at all, so any passes are flukes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20121001/0c642128/attachment-0001.html>
-------------- next part --------------
From 3af53d5c485c6aa8e1168c391cee0d140b453e3d Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Wed, 26 Sep 2012 14:37:56 +0100
Subject: [PATCH 1/4] [cmd] Convert wcmd_for to use WCMD_parameter
This patch is almost a noop other than it simplifies the wcmd_for
to remove all the manual walking of strings and uses the routine
designed for doing it in the first place (wcmd_parameter).
Note the two 'fixed todos' are not actually fixed but now pass as
the for command line is slightly better recognized. for /f just
isnt yet implemented at all, so any passes are flukes.
---
programs/cmd/builtins.c | 55 +++++++++++++-----------------
programs/cmd/tests/test_builtins.cmd.exp | 4 +--
2 files changed, 25 insertions(+), 34 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 57ac339..e54c444 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1080,7 +1080,6 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
WCHAR *firstCmd;
int thisDepth;
- WCHAR *curPos = p;
BOOL expandDirs = FALSE;
BOOL useNumbers = FALSE;
BOOL doFileset = FALSE;
@@ -1088,33 +1087,34 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
LONG numbers[3] = {0,0,0}; /* Defaults to 0 in native */
int itemNum;
CMD_LIST *thisCmdStart;
-
+ int parameterNo = 0;
/* Handle optional qualifiers (multiple are allowed) */
- while (*curPos && *curPos == '/') {
- WINE_TRACE("Processing qualifier at %s\n", wine_dbgstr_w(curPos));
- curPos++;
- switch (toupperW(*curPos)) {
- case 'D': curPos++; expandDirs = TRUE; break;
- case 'L': curPos++; useNumbers = TRUE; break;
+ WCHAR *thisArg = WCMD_parameter(p, parameterNo++, NULL, NULL, FALSE);
+ while (thisArg && *thisArg == '/') {
+ WINE_TRACE("Processing qualifier at %s\n", wine_dbgstr_w(thisArg));
+ thisArg++;
+ switch (toupperW(*thisArg)) {
+ case 'D': expandDirs = TRUE; break;
+ case 'L': useNumbers = TRUE; break;
/* Recursive is special case - /R can have an optional path following it */
/* filenamesets are another special case - /F can have an optional options following it */
case 'R':
case 'F':
{
- BOOL isRecursive = (*curPos == 'R');
+ BOOL isRecursive = (*thisArg == 'R');
if (!isRecursive)
doFileset = TRUE;
- /* Skip whitespace */
- curPos++;
- while (*curPos && (*curPos==' ' || *curPos=='\t')) curPos++;
+ /* Retrieve next parameter to see if is path/options */
+ thisArg = WCMD_parameter(p, parameterNo, NULL, NULL, !isRecursive);
/* Next parm is either qualifier, path/options or variable -
only care about it if it is the path/options */
- if (*curPos && *curPos != '/' && *curPos != '%') {
+ if (thisArg && *thisArg != '/' && *thisArg != '%') {
+ parameterNo++;
if (isRecursive) WINE_FIXME("/R needs to handle supplied root\n");
else {
static unsigned int once;
@@ -1124,38 +1124,29 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
break;
}
default:
- WINE_FIXME("for qualifier '%c' unhandled\n", *curPos);
- curPos++;
+ WINE_FIXME("for qualifier '%c' unhandled\n", *thisArg);
}
- /* Skip whitespace between qualifiers */
- while (*curPos && (*curPos==' ' || *curPos=='\t')) curPos++;
+ /* Step to next token */
+ thisArg = WCMD_parameter(p, parameterNo++, NULL, NULL, FALSE);
}
- /* Skip whitespace before variable */
- while (*curPos && (*curPos==' ' || *curPos=='\t')) curPos++;
-
/* Ensure line continues with variable */
- if (!*curPos || *curPos != '%') {
+ if (!*thisArg || *thisArg != '%') {
WCMD_output_stderr (WCMD_LoadMessage(WCMD_SYNTAXERR));
return;
}
/* Variable should follow */
- i = 0;
- while (curPos[i] && curPos[i]!=' ' && curPos[i]!='\t') i++;
- memcpy(&variable[0], curPos, i*sizeof(WCHAR));
- variable[i] = 0x00;
+ strcpyW(variable, thisArg);
WINE_TRACE("Variable identified as %s\n", wine_dbgstr_w(variable));
- curPos = &curPos[i];
-
- /* Skip whitespace before IN */
- while (*curPos && (*curPos==' ' || *curPos=='\t')) curPos++;
/* Ensure line continues with IN */
- if (!*curPos
- || !WCMD_keyword_ws_found(inW, sizeof(inW)/sizeof(inW[0]), curPos)) {
-
+ thisArg = WCMD_parameter(p, parameterNo++, NULL, NULL, FALSE);
+ if (!thisArg
+ || !(CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
+ thisArg, sizeof(inW)/sizeof(inW[0]), inW,
+ sizeof(inW)/sizeof(inW[0])) == CSTR_EQUAL)) {
WCMD_output_stderr (WCMD_LoadMessage(WCMD_SYNTAXERR));
return;
}
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 57bc82a..21440b5 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -630,7 +630,7 @@ c
------ eol option
@todo_wine at ad
@todo_wine at z@y
- at todo_wine@a|d
+a|d
@todo_wine at no output
@todo_wine at no output
------ delims option
@@ -639,7 +639,7 @@ c
@todo_wine at a d
@todo_wine at a
@todo_wine at C r
- at todo_wine@foo bar baz
+foo bar baz
@todo_wine at c:\
------ skip option
@todo_wine at c
--
1.7.9.5
More information about the wine-patches
mailing list