Commit graph

77991 commits

Author SHA1 Message Date
Hermès Bélusca-Maïto 80844dc185
[CMD] DATE: Simplify the input loop, based on the TIME command.
Set also the ERRORLEVEL in case of error.
2020-08-19 20:36:10 +02:00
Hermès Bélusca-Maïto a151893351
[CMD] DATE: The /T option is available only when extensions are enabled. 2020-08-19 20:36:10 +02:00
Hermès Bélusca-Maïto 682875d070
[CMD] TIME: The /T option is available only when extensions are enabled.
And merge two string buffers into one.
2020-08-19 20:36:09 +02:00
Hermès Bélusca-Maïto aab632644f
[CMD] Some code style and formatting fixes 2020-08-19 20:36:09 +02:00
Hermès Bélusca-Maïto 47d7de4b7b
[CMD] Simplify GetRootPath() and mark its InPath parameter pointer to const string. 2020-08-19 20:36:08 +02:00
Hermès Bélusca-Maïto f43ee81573
[CMD] CHDIR: Adjust ERROR_FILE_NOT_FOUND into ERROR_PATH_NOT_FOUND if _tchdir() fails. 2020-08-19 20:36:08 +02:00
Hermès Bélusca-Maïto 9871becced
[CMD] It is not the job of ErrorMessage() to set the errorlevel! It is set only by the commands that want it. 2020-08-19 20:36:08 +02:00
Hermès Bélusca-Maïto 3b960a1c21
[CMD] MOVE: Set the errorlevel on failure.
CORE-14261
2020-08-19 20:36:07 +02:00
Hermès Bélusca-Maïto ae649656db
[CMD] RMDIR: Improve some aspects of the /S option.
- First, the option and the APIs called by it can work directly on
  paths relative to the current directory. So there is no need to
  call GetFullPathName(), with the risk of going over MAX_PATH if the
  current path is quite long (or nested) but the RMDIR is called on a
  (short-length) relative sub-directory.

- Append a path-separator (backslash), only if the specified directory
  does not have one already, and, that it does not specify a current
  directory via the "drive-root" method, e.g. "C:" without any trailing
  backslash.

- In case there are errors during deletion of sub-directories or
  sub-files, print the error but continue deleting the other sub-dirs
  or files.

- Monitor the Ctrl-C breaker as well, and stop deleting if it has been
  triggered.

- When removing file/directory read-only attribute, just remove this
  attribute, but keep the other ones.

- When deleting the directory, first try to do it directly; if it fails
  with access denied, check whether it was read-only, and if so, remove
  this attribute and retry deletion, otherwise fails.

- When recursively deleting a drive root directory, ultimately resolve
  the dir pattern and check whether it's indeed a drive root, e.g.
  "C:\\", and if so, just return success. Indeed, calling
  RemoveDirectory() on such drive roots will return ERROR_ACCESS_DENIED
  otherwise, but we want to succeed even if, of course, we won't
  actually "delete" the drive root.
2020-08-19 20:36:07 +02:00
Hermès Bélusca-Maïto 2f9b4a2e9f
[CMD] RMDIR: Force directory deletion even if it's read-only, only when recursing over subdirectories (via the /S option). 2020-08-19 20:36:06 +02:00
Hermès Bélusca-Maïto 7c175d4999
[CMD] PATH, SET: Fix the returned error message when an environment variable does not exist.
Translators, please update the translations!
2020-08-19 20:36:06 +02:00
Hermès Bélusca-Maïto 6e09a6a3ff
[CMD] Use kernel32!lstrcmp(i) when comparing strings with the IF command.
Use kernel32!lstrcmp(i) instead of CRT!_tcs(i)cmp, so as to use the correct
current thread locale information when comparing user-specific strings.
As a result, the following comparison: 'b LSS B' will return TRUE,
instead of FALSE as it would be by using the CRT functions (and by
naively considering the lexicographical order in ANSI).
This behaviour has been introduced in Windows 2000 onwards.
2020-08-19 20:36:05 +02:00
Hermès Bélusca-Maïto 5830ccb85e
[CMD] Improve the way the ErrorMessage() helper and the MKDIR and RMDIR commands report their errors.
For MKDIR, also properly support the case of ERROR_FILE_EXISTS and
ERROR_ALREADY_EXISTS last-errors by displaying the standard error
"A subdirectory or file XXX already exists.\n"
2020-08-19 20:36:05 +02:00
Hermès Bélusca-Maïto 1efbcd3d5d
[CMD] Improve RMDIR help and MD error message. 2020-08-19 20:36:04 +02:00
Hermès Bélusca-Maïto e3ed502bb6
[CMD] Fix the output of the SET command. 2020-08-19 20:36:04 +02:00
Hermès Bélusca-Maïto ca4523658c
[CMD] Some code style and formatting fixes 2020-08-19 20:36:04 +02:00
Hermès Bélusca-Maïto 82bcb3f9f0
[CMD] Fix the implementation of EXIT /B when a batch context is active. 2020-08-19 20:36:03 +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 4c9d322c68
[CMD_ROSTEST] Add tests for EXIT and CMD returned exit code values.
CORE-10495 CORE-13672

