A STORY OF SUBMIT, EX, AND ZCPR3'S ALIAS, or How I Learned that ZCPR3 is the Pinnacle of CP/M by Rick Charnes June 12, 1986 [published in FOGHORN sometime around May-July 1987] Copyright (c) First Osborne Group and Rick Charnes. This article ¨ may not be published anywhere without the express permission, in ¨ writing, from FOG. [This was my very first introduction to ZCPR3 - rc] ZCPR3 is great. I just found/invented/discovered the most ¨ elegant way imaginable to deal with a particular application that ¨ has challenged me for a year or so. A rather simple problem, but ¨ lots of fun to deal with. But let me go back to the beginning... Say I have a series of messages I've written to upload to a ¨ BBS. (Can you guess what I'm going to do with THIS message? ¨ Don't you just love the recursion?) First I have to "filter" ¨ them. I use Irv's FILTW. Now before EX15 came out which allows ¨ Smartkey to load along with it (on top of it? below it?), I ¨ couldn't use EX14 and so used plain old SUBMIT. My easy submit ¨ file was simply:  ¨           FILTW $1 FILTW $2 FILTW $3 . . . FILTW $9  ¨ I rarely have 9 files that I need to filter...but this was just ¨ in case. On the command line I enter the filenames which get ¨ substituted as parameters, and away we go. If I only enter 3 ¨ parameters, after the .SUB file has exhausted the 3, I hit ^C and ¨ the process is halted. Of course with SUBMIT you have to put up ¨ with silly and incessant disk accesses and the initial, ¨ laborious, and often noisy creation of the $$$.SUB file, etc.  ¨  ¨    OK, then EX15 came along and most of the time Smartkey and I ¨ were happy. Nice memory-based batch processing. But alas and ¨ alack--I couldn't get this particular .SUB file to work. In this ¨ application--when I had a varying number of parameters on the ¨ command line and hence generally fewer than in the actual batch ¨ file, it just wouldn't budge. I would get the error message: No parameter or default parameter error line # 3 as in: A0>ex fil harddisk me ¨ EX 1.5 11-22-82 No parameter or default parameter error line # 3 filtw b:$3 and it simply wouldn't run. I found it somewhat ironic that a ¨ program as acknowledgedly more sophisticated than SUBMIT would be ¨ much pickier in insisting on an exact equation between the number ¨ of parameters on the command line as in the command file. SUBMIT ¨ didn't mind if there was a difference; you just hit CTL-C and it ¨ aborted. EX, however, wouldn't run at all. Now the documentation for EX that everyone has must be a ¨ classical case of how a programmer makes information as uniquely ¨ inaccessible to the user as possible. I recognized that it had ¨ something to do with what the author was calling "default ¨ parameter substitution." But for the life of me I couldn't ¨ figure out how to implement this feature; the exact syntax ¨ completely eluded me. EX wanted to have parameters to stick in ¨ where I wasn't supplying them. As long as it had nothing, rather ¨ than not having anything, it would be happy. .  ¨      I stared at the documentation until my eyes glazed over, and ¨ tried all sorts of different methods and couldn't get it to work.  ¨ Finally I called Ken Fowler over at BAKUP, an excellent ¨ programmer, and with his help I was able to piece it together.  ¨ the .SUB file actually has to have an initial line, different ¨ from the actual command lines, looking precisely like:  ¨      ^$parm1 parm2 parm3 parm4 parm5 parm6 parm7 parm8 parm9 And I don't mean type the name of a parameter when you see the ¨ string "p-a-r-m" there; you actually type the letters p-a-r-m.  ¨ EX takes it as some sort of null parameter name, I guess. All I ¨ know is that it worked finally. "Worked finally" means here simply that I got it up to the ¨ level of SUBMIT, where I could enter any number of parameters ¨ from 1 to 9 on the command line and then abort the proceedings ¨ with a CTL-C. Where FILTW.SUB is my submit/EX file, consisting ¨ of the above line as its first line, then the rest of the file ¨ exactly as the SUBMIT file, and "ME" and "JU" are filenames, my ¨ terminal display now looked like this: A0>EX FILTW ME JU EX 1.5 11-22-82 (Ex Active) A0>filtw b:ME FILTW - Wordstar file filter Input and output files open Function complete. 7 input lines read 7 output lines with: 124 high-order bits deleted 0 CTL-characters deleted 0 dot commands removed 0 form feeds retained 0 soft hyphens fixed 0 space breaks fixed 0 orphan line feeds A0>filtw b:JU FILTW - Wordstar file filter Input and output files open Function complete. 26 input lines read 26 output lines with: 668 high-order bits deleted 0 CTL-characters deleted 0 dot commands removed 0 form feeds retained 0 soft hyphens fixed 0 space breaks fixed 0 orphan line feeds A0>filtw b:parm3 FILTW - Wordstar file filter ++ SOURCE FILE NOT FOUND ++ A0>filtw b:parm4 FILTW - Wordstar file filter ++ SOURCE FILE NOT FOUND ++ A0>filtw b:parm5 FILTW - Wordstar file filter ++ SOURCE FILE NOT FOUND ++ A0>filtw b:parm6 FILTW - Wordstar file filter ++ SOURCE FILE NOT FOUND ++ A0>filtw b:parm7 FILTW - Wordstar file filter >>>Ex Aborted<<< <--- this is where I hit CTL-C Now you may not think it such a victory to be able to get a ¨ program to give you 4 error messages and then abort, but for me ¨ it was. EX was substituting "parm" for the parameters, and ¨ finding no file, was passing on to the next, hoping to do better ¨ this time. I suppose any string representing a filename that ¨ doesn't exist would do; "p-a-r-m" really means nothing specific ¨ to EX.  ¨  ¨      I was partially satisfied and left the application and went ¨ on to other things for a number of months. Until this evening ¨ when I was riding home from work on BART and dreaming of ZCPR. I ¨ was wondering if I could do something similar to the kind of work ¨ I had been doing with MexPlus. With MexPlus' advanced "script" ¨ file feature--amounting virtually to a programming language of ¨ its own, leaving the public domain version in the dust looking at ¨ its own tail--I was writing files that would ask the user how ¨ many files he was uploading or transferring, then--using a ¨ looping/incrementing feature based on ye olde tried and true -  ¨      c=number of files to be transferred a=0 label begin a=a+1 . . . if a=c goto goodbye goto begin . . . label goodbye sendout "bye" ----MexPlus would then log off after the given number of files ¨ had been transferred. So the question I was asking myself was: ¨ how could I get ZCPR to "test" a condition--how could I get it to ¨ determine how many parameters were entered and then stop by ¨ itself when it had processed all of them _but only that number?_  ¨ And furthermore, for the sake of clean and crisp programming, how ¨ could I create this with the absolute minimum of ¨ characters/words/commands?  ¨ "IF", "SETFILE", and "SYSTEM FILE #1" to the rescue. First to explain some of the individual components of Z3 ¨ that I used. Number 1: the "SETFILE" command. Z3 uses what are ¨ called "system files". You can have up to 4 of them, and you ¨ define them with the SETFILE command. System files are just ¨ files that Z3 just keeps in its mind, ready to use them for ¨ whatever you want, by typing a particular string. See, Z3 has a ¨ better mind than CP/M. It can remember these things. If you ¨ tell Z3 "SETFILE 1 VDO.COM", then from then on--until I guess you ¨ cold boot--anytime you type "$N1" Z3 will substitute "VDO" right ¨ in there and you can do with it whatever you please. You can ¨ imagine the extremely varied and powerful uses to which this can ¨ be put. It's just like a $n variable in SUBMIT except it's ¨ hardier; it stays around from program to program, application to ¨ application. Anytime you want it, it's there just for the ¨ referencing. And again, you can define up to four of them. Individual component number 2: ZCPR3 has an "IF" command ¨ which in turn has an "EXISTS" argument (can be shortened to ¨ "EX"), that does exactly the testing I want. If the condition ¨ between it and the next "FI" (endif) is true---that is, if the ¨ following named file exists--then it continues on its merry way.  ¨ If not, it aborts. Sounds just like what I need, eh?  ¨      And what ties it all together, number 3: ZCPR3's "ALIAS" ¨ command. An "ALIAS" is simply a .COM file that ZCPR makes, ¨ wrapping up any number of individual commands you give it ¨ (separated by semicolons) into a nice little package-in-one, ¨ processing them "en batch" when you give the single command. An ¨ ALIAS is a perfect medium for the "system file" concept, and it ¨ will additionally allow normal "$1" variables a la SUBMIT _on top ¨ of that_. So naturally, I defined "FILTW" to be my system file ¨ #1. My ALIAS, named FILTER.COM, now contains the following ¨ commands, which do the job in the loveliest way: $N1 $1;IF EX $2;$N1 $2;FI;IF EX $3;$N1 $3;FI;IF EX $4;$N1 $4;FI Yes, I could have simply substituted "FILTW" where I have "$N1", ¨ but I wanted to have as much fun as possible. So: remember $N1 ¨ expands to FILTW, and the parameters given on the command line ¨ substitute for the normal $1, $2, etc. parameters. So, the first ¨ thing this program (alias) does is to FILTW file1. Then it ¨ checks to see if parameter number 2 exists. If it doesn't, ¨ that's the end of that; abort. (Or, as Z3 enthusiasts put it, ¨ "set flow state to false.") Then, "FI" ends the "if" condition ¨ testing. OK, start again: test to see if parameter 3 is there.  ¨ If so, FILTW it; if not abort. Etc. Works like a charm; it'll ¨ do exactly what I want it do and no more. When it has exhausted ¨ the parameters given it, it aborts back to the Z3 prompt and ¨ we're finished, ready now to send our messages to the BBS. ¨ One of the nicest parts of it for me is the watching and the ¨ seeing, or as some would say, the "progress reporting." It's a ¨ real delight to behold. You can see it process the "if" ¨ statements and go to the "fi" statements, and watch it setting ¨ the "command flow state" to true or false. Here's what I saw ¨ (all this courtesy of IO-CAP.COM, by the way, which _does_-- despite my initial skepticism--work under Z3): [My ALIAS is ¨ called FILTER.COM]: B:WORK>filter harddisk me me <-- I've entered 3 parameters FILTW - Wordstar file filter Input and output files open Function complete. 56 input lines read 56 output lines with: 0 high-order bits deleted 0 CTL-characters deleted 0 dot commands removed 0 form feeds retained 0 soft hyphens fixed 0 space breaks fixed 0 orphan line feeds IF T <----ZCPR3 has found the "if" condition (parameter 2 ¨               exists) to be "T", that is, "true", so it ¨               continues... FILTW - Wordstar file filter Input and output files open Function complete. 7 input lines read 7 output lines with: 0 high-order bits deleted 0 CTL-characters deleted 0 dot commands removed 0 form feeds retained 0 soft hyphens fixed 0 space breaks fixed 0 orphan line feeds To No IF <--- it's found the first "fi", but bypasses it IF T FILTW - Wordstar file filter Input and output files open Function complete. 7 input lines read 7 output lines with: 0 high-order bits deleted 0 CTL-characters deleted 0 dot commands removed 0 form feeds retained 0 soft hyphens fixed 0 space breaks fixed 0 orphan line feeds To No IF ¨  IF F <---now the "if" condition is "f" "false", and after To No IF <--- this line, we're booted back to command level B:WORK>filter me <--- I tried it with only one parameter, to ¨                         see what fun could have FILTW - Wordstar file filter Input and output files open Function complete. 7 input lines read 7 output lines with: 0 high-order bits deleted 0 CTL-characters deleted 0 dot commands removed 0 form feeds retained 0 soft hyphens fixed 0 space breaks fixed 0 orphan line feeds IF F To No IF <--- ¨  IF F <--- I really like these guys; they're really neat. To No IF <--- Actually in real life they spread themselves  ¨  IF F <--- diagonally across the screen like trees in ¨  To No IF <--- bloom. [I discovered a year and thousands of adventures later that these ¨ are the result of having the NOISE equate in SYSFCP.LIB set to ¨ TRUE. This apparently was the case with the early system I was ¨ using. - rc, 2/23/88] B:WORK> All of the condition testing seems to happen in memory; there ¨ are no disk accesses for the "if"s. It's very clean, quiet, ¨ fast, and extremely intelligent---just the way I like computers ¨ to be.  ¨ And that's that. Z3 is a heck of a lot of fun. Why don't ¨ you give it a try? Rick Charnes "Home board" Morrow BBS in Oakland, California (415) 654-3882