[2/10] cmd: Get rid of longer needed 'end' parameter in WCMD_parameter
Frédéric Delanoy
frederic.delanoy at gmail.com
Thu Oct 25 16:47:59 CDT 2012
It was barely used, and is not indispensable since the introduction of the 'raw' parameter
---
programs/cmd/batch.c | 23 ++++++++-----------
programs/cmd/builtins.c | 59 ++++++++++++++++++++++++------------------------
programs/cmd/directory.c | 2 +-
programs/cmd/wcmd.h | 4 ++--
programs/cmd/wcmdmain.c | 20 ++++++++--------
5 files changed, 52 insertions(+), 56 deletions(-)
diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 7b037d7..62f726c 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -130,29 +130,26 @@ void WCMD_batch (WCHAR *file, WCHAR *command, BOOL called, WCHAR *startLabel, HA
* s [I] input string, non NULL
* n [I] # of the parameter to return, counted from 0
* start [O] Optional. Pointer to the first char of param n in s
- * end [O] Optional. Pointer to the last char of param n in s
- * raw [I] True to return the parameter in raw format (quotes maintained)
- * False returns the parameter with quotes stripped
- * wholecmdline [I] True to indicate this routine is being used to parse the
+ * raw [I] TRUE to return the parameter in raw format (quotes maintained)
+ * FALSE to return the parameter with quotes stripped (including internal ones)
+ * wholecmdline [I] TRUE to indicate this routine is being used to parse the
* command line, and special logic for arg0->1 transition
* needs to be applied.
* delims[I] The delimiter characters to use
*
* RETURNS
* Success: The nth delimited parameter found in s
- * if start != NULL, *start points to the start of the param
- * if end != NULL, *end points to the end of the param
+ * if start != NULL, *start points to the start of the param (quotes maintained)
* Failure: An empty string if the param is not found.
- * *start == *end == NULL
+ * *start == NULL
*
* NOTES
* Return value is stored in static storage (i.e. overwritten after each call).
- * Specify 'start' and/or 'end' to include delimiting double quotes as well, if any.
* By default, the parameter is returned with quotes removed, ready for use with
* other API calls, e.g. c:\"a b"\c is returned as c:\a b\c. However, some commands
* need to preserve the exact syntax (echo, for, etc) hence the raw option.
*/
-WCHAR *WCMD_parameter_with_delims (WCHAR *s, int n, WCHAR **start, WCHAR **end,
+WCHAR *WCMD_parameter_with_delims (WCHAR *s, int n, WCHAR **start,
BOOL raw, BOOL wholecmdline, const WCHAR *delims)
{
int curParamNb = 0;
@@ -160,7 +157,6 @@ WCHAR *WCMD_parameter_with_delims (WCHAR *s, int n, WCHAR **start, WCHAR **end,
WCHAR *p = s, *begin;
if (start != NULL) *start = NULL;
- if (end != NULL) *end = NULL;
param[0] = '\0';
while (TRUE) {
@@ -212,7 +208,6 @@ WCHAR *WCMD_parameter_with_delims (WCHAR *s, int n, WCHAR **start, WCHAR **end,
}
param[i] = '\0';
}
- if (end) *end = p - 1;
return param;
}
curParamNb++;
@@ -226,11 +221,11 @@ WCHAR *WCMD_parameter_with_delims (WCHAR *s, int n, WCHAR **start, WCHAR **end,
* default set of delimiter characters. For parameters, see the main
* function above.
*/
-WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **start, WCHAR **end, BOOL raw,
+WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **start, BOOL raw,
BOOL wholecmdline)
{
static const WCHAR defaultDelims[] = { ' ', '\t', ',', '=', ';', '\0' };
- return WCMD_parameter_with_delims (s, n, start, end, raw, wholecmdline, defaultDelims);
+ return WCMD_parameter_with_delims (s, n, start, raw, wholecmdline, defaultDelims);
}
/****************************************************************************
@@ -471,7 +466,7 @@ void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable,
strcpyW(outputparam,
WCMD_parameter (context -> command,
*lastModifier-'0' + context -> shift_count[*lastModifier-'0'],
- NULL, NULL, FALSE, TRUE));
+ NULL, FALSE, TRUE));
} else {
strcpyW(outputparam, forValue);
}
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 768a53b..d13cb5c 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -541,7 +541,7 @@ void WCMD_copy(WCHAR * args) {
opt_d = opt_v = opt_n = opt_z = opt_y = opt_noty = FALSE;
/* Walk through all args, building up a list of files to process */
- thisparam = WCMD_parameter(args, argno++, &rawarg, NULL, TRUE, FALSE);
+ thisparam = WCMD_parameter(args, argno++, &rawarg, TRUE, FALSE);
while (*(thisparam)) {
WCHAR *pos1, *pos2;
BOOL inquotes;
@@ -599,7 +599,7 @@ void WCMD_copy(WCHAR * args) {
}
/* This parameter was purely switches, get the next one */
- thisparam = WCMD_parameter(args, argno++, &rawarg, NULL, TRUE, FALSE);
+ thisparam = WCMD_parameter(args, argno++, &rawarg, TRUE, FALSE);
continue;
}
@@ -624,7 +624,7 @@ void WCMD_copy(WCHAR * args) {
/* Move to next thing to process */
thisparam++;
if (*thisparam == 0x00)
- thisparam = WCMD_parameter(args, argno++, &rawarg, NULL, TRUE, FALSE);
+ thisparam = WCMD_parameter(args, argno++, &rawarg, TRUE, FALSE);
continue;
}
@@ -681,7 +681,7 @@ void WCMD_copy(WCHAR * args) {
thisparam = pos1;
continue;
} else {
- thisparam = WCMD_parameter(args, argno++, &rawarg, NULL, TRUE, FALSE);
+ thisparam = WCMD_parameter(args, argno++, &rawarg, TRUE, FALSE);
}
}
@@ -1019,7 +1019,7 @@ void WCMD_create_dir (WCHAR *args) {
}
/* Loop through all args */
while (TRUE) {
- WCHAR *thisArg = WCMD_parameter(args, argno++, &argN, NULL, FALSE, FALSE);
+ WCHAR *thisArg = WCMD_parameter(args, argno++, &argN, FALSE, FALSE);
if (!argN) break;
if (!create_full_path(thisArg)) {
WCMD_print_error ();
@@ -1324,7 +1324,7 @@ BOOL WCMD_delete (WCHAR *args) {
WCHAR *thisArg;
argN = NULL;
- thisArg = WCMD_parameter (args, argno, &argN, NULL, FALSE, FALSE);
+ thisArg = WCMD_parameter (args, argno, &argN, FALSE, FALSE);
if (!argN)
break; /* no more parameters */
if (argN[0] == '/')
@@ -1715,7 +1715,7 @@ static void WCMD_parse_line(CMD_LIST *cmdStart,
}
/* Extract the parameter */
- parm = WCMD_parameter_with_delims(buffer, 0, &where, NULL, FALSE, FALSE, forf_delims);
+ parm = WCMD_parameter_with_delims(buffer, 0, &where, FALSE, FALSE, forf_delims);
WINE_TRACE("Parsed parameter: %s from %s\n", wine_dbgstr_w(parm),
wine_dbgstr_w(buffer));
@@ -1830,7 +1830,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
BOOL forf_usebackq = FALSE;
/* Handle optional qualifiers (multiple are allowed) */
- WCHAR *thisArg = WCMD_parameter(p, parameterNo++, NULL, NULL, FALSE, FALSE);
+ WCHAR *thisArg = WCMD_parameter(p, parameterNo++, NULL, FALSE, FALSE);
optionsRoot[0] = 0;
while (thisArg && *thisArg == '/') {
@@ -1854,7 +1854,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
/* Retrieve next parameter to see if is root/options (raw form required
with for /f, or unquoted in for /r) */
- thisArg = WCMD_parameter(p, parameterNo, NULL, NULL, doFileset, FALSE);
+ thisArg = WCMD_parameter(p, parameterNo, NULL, doFileset, FALSE);
/* Next parm is either qualifier, path/options or variable -
only care about it if it is the path/options */
@@ -1869,7 +1869,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
}
/* Step to next token */
- thisArg = WCMD_parameter(p, parameterNo++, NULL, NULL, FALSE, FALSE);
+ thisArg = WCMD_parameter(p, parameterNo++, NULL, FALSE, FALSE);
}
/* Ensure line continues with variable */
@@ -1903,7 +1903,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
WINE_TRACE("Variable identified as %s\n", wine_dbgstr_w(variable));
/* Ensure line continues with IN */
- thisArg = WCMD_parameter(p, parameterNo++, NULL, NULL, FALSE, FALSE);
+ thisArg = WCMD_parameter(p, parameterNo++, NULL, FALSE, FALSE);
if (!thisArg
|| !(CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
thisArg, sizeof(inW)/sizeof(inW[0]), inW,
@@ -1968,7 +1968,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
WINE_TRACE("Processing for set %p\n", thisSet);
i = 0;
- while (*(item = WCMD_parameter (thisSet->command, i, &itemStart, NULL, TRUE, FALSE))) {
+ while (*(item = WCMD_parameter (thisSet->command, i, &itemStart, TRUE, FALSE))) {
/*
* If the parameter within the set has a wildcard then search for matching files
@@ -2365,7 +2365,7 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
WINE_TRACE("Condition: %s\n", wine_dbgstr_w(condition));
if (!lstrcmpiW (condition, errlvlW)) {
- WCHAR *param = WCMD_parameter(p, 1+negate, NULL, NULL, FALSE, FALSE);
+ WCHAR *param = WCMD_parameter(p, 1+negate, NULL, FALSE, FALSE);
WCHAR *endptr;
long int param_int = strtolW(param, &endptr, 10);
if (*endptr) {
@@ -2373,32 +2373,33 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
return;
}
test = ((long int)errorlevel >= param_int);
- WCMD_parameter(p, 2+negate, &command, NULL, FALSE, FALSE);
+ WCMD_parameter(p, 2+negate, &command, FALSE, FALSE);
}
else if (!lstrcmpiW (condition, existW)) {
- test = (GetFileAttributesW(WCMD_parameter(p, 1+negate, NULL, NULL, FALSE, FALSE))
+ test = (GetFileAttributesW(WCMD_parameter(p, 1+negate, NULL, FALSE, FALSE))
!= INVALID_FILE_ATTRIBUTES);
- WCMD_parameter(p, 2+negate, &command, NULL, FALSE, FALSE);
+ WCMD_parameter(p, 2+negate, &command, FALSE, FALSE);
}
else if (!lstrcmpiW (condition, defdW)) {
- test = (GetEnvironmentVariableW(WCMD_parameter(p, 1+negate, NULL, NULL, FALSE, FALSE),
+ test = (GetEnvironmentVariableW(WCMD_parameter(p, 1+negate, NULL, FALSE, FALSE),
NULL, 0) > 0);
- WCMD_parameter(p, 2+negate, &command, NULL, FALSE, FALSE);
+ WCMD_parameter(p, 2+negate, &command, FALSE, FALSE);
}
else if ((s = strstrW (p, eqeqW))) {
/* We need to get potential surrounding double quotes, so param1/2 can't be used */
- WCHAR *leftPart, *leftPartEnd, *rightPart, *rightPartEnd;
+ WCHAR *leftPart, *rightPart;
+ unsigned int leftPartLen, rightPartLen;
s += 2;
- WCMD_parameter(p, 0+negate+caseInsensitive, &leftPart, &leftPartEnd, TRUE, FALSE);
- WCMD_parameter(p, 1+negate+caseInsensitive, &rightPart, &rightPartEnd, TRUE, FALSE);
+ leftPartLen = strlenW(WCMD_parameter(p, 0+negate+caseInsensitive, &leftPart, TRUE, FALSE));
+ rightPartLen = strlenW(WCMD_parameter(p, 1+negate+caseInsensitive, &rightPart, TRUE, FALSE));
test = caseInsensitive
? (CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
- leftPart, leftPartEnd-leftPart+1,
- rightPart, rightPartEnd-rightPart+1) == CSTR_EQUAL)
+ leftPart, leftPartLen,
+ rightPart, rightPartLen) == CSTR_EQUAL)
: (CompareStringW(LOCALE_SYSTEM_DEFAULT, 0,
- leftPart, leftPartEnd-leftPart+1,
- rightPart, rightPartEnd-rightPart+1) == CSTR_EQUAL);
- WCMD_parameter(s, 1, &command, NULL, FALSE, FALSE);
+ leftPart, leftPartLen,
+ rightPart, rightPartLen) == CSTR_EQUAL);
+ WCMD_parameter(s, 1, &command, FALSE, FALSE);
}
else {
WCMD_output_stderr(WCMD_LoadMessage(WCMD_SYNTAXERR));
@@ -2573,7 +2574,7 @@ void WCMD_remove_dir (WCHAR *args) {
/* Loop through all args */
while (argN) {
- WCHAR *thisArg = WCMD_parameter (args, argno++, &argN, NULL, FALSE, FALSE);
+ WCHAR *thisArg = WCMD_parameter (args, argno++, &argN, FALSE, FALSE);
if (argN && argN[0] != '/') {
WINE_TRACE("rd: Processing arg %s (quals:%s)\n", wine_dbgstr_w(thisArg),
wine_dbgstr_w(quals));
@@ -3345,7 +3346,7 @@ void WCMD_type (WCHAR *args) {
/* Loop through all args */
errorlevel = 0;
while (argN) {
- WCHAR *thisArg = WCMD_parameter (args, argno++, &argN, NULL, FALSE, FALSE);
+ WCHAR *thisArg = WCMD_parameter (args, argno++, &argN, FALSE, FALSE);
HANDLE h;
WCHAR buffer[512];
@@ -3439,7 +3440,7 @@ void WCMD_more (WCHAR *args) {
WCMD_enter_paged_mode(moreStrPage);
while (argN) {
- WCHAR *thisArg = WCMD_parameter (args, argno++, &argN, NULL, FALSE, FALSE);
+ WCHAR *thisArg = WCMD_parameter (args, argno++, &argN, FALSE, FALSE);
HANDLE h;
if (!argN) break;
diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c
index d9558ae..28e0231 100644
--- a/programs/cmd/directory.c
+++ b/programs/cmd/directory.c
@@ -803,7 +803,7 @@ void WCMD_directory (WCHAR *args)
prevEntry = NULL;
while (argN) {
WCHAR fullname[MAXSTRING];
- WCHAR *thisArg = WCMD_parameter(args, argno++, &argN, NULL, FALSE, FALSE);
+ WCHAR *thisArg = WCMD_parameter(args, argno++, &argN, FALSE, FALSE);
if (argN && argN[0] != '/') {
WINE_TRACE("Found parm '%s'\n", wine_dbgstr_w(thisArg));
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index 26b89c6..129b232 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -107,8 +107,8 @@ static inline BOOL WCMD_is_console_handle(HANDLE h)
return (((DWORD_PTR)h) & 3) == 3;
}
WCHAR *WCMD_fgets (WCHAR *buf, DWORD n, HANDLE stream);
-WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **start, WCHAR **end, BOOL raw, BOOL wholecmdline);
-WCHAR *WCMD_parameter_with_delims (WCHAR *s, int n, WCHAR **start, WCHAR **end, BOOL raw,
+WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **start, BOOL raw, BOOL wholecmdline);
+WCHAR *WCMD_parameter_with_delims (WCHAR *s, int n, WCHAR **start, BOOL raw,
BOOL wholecmdline, const WCHAR *delims);
WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 4e6305a..758892e 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -838,15 +838,15 @@ static void handleExpansion(WCHAR *cmd, BOOL justFors,
/* Replace use of %0...%9 if in batch program*/
} else if (!justFors && context && (i >= 0) && (i <= 9)) {
t = WCMD_parameter(context -> command, i + context -> shift_count[i],
- NULL, NULL, TRUE, TRUE);
+ NULL, TRUE, TRUE);
WCMD_strsubstW(p, p+2, t, -1);
/* Replace use of %* if in batch program*/
} else if (!justFors && context && *(p+1)=='*') {
WCHAR *startOfParms = NULL;
- WCMD_parameter(context -> command, 0, NULL, &startOfParms, TRUE, TRUE);
+ WCHAR *thisParm = WCMD_parameter(context -> command, 0, &startOfParms, TRUE, TRUE);
if (startOfParms != NULL) {
- startOfParms++; /* Skip to first delimiter then skip whitespace */
+ startOfParms += strlenW(thisParm);
while (*startOfParms==' ' || *startOfParms == '\t') startOfParms++;
WCMD_strsubstW(p, p+2, startOfParms, -1);
} else
@@ -1025,7 +1025,7 @@ void WCMD_run_program (WCHAR *command, BOOL called)
/* 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, TRUE);
+ firstParam = WCMD_parameter(command, 0, NULL, FALSE, TRUE);
if (!firstParam) return;
/* Calculate the search path and stem to search for */
@@ -1380,7 +1380,7 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
/* Otherwise STDIN could come from a '<' redirect */
} else if ((p = strchrW(new_redir,'<')) != NULL) {
- h = CreateFileW(WCMD_parameter(++p, 0, NULL, NULL, FALSE, FALSE), GENERIC_READ, FILE_SHARE_READ,
+ h = CreateFileW(WCMD_parameter(++p, 0, NULL, FALSE, FALSE), GENERIC_READ, FILE_SHARE_READ,
&sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) {
WCMD_print_error ();
@@ -1425,7 +1425,7 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
WINE_TRACE("Redirect %d (%p) to %d (%p)\n", handle, GetStdHandle(idx_stdhandles[idx]), idx, h);
} else {
- WCHAR *param = WCMD_parameter(p, 0, NULL, NULL, FALSE, FALSE);
+ WCHAR *param = WCMD_parameter(p, 0, NULL, FALSE, FALSE);
h = CreateFileW(param, GENERIC_WRITE, 0, &sa, creationDisposition,
FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) {
@@ -2357,14 +2357,14 @@ int wmain (int argc, WCHAR *argvW[])
args = 1; /* start at first arg, skipping cmd.exe itself */
opt_c = opt_k = opt_q = opt_s = FALSE;
- WCMD_parameter(cmdLine, args, &argPos, NULL, TRUE, TRUE);
+ WCMD_parameter(cmdLine, args, &argPos, TRUE, TRUE);
while (argPos && argPos[0] != 0x00)
{
WCHAR c;
WINE_TRACE("Command line parm: '%s'\n", wine_dbgstr_w(argPos));
if (argPos[0]!='/' || argPos[1]=='\0') {
args++;
- WCMD_parameter(cmdLine, args, &argPos, NULL, TRUE, TRUE);
+ WCMD_parameter(cmdLine, args, &argPos, TRUE, TRUE);
continue;
}
@@ -2389,7 +2389,7 @@ int wmain (int argc, WCHAR *argvW[])
if (argPos[2]==0 || argPos[2]==' ' || argPos[2]=='\t') {
args++;
- WCMD_parameter(cmdLine, args, &argPos, NULL, TRUE, TRUE);
+ WCMD_parameter(cmdLine, args, &argPos, TRUE, TRUE);
}
else /* handle `cmd /cnotepad.exe` and `cmd /x/c ...` */
{
@@ -2470,7 +2470,7 @@ int wmain (int argc, WCHAR *argvW[])
/* Finally, we only stay in new mode IF the first parameter is quoted and
is a valid executable, i.e. must exist, otherwise drop back to old mode */
if (!opt_s) {
- WCHAR *thisArg = WCMD_parameter(cmd, 0, NULL, NULL, FALSE, TRUE);
+ WCHAR *thisArg = WCMD_parameter(cmd, 0, NULL, FALSE, TRUE);
WCHAR pathext[MAXSTRING];
BOOL found = FALSE;
--
1.8.0
More information about the wine-patches
mailing list