Commit graph

37 commits

Author SHA1 Message Date
Jeffrey Morlan 8cf11060a9 Various fixes to the way cmd handles errorlevel and the "return values" of commands:
- Changed type of return values from BOOL to INT, with 0 indicating success and any other value indicating failure. If the left side of an || operator returns nonzero, errorlevel is set to that value.
- The return value of a batch file or FOR is the return value of the last command executed in it. An empty batch file returns 0, unless it was CALLed, in which case it returns errorlevel.
- CALL sets errorlevel to the return value of whatever was called.
- Running a GUI program doesn't change errorlevel, but always returns 0.
- CMD /C uses the command's return value, not errorlevel, as the process exit code.

svn path=/trunk/; revision=40474
2009-04-12 23:51:15 +00:00
Jeffrey Morlan db8815a497 - Implement CMD /D, /Q, and /R switches
- Do %envvar% expansions in CMD /C or /K commands
- Make SETLOCAL recognize ENABLEEXTENSIONS and DISABLEEXTENSIONS, although it doesn't do anything yet
- Make VERIFY set the errorlevel (documented in SETLOCAL /?). Also make it recognize when ON/OFF is followed by space
- Make ECHOSERR actually print to stderr, not stdout
- Make echoed display of ( ... ) blocks look nicer (Bug 4022)
- Fix some other minor display bugs

svn path=/trunk/; revision=40244
2009-03-26 01:14:25 +00:00
Jeffrey Morlan 3a52766a90 - Implement SHIFT /n.
- Make prompt code $T and %TIME% have the hours space-padded, not zero-padded.
- Allow delayed expansion in the parameter of IF ERRORLEVEL.

svn path=/trunk/; revision=40084
2009-03-18 03:52:58 +00:00
Jeffrey Morlan 341c5b2e5f - Allow running a batch file from inside a FOR
- A little cleanup

svn path=/trunk/; revision=40038
2009-03-15 15:45:17 +00:00
Jeffrey Morlan a1eb1f6ba4 Replace a couple hacks supporting specific cases of enhanced variable substitution (%~var) with a more general implementation. All tests in rostests/win32/cmd/script_testsuite can now be passed using ReactOS cmd in Windows, though still not yet in ReactOS itself.
svn path=/trunk/; revision=40024
2009-03-15 04:54:41 +00:00
Jeffrey Morlan fff257c059 Implement SETLOCAL and ENDLOCAL commands. Make delayed expansion optional (disabled by default, enabled by CMD /V switch or with SETLOCAL)
svn path=/trunk/; revision=39892
2009-03-06 18:05:45 +00:00
Jeffrey Morlan 79c11338fa - Ignore special characters in a REM line.
- Make the \n-printing in batch files with ECHO on more consistant with how Windows does it.

svn path=/trunk/; revision=39890
2009-03-06 17:27:42 +00:00
Jeffrey Morlan 516e7fa09c Rework batch-file processing so that 'call file.bat' doesn't return until the file has finished, allowing constructs like 'call file.bat & somethingelse' to work properly.
svn path=/trunk/; revision=39858
2009-03-03 20:06:54 +00:00
Jeffrey Morlan 484ee2fa7e Separate batch file contexts and FOR contexts into two different structs, since they don't actually have anything in common any more
svn path=/trunk/; revision=39846
2009-03-02 19:08:25 +00:00
Jeffrey Morlan 9ea64ffebb Fix BatchParams to handle unconventional spacing/quoting properly.
svn path=/trunk/; revision=39836
2009-03-01 20:25:13 +00:00
Jeffrey Morlan b18a547c1b Implement complete support for FOR command (including /D, /F, /L, and /R switches). cmd is now close to being able to run RosBE 1.3's initialization without errors.
svn path=/trunk/; revision=39742
2009-02-24 20:29:18 +00:00
Jeffrey Morlan 9b0334da19 Don't expand FOR variables until execution time, so that special characters in them won't cause unwanted syntactic effects.
For example, "for %a in (^>) do echo %a" should just echo the greater than sign.

svn path=/trunk/; revision=39611
2009-02-15 18:18:16 +00:00
Jeffrey Morlan 781ae61f03 - Make IF command a special form; necessary to make nested multi-line IF blocks work properly
- Implement IF /I option, IF CMDEXTVERSION, and generic comparisons (EQU etc)
- Make IF ERRORLEVEL return true if the errorlevel is greater than the number
- Remove hacked support for multi-line IF blocks from batch.c

svn path=/trunk/; revision=38280
2008-12-22 22:34:51 +00:00
Jeffrey Morlan e0d327a9ec ReadBatchLine: Add a \n to the line if it doesn't already have one
svn path=/trunk/; revision=37155
2008-11-02 21:56:34 +00:00
Jeffrey Morlan 8d7388ee07 - Batch: In a line generated by a 'for', add the \n that the parser expects. (Bug 3717)
- cmd_for: Don't leave raw_params uninitialized; could cause a crash in ExitBatch.

svn path=/trunk/; revision=36061
2008-09-08 16:23:33 +00:00
Jeffrey Morlan 6c2116d0cf - Implement call :label by creating a new batch context; this way calls can be nested and have their own %0-%9 parameters.
- GetBatchVar: Implement %~n. Remove %? (an old FreeDOS-ism; the Windows equivalent is %ERRORLEVEL%)

