c Xerox Corporation 1979y45c(635)\f3 1f0Inter-Office Memorandumz18592l4445y762\f5bTo	Alto Users	Date	July 9, 1982z18592l4445d2998e27(0,65535)(1,4657)(5,10795)(6,12876)\f1 2f0t2 1t0 10t6 1f1t0 4f0t7 1t0From	Martin Newell, Beau Sheil,	Subject	IF - Conditional execution ofPeter Deutsch, Dan Swinehart		commandsz18592l4672d2998y716e19\f1 4f0t2 1t0 26t6 1f1t0 7f0t7 1t0Filed on	[Maxc/Indigo]<AltoDocs>If.pressz18592l4445d2998e7(5,11684)(6,14146)\f1 8f0t2 1t0XEROX       z18592l508y644e8(2116)\f2 5f0INTRODUCTIONe4jk72\b1f1 11f0The program If implements conditional execution of groups of commands to the Alto Executive.  The conditions involve the existence, lengths, and read/write dates of files, as well as string matching on the contents of files.  The original motivation for If was its use in conjunction with the Bravo macros for compiling BCPL and MESA programs, though other uses have become apparent.l4269e6jk40\12i2I306f1 4f0 5f1 4f0Examplel3634e6jk72\bThe Mesa compiler creates an .errlog file only if there were errors.  Thus, a command file for compiling a Mesa program, prog.mesa, then entering Bravo only if there were errors is:l4269e6jk40Delete prog.errlogCompiler -p/c prog.mesaIf prog.errlog then Bravo/m progl5539e6jk72\f8This is a modification of the m quit macro in bravo for MESA.  Also see Examples at the end of this document.l4269e6jk40\56f1 4f0Where to find Ifl3634e6jk72\bIf is on:  [Maxc]<Alto>If.runl4269e6jk40SPECIFICATIONe6jk72\b1f1 12f0Syntaxl3634e6jk90\bIf <condition>[ then <commands>][ else <commands>]l5539e6jk40\f8where [] denotes an optional clause, and <condition> is one of:l4269e6jk40\6f8 2f0 33f8 11f0filename					(yields true if file exists)filename/l=N			(yields true if file exists and length = N)filename/l<N			(yields true if file exists and length < N)filename/l>N			(yields true if file exists and length > N)filename/s<string>	(yields true if file exists and contains <string>)filename/r=otherfilename/r	(yields true if both files exist and have equal read dates){similarly for filename/r<otherfilename/r, etc.}{similarly with either or both /r changed to /w, referring to write date}{similarly with either or both /r changed to /c, referring to creation date}l5539e6jk40(635)\f8 8f0 34f8 12f0 44f8 1f0 2f8 12f0 44f8 1f0 2f8 12f0 44f8 1f0 2f8 18f0N is a decimal constant, and <string> is a string delimited by whatever character immediately follows the switch /s, e.g. filename/s\some text\.l4269e6jk40(2116)\f8 1f0 121f8 21f0<commands> is any list of Alto executive commands separated by semicolons.l4269e6jk40\f8 10f0Note that it is necessary to escape semicolons past the Executive command line reader.l4269e6jk40It is possible to nest Ifs by enclosing <commands> in braces ('{' and '}'): the braces will be removed before the <commands> are passed to the Executive, but occurrences of " then " or " else " within the braces will not terminate the <commands> with respect to the outer If.l4269e6jk40Switches, "then", "else", and string matching all treat upper and lower case letters as equivalent.l4269e6jk40Semanticsl3634e6jk90\bIn the case that <condition> yields true the <commands> in the then clause (if present) are passed to the Executive (via rem.cm) for execution, otherwise the <commands> in the else clause (if present) are passed.l4269e6jk40In the case of the /s switch each occurence of the character * in the <string> indicates a wildcard to be matched by zero or more characters in the file.  This also has to be escaped past the Executive command line reader.l4269e6jk40EXAMPLESe6jk90\b1f1 7f01.	A quit macro in user.cm for achieving the example given in the Introduction is:l4269d3008e6jk40(1270)M.QUIT:"*qDelete @4acacacacerrlogCompiler -p/c @4 If.run/r @4acacacacerrlog then Bravo/m @4acacacacac"l4904e6jk72(2116)\f8 8f0 1f8 2f0 9f8 1f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f0o0 7f8 29f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0 23f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0This uses the MESA run switch /r.l4269e6jk40\14f1 4f02.	The equivalent of the example given in the Introduction for the BCPL world is:l4269d3008e6jk40(1270)\67f1 4f0bcpl/f prog.bcplIf prog.bt/s:ERROR: then Bravo/b progl4904e6jk72(2116)\f8String matching is needed since BCPL creates a .bt file whether or not there are errors.l4269e6jk40\32f1 4f0A quit macro in user.cm for achieving the above is:l4269e6jk40B.QUIT:"*qbcpl/f @4If @4acacacacbt/s:ERROR: then Bravo/b @4acacacacac"l4904e6jk72\f8 27f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0 28f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o0 1f1o4 1f8o03.	An extension of the above example to both load and run a successfully compiled program is:l4269d3008e6jk40(1270)bcpl/f prog.bcplIf prog.bt/s:ERROR: then bravo/b prog ^                 else bldr prog'; progl4904e6jk72(635)\f84.	A further extension, which compiles the program only if it has been edited since last being compiled, is:l4269d3008e6jk40(1270)If prog.bcpl/c>prog.br/c then bcpl/f prog.bcplIf prog.bt/s:ERROR: then bravo/b prog ^                 else bldr prog'; progl4904e6jk72(635)\f85.	A command file to edit file.bravo which may be held either locally or remotely:l4269d3008e6jk40(1270)If file.bravo else Ftp Ivy retrieve/c file.bravoBravo/n file.bravol4904e6jk72(2116)\f86.	Of course the above example is good only for the specific file file.bravo.  It makes better sense in conjunction with the system Do.run (q.v.):l4269d3008e6jk40(1270)If #1 else Ftp Ivy retrieve/c #1Bravo/n #1l4904e6jk72(2116)\f8which can be used with a command of the form:l4256e6jk40(1270)Do edit file.bravol4904e6j(2116)\f8