I have to agree that that isn't the most efficient method for keeping
track of the "errorlevel_changed". I will be resubmitting the patch
with a better implementation, using the process stack as you
suggested.
However, I would like to say that it really wouldn't be possible to only
use the success/failure value from the functions that don't change the
"errorlevel". This is because there is a subtle difference that sadly
Windows thought was a great idea (I think it should work like you say).
Windows checks if the "errorlevel" has changed in any of the commands
inside of a call and if it has then it checks the errorlevel, if it hasn't
changed it assumes a success. This means that even if the last
command "succeeds" without changing the errorlevel it doesn't matter
(e.g. "echo test") if any of the previous commands inside of a call
updated the errorlevel. Working examples can be seen on line 291-312
of programs/cmd/tests/test-builtins.cmd or a small snippet of them
below:
-snip
> :cfail
> echo %1
> call :setError 1
> goto :eof
-snip-
> call :cfail c1||call :cfail c2
-snip-
> :setError
> exit /B %1
-snip-
The code above will return (and would do so even if one inserted
a "echo foobar" after the "call :setError 1"):
c1
c2