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

Jun 3, 2008
130
3
Temecula, CA
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)​
 
Jun 3, 2008
130
3
Temecula, CA
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.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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.
 
Jun 3, 2008
130
3
Temecula, CA
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.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
Thread starter Title Forum Replies Date
vefatica Backquotes, aliases get 'em, BTMs don't? Support 1
Jay Sage Parameter %$ Different in Aliases and BTMa Support 4
vefatica Questions about aliases. Support 1
Jay Sage Request Re Aliases CD_LEAVE and CD_ENTER Support 2
Joe Caverly Expand all aliases on the command line Support 2
S Take Command crashes for aliases with length > 1015 Support 1
Joe Caverly SETLOCAL removes Aliases and Functions Support 3
vefatica Two @FUNCTIONs/aliases with the same name Support 4
D Can ANSI escape sequences be used in keystroke aliases? Support 8
Joe Caverly Documentation Aliases Overview Support 3
vefatica Display of special characters in aliases. Support 25
T aliases disappearing Support 22
J Autoexecute Keystroke Aliases Support 1
vefatica Aliases ... appending unused parameters? Support 2
cgunhouse Problem with CALL and Directory Aliases in V17 Support 9
M How to? Logic in aliases... Support 3
J Saving aliases Support 21
vefatica Aliases global vs. local Support 12
R key aliases no longer working Support 2
newbie Test to ensure aliases are loaded Support 6
D Are local aliases inherited? Support 4
T FTP.CFG file aliases Support 5
vefatica @@key aliases cause new prompt? Support 16
J TCC Out of memory with aliases and functions Support 5
J Problem with aliases Support 6
P Quick help for aliases Support 3
R Alt-key aliases? Support 3
R Bug TPIPE's pdf to text conversions don't work Support 2
vefatica Console popup windows don't work correctly Support 0
M Backquoted parameters used in GoSub don't pass string as a single parameter Support 2
V Ctrl-Home/End don't work in Win10 Support 3
vefatica Documentation Help: links to "Conditional expressions" don't work Support 2
RChrismon How to? Changes to Options Don't Save Support 8
vefatica Unicode ... I don't understand Support 1
D How to? V15.00.30 -(help!) - Floating view windows don't open Support 1
D Automatic directory changes don't work at all Support 4
W redirection with pipe don't work Support 10
vefatica @PID, ISAPP - don't see system processes Support 12
J Fixed IDE search keys don't work in TCMD 13.01.32 Support 3
M An issue I really don't understand and is too long and detailed for this "Title" line... Support 16
vefatica =~ ... still don't get it Support 4
vefatica "Administrator:" - I don't want to see it Support 0
C NTFS Descriptions don't work? Support 3
B What Don't I Understand About @SERVICE Support 9
R Don't wake up external drives on startup Support 2
vefatica Command name mix-up Support 3
vefatica TCMD and its tabbed apps ... mix 32/64? Support 1

Similar threads