home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / tcj / tcj44.ws < prev    next >
Encoding:
Text File  |  1994-09-02  |  35.1 KB  |  705 lines

  1. TCJ #44
  2.  
  3.                             The Z-System Corner
  4.  
  5.                                   Jay Sage
  6.  
  7.  
  8.    For this issue (and the next) I am going to indulge myself and writeì
  9. about about something that I enjoy, even though, strictly speaking, it hasì
  10. nothing to do with Z-System.  This subject is MEX-Plus, the most advancedì
  11. telecommunications package available for CP/M computers.  I suppose I couldì
  12. argue that there is a philosophical or spiritual connection, since MEX-Plusì
  13. allows the user do for telecommunications many of the same things that Z¡
  14. System allows one to do with the operating system, namely automate.  Inì
  15. particular, I will be describing MEX-Plus's scripting capabilities, whichì
  16. are similar in some ways to alias and ARUNZ scripts in Z-System.
  17.  
  18.    I had been hoping that a regular MEX column would develop here in TCJ,ì
  19. but that hasn't happened.  Two of the people who might have gotten it going,ì
  20. Bruce Morgen and Rick Charnes, are now employed in the MS-DOS industry, and,ì
  21. after programming all day professionally, they don't seem to have as muchì
  22. energy left for hobby computing as they used to.  Recently, Davidì
  23. Goodenough, author of the QTERM telecommunications package, came over to myì
  24. house and got QTERM running on my SB180 with its Wyse 50 terminal.  I amì
  25. enormously impressed with what David has accomplished with this program; itì
  26. is rapidly developing many of the capabilities of MEX-Plus.  I can envisionì
  27. much discussion in the future of both MEX-Plus and QTERM scripts.  You canì
  28. also expect an article or two about QTERM.
  29.  
  30.    For this column I will give an overview of MEX's command structure, andì
  31. next time I will describe in detail my suite of scripts for using PC-Pursuitì
  32. as an example of what can be done using those commands.  (I originallyì
  33. planned to cover both in one article, but after finishing the description ofì
  34. the commands, I was already at my limit.)  Along the way I will try to pointì
  35. out some of the bugs and idiosyncrasies that users have discovered in MEXì
  36. commands and suggest means to get around them.  I hope that my examples willì
  37. help give others ideas about how to make better use of MEX-Plus.  Althoughì
  38. regrettably I have had very few takers in the past, I again extend anì
  39. invitation to readers to send me suggestions and examples for scripts.
  40.  
  41.  
  42.                          Overview of MEX Commands
  43.  
  44.  
  45.    The original CP/M telecommunication program MODEM7 and its derivatives,ì
  46. such as IMP, operate in two modes: terminal mode and command mode.  Terminalì
  47. mode is used for talking to the remote system, while command mode is used toì
  48. control the local system.  These programs have a relatively small set ofì
  49. commands falling principally into two classes: those required for fileì
  50. transfers and those related to the setup of the program.
  51.  
  52.    In MEX-Plus the arsenal of commands is extended enormously, and anythingì
  53. that could be done from terminal mode can be done from command mode as well. ì
  54. (You would not want to run an interactive session this way, but it could beì
  55. done.)  There are so many commands that, though I will mention almost all ofì
  56. them, I will not be able to explain them all in detail.  Rather, I hope toì
  57. give you a general picture of the kinds of tools one has to work with inì
  58. MEX-Plus.  I will take up the commands in groups.
  59.  
  60.  
  61. Setup Commands
  62. --------------
  63.  
  64.    Most of MEX's configuration is controlled by three commands: STAT, SET,ì
  65. and TSET.  The STAT command works with more than 50 different options!  Allì
  66. of them can display information about how the system is configured, and allì
  67. but a few also allow the configuration to be changed.  The MEX STATì
  68. parameters fall into four classes: switches, characters, values, andì
  69. miscellaneous.
  70.  
  71.    Switches have values of ON or OFF.  One example is FILTER, which controlsì
  72. whether MEX will filter from the incoming modem stream any controlì
  73. characters other than tab, backspace, carriage return, and linefeed.  If oneì
  74. wants to perform full screen operations, this filter must be off. ì
  75. Otherwise, the escape characters that initiate a screen control sequenceì
  76. will be swallowed by MEX.
  77.  
  78.    Character STAT parameters take a single ASCII character as their value. ì
  79. An example is SEP, the multiple command separator (like Z-System, MEX-Plusì
  80. allows multiple commands on a line).  Value parameters take on numericalì
  81. values.  For example, PAGE sets the number of lines in a page on the screen,ì
  82. and CLOCK is set to the clock speed of your microprocessor chip so thatì
  83. timing delays will come out right.  The miscellaneous STAT parameters mostlyì
  84. control the display of groups of information.  "STAT ?" lists all the STATì
  85. parameters; "STAT VAL" shows the value parameters.
  86.  
  87.    The SET command controls the modem setup.  It is used for setting theì
  88. baud rate, word length, number of stop bits, and parity mode.  The TSETì
  89. command was one I never used until working on this article.  It controlsì
  90. special features related to the terminal (what is does depends on theì
  91. terminal you are using).  With my Wyse 50, a TSET parameter can force allì
  92. characters to be displayed in upper case characters or in highlighted videoì
  93. (that should give you some idea of why I have never used this command).
  94.  
  95.  
  96. Operating System Commands
  97. -------------------------
  98.  
  99.    Another group of commands deals with the interface to the operatingì
  100. system.
  101.  
  102.    Naturally, there has to be a way to get out of MEX and back to theì
  103. operating system prompt.  Have you ever been trapped inside a program, notì
  104. knowing how to exit?  Well, MEX author Ron Fowler must have had such aì
  105. harrowing experience, because he has six (count 'em!) commands for gettingì
  106. out: BYE, EXIT, QUIT, CPM, DOS, and SYSTEM.  SYSTEM must come from BASIC,ì
  107. which is the only CP/M program I ever became trapped inside.  MEX-Plus isì
  108. available in an MS-DOS version as well, and that is where the exit commandì
  109. DOS comes from.  As a CP/M diehard, I take great pleasure, as you canì
  110. imagine, in exiting from my DOS version using the command CPM (it doesn'tì
  111. help -- I'm still in MS-DOS after I exit).
  112.  
  113.    There are commands for doing operating system chores: DIR, REN, ERA (or,ì
  114. following MS-DOS, DEL), TYPE, and LOG (change drive/user).  Some of theseì
  115. commands not only perform their functions; they also return information forì
  116. use in a script file.  DIR, for example, sets a special variable to theì
  117. number of matching files found, and thus can be used to determine whether aì
  118. particular file exists or not.
  119.  
  120.    There are the commands KEY for associating strings with any ASCII key onì
  121. the keyboard and PHONE for entering phone numbers into a dialing library. ì
  122. The key definitions and phone number library can be stored in disk filesì
  123. with the respective extensions KEY and PHN.  The commands SAVE and LOADì
  124. write the data to and read the data from the files.
  125.  
  126.    MEX-Plus has a facility, via the INSTALL command, to load optional extraì
  127. code modules.  One such module (the REMOTE module) allows MEX-Plus to beì
  128. operated as a remote access system.  I have used this with both direct wireì
  129. and modem connections between machines.  The former is handy when twoì
  130. machines are connected by a cable, as it relieves one of the need to runì
  131. back and forth between the two keyboards to issue file transfer commands.  Iì
  132. sometimes leave my system at work in remote mode so that I can call it fromì
  133. home to pick up a file that I forgot to take with me.  Other optionalì
  134. modules support emulation of various terminals, including the VT100.
  135.  
  136.    The TERM and TERMA commands open a file to record the incoming characterì
  137. stream from the modem.  TERM creates a new file, while TERMA appends the newì
  138. text to an existing file.  The terminal mode commands T, L, and E describedì
  139. below can also take an optional 'A' suffix and capture file name.  In thoseì
  140. cases, once the capture file has been opened, MEX is put into terminal mode. ì
  141. The TERM and TERMA commands leave MEX in command mode for further scriptì
  142. processing.  The VIEW command allows the contents of the capture file to beì
  143. reviewed while online, thereby affording some scroll-back capability (thatì
  144. is, a way to see text that has already scrolled off the screen).  WRT closesì
  145. the capture file (saves it) when you are done; DEL discards it.
  146.  
  147.    The ALT command specifies an alternate drive/user area (in addition toì
  148. the currently logged one) where MEX can search automatically for filesì
  149. (e.g., scripts, phone directory, etc.).  The SEARCH command tells MEX how toì
  150. go about searching for files, such as whether to search the alternate areaì
  151. before or after the logged area.
  152.  
  153.    As you can probably guess already, it is not easy to remember all theseì
  154. commands and the syntax they require.  That is where the HELP command comesì
  155. in handy.  It accesses an extensive HLP file (over 70K).  There is also theì
  156. wonderful CLONE command, which creates a new version of MEX (i.e., a new COMì
  157. file) with the current configuration embedded -- after the STAT, SET, TSET,ì
  158. and other commands have been used to change parameters to one's liking.
  159.  
  160.  
  161. Telephone Interface Commands
  162. ----------------------------
  163.  
  164.    MEX-Plus has two phone-dialing commands, CALL and DIAL.  Both acceptì
  165. lists of either literal telephone numbers or names from the phone library. ì
  166. Numbers and names may be mixed.  Numbers in the library may have associatedì
  167. baud rates, which will be selected automatically when that number is dialed. ì
  168. An optional parameter specifies the number of times to try connecting to theì
  169. numbers before giving up, and the commands return a value to indicate whichì
  170. number, if any, was reached.  Here is an example:
  171.  
  172.                 CALL LADERA 617-965-7259 #3
  173.  
  174. This will alternately called the Ladera Z-Node (whose number is in theì
  175. library) and my Z-Node up to three times before giving up.  The commandsì
  176. differ in that CALL puts one in terminal mode after a successful connection,ì
  177. while DIAL leaves one in command mode for further script processing.
  178.  
  179.    There is also a way to get out of a connection.  DSC will tell the modemì
  180. to drop the connection.  It can be configured (using a STAT command, ofì
  181. course) to use either the DTR (data terminal ready) hardware control line orì
  182. the Hayes AT hangup command.
  183.  
  184.  
  185. Terminal Commands
  186. -----------------
  187.  
  188.    There are three commands for entering terminal mode.  The command Tì
  189. (terminal) sets up a full-duplex terminal mode.  Characters typed at theì
  190. keyboard are sent to the modem; characters received from the modem are sentì
  191. to the screen.  If you are to see what you are typing, the remote systemì
  192. must echo back the characters it receives from you.  Most microcomputer BBSì
  193. systems do that.
  194.  
  195.    The L (local echo) command sets up a half-duplex terminal mode.  Theì
  196. difference is that the characters that you type are not only sent to theì
  197. modem for transmission to the remote system; they are also echoed locally. ì
  198. This mode would be used with systems like GEnie that do not normally echoì
  199. the characters they receive from you.
  200.  
  201.    Finally, the E (echo) command sets you up as if you were a remote host. ì
  202. Every character you receive is then echoed back to the modem.  If two peopleì
  203. running MEX call each other (or two machines are hooked up by cable as Iì
  204. mentioned earlier), either both should be in L mode, or one should be in Tì
  205. mode and the other in E mode.  I prefer the latter, since seeing theì
  206. characters on the screen of the machine in T mode assures that theì
  207. connection is working.  I leave it as an exercise to the reader to figureì
  208. out what will happen if both machines are in E mode.  (Hint: feel free toì
  209. experiment; you can get out of the infinite loop by exiting from terminalì
  210. mode; you don't have to reboot.)
  211.  
  212.  
  213. File Transfer Commands
  214. ----------------------
  215.  
  216.    Files are sent to the other computer using the S command, and receivedì
  217. from the other computer using the R command.  MEX-Plus supports three fileì
  218. transfer protocols: KERMIT, XMODEM, and YMODEM.  The default protocol is setì
  219. with the PROTO command.  The protocol can also be specified explicitly usingì
  220. a prefix (K, M, or Y) to the S or R command.
  221.  
  222.    The commands will also accept any of several suffixes as well.  Theì
  223. suffix B indicates a batch-mode transfer.  The K suffix with the S commandì
  224. indicates that the file should be sent in blocks of 1K bytes instead of theì
  225. standard 128 bytes.  If you append T, L, or E, you will return to theì
  226. corresponding terminal mode after the transfer is completed.  The D and Xì
  227. suffixes will tell MEX to disconnect from the remote system after theì
  228. transfer is finished; with D you will return to MEX, while with X you willì
  229. exit MEX as well.  Here is an example.
  230.  
  231.                 YSBKX FILE1 FILE2 FILE3
  232.  
  233. This will send the three files using YMODEM batch with 1K blocks, hang upì
  234. the phone, and exit from MEX.
  235.  
  236.    Transactions with a host in the KERMIT server mode are supported with aì
  237. number of special commands (KGET, KPUT, KBYE, KLOG, KFIN).
  238.  
  239.  
  240. Video Commands
  241. --------------
  242.  
  243.    These are the commands that Rick Charnes loves so!  There are commandsì
  244. for cursor addressing (@), beginning and ending the use of up to four videoì
  245. attributes (START and END), displaying special line-drawing graphicsì
  246. characters (DRAW), and creating lines and boxes (HLINE, VLINE, BOX).  Theì
  247. screen can be cleared (CLS).  It can also be turned on and off (SCREEN) soì
  248. you can control what output is seen and what is not.
  249.  
  250.  
  251. Variables
  252. ---------
  253.  
  254.    It is hard to do very sophisticated processing without variables.  MEX¡
  255. Plus offers variables of two types: numerical and string.  The former areì
  256. 16-bit integers (i.e., numbers from 0 to 65535); the latter are strings ofì
  257. up to 32 characters.
  258.  
  259.    There are 26 numerical user variables designated by a percent signì
  260. followed by a letter (case does not matter, e.g., %a or %S).  There are sixì
  261. string variables designated by the letters A through F.  I've never run outì
  262. of numerical variables, but I sure wish there were more string variables.
  263.  
  264.    There are also two special numerical variables called VALUE and STACK. ì
  265. The former is used to hold the value returned from a number of MEX commandsì
  266. (DIR and DIAL/CALL were mentioned earlier).  STACK is a more long-livedì
  267. variable that can be exchanged in various ways with VALUE (the commandsì
  268. PUSH, POP, and XCHG).  I think these are left over from earlier versions ofì
  269. MEX that did not offer the 26 user variables.  There is little reason to useì
  270. STACK any more.  There are three special operations (ADD, SUB, and XOR) thatì
  271. can be performed on the VALUE variable.  I've never found any use for these,ì
  272. either.
  273.  
  274.    MEX can evaluate arithmetic expressions consisting of combinations ofì
  275. literal numbers, numerical variables, and arithmetic operators (+-*/).  Hereì
  276. is an example that returns the least significant byte of the two-byteì
  277. variable %V:
  278.  
  279.                 %V - 256 * ( %V / 256 )
  280.  
  281. Numbers can be entered in hexadecimal format by prefixing the number with aì
  282. dollar sign ($100 is 256).
  283.  
  284.    The value of an expression is assigned to a variable by the equalì
  285. operator (=) as in %B=%A+3.  NOTE: in most places in MEX-Plus, extra spacesì
  286. may be included in command expressions.  However, there are unfortunately aì
  287. number of bugs in MEX-Plus, and some rear their heads in this area. ì
  288. Therefore, I recommend that extra spaces be omitted in working scripts (asì
  289. opposed to fully commented reference versions, where extra spaces might beì
  290. included to improve readability).
  291.  
  292.    Literal string expressions are composed by surrounding text with double¡
  293. quote characters (").  The MEX manual says that values are assigned toì
  294. string variables using the STORE command as in:
  295.  
  296.              STORE "this is a test" TO A.
  297.  
  298. Experiment shows that the following simpler, undocumented syntax also works:ì
  299. A="test".  Here I know from bitter experience that there should be no extraì
  300. spaces around the equal sign.  It often works, but not always.  Mostì
  301. commands that accept quoted literal strings will also accept stringì
  302. variables (e.g., B=A or COMP A "yes").
  303.  
  304.    Command line parameters are also available to scripts; they are passed inì
  305. the form of variables represented by the numbers 1 through 9 surrounded byì
  306. curly braces.  These variables can always act as strings.  If they express aì
  307. number, they can also be used as numerical expressions.  Thus, we might haveì
  308. A="{1}" or %A={1}.  The latter expression will produce an error if the firstì
  309. command line token does not represent a number.
  310.  
  311.    If the script invocation command line does not have a token referenced byì
  312. an expression of the form {1}, {2}, etc., the script will bomb with an errorì
  313. message.  The expression {n:default) allows a default value to be used forì
  314. parameter 'n' if none is given on the command line.  This default value canì
  315. be null, as in {1:}.
  316.  
  317.    String variables can, like the command line tokens, be represented inì
  318. expressions by curly braces around the letter (e.g., {B}).  In such a case,ì
  319. the value of the expression is the string of characters alone, and doubleì
  320. quote characters must surround the expression in most situations.  There areì
  321. exceptions.  The SAY and SENDOUT commands (described in the next section)ì
  322. can be used directly with a variable, as in SAY A.  The following twoì
  323. commands are equivalent:
  324.  
  325.                 SAY "Variable A has the value: ",A,"/n"
  326.                 SAY "Variable A has the value: {A}/n"
  327.  
  328.    The curly-brace expressions can be used to concatenate text, as in
  329.  
  330.                 A="{B} and {C}"
  331.  
  332. Expressions of this type are not documented and work only in script files;ì
  333. they will not work if entered directly at the MEX command prompt.  Similarì
  334. expressions can also be used to finesse variables into commands thatì
  335. normally do not take them.  Here are some examples:
  336.  
  337.                 set baud {b}       (where, say, B="1200")
  338.                 set baud {c}00     (where, say, C="24")
  339.                 goto {1}           (where, say, token 1 is LOOP)
  340.                 {a}                (where, say, A="set baud 1200")
  341.  
  342.    I have not figured out how to split a string variable into parts (such asì
  343. words).  I also had never been able to figure out a way to convert aì
  344. numerical variable into a string.  I still can't do it directly (things likeì
  345. B={%B} do not work), but the script in Fig. 1 does it indirectly (inventionsì
  346. like this are part of the fun of writing this column).  You may not be ableì
  347. to fully understand that script until you have read through the rest of theì
  348. command descriptions.
  349.  
  350. -----------------------------------------------------------------------------
  351.  
  352. B=""                    initialize to null string
  353. %y=%b                   set up scratch variable %y
  354.  
  355. LABEL LOOP              loop
  356. %x=%y-10*(%y/10)        get the lowest digit ( %y MOD 10 )
  357. if %x=0 B="0{B}"        preconcatenate the appropriate digit
  358. if %x=1 B="1{B}"
  359. if %x=2 B="2{B}"
  360. if %x=3 B="3{B}"
  361. if %x=4 B="4{B}"
  362. if %x=5 B="5{B}"
  363. if %x=6 B="6{B}"
  364. if %x=7 B="7{B}"
  365. if %x=8 B="8{B}"
  366. if %x=9 B="9{B}"
  367. %y=%y/10                divide number by 10
  368. if %y>0 GOTO LOOP       continue until number is reduced to 0
  369.  
  370. Figure 1.  Commented listing of a script that will convert the numericalì
  371. variable %B into string form in string variable B, from which it can be usedì
  372. in various commands, such as: SET BAUD {B}.  This code could be made into aì
  373. subroutine by adding the command PROC NUM2STR at the beginning and ENDP atì
  374. the end.  If you try this script, do not enter the comments, of course.
  375.  
  376. -----------------------------------------------------------------------------
  377.  
  378.  
  379. Input/Output Commands
  380. ---------------------
  381.  
  382.    Programs generally are not terribly useful if there is no way to get dataì
  383. in or out.  Here is what MEX-Plus offers.
  384.  
  385.    The SAY command allows one to send characters to the screen.  It acceptsì
  386. arguments of literal strings, string variables, and numerical expressions,ì
  387. as in
  388.  
  389.                 SAY "The sum is",%A+%B,"/n"
  390.  
  391. There are special character codes, such as "/n" (newline) or "/r" (return). ì
  392. Combined with the video commands mentioned earlier, the SAY command canì
  393. produce some pretty fancy displays.
  394.  
  395.    There is also the undocumented PRINT command that does almost exactlyì
  396. what SAY does, except that it does not need quotation marks around theì
  397. literal text and does not interpret any special expressions.  To PRINT,ì
  398. everything is a pure string.  There are, thus, a couple of things PRINT canì
  399. do that SAY cannot.  Here are some examples:
  400.  
  401.                 PRINT Please enter "Hello" at the prompt.
  402.         PRINT Use the expression {1} for a token.
  403.  
  404. In the first case, PRINT allows one to send a double quote character to theì
  405. screen.  In the second case, a string that would be a variable expressionì
  406. can be displayed.
  407.  
  408.    The SENDOUT command is used to send literal text or the contents ofì
  409. string variables to the modem.  The PREFIX and SUFFIX commands can be usedì
  410. to define strings that are automatically sent before and after theì
  411. designated text to save one the trouble of having to include certainì
  412. characters (such as, perhaps, a carriage return and linefeed) explicitlyì
  413. with each string.  Longer, fixed strings can be sent using the TRANSMITì
  414. command, which sends the contents of a file just as if you were typing it inì
  415. terminal mode.  A pair of delay constants controls the speed with which thisì
  416. "automatic typist" performs.
  417.  
  418.    The INPUT command allows interactive entry of the value for a numericalì
  419. variable; ACCEPT does the same thing for a string variable.  The TIME andì
  420. DATE commands allow one to access a real-time clock.  Besides displaying theì
  421. information on the screen, the commands are supposed to put theì
  422. corresponding data into the VALUE variable.  There is a bug here, and theì
  423. time value is used by both commands.  There appears to be no way toì
  424. determine the date from within a script.  The PEEK and POKE commands allowì
  425. one to look at and modify memory for the ultimate in hacking from a script! ì
  426. (That probably means that there would be a way to find the date if oneì
  427. really needed it badly.  It also means that the complete Z-Systemì
  428. environment can be accessed.)
  429.  
  430.  
  431. Flow Control Commands
  432. ---------------------
  433.  
  434.    Like Z-System, MEX-Plus has flow control commands to allow a script toì
  435. perform tests and to act differently depending on the results.  There is theì
  436. standard set of flow commands IF, ELSE, and ENDIF.  They support 8 levels ofì
  437. nesting (just like Z-System).  Here is an example:
  438.  
  439.                 IF %B=1200
  440.                   B="1200"
  441.                 ELSE
  442.                   B="2400"
  443.                 ENDIF
  444.  
  445.    Additionally, there is a single-line IF command.  It is distinguishedì
  446. from the multiple-line IF by a command (a 'then' clause) that is part of theì
  447. IF statement.  Here is an example:
  448.  
  449.                 IF %B=2400 B="2400";SAY "2400 bps";GOTO CONTINUE
  450.  
  451. With the single-line IF, when the test fails, the entire line is ignored. ì
  452. Please note that had there been a semicolon after the "IF %B=2400", thenì
  453. this would have been a multiple-line IF (albeit with several of its 'lines'ì
  454. on one line).
  455.  
  456.    The single-line IF command comes in especially handy, because it isì
  457. generally awkward to perform a GOTO jump out of an IF/ELSE/ENDIF block. ì
  458. Although the manual warns against it, there is (I'm pretty sure) no harm perì
  459. se in doing it.  It is just that you have to make sure that the ENDIF is notì
  460. skipped lest you get nested deeper and deeper.  As with Z-System, you haveì
  461. to make sure the IFs get terminated; unfortunately, this is not so easy,ì
  462. because, unlike Z-System, MEX-Plus has no XIF or ZIF command.  Here is aì
  463. very convoluted example of a way in which it could be done:
  464.  
  465.                 if %b
  466.                   say "TRUE/n"
  467.                   goto cont
  468.                 endif
  469.                 .
  470.                 say "FALSE/n"
  471.                 goto done
  472.                 .
  473.                 label cont
  474.                 endif
  475.                 .
  476.                 label done
  477.                 say "Now we are done/n"
  478.  
  479.    There is also a SKIPIF command.  If its test is true, then the nextì
  480. command is skipped.  Note well that while the IF command may skip an entireì
  481. line of commands, SKIPIF skips only one command, no matter how many commandsì
  482. may appear on the same line.
  483.  
  484.  
  485. Numerical Tests
  486. ---------------
  487.  
  488.    Flow control would not be very useful without ways to test things.  Firstì
  489. we will consider tests on numbers.
  490.  
  491.    Test results are expressed numerically, with 0 representing false andì
  492. non-zero (usually 1) representing true.  You can see this for yourself byì
  493. entering the command "SAY 1<2" or "SAY 1>2".  The following logicalì
  494. operators can be used for comparisons: equals (=), not equals (<>), lessì
  495. than (<), less than or equal to (<= or =<), greater than (>), or greaterì
  496. than or equal to (>= or =>).  Note that the MEX manual has a misprint in oneì
  497. place and gives the not-equal-to operator as '!'.  That is incorrect andì
  498. will not work.
  499.  
  500.    Although comparison tests return a numerical value, those values for someì
  501. reason cannot be used in arithmetic expressions.  In other words, you can'tì
  502. have (%A>%B)*(%A<%C).  As far as I can tell, this means that you cannotì
  503. perform compound tests, such as "IF %A>%B AND %A<%C".  Performing suchì
  504. compound tests is made more difficult by the fact that the 'then' clause ofì
  505. a single-line IF cannot be another IF.  If you won't be using GOTO, nestedì
  506. multi-line IF commands will do the trick.  Otherwise, you might have toì
  507. resort to some explicit arithmetic as in the following:
  508.  
  509.                 %z=1
  510.                 if %a<=%b then %z=0
  511.                 if %a>=%c then %z=0  
  512.                 if %z then ....
  513.  
  514. We started out assuming TRUE (%z=1).  Then if either condition was false, weì
  515. set %z to false.
  516.  
  517.    Before we leave this topic (I know we've been here a long time), I haveì
  518. to mention that MEX has a bug that causes it to issue fallacious but veryì
  519. annoying error reports when comparison operations are performed withì
  520. numerical variables having particular values.  I have carried out a numberì
  521. of experiments to try to determine the exact circumstances under which thisì
  522. problem occurs, but so far I cannot fathom a pattern.  The trouble oftenì
  523. appears, however, with comparisons to standard data rate values, such asì
  524. 300.  To get around the problem, I sometimes divide the variable by 100,ì
  525. compare it to 3, 12, or 24, and then multiply it by 100 to restore itsì
  526. original value.  What a pain!
  527.  
  528.  
  529. String Tests
  530. ------------
  531.  
  532.    Strings are compared using the COMP command.  It accepts two strings,ì
  533. each of which can be either a literal string or a string variable.  Theì
  534. result of the comparison is returned in the VALUE variable, which can thenì
  535. be tested for a value of 0 or 1.  The STAT CASE setting determines whetherì
  536. the comparison will be case sensitive or not.  There is a bug with the COMPì
  537. command; it will not give the answer 1 (true) when both strings are nullì
  538. (""), though it will work if only one string is null.  If you want to see ifì
  539. a command line token was given, you can use the following tests:
  540.  
  541.                 COMP "{1:} " " "
  542.                 COMP "{1:}X" "X"
  543.  
  544. An extra character (space or 'X') is concatenated to the string representedì
  545. by {1:}.  You might also use
  546.  
  547.                 COMP "{1:null}" "null"
  548.  
  549. Here, the first parameter cannot be null.  If token 1 is not given, theì
  550. default value "null" will be used instead.  Of course, if the user entersì
  551. "null", the same result will be obtained.  The two earlier examples are,ì
  552. thus, more robust.
  553.  
  554.    There is one oddball command that I don't know where to put: SLEEP.  Itì
  555. is sort of a flow control command, so I'll stick it here.  It just tells theì
  556. system to go to sleep (pause) for a designated time interval.
  557.  
  558.  
  559. Program Control Commands
  560. ------------------------
  561.  
  562.    MEX-Plus supports several script program structures.  The main unit of aì
  563. script program is a script file, which has a file extension of MEX.  It canì
  564. be invoked as a main program by the READ command.  It can also be invoked asì
  565. a subprogram by the DO command, which allows scripts to be nested.  I do notì
  566. know how deep this nesting can be, but I just tested it to five levels.  Theì
  567. STOP command is used to exit from a READ or DO command.  In the former case,ì
  568. control returns to the MEX program (possibly in terminal mode); in theì
  569. latter, control returns to the script that called the current script.  Aì
  570. script also terminates automatically at the end-of-file.  The STOP commandì
  571. unfortunately displays an annoying message about the script being aborted. ì
  572. To exit gracefully, it is better to put a label at the end (e.g., LABEL END)ì
  573. and to exit using GOTO END.
  574.  
  575.    A READ command may be given inside a script.  In this case, control isì
  576. transferred to the new script, which overwrites the old script in memory. ì
  577. With the DO command, the new script lines are read into memory along withì
  578. the currently running script.
  579.  
  580.    I always enjoy writing these columns because I end up asking some newì
  581. questions and learning some new answers.  Just now, to see how MEX works, Iì
  582. was examining the memory image after a MEX script file ran.  First, Iì
  583. learned that the script text is stored backwards in memory starting fromì
  584. near the top.  I verified that after each DO is finished, the memory isì
  585. reclaimed and is available for use by another subroutine script.  I alsoì
  586. discovered that the entire script file, including all comments, is read intoì
  587. memory.
  588.  
  589.    We can draw some important conclusions from these observations about howì
  590. complex scripts should be implemented.  First, there are several advantagesì
  591. to using versions of script files from which comments have been stripped. ì
  592. The files will, of course, load faster, and there will also be more room inì
  593. memory for such things as file transfer buffers.  Many MEX users have runì
  594. into problems of insufficient memory while running complex scripts.  Second,ì
  595. it is a good idea to chain from one script to another rather than buildingì
  596. everything into a single script.  In my PC-Pursuit script, I chain to a veryì
  597. small script just after the remote system has been reached and the script isì
  598. about to put me into terminal mode.
  599.  
  600.    Structure is permitted within an individual script file as well in theì
  601. form of internal subroutines.  Subroutines begin with a PROC (procedure)ì
  602. command and end with an ENDP (end-procedure) command.  They are invoked byì
  603. the GOSUB command.  Again, I do not know how deeply they may be nested, butì
  604. I just tested them to 9 levels.
  605.  
  606.    Script files may also contain unstructured program groupings (thatì
  607. anathema to modern structured programming).  The LABEL command allows anyì
  608. point in the script to be given a name, and the GOTO command allows a branchì
  609. to that point.  The manual indicates that the name may have up to 16ì
  610. alphabetic characters and warns that the line with the LABEL command may notì
  611. have any other commands on the line.  I know that I have run afoul of thatì
  612. restriction in the past, but, oddly enough, in my testing now I was totallyì
  613. unable to generate a problem.  I tried everything I could think of: anì
  614. immediate semicolon, a semicolon after a space or a tab, tabs after theì
  615. semicolon.  They all worked just fine (how could MEX tell that this was justì
  616. a test?).
  617.  
  618.    The manual is clearly wrong when it says that only alphabetic charactersì
  619. can be used.  I assumed that it really meant alphanumeric, but in myì
  620. experiments I learned that absolutely any characters can be used, includingì
  621. spaces!  Here are the rules that emerged from my testing.  First, all spacesì
  622. and tabs after the LABEL command are ignored.  That point marks theì
  623. beginning of the name.  Next one starts from the end of the line or theì
  624. command separator character and strips all tabs and spaces backward.  Thatì
  625. point marks the end of the name.  What is between those marks is taken asì
  626. the label.  For example, one can have a label of "ENTRY 1" (with theì
  627. embedded space and with or without the quote characters, in fact).  Mindì
  628. you, I am not by any means suggesting that you use such labels.  As Iì
  629. mentioned before, I have not always found MEX to behave exactly the way itì
  630. did in these experiments.  If anyone can figure this out more precisely, Iì
  631. would really like to hear about it.
  632.  
  633.    The other thing I learned from these experiments is that MEX always scansì
  634. for a label from the beginning of the script.  This means that if you useì
  635. the same label a second time, the second occurrence will never be found.
  636.  
  637.  
  638.                             One Script Example
  639.  
  640.    I just don't feel right about presenting all this information about MEX¡
  641. Plus commands without showing at least one real-life example.  Figure 2ì
  642. shows the final script in my PC-Pursuit script suite.  Once I haveì
  643. successfully connected to the outdial city and reached the remote systemì
  644. there, I chain to this script.  Let's look at it line by line.
  645.  
  646.    The first line begins with a period, so it is a comment.  I alwaysì
  647. include a title line and often add some description of the function of theì
  648. script and the parameters it takes.
  649.  
  650.    The real work of the script begins at line 3.  In many parts of theì
  651. script, I do not want the output from commands to show on the screen.  Now Iì
  652. do, so I issue the "SCREEN ON" command.  I'd also like to start with a cleanì
  653. screen, so I issue CLS, too.
  654.  
  655.    In line 5, the script tells the user the name of the system that has beenì
  656. reached (that was previously stored in string variable F) and at what baudì
  657. rate (previously stored in string variable B).  Then the script drops oneì
  658. into terminal mode, where one can work interactively as long as one likes.
  659.  
  660.    When terminal mode is exited (by pressing <ESC> E), the script resumes atì
  661. the label LOOP.  Line 9 prompts the user to enter a command.  If the userì
  662. enters "M", then the main menu script is run, allowing one to call anotherì
  663. system in another or the same city.  Line 10 accepts the answer from theì
  664. user and places it into string variable A.
  665.  
  666.    In line 11, the user's answer is compared to the string "M".  If it wasì
  667. "M", then the variable VALUE will have the value 1 (true), and line 12 willì
  668. cause the script to chain to the script file PCPMENU.MEX.  If the userì
  669. entered anything other than "M", then execution will continue at line 13,ì
  670. where the user's command is executed.  When that command has completed,ì
  671. control will return to line 14, which branches back to label LOOP and aì
  672. prompt for another command.
  673.  
  674.    The user's command can be just about anything.  For example, if it isì
  675. "T", then MEX will enter terminal mode for more interactive work.  The oneì
  676. restriction I have found, is that only a single command can be entered.  Aì
  677. multiple command line, with commands separated by semicolons (or whateverì
  678. the designated SEP character is), does not work for reasons I do not yetì
  679. understand.  Maybe I will have figured it out (or one of you will have) byì
  680. next time, when I will cover the real guts of the PC-Pursuit script.
  681.  
  682. -----------------------------------------------------------------------------
  683.  
  684. 01  .. PCPCONN SCRIPT -- Connected to Destination System
  685. 02  
  686. 03  screen on
  687. 04  cls
  688. 05  say "Connected to ",F," at ",B,"00 bps/n/n"
  689. 06  t
  690. 07  
  691. 08  LABEL LOOP
  692. 09  say "/nEnter single MEX command (or M for menu): "
  693. 10  accept A
  694. 11  comp A "M"
  695. 12  if value=1 READ PCPMENU
  696. 13  {A}
  697. 14  GOTO LOOP
  698.  
  699. Figure 2.  This is the final script in my PC-Pursuit suite.  Just afterì
  700. connecting to a remote system, I chain to this script to free up as muchì
  701. memory as possible for other uses, such as capture buffers and/or fileì
  702. transfer buffers.  Line numbers have been added for reference purposes inì
  703. the text.
  704.  
  705.