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 ...@@ -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) { WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) {
int curParamNb = 0;
int i = 0; static WCHAR param[MAX_PATH];
static WCHAR param[MAX_PATH]; WCHAR *p = s, *q;
WCHAR *p; BOOL quotesDelimited;
if (where != NULL) *where = NULL; if (where != NULL) *where = NULL;
p = param; param[0] = '\0';
while (TRUE) { while (TRUE) {
switch (*s) { while (*p && ((*p == ' ') || (*p == ',') || (*p == '=') || (*p == '\t')))
case ' ': /* Skip leading spaces */ p++;
case '\t': /* Treat tabs as spaces */ if (*p == '\0') return param;
s++;
break; quotesDelimited = (*p == '"');
case '"': if (where != NULL && curParamNb == n) *where = p;
if (where != NULL && i==n) *where = s;
s++; if (quotesDelimited) {
while ((*s != '\0') && (*s != '"')) { q = ++p;
*p++ = *s++; while (*p && *p != '"') p++;
}
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++;
} else { } 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