Commit graph

4 commits

Author SHA1 Message Date
Hermès Bélusca-Maïto 37bda06eed
[CMD] CALL: Fix the implementation of the CALL command, make it more compatible with Windows' CMD.
- Fail if no parameter is provided.

- The "CALL :label args..." syntax is available only when command extensions
  are enabled. Fail if this syntax is used outside of a batch context.

- Reparse the CALL command parameter with the command parser, in order
  to accurately parse and interpret it as a possible command (including
  escape carets, etc...) and not duplicate the logic.
  ** CURRENT Windows' CMD-compatibility LIMITATION ** (may be lifted in
  a "ROS-specific" running mode of CMD): only allow standard commands to
  be specified as parameter of the CALL command.

  This reparsing behaviour can be observed in Windows' CMD, by dumping
  the interpreted commands after enabling the cmd!fDumpParse flag from
  a debugger (using public symbols).

- When reparsing, we should tell the parser to NOT ignore lines that
  start with a colon, because in this situation these are to be
  considered as valid "commands" (for parsing "CALL :label").

  * For Windows' CMD-compatibility, the remaining escape carets need to
    be doubled again so that, after the new parser step, they are escaped
    back to their original form. But then we also need to do it the "buggy"
    way à la Windows, where carets in quotes are doubled either! However
    when being re-parsed, since they are in quotes they remain doubled!!
    (see "Phase 6" in https://stackoverflow.com/a/4095133/13530036 ).

  * A MSCMD_CALL_QUIRKS define allows to disable this buggy behaviour,
    and instead tell the parser to not not interpret the escape carets.

- When initializing a new batch context when the "CALL :label" syntax is
  used, ensure that we reuse the same batch file position pointer as its
  parent, so as to have correct call label ordering behaviour.

  That is,

  :label
  ECHO hi
  CALL :label
  :label
  ECHO bye

  should display:

  hi
  bye
  bye

  i.e., the CALL calls the second label instead of the first one (and
  thus entering into an infinite loop).

  Finally, the "CALL :label" syntax strips the first ':' away, so, as a
  side-effect, the command "CALL :EOF" fails (otherwise it would perform
  a "GOTO :EOF" and succeeds), while "CALL ::EOF" succeeds.

Fixes some cmd_winetests.
2020-09-27 19:05:23 +02:00
Hermès Bélusca-Maïto d78e8029b8
[CMD] Additional fixes for ERRORLEVEL and last returned exit code from EXIT, CALL commands and CMD.
CORE-10495 CORE-13672

- Fix how the ERRORLEVEL and the last returned exit code are set by
  EXIT and CALL commands, when batch contexts terminate, and when CMD
  runs in single-command mode (with /C).

  Addendum to commit 26ff2c8e, and reverts commit 7bd33ac4.
  See also commit 8cf11060 (r40474).

  More information can be found at:
  https://ss64.com/nt/exit.html
  https://stackoverflow.com/a/34987886/13530036
  https://stackoverflow.com/a/34937706/13530036

- Move the actual execution of the CMD command-line (in /C or /K
  single-command mode) from Initialize() to _tmain(), to put it on par
  with the ProcessInput() interactive mode.

- Make ProcessInput() also return the last command's exit code.
2020-08-19 20:36:03 +02:00
Hermès Bélusca-Maïto 24ed534474
[CMD] Code formatting only. 2017-11-18 23:52:50 +01:00
Colin Finck c2c66aff7d Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers into modules, and delete rossubsys. 2017-10-03 07:45:34 +00:00
Renamed from reactos/base/shell/cmd/call.c (Browse further)