c Xerox Corporation 1979Inter-Office MemorandumToAlto UsersDateJuly 9, 1982FromMartin Newell, Beau Sheil,SubjectIF - Conditional execution ofPeter Deutsch, Dan SwinehartcommandsFiled on[Maxc/Indigo]If.pressXEROX INTRODUCTIONThe program If implements conditional execution of groups of commands to the AltoExecutive. The conditions involve the existence, lengths, and read/write dates of files, aswell as string matching on the contents of files. The original motivation for If was its usein conjunction with the Bravo macros for compiling BCPL and MESA programs, though otheruses have become apparent.ExampleThe Mesa compiler creates an .errlog file only if there were errors. Thus, a command filefor compiling a Mesa program, prog.mesa, then entering Bravo only if there were errors is:Delete prog.errlogCompiler -p/c prog.mesaIf prog.errlog then Bravo/m progThis is a modification of the m quit macro in bravo for MESA. Also see Examples at theend of this document.Where to find IfIf is on: [Maxc]If.runSPECIFICATIONSyntaxIf [ then ][ else ]where [] denotes an optional clause, and is one of:filename(yields true if file exists)filename/l=N(yields true if file exists and length = N)filename/lN(yields true if file exists and length > N)filename/s(yields true if file exists and contains )filename/r=otherfilename/r(yields true if both files exist and have equal readdates){similarly for filename/r is a string delimited by whatever characterimmediately follows the switch /s, e.g. filename/s\some text\. is any list of Alto executive commands separated by semicolons.Note that it is necessary to escape semicolons past the Executive command line reader.It is possible to nest Ifs by enclosing in braces ('{' and '}'): the braces will beremoved before the are passed to the Executive, but occurrences of " then "or " else " within the braces will not terminate the with respect to the outerIf.",pqX]g~ri bAs1qX *+s2Lq ^s1q*+s2Lq@]K2L ZsF1qTtqX Rhuv Pq wq$N&6MUK$sqsqJ2GuEQq<CVAux?>m<q7sq:289u5q 3uv 212u.x2,qxq!x q *+x'q(x 'q)xq'#x 'q)xq%x 'q)xq$x'q2"' (!0 IL/xq')(xqSx q@N<" >S 8d <2Switches, "then", "else", and string matching all treat upper and lower case letters asequivalent.SemanticsIn the case that yields true the in the then clause (if present) arepassed to the Executive (via rem.cm) for execution, otherwise the in the elseclause (if present) are passed.In the case of the /s switch each occurence of the character * in the indicates awildcard to be matched by zero or more characters in the file. This also has to be escapedpast the Executive command line reader.EXAMPLES1.A quit macro in user.cm for achieving the example given in the Introduction is:M.QUIT:"*qDelete @4acacacacerrlogCompiler -p/c @4 If.run/r @4acacacacerrlog then Bravo/m @4acacacacac"This uses the MESA run switch /r.2.The equivalent of the example given in the Introduction for the BCPL world is:bcpl/f prog.bcplIf prog.bt/s:ERROR: then Bravo/b progString matching is needed since BCPL creates a .bt file whether or not there are errors.A quit macro in user.cm for achieving the above is:B.QUIT:"*qbcpl/f @4If @4acacacacbt/s:ERROR: then Bravo/b @4acacacacac"3.An extension of the above example to both load and run a successfully compiled programis:bcpl/f prog.bcplIf prog.bt/s:ERROR: then bravo/b prog ^ else bldr prog'; prog4.A further extension, which compiles the program only if it has been edited since last beingcompiled, is:If prog.bcpl/c>prog.br/c then bcpl/f prog.bcplIf prog.bt/s:ERROR: then bravo/b prog ^ else bldr prog'; prog5.A command file to edit file.bravo which may be held either locally or remotely:If file.bravo else Ftp Ivy retrieve/c file.bravoBravo/n file.bravo6.Of course the above example is good only for the specific file file.bravo. It makes bettersense in conjunction with the system Do.run (q.v.):If #1 else Ftp Ivy retrieve/c #1Bravo/n #1which can be used with a command of the form:Do edit file.bravoNfqbL ` 2^Bu[q PZfOXVEUIS' Q+uv NqO(L{xqx(JqxK>sJxK>sJxK>sJxK>sJq(HxIssHxIssHxIssHxIssHxIssHxIssHxIssHxIssHxIss(GbxE q sq B@sq (@[x(>%<qsq,:'3(7x (6K(45s4x5s4x5s4x5s4x5s4x5s4x5s4x5s4x5s(2x 0qV/!(,x(+E'()& 'iq#8% (#x.(" '( & .qO(x0(R q=v3(x( Cq-( xz =ZgjMATH  TIMESROMAN  TIMESROMAN  TIMESROMANLOGO TIMESROMAN  TIMESROMAN TIMESROMAN GACHA  j/U?if.bravo SwinehartJuly 9, 1982 9:05 AM