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 / UUCP / UUCP21B.LBR / QTCHAT.DYC / QTCHAT.DYC
Text File  |  2000-06-30  |  22KB  |  587 lines

  1. QTERM chat scripts
  2. ==================
  3.  
  4. A chat script is a means for getting QTERM to automatically send and
  5. receive text, this can be used to auto-dial, connect to remote systems,
  6. log in to them, and do whatever else is wanted. In addition, chat scripts
  7. have a number of commands available, to do such things as protocol sends
  8. and receives, transfer of text files, and many other things.
  9.  
  10. There are two ways of invoking a chat script. Firstly when QTERM is
  11. executed from CP/M, a chat script and parameters can be provided there:
  12.  
  13.     A>QTERM SCRIPT 1200
  14.  
  15. would be an example, alternatively the ^\ X command will prompt for a
  16. filename, the response can be exactly the same:
  17.  
  18.     Filename: SCRIPT 1200
  19.  
  20. will have the same effect.
  21.  
  22. QTERM will look in several places to try to find the script. The first
  23. thing it will do is to take the filename as given (subject to the
  24. current default drive/user, which may have been changed by the !n or
  25. ^\ N commands). If this is not successful, QTERM then searches the
  26. drive/user area that was active when it first started. It should be
  27. noted that if the entry subroutine includes BDOS calls to change either
  28. the drive or user, then the values rememberd by QTERM will be those on
  29. exit from the entry subroutine. This provides a mechanism for setting
  30. up a default script area, a place where QTERM will always try to find
  31. scripts. In addition, if it can't find the script as a file in the
  32. default script area, QTERM will look for a .LBR file /QTERM.LBR and
  33. see if this library contains the script. The reason behind this is that
  34. scripts tend be fairly small, and it is far more efficient to keep them
  35. all together in one .LBR, since this saves disk space. It goes without
  36. saying that QTERM cannot deal with squeezed or crunched scripts, they
  37. must be saved in the .LBR as pure ASCII text files.
  38.  
  39. When a chat script is running it can be terminated prematurely by typing
  40. ^X on the keyboard: this will return to normal terminal mode.
  41.  
  42. There are two types of lines in a chat script: send/expect lines, and
  43. command lines. Command lines are always started with a '!' character,
  44. any other character starts a send/expect line.
  45.  
  46. Looking first at send/expect lines, they can contain up to six fields,
  47. and the first two must be provided, even if they are empty. An example
  48. of such a line is:
  49.  
  50.     -AT\r-OK\r\n-3-2-3-0-
  51.  
  52. In this example the '-' (first character) is the delimiter used to
  53. separate fields. Any character can be used except for '!', but whatever
  54. character is chosen cannot appear in the strings. Also note that
  55. chosing a delimiter from the characters above 'z' in the ASCII character
  56. set (i.e. '{', '|', '}', and '~') has a special effect, which is explained
  57. below. Taking the fields in order they are SEND, EXPECT, TIME, TRIES,
  58. SUCCESS, and FAIL. SEND is a string that is transmitted by QTERM, so in
  59. the example above QTERM would transmit 'AT<carriage return>'. As was noted
  60. above, delimiters above 'z' have a special effect: they cause the SEND
  61. string to be written out slowly: there is a tenth of a second delay
  62. after each character. EXPECT is a string that QTERM is looking for in
  63. response to it's SEND string: so in the above example, QTERM would be
  64. looking for the 'OK<carriage return><linefeed>' that a Hayes compatible
  65. modem would respond with, when presented with 'AT<return>'.
  66.  
  67. The remining four fields are all decimal numbers, and can be omitted
  68. as QTERM will provide default values. TIME is the number of seconds
  69. to wait before assuming failure, if not given it defaults to 15. TRIES
  70. is the number of times to retry on failure, so taking our first example,
  71. TRIES is 2. If QTERM matched the EXPECT string on the first sending of
  72. SEND, all is well, but on the first failure it would resend the SEND string
  73. and look for the EXPECT string a second time. If it failed on this second
  74. attempt, only then would it consider this line to have failed. SUCCESS
  75. specifies the line number to transfer to in the chat script if it matched
  76. the EXPECT string. The default for this is the line following the current
  77. line. FAIL is the line to transfer to if the EXPECT string is not
  78. matched. This can be a line in the chat script, or as shown above 0 is
  79. allowed, which terminates the script immediately.
  80.  
  81. In the example above, the success and fail values are given as simple
  82. line numbers, it is also possible to use labels in chat scripts, see !:
  83. below for an explanation of how to define a label. If a label is being
  84. used, the line might look like this:
  85.  
  86.     -ATDT5551234\r-CONNECT-30--`connect-`fail-
  87.  
  88. In this case, the `connect and `fail are label usages, and cause transfer
  89. to wherever the corresponding label is. Label useage is introduced with the
  90. backquote character `, which must be followed by the label itself, with no
  91. intervening white space: -` connect- will not work. Using an undefined label
  92. does not directly cause an error, but the substitution of the non-existant
  93. label will usually create a line that cannot be parsed, thus flagging the
  94. error.
  95.  
  96. In another example, if the first line were:
  97.  
  98.     -AT\r-OK\r\n--5-
  99.  
  100. since TIME is empty, it defaults to 15, but as TRIES is 5, this line
  101. would try five times before giving up. Note also from this example
  102. that there are two ways of causing QTERM to default a value: an empty
  103. field (TIME) or end of the string (SUCCESS and FAIL). Note that the
  104. closing '-' after the 5 for TRIES is necessary. On the basis of this,
  105. the absulute minimum line is:
  106.  
  107.     -send-expect-
  108.  
  109. This uses all four defaults: 15 seconds timeout, 1 try, success goes to
  110. the next line, failure terminates the script. The idea behind these
  111. defaults is that a collection of simple send/expect lines like the above
  112. allow a "conversation" to be held with the remote system.
  113.  
  114. It is possible that either of SEND or EXPECT can be empty: an empty SEND
  115. causes nothing to be sent, but the EXPECT must be matched to continue;
  116. an empty EXPECT automatically matches. Note that if both are empty then
  117. the chat script will terminate when it reaches that line, so a line like:
  118.  
  119.     ---
  120.  
  121. will serve as a means to terminate a chat script, returning to terminal
  122. mode.
  123.  
  124. Command lines in chat scripts start with '!', and following the '!' is
  125. a command letter. If input is needed (e.g. for a '!b' or '!s' line)
  126. it should be placed after the command letter:
  127.  
  128.     !b 1200 8n1 -5 30 500 +\x13\x11
  129.  
  130. As is shown in the above example, spaces are permitted after the command
  131. letter, but not before.
  132.  
  133. Several of the ! commands correspond to ^\ commands available from terminal
  134. mode: the !b above would set the baud rate etc., just like the corresponding
  135. ^\ B command would.
  136.  
  137. Commands available in this group are:
  138.  
  139. !,    hangup
  140. !.    break
  141. !B    set baud rate
  142. !E    set local echo
  143. !H    set half duplex
  144. !J    toggle junking of control characters
  145. !L    set linefeed send for 'P'
  146. !M    set bit 7 mask
  147. !N    select new drive/user
  148. !V    toggle VT100 emulation
  149. !W    toggle split window mode
  150. !K    program function key
  151. !P    print file to remote
  152. !U    invoke user function
  153. !R    protocol receive
  154. !S    protocol send
  155. !X    activate chat script
  156. !Q    exit QTERM
  157.  
  158. Note also that the toggles ('!E', '!H', '!J', '!L', '!M', '!V' and '!W')
  159. behave a little differently. Since the state of these toggles is not defined
  160. when a chat script starts, with one exception (!W) there are three ways of
  161. invoking these. Using '!H' as an example:
  162.  
  163.     !h
  164.  
  165. behaves as would an <escape> 'H' in normal operation, i.e. it toggles
  166. the half duplex switch. However, if the following is given:
  167.  
  168.     !h 1
  169.  
  170. the trailing '1' forces half duplex to be enabled, irrespective of
  171. it's original state, and:
  172.  
  173.     !h 0
  174.  
  175. guarantees to turn half duplex off. The other toggles work in the same
  176. manner: a trailing '0' always disables, and a trailing '1' always
  177. enables. !W is a little different, in that there are three possibilities:
  178. window mode off, window mode on with big receive, and on with small. Also
  179. allowing a pure toggle could have undefined results, since if window mode
  180. were toggled on, there would be no indication what size was wanted. As
  181. a result of this, there are three forms for the !W command in a script:
  182.  
  183.     !w 0
  184.  
  185. forces window mode off,
  186.  
  187.     !w b
  188.  
  189. forces it on with a big receive window, and:
  190.  
  191.     !w s
  192.  
  193. forces it on, but with a small window. With all these toggles (!h etc. and
  194. !w) the options above are guaranteed, using any other option letters will
  195. have undefined results.
  196.  
  197. The 'X' command to activate a chat script can be used to chain scripts
  198. together: when an 'X' is encountered the specified chat script is
  199. invoked, however the current script is lost: it is overwritten by the
  200. new one.
  201.  
  202. There are other commands that are not normally available are as follows:
  203.  
  204.  
  205. !a - This simply alerts it's passing by ringing the terminal bell, this
  206. may be useful if a chat script is being used to repeatedly call a number
  207. until a connection is made: by putting a !a into the script, the
  208. system will beep when a connection is made.
  209.  
  210.  
  211. !f - Capture an ASCII text file. Since 'C' catch files are disabled during
  212. chat script operation, 'F' is provided as an alternative means for data
  213. capture. A typical 'F' line would be:
  214.  
  215.     !f b:catch.txt 6 string
  216.  
  217. This would open B:CATCH.TXT for output, then send 'string' out, and
  218. transfer all subsequent data to that file until a timeout of 6 seconds
  219. occurred. As with files opened by ^\ C, the specified file will be opened
  220. for append if it already exists, assuming it is writable. If it exists,
  221. but is read only, then QTERM will not do the open. 'string' is a string
  222. that can contain backslash escape sequences, just like a SEND string in
  223. normal chat operation. Any timeout can be given, up to about 250 seconds.
  224. Note that since this uses the same buffer as the <escape> C command, if
  225. there is already a catch file open, it will be automatically closed prior
  226. to execution of a '!f'.
  227.  
  228.  
  229. !: - Define a label. Label usage was described above: the '`' character
  230. introduces a label usage. NOTE that this is the BACKQUOTE character, not
  231. the usual single quote character. To define a label, simply include a
  232. line of the form:
  233.  
  234. !: connect
  235.  
  236. in the script. A few comments may make labels easier to use, firstly
  237. they cannot be longer than seven characters, and where they are defined
  238. there should be no trailing blanks. When a label is used, it is done by
  239. means of a simple text substitution: after seeing a '`' character, QTERM
  240. tries to match the following text with a label in the script, and it
  241. stops at the first match. So if you have two labels one of which is a
  242. prefix of the other, the results can be unpredictable. As a byproduct
  243. of this, undefined labels do not generate an error (they just become
  244. line zero), but the text substitution doesn't remove the label, so the
  245. resulting line usually generates an error. In the event that a '`'
  246. character is needed as part of a send or expect string, it can be
  247. escaped by preceeding it with a $, so the line:
  248.  
  249.     .send.exp$`ect.
  250.  
  251. will look for exp`ect, whereas:
  252.  
  253.     .send.exp`ect.
  254.  
  255. will not work, it would try to look for and substitute the label 'ect'.
  256.  
  257.  
  258. The commands !@ and !# can be used for variable manipulation. Their
  259. main purpose is to prevent infinite loops in chat scripts. In the
  260. following example:
  261.  
  262.     !: reset
  263.     .AT\r.OK\r\n.5.5.
  264.     .ATDT5551212\r.CONNECT.30..`connect.`reset.
  265.     !: connect
  266.     . ........
  267.  
  268. if the system being called is off line and not answering, QTERM will
  269. loop here for ever. The !@ and !# provide the ability to keep count and
  270. terminate the loop after some specified number of tries.
  271.  
  272.     !@ var term +/- term
  273.  
  274. is the form of an @ line. var is a single letter variable (there are 26
  275. available: a through z), and term is either a number or a variable. This
  276. is very simplistic, in that two terms must be present: to set a variable
  277. simply say something like:
  278.  
  279.     !@ a 5 + 0
  280.  
  281. the operator can be either + or - and they act as you would expect. so:
  282.  
  283.     !@ a a - 1
  284.  
  285. will subtract 1 from a, or:
  286.  
  287.     !@ a a + b
  288.  
  289. will add b to a, etc. etc. Note that variables are recognised in either
  290. upper or lower case:
  291.  
  292.     !@ A a + B
  293.  
  294. would have exactly the same effect as the line above. Note that these are
  295. single bytes, so there is some risk of working with values above 255.
  296.  
  297. !# tests variables: the general syntax is:
  298.  
  299.     !# var operator term line
  300.  
  301. where var is a variable letter, term is a variable or a number, and the
  302. operator can be '=' to test for equality, '#' to test for inequality, '<'
  303. to check for less than and '>' to test for greater than. line is simply
  304. the line number in the script to go to is the test succedes. Note that this
  305. also provides a goto capability:
  306.  
  307.     !# a = a line
  308.  
  309. will always go to line, since a is always equal to itself. In this case,
  310. line can be a label usage:
  311.  
  312.     !# a = a `doit
  313.  
  314. All variables are initialized to zero when the first script in a series is
  315. invoked, but values are retained when a !x command chains from one script
  316. to another.
  317.  
  318.  
  319. Two commands have been added to manipulate the appearance of chat scripts:
  320.  
  321.     !> This is a line of text\r\n
  322.  
  323. !> simply prints the text, after processing '\' escapes. Note that
  324. leading and trailing spaces are ignored, so the above case would start
  325. with the 'T' of 'This'. In order to start or end with a with a space,
  326. \x20 can be used.
  327.  
  328.     !%
  329.  
  330. This command is actually several different commands rolled into one:
  331. !% o manipulates the echoing of characters received from the modem
  332. while the script is running:
  333.  
  334.     !% o 1
  335.  
  336. forces modem echo on,
  337.  
  338.     !% o 0
  339.  
  340. forces it off, and:
  341.  
  342.     !% o
  343.  
  344. simply switches state. In the same manner, !% m controls printout of
  345. the 'Match: OK' messages that are printed when QTERM matches the expect
  346. string in a send/expect line.
  347.  
  348.  
  349. As a complement to !>, teh !< command can be used to take keyboard input,
  350. and make decisions based on what happens. This includes four subcommands
  351. altogether:
  352.  
  353.     !< -
  354.  
  355. The '-' causes QTERM to prompt for a line of input using CP/M's BDOS
  356. buffered command. The line is then saved, and can be tested with the !< =
  357. command:
  358.  
  359.     !< = string line
  360.  
  361. If the input read in the !< - command is 'string' then transfer to line
  362. (which can be a label). Note that string is NOT processed for escapes,
  363. since the is intended only for printable ascii text comparisons.
  364.  
  365. This allows for such things as multiple choice:
  366.  
  367.     !> \r\nSelect system to call\r\n
  368.     !> 1. System 1 ..... \r\n
  369.     !> 2. System 2 ..... \r\n
  370.     !> 3. System 3 ..... \r\n
  371.     !: prompt
  372.     !> Enter 1, 2 or 3:\x20
  373.     !< -
  374.     !< = 1 `sys1
  375.     !< = 2 `sys2
  376.     !< = 3 `sys3
  377.     !> Error, invalid input\r\n
  378.     !# a = a `prompt
  379.  
  380. Where the first 4 lines print a menu, the next line defines a label. Then
  381. comes a prompt, followed by an input command. After this, the line is
  382. checked against 1, 2 and 3, and a jump is made to the appropriate label.
  383. If there is no match an error message is printed, and the !# a = a line
  384. is used as a goto, since a is always equal to a.
  385.  
  386. In a similar manner, '!< .' and '!< ,' provide "hot key" comparisons, the
  387. !< . command simply reads a single character from the keyboard, and !< ,
  388. compares against a single character value just like !< = does:
  389.  
  390.     !< , \r `return
  391.  
  392. would be the test for a hot key input of a single carriage return. Note that
  393. in this case, \ escapes are permitted.
  394.  
  395.  
  396. The ![ command provides a similar function to the !< command, but it
  397. works on text coming from the modem. There are three forms:
  398.  
  399.     ![ -
  400.  
  401. reads text from the modem. In this instance there are two ways that
  402. reading can end:
  403.  
  404.     ![ - 15
  405.  
  406. would simply read text for 15 seconds. This numeric timeout must be
  407. provided, but in addition up to four extra strings can be provided:
  408.  
  409.     ![ - 5 .string1.string2.string3.string4.
  410.  
  411. in which case input will terminate when 5 seconds have elapsed, or one
  412. of the four strings is read. In this line, the '.' following the 5 is a
  413. delimiter, this serves to separate the strings exactly like the delimiter
  414. in a send / expect line. Not all four strings need to be there:
  415.  
  416.     ![ - 5 .OK.ERROR.
  417.  
  418. is acceptable, but the trailing delimiter must be there after the last
  419. string. In addition to scanning for the four lines, QTERM keeps the last
  420. sixty-four characters seen in a buffer, these can then be inspected with
  421. ![ = and ![ + lines. These do very similar functions, in that they both
  422. look for a string in the last 64 characters seen.
  423.  
  424.     ![ = string line
  425.  
  426. searches the saved text for the string, which in this case can include
  427. \ escapes. If string occured anwhere in the last 64 characters, control
  428. goes to line. ![ + looks exactly the same, but the difference is whether
  429. the test is done on seven or eight bit data: ![ = just compares the least
  430. significant seven bits, ignoring the parity bit, whereas ![ + compares
  431. all eight. Note also that the strings provided in the ![ - line are only
  432. checked in seven bit mode.
  433.  
  434.  
  435. The !~ command has been added for rudimentary file manipulation
  436. during chat script operation. Three options exist:
  437.  
  438.     !~ - file
  439.  
  440. will erase a file. Note that QTERM will silently ignore this command
  441. if the file doesn't exist, or if it is write protected. As with all
  442. filenames, a drive/user can be given:
  443.  
  444.     !~ - d15:foo.bar
  445.  
  446. does like you'd expect.
  447.  
  448.     !~ = newname = oldname
  449.  
  450. renames a file: note that if a drive/user is given on oldname, it will
  451. be ignored: newname completely defines where the action will happen.
  452. This will fail silently if newname already exists, or if old name doesn't,
  453. or if oldname does exist but is write protected.
  454.  
  455.     !~ + newname = oldname
  456.  
  457. copies a file. In this case a file can be copied to a different
  458. drive / user, so if needed a drive / user spec should be attached to
  459. oldname. This will fail silently if newname exists or if oldname doesn't.
  460. These can be used to good effect when QTERM is sending text files as
  461. messages to a BBS, after sending the file with a !P command, a !~ - will
  462. erase it, or files can be erased after uploading, or a file might be
  463. renamed after a batch download.
  464.  
  465.  
  466. Parameters can be passed to chat scripts, in much the same way as to
  467. SUBMIT operation: invoking a script:
  468.  
  469.     SENDFILE b3:*.asm
  470.  
  471. where there is a line in it:
  472.  
  473.     !s xky $1
  474.  
  475. causes the line to become:
  476.  
  477.     !s xky b3:*.asm
  478.  
  479. Warning: when a script is invoked directly from CP/M the parameters will all
  480. be forced to upper case - this is a byproduct of the behaviour of the CCP.
  481. It is for this reason that variables are recognised in both upper and lower
  482. case: there are interesting things that can be done by mixing $n parameters
  483. and variables: more in a minute.
  484.  
  485. In some cases it may be desirable to set a default value for a parameter,
  486. a further line has been added to do this:
  487.  
  488.     !$n stuff
  489.  
  490. the '!' and '$' are just that, 'n' is the number of a parameter ('1'
  491. through '9') and stuff will become the default value. In the following
  492. case:
  493.  
  494.     !$3 default
  495.  
  496. if parameter 3 is not set (i.e. blank) it is expanded to default,
  497. otherwise it is left alone. This might be useful when using one script
  498. to call at one of several baud rates:
  499.  
  500.     CALLBBS 1200
  501.  
  502. could be done in conjunction with:
  503.  
  504.     !b $1 8n1 .....
  505.  
  506. inside CALLBBS. However if the script is invoked:
  507.  
  508.     CALLBBS
  509.  
  510. without a parameter, and the following line:
  511.  
  512.     !$1 2400
  513.  
  514. exists, then the baud rate in the !b command would default to 2400. In
  515. order for these default set commands to work, they MUST be provided in
  516. the correct sequence:
  517.  
  518.     !$2 something
  519.     !$1 hello
  520.  
  521. will do very strange things. Also skipping values will do unexpected things,
  522. as will putting spaces in the default string. A place where this can be used
  523. to good effect is a script chain that calls several BBS's. By running a
  524. variable from 0 to 25 to escape the infinte loop described above:
  525.  
  526.     !: reset
  527.     !@ a a + 1
  528.     !# a > 25 `exit
  529.     .AT\r.OK\r\n.5.5.
  530.     .ATDT5551212\r.CONNECT.30..`connect.`fail.
  531.     !: fail
  532.     .XXX\r.YYY.30.5.`reset.`reset.
  533.     !: connect
  534.  
  535. when time runs out, this jumps to exit. Now, consider the following:
  536.  
  537.     !$1 y
  538.     !@ n 26 + 0
  539.     !@ a $1 + 0
  540.  
  541. Taking these lines in order: the first defaults parameter 1 to y
  542. The second sets variable n to 26. The last sets a to the variable
  543. named by parameter 1, so if the script is invoked:
  544.  
  545.     CALLBBS N
  546.  
  547. $1 will be N, and the last line will set a to 26 (n + 0). So when
  548. control enters the loop above, a is already set to 26, and the script
  549. immediately goes to `exit, thus bypassing the board. However, if it
  550. is invoked as just:
  551.  
  552.     CALLBBS
  553.  
  554. $1 defaults to y, and line three sets a to 0, thus causing the BBS to
  555. be tried. By repeating this for several boards:
  556.  
  557.     CALLBBS Y N Y Y N
  558.  
  559. will call the first, third and fourth, but bypass two and five. VERY
  560. IMPORTANT NOTE: in a sequence of chat scripts, chained by the !x command
  561. the parameters are lost after the !x command. However, by saying
  562.  
  563.     !x script param1 param2 param3
  564.  
  565. parameters can be passed from one script to another, and indeed other
  566. parameters can be added, and some removed.
  567.  
  568. As is done with labels, $n parameters are handled by simple text
  569. substitution, so a little care will make their use easier. As was
  570. described above, '$' is used to escape '`' characters in strings, it is
  571. also used to escape itself. i.e. to actually place a '$' character in a
  572. string say '$$', so that:
  573.  
  574.     .send.exp$$ect.
  575.  
  576. would look for the string 'exp$ect'. There are only three things that
  577. can follow a '$' sign: either '$' or '`' for escaping purposes,
  578. and '1' through '9' for parameter substitution. Placing any other
  579. character after a '$' will have an undefined result.
  580.  
  581.  
  582. As a final note, any other command character is silently ignored,
  583. this can be put to use to introduce comments. At this stage, !; is
  584. not in use, and this is the official comment entry, it is guaranteed
  585. that !; will never be used for a command line function in a QTERM
  586. chat script.
  587.