cmd: Introduce an option_equals helper for WCMD_parse_forf_options.

This commit is contained in:
Alex Henrie 2023-08-16 20:37:35 -06:00 committed by Alexandre Julliard
parent 79e78218ec
commit c27f8f72d1

View file

@ -1631,6 +1631,19 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
return; return;
} }
static BOOL option_equals(WCHAR **haystack, const WCHAR *needle)
{
int len = wcslen(needle);
if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
*haystack, len, needle, len) == CSTR_EQUAL) {
*haystack += len;
return TRUE;
}
return FALSE;
}
/***************************************************************************** /*****************************************************************************
* WCMD_parse_forf_options * WCMD_parse_forf_options
* *
@ -1653,11 +1666,6 @@ static BOOL WCMD_parse_forf_options(WCHAR *options, WCHAR *eol, int *skip,
WCHAR *pos = options; WCHAR *pos = options;
int len = lstrlenW(pos); int len = lstrlenW(pos);
const int eol_len = lstrlenW(L"eol=");
const int skip_len = lstrlenW(L"skip=");
const int tokens_len = lstrlenW(L"tokens=");
const int delims_len = lstrlenW(L"delims=");
const int usebackq_len = lstrlenW(L"usebackq");
/* Initialize to defaults */ /* Initialize to defaults */
lstrcpyW(delims, L" \t"); lstrcpyW(delims, L" \t");
@ -1678,36 +1686,28 @@ static BOOL WCMD_parse_forf_options(WCHAR *options, WCHAR *eol, int *skip,
pos++; pos++;
/* Save End of line character (Ignore line if first token (based on delims) starts with it) */ /* Save End of line character (Ignore line if first token (based on delims) starts with it) */
} else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, } else if (option_equals(&pos, L"eol=")) {
pos, eol_len, L"eol=", eol_len) == CSTR_EQUAL) { *eol = *pos++;
*eol = *(pos + eol_len);
pos = pos + eol_len + 1;
WINE_TRACE("Found eol as %c(%x)\n", *eol, *eol); WINE_TRACE("Found eol as %c(%x)\n", *eol, *eol);
/* Save number of lines to skip (Can be in base 10, hex (0x...) or octal (0xx) */ /* Save number of lines to skip (Can be in base 10, hex (0x...) or octal (0xx) */
} else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, } else if (option_equals(&pos, L"skip=")) {
pos, skip_len, L"skip=", skip_len) == CSTR_EQUAL) {
WCHAR *nextchar = NULL; WCHAR *nextchar = NULL;
pos = pos + skip_len;
*skip = wcstoul(pos, &nextchar, 0); *skip = wcstoul(pos, &nextchar, 0);
WINE_TRACE("Found skip as %d lines\n", *skip); WINE_TRACE("Found skip as %d lines\n", *skip);
pos = nextchar; pos = nextchar;
/* Save if usebackq semantics are in effect */ /* Save if usebackq semantics are in effect */
} else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, pos, } else if (option_equals(&pos, L"usebackq")) {
usebackq_len, L"usebackq", usebackq_len) == CSTR_EQUAL) {
*usebackq = TRUE; *usebackq = TRUE;
pos = pos + usebackq_len;
WINE_TRACE("Found usebackq\n"); WINE_TRACE("Found usebackq\n");
/* Save the supplied delims. Slightly odd as space can be a delimiter but only /* Save the supplied delims. Slightly odd as space can be a delimiter but only
if you finish the optionsroot string with delims= otherwise the space is if you finish the optionsroot string with delims= otherwise the space is
just a token delimiter! */ just a token delimiter! */
} else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, } else if (option_equals(&pos, L"delims=")) {
pos, delims_len, L"delims=", delims_len) == CSTR_EQUAL) {
int i=0; int i=0;
pos = pos + delims_len;
while (*pos && *pos != ' ') { while (*pos && *pos != ' ') {
delims[i++] = *pos; delims[i++] = *pos;
pos++; pos++;
@ -1717,11 +1717,9 @@ static BOOL WCMD_parse_forf_options(WCHAR *options, WCHAR *eol, int *skip,
WINE_TRACE("Found delims as '%s'\n", wine_dbgstr_w(delims)); WINE_TRACE("Found delims as '%s'\n", wine_dbgstr_w(delims));
/* Save the tokens being requested */ /* Save the tokens being requested */
} else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, } else if (option_equals(&pos, L"tokens=")) {
pos, tokens_len, L"tokens=", tokens_len) == CSTR_EQUAL) {
int i=0; int i=0;
pos = pos + tokens_len;
while (*pos && *pos != ' ') { while (*pos && *pos != ' ') {
tokens[i++] = *pos; tokens[i++] = *pos;
pos++; pos++;