See also commits 8cf11060 (r40474), 26ff2c8e and 7bd33ac4.

More information can be also found at:
https://stackoverflow.com/a/34987886/13530036
and
https://stackoverflow.com/a/34937706/13530036
2020-08-19 20:36:02 +02:00
Hermès Bélusca-Maïto 2e4c8c019e
[CMD] GOTO: Fix label parsing.
We note two things, when CMD searches for the corresponding label in the
batch file:
- the first character of the line is always ignored, unless it's a colon;
- the escape caret ^ is supported and interpreted.

Fixes some cmd_winetests.
2020-08-19 20:36:01 +02:00
Hermès Bélusca-Maïto 71cd64d66a
[CMD_ROSTEST] Add tests for GOTO label parsing. 2020-08-19 20:36:01 +02:00
Hermès Bélusca-Maïto c5e6e5a19c
[CMD] GOTO: Fix handling of the ':EOF' label handling.
- The ':EOF' label feature is available only when extensions are enabled.

- Anything that follows the ':EOF' label, separated by at least one
  whitespace character, is ignored, and the batch file terminates.
2020-08-19 20:36:01 +02:00
Hermès Bélusca-Maïto aee1dd2972
[CMD_ROSTEST] Add tests for GOTO :EOF 2020-08-19 20:36:00 +02:00
Hermès Bélusca-Maïto f911bb482d
[CMD] GOTO: The command should search labels from its position down to the end, then loop back to the beginning of the batch and down to the original position. 2020-08-19 20:36:00 +02:00
Hermès Bélusca-Maïto 8ed9a46dc2
[CMD_ROSTEST] Add tests for GOTO and CALL label search ordering. 2020-08-19 20:35:59 +02:00
Hermès Bélusca-Maïto 495c82ccde
[CMD] Syntax errors during parsing of batch parameters expansion, or FOR and IF commands, are fatal, and batch execution should stop.
- To this purpose use the ParseErrorEx() that correctly sets the
  bParseError flag, and return the partially-parsed command so that
  it gets echoed as well for diagnostics purposes (Windows-compatible).

- Any other parameters specified after (or before) the '/?' switch for
  the FOR and IF commands, are considered fatal syntax errors as well,
  thus we employ the ParseErrorEx() as well.
2020-08-19 20:35:59 +02:00
Hermès Bélusca-Maïto 6eb1cae348
[CMD] Fixes for Batch error execution control flow.
CORE-13713 CORE-13736

- In case execution of all batch contexts is stopped (by selecting "All"
  at the Ctrl-C/Ctrl-Break prompt), notify as well the CheckCtrlBreak()
  signal handler once there are no more batch contexts (this in effect
  resets the internal 'bLeaveAll' static flag in CheckCtrlBreak).
  This is an adaptation of the fix present in FreeCOM 1.5, first
  described in https://gcfl.net/FreeDOS/command.com/bugs074g.html .

- Introduce a ParseErrorEx() helper that sets the 'bParseError' flag and
  displays a customized syntax-error message, only for the first syntax
  error encountered. Implement ParseError() around the *Ex function.

- In batch mode, echo the original pre-parsed batch file line if a parse
  error has been encountered.

- When running a compound command - including IF, FOR, command blocks -,
  and that control flow is modified by any CALL/GOTO/EXIT command,
  detect this while running the compound command so as to stop it and go
  back to the main batch execution loop, that will then set up the actual
  new command to run.

- In GOTO, do not process any more parts of a compound command only when
  we have found a valid label.
2020-08-19 20:35:58 +02:00
Hermès Bélusca-Maïto 7f8792e005
[CMD_ROSTEST] Add tests for batch execution flow with GOTO and CALL commands.
- Tests for GOTO across IF parenthesized block (parser test with line
  continuation at closing parenthesis).

- Tests for showing how FOR-loops stop when a GOTO is encountered.

- Tests for EXIT command within IF block.
2020-08-19 20:35:58 +02:00
Hermès Bélusca-Maïto ca912d7b36
[CMD] Further code style and formatting fixes. 2020-08-19 20:35:57 +02:00
Hermès Bélusca-Maïto c93f511241
[CMD] Reduce stack memory usage when parsing or echoing commands recursively.
- Use a common large string buffer for temporary command substitutions/expansions,
  instead of having such a buffer in the local stack of the parsing and
  echoing functions that may be called recursively. Since CMD executes
  synchronously we know that this common buffer can only be used once at
  a time.

