Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

WAD 'if' and aliases don't mix so well

Jun
137
3
I have a couple of aliases I had defined:

ScriptUpdate=iff isdir "Script Files" then %+ pushd "Script Files" %+ else %+ pushd %+ endiff %+ if isfile Setup.ino del /qk Setup.ino;Setup.obs %+ cd .. %+ if %@index[%$,/y] GE 0 set _YN=y %+ if %@index[%$,/n] GE 0 set _YN=n %+ if (%_YN) = () inkey Update debug files? %%_YN %+ for /h /a:d %a in (Media\*) for /h /a:d %b in (%@MaybeQuote[%a\*]) for /h /a:d %c in (%@MaybeQuote[%b\*]) SetupInsUpdate %c%+ popd %+ unset /q _YN

SetupInsUpdate=if isfile %@MaybeQuote[%$\Setup.exe] (echo. %+ update /p "Script Files\Setup.ins" %@MaybeQuote[%$\Setup.ins] %+ echo. %+ iff %@MaybeQuote[%$] %+ else %+ if isfile %@MaybeQuote[%$\Setup.dbg;*.rul;*.h] del /k %@MaybeQuote[%$\Setup.dbg;*.rul;*.h] %+ endiff)​

(update is a form of the copy command, and MaybeQuote is a function that puts quotes around a string if there are spaces in it)

When I called ScriptUpdate, it stopped executing after the first 'if' statement. After digging a while and liberally injecting 'echo' statements, I figured out that it was the 'if' that causes problems. If I changed them to 'iff'/'endiff' pairs, all worked fine. Is this a known bug?

Modifying the two above to this form, they now work properly:

ScriptUpdate=iff isdir "Script Files" then %+ pushd "Script Files" %+ else %+ pushd %+ endiff %+ del /qk Setup.ino;Setup.obs %+ cd .. %+ iff %@index[%$,/y] GE 0 then %+ set _YN=y %+ endiff %+ iff %@index[%$,/n] GE 0 then %+ set _YN=n%+ endiff %+ iff (%_YN) = () then %+ inkey Update debug files? %%_YN %+ endiff %+ for /h /a:d %a in (Media\*) for /h /a:d %b in (%@MaybeQuote[%a\*]) for /h /a:d %c in (%@MaybeQuote[%b\*]) SetupInsUpdate %c %+ popd %+ unset /q _YN

SetupInsUpdate=if isfile %@MaybeQuote[%$\Setup.exe] (echo. %+ update /p "Script Files\Setup.ins" %@MaybeQuote[%$\Setup.ins] %+ echo. %+ iff %@MaybeQuote[%$] %+ else %+ if isfile %@MaybeQuote[%$\Setup.dbg;*.rul;*.h] del /k %@MaybeQuote[%$\Setup.dbg;*.rul;*.h] %+ endiff)​
 
Why would that matter? Because although in this case there is no comparable batch file for cmd.exe, there are other instances where I do use batch files that must run identically under tcc.exe and cmd.exe.
 
What TCC version are you using? Since 4nt V7 the @quote[] function has been built in, which seems to do what your @MaybeQuote[] is described as.
I had never had a problem with IF in an alias (nor @IF, though it always evaluates both the true and the false expressions, before throwing one of them away). But I never had the Duplicate CMD bugs flag on. Why does it matter? Because CMD ignores all commands in a command group that follow a failing IF (or something similar, do not recall the exact issue - not relevant in TCC with the flag off) and thus TCC must as well when the flag is set, including the execution of an alias!
Regardless, I would actually make those two into batch files, and use an alias as a shorthand invocation. I doubt you would ever notice the performance difference; OTOH you could not only document what you are doing, but you could check that the commands invoking them do not accidentally have both /n and /y present, in which case your current logic would always accept the /n and ignore the /y. You could also use the Querybox if neither /n nor /y is present. Incidentally, the test if defined _YN is simpler to code and easier to read then the old COMMAND.COM style if (%_YN) == () which I used to use myself before defined was introduced back in the 4DOS days.
 
What TCC version are you using? Since 4nt V7 the @quote[] function has been built in, which seems to do what your @MaybeQuote[] is described as.


I had been using 4nt v6. Wouldn't you know? :-)

I had never had a problem with IF in an alias (nor @IF, though it always evaluates both the true and the false expressions, before throwing one of them away). But I never had the Duplicate CMD bugs flag on. Why does it matter? Because CMD ignores all commands in a command group that follow a failing IF (or something similar, do not recall the exact issue - not relevant in TCC with the flag off) and thus TCC must as well when the flag is set, including the execution of an alias!
Regardless, I would actually make those two into batch files, and use an alias as a shorthand invocation. I doubt you would ever notice the performance difference; OTOH you could not only document what you are doing, but you could check that the commands invoking them do not accidentally have both /n and /y present, in which case your current logic would always accept the /n and ignore the /y. You could also use the Querybox if neither /n nor /y is present. Incidentally, the test if defined _YN is simpler to code and easier to read then the old COMMAND.COM style if (%_YN) == () which I used to use myself before defined was introduced back in the 4DOS days.

Yeah, but it's hard to teach old dogs new tricks! :-) Come on, Steve, I'm sure you remember me (probably not) from my pestering back in the 4dos days. Yeah, I hadn't upgraded since 4nt 6.02, because I didn't like TCMD and hadn't realized you could just use the TCC window directly. Then when my box went from XP 32-bit to Windows 7 64-bit a few months ago, I ran into other issues and management sprung for the upgrade.

Anyway, now that I've read up in detail about what that compatibility bugs really mean, I'm OK with setting it that way.
 
Well, I use TCC many hours a day, but I am too keyboard oriented (and use hotkeys to switch windows) to get much out of TCMD myself. I hate to take my hands off the keyboard when I am dealing with textual issues, where the poiinting device only has a minor, auxiliary role. This is particularly true when I use one of th fancy keyboards with calculatorm favorites, email, ... buttons, and so on.OTOH. when I use the trackball, the keyboard is out of the way. My laptop (which is presently my primarily used machine) has both an integrated joystick and a touch pad, but both of those are too awkward to use. I do recall with great fondness the 3-button trackball integrated into the keyboard I once owned, but alas! The modern versions are priced outrageously, and most do not have 3 buttons.
 

Similar threads

Back
Top