Commit 7b9af226 authored by Frédéric Delanoy's avatar Frédéric Delanoy Committed by Alexandre Julliard

cmd: Simplify WCMD_parameter function.

parent 40c6ff8a
......@@ -138,59 +138,37 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
*/
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) {
int i = 0;
static WCHAR param[MAX_PATH];
WCHAR *p;
if (where != NULL) *where = NULL;
p = param;
while (TRUE) {
switch (*s) {
case ' ': /* Skip leading spaces */
case '\t': /* Treat tabs as spaces */
s++;
break;
case '"':
if (where != NULL && i==n) *where = s;
s++;
while ((*s != '\0') && (*s != '"')) {
*p++ = *s++;
}
if (i == n) {
*p = '\0';
return param;
}
if (*s == '"') s++;
param[0] = '\0';
i++;
p = param;
break;
/* The code to handle bracketed parms is removed because it should no longer
be necessary after the multiline support has been added and the for loop
set of data is now parseable individually. */
case '\0':
return param;
default:
/* Only return where if it is for the right parameter */
if (where != NULL && i==n) *where = s;
while ((*s != '\0') && (*s != ' ') && (*s != ',') && (*s != '=') && (*s != '\t')) {
*p++ = *s++;
}
if (i == n && (p!=param)) {
*p = '\0';
return param;
}
/* Skip double delimiters, eg. dir a.a,,,,,b.b */
if (p != param) {
param[0] = '\0';
i++;
int curParamNb = 0;
static WCHAR param[MAX_PATH];
WCHAR *p = s, *q;
BOOL quotesDelimited;
if (where != NULL) *where = NULL;
param[0] = '\0';
while (TRUE) {
while (*p && ((*p == ' ') || (*p == ',') || (*p == '=') || (*p == '\t')))
p++;
if (*p == '\0') return param;
quotesDelimited = (*p == '"');
if (where != NULL && curParamNb == n) *where = p;
if (quotesDelimited) {
q = ++p;
while (*p && *p != '"') p++;
} else {
s++; /* Skip delimiter */
q = p;
while (*p && (*p != ' ') && (*p != ',') && (*p != '=') && (*p != '\t'))
p++;
}
p = param;
if (curParamNb == n) {
memcpy(param, q, (p - q) * sizeof(WCHAR));
param[p-q] = '\0';
return param;
}
if (quotesDelimited && *p == '"') p++;
curParamNb++;
}
}
}
/****************************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment