[CMD] SET: Diverse fixes for the arithmetic-expression parser (/A option).
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 19 Jul 2020 19:30:50 +0000 (21:30 +0200)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Tue, 22 Sep 2020 22:22:48 +0000 (00:22 +0200)
commit17e094cd34648d48d3804f9419b78718fb2c207e
treec6b26f3ddd9ff048aaac1b20b728cf52c9880a5f
parentf5cf67f455f22ac03002165707bb41a8fdfa8535
[CMD] SET: Diverse fixes for the arithmetic-expression parser (/A option).

- Detect whether a division by zero is done, and fail if so.

- Detect whether an invalid number is provided:
  * If _tcstol() fails with errno == ERANGE, we've got an overflow or
    underflow.
  * If the next character where _tcstol() is not a whitespace but is a
    character compatible with the first character of an identifier, the
    number is invalid.

- Add + to the list of existing unary operators (!,~,-), and parse them
  where many of these are present. Indeed, expressions like: +3, -+-+3,
  !!-+3 (or with other unary ops, etc.) are valid.

- Operators constituted of more than one characters, can contain
  whitespace separating their constituting characters.
  Thus, "a + = 3" is equivalent to "a += 3" (and the same for -=, *=,
  /=, %=, &=, |= and ^=), and "a < < 3" is equivalent to "a << 3" (and
  the same for >>, <<= and >>=).

- After evaluating everything, if unparsed data remains, fail and bail out.

- Return Windows' CMD-compatible errorlevels.

See https://ss64.com/nt/set.html for more details.

Fixes some cmd_winetests.
base/shell/cmd/set.c