home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / ZCPR33 / TCJ / TCJ27.MAG < prev    next >
Text File  |  2000-06-30  |  31KB  |  549 lines

  1.  The ZSIG Column #3, January 10, 1987
  2. 
  3.  This file was prepared with the PMATE text editor.  All of these header
  4.  lines should be stripped away for use with other word processors.
  5.  I have used control-n in several places in the text to toggle underlining
  6.  on and off.
  7. 
  8. ZL14_10I
  9. R76;I8
  10.                               The ZSIG Column
  11.  
  12.                                   Jay Sage
  13.                              1435 Centre Street
  14.                           Newton Centre, MA 02159
  15.  
  16.  
  17.  
  18.      When I first offered to write a regular column for The Computerì
  19. Journal, I wondered if I would have enough material for a column every twoì
  20. months.  Instead, the problem has become one of finding the time to set downì
  21. all the thoughts I have.  For this issue I had planned to cover four topics,ì
  22. there is only room for three of them.  They are: 1) corrections of someì
  23. errors in the last column (and an excuse for more discussion of flow controlì
  24. in Z System); 2) a brief rundown on the files in the first officiallyì
  25. released ZSIG diskette; and 3) a discussion of command-line-buildingì
  26. programs in ZCPR3, including aliases and shells.
  27.  
  28.  
  29.                                 Corrections
  30.                 -----------
  31.  
  32.      There were two errors that I noticed in the last column.  One was aì
  33. minor one that was Art Carlson's fault; the other was more serious and wasì
  34. my doing.  First for the easy one.  Art was kind enough to add informationì
  35. at the end of the column on how to contact me, but the Z-Node he listedì
  36. there was not mine.  It was the Lillipute Z-Node in Chicago, which is theì
  37. official ZSIG remote access system (its phone number is 312-649-1730). ì
  38. Messages left for me there will get to me, but I will get them sooner ifì
  39. they are left for me on my own node in Boston at 617-965-7259.  I can alsoì
  40. be reached on my voice phone at 617-965-3552 (please don't mix the twoì
  41. numbers up, especially if you are calling in the middle of the night!). ì
  42. Finding me at home is not always easy, and your chances will be best if youì
  43. call between 10pm and just after 11pm (Boston time, of course).
  44.  
  45.      Now for the error I made.  In the discussion of the flow controlì
  46. package (FCP) and the transient IF.COM, I said that one can force use of theì
  47. transient program by including a DU: or DIR: prefix or even just a colon inì
  48. front of the 'IF'.  This is not true.  I thought I had verified theì
  49. statement experimentally, but my experiment was flawed, and the conclusionì
  50. incorrect.  A colon does force the command processor to skip commands in theì
  51. resident command package (RCP) and in the CPR itself and to proceed with aì
  52. search for a COM file, but all the FCP resident commands are intercepted noì
  53. matter whether there is a colon or not.  There is a very good reason forì
  54. this.  The FCP commands must be executed even when the current IF state isì
  55. false.  This is especially clear for commands like ELSE, which reverses theì
  56. current IF state, and FI, which terminates the current IF state.  Transientsì
  57. ELSE.COM and FI.COM could not do this.  After a bit of thought you canì
  58. probably see that this is true for all the flow control commands.
  59.  
  60.      I have long been searching for ways to give the user control overì
  61. whether IF processing is performed by resident or transient code.  Oneì
  62. solution that I introduced some time ago was adding alternative names forì
  63. condition options in IF.COM so that one could force the more powerfulì
  64. transient processing to be performed even when the function was supported byì
  65. the resident FCP.  The trick was to use condition names in IF.COM that wereì
  66. different from the names of the same functions in the FCP module. ì
  67. Specifically, I changed the first letters to 'X' (for example XXIST forì
  68. EXIST and XNPUT for INPUT).  Frank Gaude' in the Echelon Z-News has reportedì
  69. examples in which the transient program is given a name other than IF.COMì
  70. (such as IF13.COM).  Then the command "IF INPUT" gives resident processingì
  71. and "IF13 INPUT" transient processing.  This will work correctly for firstì
  72. level IF processing but will not work in general.
  73.  
  74.      Neither of these solutions was really satisfactory.  A proper solution,ì
  75. I felt, would operate both correctly and automatically.  I have now writtenì
  76. a new FCP package (FCP10) that is presently under test by ZSIG programì
  77. committee members and should be ready for release with the next ZSIGì
  78. diskette.  It handles both resident and transient code.  It can examine theì
  79. command line to see if there was a colon before the IF.  In that case, theì
  80. FCP ignores its internal condition options and invokes the transient IF.COMì
  81. immediately.  If no colon was present, the FCP first looks to see if theì
  82. condition option is included in the resident code.  If not, it automaticallyì
  83. invokes the transient IF processor.  The user need not be concerned withì
  84. which options are resident in the FCP.  The script "IF NULL $1" in an aliasì
  85. will take advantage of fast resident processing if the NULL option isì
  86. supported in the resident code or will automatically invoke transientì
  87. processing if not.  When one wants to be sure to get transient processing,ì
  88. one simply uses the colon as in ":IF EXIST FILE1,FILE2". 
  89.  
  90.      To go along with FCP10 there is a new transient IF processor, COMIF10. ì
  91. It supports dozens of additional condition tests.  One is AMBIG, which testsì
  92. a file specification for ambiguity (question marks or asterisks).  Registerì
  93. (numeric) and string (alphabetic) comparisons are now extended to the fullì
  94. range of tests: equal, not equal, greater, less, greater than or equal, andì
  95. less than or equal.  I plan to add file attribute testing (SYS, DIR, RO, RW,ì
  96. ARC, WP) and testing for the presence of Plu*Perfect Software's excitingì
  97. Backgrounder task-swapping program.
  98.  
  99.      The new FCP/COMIF combination also adds an important new twist inì
  100. transient processing.  They have the option of loading the transient codeì
  101. not at 100H, as has been done until now, but high in memory, where it willì
  102. not overwrite a user program that is loaded at 100H.  In this way the GOì
  103. command can be used to rerun the last user program after flow controlì
  104. processing no matter whether resident or transient flow processing was used. ì
  105. Thus the user need not concern himself with how the flow processing wasì
  106. performed.
  107.  
  108.      While I was at it, I also added two new commands to the FCP module. ì
  109. One, IFQ (if query), is designed to help users -- advanced as well as noviceì
  110. -- learn how flow control works (or, perhaps, is not working as oneì
  111. intends).  It displays on the screen the complete flow state of the systemì
  112. -- the true/false status of all IF levels.  The second is ZIF (zero ifs). ì
  113. It is like XIF (end all ifs) except for one thing.  XIF clears all IF statesì
  114. only if the current IF state is true; if the current IF state is false, XIFì
  115. is flushed (ignored) just like any other command.  ZIF, on the other hand,ì
  116. clears all IF states no matter what.  I'm sure that everyone who hasì
  117. experimented with flow control has at one time or another gotten himself soì
  118. messed up that nothing seemed to work.  The only way out, short ofì
  119. rebooting, was to type a string of FI's until things started working again. ì
  120. ZIF is a quick way to reinitialize the flow control system (and it takesì
  121. very little code in the FCP).
  122.  
  123.  
  124.                               ZSIG Diskette #1
  125.                   ----------------
  126.  
  127.  
  128.      Now that I have atoned, I hope, for my sin in the last issue, I willì
  129. turn to the first new subject, the inaugural ZSIG diskette.  Let me remindì
  130. you that this diskette and a number of others put out by NAOG/ZSIG (NAOG =ì
  131. North American One-Eighty Group, the group formed to support the SB180ì
  132. computer and other computers using the Hitachi HD64180 microprocessor) canì
  133. be ordered from NAOG/ZSIG (P.O. Box 2781, Warminster, PA 18974).  Iì
  134. encourage all of you to join ZSIG ($15).  You'll get a nice newletter with Zì
  135. System tips and details on all the NAOG/ZSIG diskettes.
  136.  
  137.      Here is a listing of the files in ZSIG diskette #1.
  138.  
  139.     Z-RIP.LBR    VERROR17.LBR    VCED18.LBR
  140.  
  141.     ZCRCK.LBR    ZFINDU.LBR    ZLDIR.LBR
  142.     ZTXTTOWS.LBR    ZWC.LBR
  143.  
  144.     PPIP14.LBR    UF.LBR
  145.  
  146.     LDSK20.LBR    W20.LBR
  147.  
  148. The first three programs are by Paul Pomerleau.  Paul is a speed freak and,ì
  149. like many of us, found the process of installing Z programs with Z3INS (theì
  150. standard installation utility) tedious and slow.  So Paul wrote Z-RIP, givenì
  151. that name because it rips through an entire disk of files at incredibleì
  152. speed, automatically identifying the ZCPR programs and installing them.  Theì
  153. new autoinstall versions of ZCPR3 may make Z-RIP (not to mention Z3INS)ì
  154. obsolete, but it is great for those running standard ZCPR.  VERROR is Paul'sì
  155. video error handler.  It provides a screen display of the entire commandì
  156. line in which an error was detected and allows the user to edit it freely,ì
  157. moving about using WordStar-like commands.  VCED is Paul's Video Commandì
  158. EDitor, a video history shell.  With VCED running as a shell, the userì
  159. always has full command-line editing.  In addition, past commands can beì
  160. recalled, searched for, edited, and run.  As if that were not enough, itì
  161. doubles as a video error handler as well!  Paul astutely noted theì
  162. functional similarity between correcting old commands with errors andì
  163. entering new commands -- so he combined the two functions in a singleì
  164. program.
  165.  
  166.      The next group of five programs comprises Z versions of common CP/Mì
  167. utilities.  Most of these were created by the prolific program fixer andì
  168. NAOG/ZSIG chief, Bruce Morgen.  The main feature that makes these programsì
  169. ZCPR3-compatible is their ability to accept named directory (DIR:)ì
  170. references as well as drive/user (DU:) references.  For programmers andì
  171. aspiring programmers reading this, you should know that the code to do thisì
  172. in ZCPR3 is actually much simpler than the CP/M code needed just toì
  173. recognize the DU: form.  This is because the ZCPR3 command processor alreadyì
  174. does all the work for the first two arguments on the command line (includingì
  175. translating named directory references into drive/user values).  Unlikeì
  176. CP/M, ZCPR3 saves not only the drive but also the user number in the defaultì
  177. file control blocks at 5CH and 6CH.  A ZCPR3 program need only fetch theì
  178. values from the appropriate locations.  The hardest part of making theseì
  179. ZCPR3 versions of the CP/M programs was stripping out the complex andì
  180. lengthy parsers required to accept DU: syntax in CP/M.  (So much for theì
  181. myth of ZCPR3 complexity!  Programming in ZCPR3 is often, as in thisì
  182. example, simpler than programming in standard CP/M.)
  183.  
  184.      The third group of programs includes two more ZCPR3 versions of CP/Mì
  185. programs.  They are listed separately only because they do not have namesì
  186. with Z's in front!  Here is a quick listing of the functions of all seven ofì
  187. these converted programs:
  188.  
  189.     ZCRCK        computes cyclic redundancy check codes for files
  190.             using both common CRC polynomials
  191.     ZFINDU        searches for text strings in files, including
  192.             files that are squeezed
  193.     ZLDIR        displays a directory of the files in a library
  194.     ZTXTTOWS    converts standard text files to WordStar files
  195.     ZWC        counts the number of words in a text file
  196.     PPIP14        copies files (as does PIP) but with nicer
  197.             interface and fast -- I renamed it to COPY
  198.             and use it all the time
  199.     UF        Steven Greenberg's ultrafast file unsqueezer
  200.  
  201.      The last two programs are original creations for the Z System.  LDSK,ì
  202. by Wilson Bent with modifications by Earl Boone, solves a longstandingì
  203. problem that owners of floppy-disk-based computers had with namedì
  204. directories.  With hard disks, there is an unchanging association betweenì
  205. directory names and drive/user values, but with floppies the associationì
  206. changes every time the diskette is changed.  Wilson devised this niftyì
  207. scheme for automatically loading the named directory register (NDR) with theì
  208. names associated with user areas on a floppy diskette.  To give a user areaì
  209. a name, one simply puts a (usually zero-length) file in that user area withì
  210. a name of the form "-NAME".  When LDSK is run (specifying the drive to beì
  211. loaded), it scans the disk for files of this type, strips the leadingì
  212. hyphen, and creates an entry in the NDR associating the name with that userì
  213. number on the drive.  As I wrote in the last column, I still have a lot ofì
  214. floppy-only systems, and I love LDSK.
  215.  
  216.      Haven't you at times wished that you could take some program that onlyì
  217. works on a single file and magically make it work with an ambiguous fileì
  218. reference.  Well, Steve Cohen did, so out of his programmer's hat he pulledì
  219. the wildcard shell 'W' to do it.  It just shows again that the only realì
  220. limitation with the Z System is one's imagination!  Here are some examplesì
  221. of how 'W' can be used.  Bob Freed wrote a quick little program called PCPCKì
  222. that checks a file for proper transmission over Telenet's PC-Pursuit packetì
  223. network (certain character sequences cause problems).  The trouble is, PCPCKì
  224. only works on a single file, and it is no fun to run it manually on everyì
  225. file one is about to send somewhere.  But along comes 'W' and all I have toì
  226. do is enter "W PCPCK *.*" and away we go.  Or suppose you are just lazy andì
  227. hate typing exact names of files.  Just put a 'W' in front of the commandì
  228. and enter a wildcard file name that specifies the file you want.  That's allì
  229. there is to it.  I have 'W' implemented in an alias on my Z-Node system soì
  230. that users can type a file without having to enter the exact name.  If aì
  231. user can't remember (or doesn't really care) whether the file isì
  232. AUTOINST.FIX or AUTOINST.FQZ or AUTOINST.FZX, all he has to enter is "TYPEì
  233. AUTO*.*" and the file (whatever it is called) will appear on the screen.
  234.  
  235.  
  236.                           Command Line Generators
  237.               -----------------------
  238.  
  239.      Many people call me about problems they are having getting an alias orì
  240. VFILER script to work correctly.  Often the problem turns out to be aì
  241. misunderstanding of what command line generators are really doing.  I willì
  242. try to shed a little more light on that subject here.
  243.  
  244.      First a little philosophy.  There are many features in the Z Systemì
  245. about which one might well at first just shrug one's shoulders and say, "Soì
  246. what!"  The flow control system discussed earlier is one such feature, andì
  247. multiple commands on a line might be another.  After all, how many of usì
  248. actually think far enough ahead to enter more than one command at a timeì
  249. anyway?  Well, the answer lies in the interplay of all the features in Zì
  250. System and in the ways they allow things to be accomplished automatically.
  251.  
  252.  
  253.                                   Aliases
  254.  
  255.      The multiple command capability of Z System, for example, is importantì
  256. not so much because it allows the user to enter a whole sequence of commandsì
  257. manually but rather because it allows other programs to do so automatically. ì
  258. The simple, standalone 'alias' created with the original ALIAS.COM or one ofì
  259. the more sophisticated alias programs like TALIAS, BALIAS, or VALIAS is aì
  260. good example.  Let's see how such an alias might be used.  Suppose we areì
  261. working on a new program with a source file called MYPROG.Z80.  Our standardì
  262. sequence of operations is to edit the source with a command like "EDITì
  263. MYPROG.Z80" and then to assemble it with a command like "ASM MYPROG.AAZ" andì
  264. then to load it with a command like "MLOAD MYPROG".  We can speed things upì
  265. and reduce the amount of typing (and the number of typos!) by creating anì
  266. alias which we might give the name DO.COM.  We would create it, with VALIASì
  267. for example, with the following script (command line form):
  268.  
  269.     EDIT MYPROG.Z80;ASM MYPROG.AAZ;MLOAD MYPROG
  270.  
  271. Now when we want to start a new cycle, we just enter the easily spelledì
  272. command "DO".  The rest is automatic.
  273.  
  274.      But how does this alias actually work?  When you enter the commandì
  275. "DO", the operating system loads DO.COM into memory and starts running it. ì
  276. DO contains within its file the script line put there by VALIAS.COM (forì
  277. example) when the alias was created.  DO.COM has code to determine where theì
  278. Z System multiple command line is located in memory (this information comesì
  279. from what is called the environment descriptor, whose address is installedì
  280. in a standard location near the beginning of all true Z System programs). ì
  281. Next DO.COM takes its command script, appends any other commands in theì
  282. multiple command line that come after the "DO" command, and then writes theì
  283. result back to the command line buffer.  When it then returns to Z System,ì
  284. the ZCPR3 command processor, as usual, looks at the command line buffer toì
  285. see if there are more jobs listed there for it to do.  Since DO.COM hasì
  286. filled the command line buffer with the script, ZCPR3 responds just as if weì
  287. had typed the long command line script instead of the simple "DO".
  288.  
  289.      Now let's see how flow control can be used with alias scripts.  Oneì
  290. problem with the command sequence in our example arises when the assemblerì
  291. reports an error.  In that case there is no sense going through the MLOADì
  292. operation.  Assemblers like ZAS from Echelon and Z80ASM from SLR Systems setì
  293. a flag in the Z System to show whether or not they encountered any fatalì
  294. errors during the assembly, and the flow control command "IF ERROR" can testì
  295. the state of that flag.  We can improve our script as follows:
  296.  
  297.     EDIT MYPROG.Z80;ZAS MYPROG;IF ~ERROR;MLOAD MYPROG;FI
  298.  
  299. In this script the MLOAD command will only be executed if the program errorì
  300. flag has not been set by ZAS (the tilde '~' has the meaning 'not').  Typingì
  301. all those flow control commands manually would be more trouble than enteringì
  302. single commands at a time, but with an alias we are still typing only twoì
  303. letters: "DO".
  304.  
  305.      So far so good.  But what happens when we want to start work on anotherì
  306. program, say NEWPROG?  Do we have to create a new alias, such as DONEW?  Theì
  307. answer is that the alias program actually does much more than just copy aì
  308. command script as is into the multiple command line buffer.  It is capableì
  309. of making parameter expansions, the simpler examples of which are like theì
  310. parameter expansions that occur with the CP/M SUBMIT program.  We can storeì
  311. the alias script as
  312.  
  313.     EDIT $1.Z80;ZAS $1;IF ~ERROR;MLOAD $1;FI
  314.  
  315. The '$1' is a symbol representing the first token after the command on theì
  316. command line that invoked the alias program.  Thus when we enter the commandì
  317. "DO MYPROG" we get the first script we discussed, but when we enter "DOì
  318. NEWPROG" we get a command line for working on NEWPROG instead.  A singleì
  319. alias thus becomes very flexible.  There are quite a number of parameterì
  320. forms that can be processed by aliases, and I refer you to Rick Conn'sì
  321. "ZCPR3, The Manual" and various HELP files for more detailed information.
  322.  
  323.      Now let's try something a little trickier.  Sometimes we have alreadyì
  324. edited a file and just want to assemble and load it (if there is no error inì
  325. assembling, of course).  So we create an alias called AL (for assemble/link)
  326.  
  327.     ZAS $1;IF ~ERROR;MLOAD $1;FI
  328.  
  329. [I am using ZAS in these examples rather than the SLR Z80ASM, which Iì
  330. prefer, because the SLR assemblers can produce a COM file directly in oneì
  331. pass and do not need MLOAD or the flow control error checking.  Thus they doì
  332. not serve the purposes of my example here.]  Now what do you think willì
  333. happen if we define our DO alias as follows:
  334.  
  335.     EDIT $1.Z80;AL $1
  336.  
  337. Do you think that will work?  One alias inside another?  Well, it willì
  338. indeed!  Aliases can be nested.  How deeply?  Without any limit!  Before weì
  339. explain why this is, let's look at an even more fascinating example.  When Iì
  340. sit down to work on a program, I typically go through one edit/assembleì
  341. cycle after another (just don't seem to be able to get it right the firstì
  342. time).  So I make my DO alias have the following script:
  343.  
  344.     EDIT $1.Z80;AL $1;DO $1
  345.  
  346. This alias actually invokes itself!!  When one cycle is finished, it justì
  347. goes back for more.  Now let's look at what goes on in the system after weì
  348. enter the command "DO MYPROG".  The DO alias expands its script and writesì
  349. the following command line into the multiple command line buffer:
  350.  
  351.     EDIT MYPROG.Z80;AL MYPROG;DO MYPROG.
  352.  
  353. After the editing is finished, AL runs, expands its script, and fills theì
  354. command line buffer with the following command line:
  355.  
  356.     ZAS MYPROG;IF ~ERROR;MLOAD MYPROG;FI;DO MYPROG
  357.  
  358. Note that the alias always appends to its own script any other commands inì
  359. the command line after itself (hence the DO MYPROG on the end).  Now ZASì
  360. runs, and, depending on whether there were errors or not, MLOAD may run. ì
  361. Finally ZCPR3 gets to the DO command, and we are right back where weì
  362. started.  The whole process is repeated (and repeated again).  In fact, theì
  363. only trouble with this alias is that there is no way out!  You can't stop!
  364.  
  365.      Well, we all hope we will get the program right eventually, so weì
  366. really would like to be able to get out of the alias.  Flow control can helpì
  367. us again.  Consider the script
  368.  
  369.     EDIT $1.Z80;AL $1;ECHO EDIT AGAIN?;IF INPUT;DO $1;FI
  370.  
  371. Now, before reinvoking DO, the alias asks us if we want to edit the fileì
  372. again.  If we give a negative answer (anything other than carriage return,ì
  373. space bar, 'Y' for yes, or 'T' for true), the loop is broken.  If we answerì
  374. affirmatively with a quick tap of the return key, we start again.  Veryì
  375. quick and easy.
  376.  
  377.      There is one subtle problem, however.  If you go through the exerciseì
  378. of expanding the alias scripts, you will see that with each cycle an extraì
  379. 'FI' builds up at the end of the command line.  Even more careful analysisì
  380. will show that with each cycle we go one IF level deeper as well.  One ofì
  381. two problems will eventually spoil our plan.  Either the command line willì
  382. get so long that it won't fit in the command line buffer, or we will run outì
  383. of IF levels (eight is the maximum).  What can we do about these problems?
  384.  
  385.      The FCP has the XIF command precisely for this reason.  If we put anì
  386. XIF command at the beginning of the script, we will reset the IF system toì
  387. level 0 every time we reenter the loop.  Then the limit will be overflow ofì
  388. the command line.  When this happened to me, I invented a special type ofì
  389. alias -- the recursive alias -- and incorporated it into my VALIAS programì
  390. (as far as I know only VALIAS and ARUNZ support this alias type).  It worksì
  391. the same as a regular alias except for one thing -- it does not append toì
  392. the script expansion any commands that were pending in the command lineì
  393. buffer; it just throws them away.  Thus in the above example all the FIsì
  394. would be discarded when DO was invoked again, and the pileup would beì
  395. avoided.  When an alias is created with VALIAS, one can select either aì
  396. normal alias or a recursive alias.  But note that no other command can everì
  397. follow a recursive alias on a multiple command line.  Recursive aliasesì
  398. should be used only in special cases like the one described here.
  399.  
  400.  
  401.                                    Shells
  402.  
  403.      Aliases are not the only command line generators.  Most shells alsoì
  404. generate command lines for the user.  In some cases (VCED, described above,ì
  405. and MENU) this is their main purpose; in other cases it is secondaryì
  406. (VFILER).  Before we examine the way they generate command lines, let's lookì
  407. at the way shells operate in the Z System.
  408.  
  409.      The essential purpose of shells is to create just the kind of recursiveì
  410. command situation we were just developing with our alias example.  But theyì
  411. achieve that function in a very different way.  A shell has a kind ofì
  412. schizophrenic personality as a result of being invoked in two significantlyì
  413. different circumstances.  One circumstance is when it is invoked directly orì
  414. indirectly (e.g., from an alias) as the result of a user command.  In thisì
  415. case, the shell has one basic purpose -- to perpetuate its own existence asì
  416. a command.  It does this by entering its name as a command into a specialì
  417. buffer (area in memory) in the Z System called the shell stack.  Having doneì
  418. that, it can then return control to the operating system.  (The smarterì
  419. shells generally do something a little more sophisticated at this point, butì
  420. the principle is correct as I have described it.)
  421.  
  422.      Now we come to the unique role of shells in the Z System.  The CP/Mì
  423. command processor gets commands from only two possible sources: 1) from aì
  424. submit file, if one exists, or 2) from the user.  The Z System gets commandsì
  425. from at least four sources and in the following order of priority (ignoringì
  426. the tricky role of ZEX): 1) from the multiple command line buffer; 2) from aì
  427. submit file; 3) from the shell stack; and 4) if all else fails, from theì
  428. user.  Observe that so long as the shell stack has a command in it, theì
  429. command processor will never turn to the user for input!  That is why oneì
  430. can regard the shell as taking over the command processor function.  Whileì
  431. the shell is running, it becomes the source of commands for the system.
  432.  
  433.      How does the shell do this?  By expressing its second and more dramaticì
  434. personality.  Another special buffer in the Z System, the message buffer,ì
  435. contains a flag byte that is set by the ZCPR3 command processor to indicateì
  436. whether a program has been invoked as a user command or as a shell (or as anì
  437. error handler).  We have already discussed the simple goal of the shell inì
  438. the former case.  In the latter case the shell actually carries out its realì
  439. function in life.  Let's consider the MENU shell as an example.
  440.  
  441.      When the MENU.COM is loaded as a shell, it displays a screen of commandì
  442. choices to the user.  Each single-character choice is associated with aì
  443. command line script, much like the alias script.  When the user strikes aì
  444. key, MENU looks up the script associated with that character, expands theì
  445. script (substituting parameters), and puts the resulting command into theì
  446. multiple command line buffer.  It then returns control to the ZCPR3 commandì
  447. processor.  ZCPR3 executes the commands in the command buffer one afterì
  448. another until they have all been performed.  Then, when the command bufferì
  449. is empty again, ZCPR3 looks in the shell stack, finds the MENU commandì
  450. there, and runs MENU again.  This process continues until a special user keyì
  451. is entered (control-c in the case of MENU) that signals the shell that itì
  452. should remove itself from the shell stack.  Then things return to the stateì
  453. they were in before the shell was invoked initially by the user.     ì
  454. Shells, by the way, can be nested (the usual shell stack is four entriesì
  455. deep), so when one shell removes itself from the shell stack, control mayì
  456. still not return to the user.  Another shell, whose role was superceded byì
  457. the most recent shell, may now come back into control.
  458.  
  459.      With the MENU.COM the displayed menu of choices and the scriptsì
  460. associated with the choices are both included in a text file that is read inì
  461. by the program.  This makes it very easy for the user to create and modifyì
  462. the display and the scripts.  Considering again our program developmentì
  463. example, we might create a menu screen with the following display:
  464.  
  465.         S. Select name of program
  466.         E. Edit program source code
  467.         A. Assemble program to HEX file
  468.         L. Load program to COM file
  469.         R. Run program
  470.         F. Full cycle (edit, assemble, load)
  471.  
  472. These choices might be associated with the following command scripts:
  473.  
  474.     S setfile 1 "Enter name (only) of program to work on: "
  475.     E edit $n1.Z80
  476.     A zas $n1
  477.     L mload $n1
  478.     R $n1
  479.     F edit $n1.z80;zas $n1;if ~er;mload $n1;fi
  480.  
  481.      There are two interesting new parameters illustrated in these scripts. ì
  482. One is the $N1 parameter.  As part of the Z System environment buffer, fourì
  483. system file names are defined.  MENU can read these four file names and putì
  484. into scripts the complete filename ($Fn), the name only ($Nn), or the typeì
  485. only ($Tn), where 'n' is 1, 2, 3, or 4.  The 'S' selection sets the firstì
  486. system file name using the program SETFILE, and the others then use it.
  487.  
  488.      The 'S' selection illustrates the other new script parameter --ì
  489. prompted user input.  When the script for choice 'S' is being expanded, theì
  490. text between quotes will be displayed as a prompt to the user, and one lineì
  491. of user input will be substituted into the command line in place of theì
  492. prompt.  It is with prompted input that many users get confused and makeì
  493. mistakes.  Suppose you want to be clever and helpful by displaying aì
  494. directory of existing programs to jog the user's memory before asking forì
  495. his choice.  You might think of using the script
  496.  
  497.     S dir *.z80;setfile 1 "Enter program name: "
  498.  
  499. This will not have the effect intended!  One must not forget that the userì
  500. is prompted for input by the shell at the time the script is expanded, notì
  501. at the time when the command line is executed.  In this example the userì
  502. will be prompted for his choice before the directory is displayed.  Thus,ì
  503. the directory display is useless.
  504.  
  505.      To achieve the result intended above you must combine scripts.  You canì
  506. create an ARUNZ alias called SETNAME with the following script (ARUNZì
  507. supports prompted input):
  508.  
  509.     SETNAME setfile 1 "Enter name of file: "
  510.  
  511. The MENU script would then be
  512.  
  513.     S dir *.z80;arunz setname
  514.  
  515. When the MENU script is expanded, the command becomes "DIR *.Z80;ARUNZì
  516. SETNAME", and this command is then run.  It is not until ARUNZ SETNAME isì
  517. executed that ARUNZ prompts the user for the name of the file.  At thisì
  518. point the directory of files with type Z80 has already been displayed on theì
  519. screen.
  520.  
  521.      There is obviously much more that could be said about the command lineì
  522. generators in ZCPR3.  The discussion here has been only an overview, but Iì
  523. hope that it will inspire you to take a fresh look at and to experiment withì
  524. aliases and shells of all kinds: the standalone aliases generated by ALIAS,ì
  525. VALIAS, TALIAS, or BALIAS; the text-file-based alias generator ARUNZ withì
  526. its ALIAS.CMD file; the menu- or macro-type shells MENU, VMENU, FMANAGER,ì
  527. VFILER, and ZFILER; and the command-line history shells HSH and VCED.
  528.  
  529.  
  530.                             Plans for Next Time
  531.                 -------------------
  532.  
  533.      As I said at the beginning of the article, I had planned to cover,ì
  534. along with all the subjects above, techniques for customizing the Z-COMì
  535. self-installing version of Z System.  But there just isn't the time orì
  536. space.  So I will have to leave that for the next issue.  Let me just sayì
  537. one thing here.  If you do not already have Z System running on yourì
  538. computer and have held back on buying Z-COM from Echelon because you thoughtì
  539. it would not offer you the flexibility of a custom installation, hold off noì
  540. longer.  Buy Z-COM!  Start the exhilarating process of discovering Z Systemì
  541. now.  By the time my discussion of Z-COM hacking is complete, you will knowì
  542. how to get just as much flexibility with Z-COM as with a manually installedì
  543. version.  It is much more fun to start with something that is working and toì
  544. improve it than it is to spend many frustrating weeks trying to get anì
  545. initial manual version working.
  546.  
  547.      I want to close with my usual invitation and encouragement -- pleaseì
  548. write and call with your comments and suggestions of all kinds.
  549.