svn path=/trunk/; revision=35681
2008-08-26 20:36:38 +00:00
Jeffrey Morlan 8b52a8e50a - Extract the line-reading code in ProcessInput to a separate function (ReadLine) that the parser can call. Now line continuations (using ^ at the end of a line) and multi-line parenthesized blocks work.
- ReadBatchLine: Don't strip the trailing \n, the parser needs it. Remove handling of :labels and @quiet commands, now done by the parser.
- ReadCommand: Add a \n to the line. Move PrintPrompt call out, since the prompt shouldn't be printed for additional lines read in a command beyond the first.

svn path=/trunk/; revision=35530
2008-08-22 14:37:11 +00:00
Jeffrey Morlan 07912f2b23 - Implement X>&Y redirections. Hold redirections in a linked list structure, because order matters (>x 2>&1 is not the same as 2>&1 >x). Allow redirection of any handle number from 0 to 9.
- Allow quotes around the redirection file name.
- Batch: Fix buffer overflow bug (incorrect size for bc->BatchFilePath)

svn path=/trunk/; revision=35508
2008-08-21 15:33:59 +00:00
Jeffrey Morlan b75ff606ba - Fix cmd's SearchForExecutable: it was inside out, giving extension priority over directory.
- Remove code that checked if the file's extension was in PATHEXT. Windows does not check, and it's very handy to be able to "run" non-executable files.
- Allow explicit paths with no backslash (like "A:file")
- Batch: use GetFullPathName to get the batch file's absolute path; this way %~dp0 will always give the right directory even in the weird case of running the .bat via a relative path in PATH. Remove code in SearchForExecutable which tried to make sure it returned an absolute path (but it didn't in that case).

svn path=/trunk/; revision=35187
2008-08-08 16:48:21 +00:00
Colin Finck 92545f124e - Minor fixes to work more like WinXP's cmd
- Removed the now obsolete "seta_test.cmd"

svn path=/trunk/; revision=33561
2008-05-17 20:07:31 +00:00
Hervé Poussineau c79d92ab52 Fix debug output of strings
svn path=/trunk/; revision=33536
2008-05-15 20:29:50 +00:00
Hervé Poussineau 2f9c333ded cmd: replace static traces by dynamic ones
svn path=/trunk/; revision=33533
2008-05-15 20:02:05 +00:00
Christoph von Wittich 8872eea630 ZeroMemory the batchfile path
svn path=/trunk/; revision=32076
2008-02-01 20:30:51 +00:00
Peter Ward 4e8df678d2 - Make dp0 give the directory the batch was run from instead of the current directory.
svn path=/trunk/; revision=32074
2008-02-01 14:15:41 +00:00
Christoph von Wittich 76569bc213 handle call :Label
fix goto :Label

svn path=/trunk/; revision=32070
2008-01-31 20:55:05 +00:00
Christoph von Wittich 11ca34b0e3 support else
handle negative values in special envvars
stdin,out,err can't be redirected for windows gui apps

svn path=/trunk/; revision=32068
2008-01-31 17:59:02 +00:00
Christoph von Wittich 8f8faff777 allow nested (...) blocks (but still no support for else)
svn path=/trunk/; revision=32065
2008-01-31 15:11:25 +00:00
Filip Navara 874eec2648 Remove redundant memset call.
svn path=/trunk/; revision=31906
2008-01-20 15:41:49 +00:00
Christoph von Wittich 67ed022d72 support blocks ( ... )
support parsing of env vars like %TIMERAW:~0,2%
there is still room for improvement... 

svn path=/trunk/; revision=31903
2008-01-20 14:29:18 +00:00
Christoph von Wittich afb39ce8fa fix a buffer overflow
svn path=/trunk/; revision=31901
2008-01-20 12:21:39 +00:00
Christoph von Wittich 21d4613b0f fix memory leak
svn path=/trunk/; revision=31894
2008-01-19 17:29:49 +00:00
Thomas Bluemel df91a99233 - Add code to detect buffer overflows and buffer underflows on memory operations. This code is only enabled if _DEBUG is defined.
- Change all calls to malloc, realloc and free to cmd_alloc, cmd_realloc and cmd_free

svn path=/trunk/; revision=28065
2007-08-01 10:17:13 +00:00
Eric Kohl e0364c78da Remove outdated email addresses.
svn path=/trunk/; revision=26648
2007-05-05 11:32:25 +00:00
Christoph von Wittich d5de43d13e * fixed some warnings
svn path=/trunk/; revision=25316
2007-01-05 20:22:44 +00:00
Brandon Turner 410ae9c26b Unicode fixes and error checking.
svn path=/trunk/; revision=22690
2006-06-29 15:08:10 +00:00
Brandon Turner c6661f1f9e expand %* to batch file params.
bug: #1629

svn path=/trunk/; revision=22683
2006-06-29 02:48:52 +00:00
Ged Murphy a5c746a592 move explorer and cmd. Add a few .rbuild files
svn path=/trunk/; revision=21019
2006-02-16 23:23:37 +00:00