- Also do a small code cleanup in ParseIf(), ParseFor() and ParseCommandPart().
2020-08-19 20:35:57 +02:00
Hermès Bélusca-Maïto 26cfadc352
[CMD] Make the command echoer Windows-CMD-compatible. CORE-14025
Add a MSCMD_ECHO_COMMAND_COMPAT define to be able to switch back to our
older but less broken behaviour at compile-time.

- Append a trailing space to commands when those have a parameter,
  as well as after a command-block closing parenthesis.

- Space around redirection strings need to be switched around.
2020-08-19 20:35:56 +02:00
Hermès Bélusca-Maïto 47ea3f1faa
[CMD] Fix the command echo-er/unparser.
- Use ConOutPuts() instead of ConOutPrintf() for displaying strings that
  are not printf formatted.

- When echo-ing/unparsing FOR command, any possible FOR variables
  present in the FOR parenthesized list (before the "do" part) should be
  substituted as well.
2020-08-19 20:35:56 +02:00
Hermès Bélusca-Maïto 6f87d45e1c
[CMD] Add a command tree dumper, for debugging purposes of the parser code.
This feature is also present in Windows' CMD, and has been documented
e.g. at:
https://www.fireeye.com/blog/threat-research/2018/11/cmd-and-conquer-de-dosfuscation-with-flare-qdb.html
https://www.real-sec.com/2019/08/cmd-and-conquer-de-dosfuscation-with-flare-qdb/
2020-08-19 20:35:55 +02:00
Hermès Bélusca-Maïto 988f8bd2f6
[CMD_ROSTEST] Add tests for the command echoer. 2020-08-19 20:35:55 +02:00
Hermès Bélusca-Maïto 04eef6d20c
[CMD] parser.c, cmd.c/h : Code style and formatting fixes.
- Change C_IFFAILURE, C_IFSUCCESS into C_OR, C_AND respectively.
2020-08-19 20:35:54 +02:00
Hermès Bélusca-Maïto 93ee4e7efa
[CMD] Fix some messages formatting.
- Fix ECHO state output string.
- Add missing newlines to some help and error messages.
- Add trailing space after the PAUSE command message.
2020-08-19 20:35:54 +02:00
Hermès Bélusca-Maïto 23a52b2285
[CMD_ROSTEST] Minor improvements for the echo-ed info of the builtins tests. 2020-08-19 20:35:53 +02:00
Hermès Bélusca-Maïto d85d991679
[CMD_ROSTEST] Sync batch.c with cmd_winetest' counterpart. 2020-08-19 20:35:53 +02:00
Hermès Bélusca-Maïto 7115d7ba8e
[CMD_WINETEST] Sync with Wine 5.12. 2020-08-19 20:35:53 +02:00
Hermès Bélusca-Maïto ea801338f6
[CMD] todo.txt: Remove some points that have already been implemented since ages. 2020-08-19 20:35:52 +02:00
Hermès Bélusca-Maïto 86c5e7e41f
[CMD] Remove deprecated definition in CMakeLists.txt. 2020-08-19 20:35:52 +02:00
Thomas Schneider a245c98fc6
[FREELDR] Bootsector fix for CHS read on old BIOSes which lack INT 3e (#3078)
At line 263 a 'pop es' is missing before 'ret' in ReadCHS() function,
just like in the ReadLBA() function. CORE-17178

Co-authored-by: Dmitry Borisov <di.sean@protonmail.com>
2020-08-19 19:10:02 +03:00
Andreas Hausmann a54004893f
[BROWSEUI] Few corrections for German (de-DE) translation (#3067)
Corrected some mistakes
2020-08-19 18:18:05 +03:00
Dmitry Borisov 27cd9eaf1a
[PC98VID] Add framebuffer video miniport driver for NEC PC-98 series (#3040)
This adds generic graphics support on PC-9821.
2020-08-19 00:50:08 +03:00
Stanislav Motylkov f7e84e231b
[TASKMGR] Revert 535e262 (#3016)
This reverts a change which introduced a regression.

CORE-17115
2020-08-18 20:23:34 +03:00
Stanislav Motylkov 78607860b7
[SHELL32] Addendum to 4156fd5 2020-08-18 16:50:59 +03:00
Stanislav Motylkov 4156fd5182
[SHELL32] Improve Russian translation
Addendum to 46ff964. CORE-11132
2020-08-18 16:26:52 +03:00
Zheng Jianping 5b80b5db17
[UMANDLG] Update Chinese Simplified (zh-CN) translation (#2545) 2020-08-18 15:26:06 +03:00
Zheng Jianping 4a3ef0d053
[OSK] Update Chinese Simplified (zh-CN) translation (#2546) 2020-08-18 14:52:06 +03:00
Aobi Chan CL 53bb510352
[TRANSLATION] Improve Chinese Traditional (zh-TW) translation (#3065) 2020-08-18 14:26:04 +03:00