home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / infomtch.zip / infomtch.cmd next >
OS/2 REXX Batch file  |  1995-09-20  |  37KB  |  732 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                              INFOMTCH.CMD                                */
  3. /*                                  v1.5                                    */
  4. /*                                                                          */
  5. /*                 Attachment script for Infomatch Internet                 */
  6. /*--------------------------------------------------------------------------*/
  7. /* Created from the sample ANNEX.CMD script distributed with IBM OS/2 Warp  */
  8. /* and it's Internet Access Kit.  Changes to original script made by Graham */
  9. /* TerMarsch.                                                               */
  10. /*--------------------------------------------------------------------------*/
  11. /* Portions of this script written by Harold Roussel, who can be reached at */
  12. /* roussel@physics.mcgill.ca.                                               */
  13. /*--------------------------------------------------------------------------*/
  14. /*                                                                          */
  15. /* Please refer to the INFOMTCH.DOC and the README file for information on  */
  16. /* the distribution of this script, its usage, and restrictions.            */
  17. /*                                                                          */
  18. /*--------------------------------------------------------------------------*/
  19. /* Graham is available for contract work involving OS/2.  He has been an    */
  20. /* avid user since 1992, and was involved in all of the beta programs since */
  21. /* then.  A registered OS/2 DAP member, Graham does most of his work in     */
  22. /* C/C++.  Being a starving student, Graham is almost always available for  */
  23. /* programming/installation/support work.  Contact him at 604-689-2073 or   */
  24. /* gtermars@infomatch.com for more information.                             */
  25. /*--------------------------------------------------------------------------*/
  26. /*                              DISCLAIMER                                  */
  27. /*                                                                          */
  28. /* You were waiting for this weren't you?  Well, it's a standard disclaimer;*/
  29. /* I've managed to get this working on my machine and have thus provided it */
  30. /* to others.  By use of this script you acknowledge that I am not          */
  31. /* responsible for any damages that may be incurred through it's use.  Yes, */
  32. /* I am available to answer your questions if you have a problem but I take */
  33. /* no responsibility for your actions.  You downloaded it, and if you use   */
  34. /* it you take full responsibility into your own hands.  If you do not      */
  35. /* agree with this then discontinue your use of this script.                */
  36. /*--------------------------------------------------------------------------*/
  37.  
  38.  
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /* Define and initialize all variables:                                     */
  42. /*                                                                          */
  43. /* cr                  - ASCII code for carriage return.                    */
  44. /* lf                  - ASCII code for line feed.                          */
  45. /* crlf                - ASCII code for carriage return and line feed.      */
  46. /* max_attempts        - Maximum number of redial attempts to make.  A      */
  47. /*                       value of zero means dial until connection is made. */
  48. /* curr_attempt        - Current dialing attempt number.                    */
  49. /* username            - User name to log in with.                          */
  50. /* password            - Password to log in with.                           */
  51. /* should_beep         - Should the bell be sounded upon connection or      */
  52. /*                       failure to connect?  A value of zero means NO, and */
  53. /*                       a value of one means YES.                          */
  54. /* should_autostart    - Should the LOGGEDIN.CMD file be run upon a         */
  55. /*                       successful connection?  A value of zero means NO,  */
  56. /*                       and a value of one means YES.                      */
  57. /* os2_address         - Dotted decimal notation for the IP address that    */
  58. /*                       this OS/2 machine will have when a connection has  */
  59. /*                       been made.                                         */
  60. /* how_many_numbers    - Number of phone numbers in the dialing list.       */
  61. /* phone_number        - Array containing the dialing list of numbers.      */
  62. /*                                                                          */
  63. /*                                                                          */
  64. /*--------------------------------------------------------------------------*/
  65. cr = '0d'x
  66. lf = '0a'x
  67. crlf = '0d0a'x
  68. max_attempts = 0
  69. curr_attempt = 0
  70. username = ''
  71. password = ''
  72. should_beep = 1
  73. should_autostart = 1
  74. how_many_numbers = 6
  75. phone_number.0 = "421-3288"
  76. phone_number.1 = "421-3957"
  77. phone_number.2 = "421-3914"
  78. phone_number.3 = "421-3886"
  79. phone_number.4 = "421-0411"
  80. phone_number.5 = "421-3277"
  81.  
  82. /*--------------------------------------------------------------------------*/
  83. /* Parse the command line options.  Keep in mind that while parsing the     */
  84. /* arguments, if an error is found the program will abort; we will NOT end  */
  85. /* up back here with any error conditions to check.                         */
  86. /*--------------------------------------------------------------------------*/
  87. parse arg interface, arguments
  88. call parse_arguments arguments
  89.  
  90. /*--------------------------------------------------------------------------*/
  91. /* Load any of the RexxUtil functions that we might require later.          */
  92. /*--------------------------------------------------------------------------*/
  93. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  94. call RxFuncAdd 'SysDropFuncs', 'RexxUtil', 'SysDropFuncs'
  95.  
  96. /*--------------------------------------------------------------------------*/
  97. /* Say hello to the user and provide author information.                    */
  98. /*--------------------------------------------------------------------------*/
  99. say ''
  100. say 'INFOMTCH - Infomatch Internet SLIP login interface, version 1.5'
  101. say 'Written by Graham TerMarsch, 604-689-2073, gtermars@infomatch.com'
  102. say 'Portions by Harold Roussel, roussel@physics.mcgill.ca' || cr
  103.  
  104. /*--------------------------------------------------------------------------*/
  105. /* Prompt the user for any information that might have been missing from    */
  106. /* the command line.                                                        */
  107. /*--------------------------------------------------------------------------*/
  108. if (os2_address  = '') then do
  109.         call charout , 'Your IP address: '
  110.         parse pull os2_address
  111. end
  112.  
  113. if ( (username = '') | (username = '*') ) then do
  114.         call charout , 'User Name: '
  115.         parse pull username
  116. end
  117.  
  118. if ( (password = '') | (password = '*') ) then do
  119.         call charout , 'Password: '
  120.         password = readpass()
  121. end
  122.  
  123. /*--------------------------------------------------------------------------*/
  124. /* Flush any left over stuff from previous COM activity.                    */
  125. /*--------------------------------------------------------------------------*/
  126. call flush_receive
  127.  
  128. /*--------------------------------------------------------------------------*/
  129. /* Reset the modem to it's factory default settings.                        */
  130. /*--------------------------------------------------------------------------*/
  131. call charout , cr || 'Resetting modem to factory defaults...'
  132. call send '+++'
  133. call send 'AT&F' || cr
  134. call waitfor 'OK', 5
  135. call flush_receive 'echo'
  136.  
  137. if (RC = 1) then do
  138.         call lineout , 'Modem not resetting... Trying again'
  139.         call send '+++'
  140.         call waitfor 'OK'
  141.         call send 'ATHZ' || cr
  142.         call waitfor 'OK', 3
  143. end
  144.  
  145. /*--------------------------------------------------------------------------*/
  146. /* Now we'll attempt to do the dialing.  We'll continue to dial until we    */
  147. /* get connected.                                                           */
  148. /*--------------------------------------------------------------------------*/
  149. which_number = 0                       /* Which number should I be dialing? */
  150.  
  151. do while ( (max_attempts = 0) | (curr_attempt < max_attempts) )
  152.         curr_attempt = curr_attempt + 1
  153.  
  154.         /*------------------------------------------------------------------*/
  155.         /* Wait a bit to be polite to the rest of the system.               */
  156.         /*------------------------------------------------------------------*/
  157.         SysSleep( 1 )
  158.  
  159.         /*------------------------------------------------------------------*/
  160.         /* Hang up on any existing call.                                    */
  161.         /*------------------------------------------------------------------*/
  162.         call send '+++'
  163.         call send 'ATHZ' || cr
  164.         call waitfor 'OK', 3
  165.         call send 'ATM0' || cr
  166.         call waitfor 'OK', 3
  167.  
  168.         /*------------------------------------------------------------------*/
  169.         /* Dial the remote server.                                          */
  170.         /*------------------------------------------------------------------*/
  171.         call charout , cr || 'Now Dialing...'
  172.  
  173.         /*------------------------------------------------------------------*/
  174.         /* Choose the number to call and dial it.                           */
  175.         /*------------------------------------------------------------------*/
  176.         call send 'ATDT' || phone_number.which_number || cr
  177.         which_number = which_number + 1
  178.  
  179.         if (which_number = how_many_numbers) then
  180.                 which_number = 0
  181.  
  182.         /*------------------------------------------------------------------*/
  183.         /* Wait for either a connection or an error message.  The return    */
  184.         /* value will come back through the variable 'stringchosen'.        */
  185.         /*------------------------------------------------------------------*/
  186.         call waitfor3 'CONNECT', 'BUSY', 'NO CARRIER'
  187.         call flush_receive
  188.  
  189.         /*------------------------------------------------------------------*/
  190.         /* If we've successfully connected, get out of the while loop.      */
  191.         /* 'stringchosen' represents which string from the last call to     */
  192.         /* waitfor3 that was detected; a value of 1 means that we got a     */
  193.         /* 'CONNECT'.                                                       */
  194.         /*------------------------------------------------------------------*/
  195.     if (stringchosen = 1) then leave    
  196. end     /* end of 'do while...' */
  197.  
  198. /*--------------------------------------------------------------------------*/
  199. /* Check to see why we ended up out of the previous dialing loop.  Was it   */
  200. /* because we have a connection or because we ran out of dialing attempts.  */
  201. /*--------------------------------------------------------------------------*/
  202. if (stringchosen > 1) then do
  203.         /*------------------------------------------------------------------*/
  204.         /* Inform the user that we have reached the maximum number of       */
  205.         /* dialing attempts.                                                */
  206.         /*------------------------------------------------------------------*/
  207.         say cr || 'Reached maximum dialing attempts.' || cr
  208.  
  209.         /*------------------------------------------------------------------*/
  210.         /* If we are supposed to sound a bell to let the user know that an  */
  211.         /* error occured, sound the bell.                                   */
  212.         /*------------------------------------------------------------------*/
  213.         if (should_beep = 1) then call failure_beep 1
  214.  
  215.         return_value = 1
  216. end
  217. else do
  218.         /*------------------------------------------------------------------*/
  219.         /* Now that we have a connection at the other end of the line, try  */
  220.         /* to do the login.  Wait for the standard strings, and then flush  */
  221.         /* everything else that we do not need (trailing spaces, etc.).     */
  222.         /*------------------------------------------------------------------*/
  223.         call waitfor 'login:'
  224.         call flush_receive 'echo'
  225.         call send username || cr
  226.  
  227.         call waitfor 'Password:'
  228.         call flush_receive 'echo'
  229.         call send password || cr
  230.  
  231.         /*------------------------------------------------------------------*/
  232.         /* Wait for the connection established notification from the server.*/
  233.         /*------------------------------------------------------------------*/
  234.         call waitfor 'starting slip login for'
  235.         call flush_receive 'echo'
  236.  
  237.         /*------------------------------------------------------------------*/
  238.         /* Now we check to ensure that we've connected properly.  If so,    */
  239.         /* set the IP address and add the name server to our routing table. */
  240.         /* Otherwise, display an error message to the user.                 */
  241.         /*------------------------------------------------------------------*/
  242.         say ''
  243.         if RC = 0 then do
  244.                 'ifconfig sl0' os2_address '199.60.99.1 netmask 255.255.255.0'
  245.                 'route add default 199.60.99.1 1'
  246.                 say cr || 'SLIP Connection Established!' || cr
  247.  
  248.                 /*----------------------------------------------------------*/
  249.                 /* If we are supposed to autostart any other applications,  */
  250.                 /* start the LOGGEDIN.CMD script file.                      */
  251.                 /*----------------------------------------------------------*/
  252.                 if (should_autostart = 1) then detach LOGGEDIN.CMD
  253.  
  254.                 /*----------------------------------------------------------*/
  255.                 /* If we are supposed to sound a bell to let the user know  */
  256.                 /* that a successful connection has been made, sound the    */
  257.                 /* bell.                                                    */
  258.                 /*----------------------------------------------------------*/
  259.                 if (should_beep = 1) then call success_beep 3
  260.  
  261.                 return_value = 0
  262.         end
  263.         else do
  264.                 say cr || 'ERROR:  NO Connection Established!' || cr
  265.  
  266.                 /*----------------------------------------------------------*/
  267.                 /* If we are supposed to sound a bell to let the user know  */
  268.                 /* that an error occured, sound the bell.                   */
  269.                 /*----------------------------------------------------------*/
  270.                 if (should_beep = 1) then call failure_beep 1
  271.  
  272.                 return_value = 1
  273.         end
  274. end
  275.  
  276. /*--------------------------------------------------------------------------*/
  277. /* At this point, we are finished; we've either ran out of dial attempts,   */
  278. /* made a successful connection, or failed in a connection.  So, clean up   */
  279. /* any REXX functions that we loaded and exit the script.                   */
  280. /*--------------------------------------------------------------------------*/
  281. call SysDropFuncs
  282. exit return_value
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289. /*--------------------------------------------------------------------------*/
  290. /*                         success_beep ( numTimes )                        */
  291. /*..........................................................................*/
  292. /*                                                                          */
  293. /* Routine to beep several times to indicate a successful connection.       */
  294. /*                                                                          */
  295. /*--------------------------------------------------------------------------*/
  296. success_beep:
  297.         parse arg numTimes
  298.  
  299.         do while (numTimes > 0)
  300.                 call beep 580, 90
  301.                 call beep 650, 90
  302.                 call beep 800, 80
  303.                 numTimes = numTimes - 1
  304.         end
  305. return
  306.  
  307.  
  308. /*--------------------------------------------------------------------------*/
  309. /*                         failure_beep ( numTimes )                        */
  310. /*..........................................................................*/
  311. /*                                                                          */
  312. /* Routine to beep several times to indicate a failed connection.           */
  313. /*                                                                          */
  314. /*--------------------------------------------------------------------------*/
  315. failure_beep:
  316.         parse arg numTimes
  317.  
  318.         do while (numTimes > 0)
  319.                 call beep 600, 90
  320.                 call beep 500, 90
  321.                 call beep 300, 300
  322.                 numTimes = numTimes - 1
  323.         end
  324. return
  325.  
  326.  
  327. /*--------------------------------------------------------------------------*/
  328. /*                            send ( sendstring )                           */
  329. /*..........................................................................*/
  330. /*                                                                          */
  331. /* Routine to send a character string off to the modem.                     */
  332. /*                                                                          */
  333. /*--------------------------------------------------------------------------*/
  334. send:
  335.         parse arg sendstring
  336.         call slip_com_output interface , sendstring
  337. return
  338.  
  339.  
  340. /*--------------------------------------------------------------------------*/
  341. /*                       parse_arguments ( arguments )                      */
  342. /*..........................................................................*/
  343. /*                                                                          */
  344. /* Parses the command line arguments to this script file.  Any known        */
  345. /* arguments will set the appropriate variables in the program.  If we      */
  346. /* encounter an invalid argument or an argument without a value, display an */
  347. /* error message and abort the script completely.                           */
  348. /*                                                                          */
  349. /*--------------------------------------------------------------------------*/
  350. parse_arguments:
  351.         parse arg argument arg_value arguments
  352.  
  353.         /*------------------------------------------------------------------*/
  354.         /* If we have no argument, then simply return.  This is required as */
  355.         /* this routine is called recursively.                              */
  356.         /*------------------------------------------------------------------*/
  357.         if (argument = '') then return
  358.  
  359.         /*------------------------------------------------------------------*/
  360.         /* Translate the argument into upper case so it will be easeir to   */
  361.         /* parse.                                                           */
  362.         /*------------------------------------------------------------------*/
  363.         argument = translate( argument )
  364.  
  365.         /*------------------------------------------------------------------*/
  366.         /* Depending on which command line argument we have, set the        */
  367.         /* appropriate variable.  If the value given either doesn't exist   */
  368.         /* or is invalid, display an error message to the user and abort.   */
  369.         /*------------------------------------------------------------------*/
  370.         SELECT
  371.                 WHEN (argument = '-ATTEMPTS') then do
  372.                         /*--------------------------------------------------*/
  373.                         /* Check to see that we have a numeric value here.  */
  374.                         /* If not, display an error message and quit.       */
  375.                         /*--------------------------------------------------*/
  376.                         if (arg_value \= '') then do
  377.                                 if (datatype( arg_value ) = 'NUM') then do
  378.                                         max_attempts = arg_value
  379.                                 end
  380.                                 else do
  381.                                         say 'Attempts requires a numeric parameter.' || cr
  382.                                         exit 1
  383.                                 end
  384.                         end
  385.                         else do
  386.                                 say 'Attempts requires a parameter.' || cr
  387.                                 exit 1
  388.                         end
  389.                 end
  390.                 WHEN (argument = '-NAME') then do
  391.                         /*--------------------------------------------------*/
  392.                         /* Check to see that we have been given a username. */
  393.                         /* If not, display an error message and quit.       */
  394.                         /*--------------------------------------------------*/
  395.                         if (arg_value = '') then do
  396.                                 say 'Name requires a username parameter.' || cr
  397.                                 exit 1
  398.                         end
  399.                         else do
  400.                                 username = arg_value
  401.                         end
  402.                 end
  403.                 WHEN (argument = '-PASSWORD') then do
  404.                         /*--------------------------------------------------*/
  405.                         /* Check to seee that we have been given a password.*/
  406.                         /* If not, display an error message and quit.       */
  407.                         /*--------------------------------------------------*/
  408.                         if (arg_value = '') then do
  409.                                 say 'Password requires a password parameter.' || cr
  410.                                 exit 1
  411.                         end
  412.                         else do
  413.                                 password = arg_value
  414.                         end
  415.                 end
  416.                 WHEN (argument = '-BEEP') then do
  417.                         /*--------------------------------------------------*/
  418.                         /* Translate the argument value into uppercase.     */
  419.                         /*--------------------------------------------------*/
  420.                         arg_value = translate( arg_value )
  421.  
  422.                         /*--------------------------------------------------*/
  423.                         /* Check to see that the given parameter is either  */
  424.                         /* ON or OFF.  If not, display an error message and */
  425.                         /* quit.                                            */
  426.                         /*--------------------------------------------------*/
  427.                         if (arg_value = 'ON') then do
  428.                                 should_beep = 1
  429.                         end
  430.                         else do
  431.                                 if (arg_value = 'OFF') then do
  432.                                         should_beep = 0
  433.                                 end
  434.                                 else do
  435.                                         say 'Beep requires either ON or OFF as a parameter.' || cr
  436.                                         exit 1
  437.                                 end
  438.                         end
  439.                 end
  440.                 WHEN (argument = '-AUTOSTART') then do
  441.                         /*--------------------------------------------------*/
  442.                         /* Translate the argument value into uppercase.     */
  443.                         /*--------------------------------------------------*/
  444.                         arg_value = translate( arg_value )
  445.  
  446.                         /*--------------------------------------------------*/
  447.                         /* Check to see that the given parameter is either  */
  448.                         /* ON or OFF.  If not, display an error message and */
  449.                         /* quit.                                            */
  450.                         /*--------------------------------------------------*/
  451.                         if (arg_value = 'ON') then do
  452.                                 should_autostart = 1
  453.                         end
  454.                         else do
  455.                                 if (arg_value = 'OFF') then do
  456.                                         should_autostart = 0
  457.                                 end
  458.                                 else do
  459.                                         say 'Autostart requires either ON or OFF as a parameter.' || cr
  460.                                         exit 1
  461.                                 end
  462.                         end
  463.                 end
  464.                 WHEN (argument = '-ADDRESS') then do
  465.                         /*--------------------------------------------------*/
  466.                         /* Unfortunately, I can't do much error checking    */
  467.                         /* here.  So, we'll at least ensure that we have    */
  468.                         /* been given a value and that it is a string.  If  */
  469.                         /* not, display an error message and quit.          */
  470.                         /*--------------------------------------------------*/
  471.                         if ( (arg_value \= '') & (datatype(arg_value) = 'CHAR') ) then do
  472.                                 os2_address = arg_value
  473.                         end
  474.                         else do
  475.                                 say 'Address requires a dotted decimal notation address as a parameter.' || cr
  476.                                 exit 1
  477.                         end
  478.                 end
  479.         OTHERWISE do
  480.                 say 'Invalid command line argument: ' || argument || cr
  481.                 exit 1
  482.         end     /* END for the OTHERWISE statement                         */
  483.         END     /* END for the SELECT statement                            */
  484.  
  485.         /*------------------------------------------------------------------*/
  486.         /* Recurse to parse any remaining command line arguments.           */
  487.         /*------------------------------------------------------------------*/
  488.         call parse_arguments( arguments )
  489. return
  490.  
  491.  
  492. /*--------------------------------------------------------------------------*/
  493. /*                    waitfor ( waitstring , [timeout] )                    */
  494. /*..........................................................................*/
  495. /*                                                                          */
  496. /* Waits for the supplied string to show up in the COM input.  All input    */
  497. /* from the time this function is called until the string shows up in the   */
  498. /* input is accumulated in the "waitfor_buffer" variable.                   */
  499. /*                                                                          */
  500. /* If timeout is specified, it says how long to wait if data stops showing  */
  501. /* up on the COM port (in seconds).                                         */
  502. /*                                                                          */
  503. /*--------------------------------------------------------------------------*/
  504. waitfor:
  505.         parse arg waitstring , timeout
  506.  
  507.         if timeout = '' then timeout = 5000  /* LONG delay if not specified */
  508.  
  509.         waitfor_buffer = ''
  510.         done = -1
  511.         curpos = 1
  512.         ORI_TIME=TIME('E')
  513.  
  514.         if (remain_buffer = 'REMAIN_BUFFER') then do
  515.                 remain_buffer = ''
  516.         end
  517.  
  518.         do while (done = -1)
  519.                 if (remain_buffer \= '') then do
  520.                         line = remain_buffer
  521.                         remain_buffer = ''
  522.                 end
  523.                 else do
  524.                         line = slip_com_input(interface,,10)
  525.                 end
  526.  
  527.                 waitfor_buffer = waitfor_buffer || line
  528.                 index = pos(waitstring,waitfor_buffer)
  529.  
  530.                 if (index > 0) then do
  531.                         remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  532.                         waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  533.                         done = 0
  534.                 end
  535.  
  536.                 call charout , substr(waitfor_buffer,curpos)
  537.                 curpos = length(waitfor_buffer)+1
  538.  
  539.                 if ((done \= 0) & (TIME('E')>timeout)) then do
  540.                         done = 1
  541.                 end
  542.         end     /* end of 'while done = -1' */
  543.  
  544.         timeout=0
  545.         RC=done
  546. return RC
  547.  
  548.  
  549.  
  550. /*--------------------------------------------------------------------------*/
  551. /*                               readpass ()                                */
  552. /*..........................................................................*/
  553. /*                                                                          */
  554. /* Routine used to read a password from the user without echoing the        */
  555. /* password to the screen.                                                  */
  556. /*                                                                          */
  557. /*--------------------------------------------------------------------------*/
  558. readpass:
  559.         answer = ''
  560.  
  561.         do until key = cr
  562.                 key = slip_getch()
  563.  
  564.                 if key \= cr then do
  565.                         answer = answer || key
  566.                 end
  567.         end
  568.  
  569.         say ''
  570. return answer
  571.  
  572.  
  573. /*--------------------------------------------------------------------------*/
  574. /*                             flush_receive ()                             */
  575. /*..........................................................................*/
  576. /*                                                                          */
  577. /* Routine to flush any pending characters to be read from the COM port.    */
  578. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  579. /* point it returns.                                                        */
  580. /*                                                                          */
  581. /* The optional echo argument, if 1, says to echo flushed information.      */
  582. /*                                                                          */
  583. /*--------------------------------------------------------------------------*/
  584. flush_receive:
  585.         parse arg echo
  586.  
  587.         /* If echoing the flush - take care of waitfor remaining buffer     */
  588.         if (echo \= '') & (length(remain_buffer) > 0) then do
  589.                 call charout , remain_buffer
  590.                 remain_buffer = ''
  591.         end
  592.  
  593.         /* Eat anything left in the modem or COM buffers.  Stop when        */
  594.         /* new appears for 100ms.                                           */
  595.         do until line = ''
  596.                 line = slip_com_input(interface,,100)
  597.                 if echo \= '' then call charout , line
  598.         end
  599. return
  600.  
  601.  
  602.  
  603. /*--------------------------------------------------------------------------*/
  604. /* NOTE: The following two procedures (waitfor3, waitfor2) were written by  */
  605. /*       Harold Roussel (roussel@physics. mcgill.ca).                       */
  606. /*--------------------------------------------------------------------------*/
  607.  
  608. /*--------------------------------------------------------------------------*/
  609. /*    waitfor3 ( waitstring1 , waitstring2 , waitstring3)                   */
  610. /*..........................................................................*/
  611. /*                                                                          */
  612. /* Waits for the supplied strings to show up in the COM input.  All input   */
  613. /* from the time this function is called until the string shows up in the   */
  614. /* input is accumulated in the "waitfor_buffer" variable.                   */
  615. /*                                                                          */
  616. /*--------------------------------------------------------------------------*/
  617. /* modified to accomodate three strings                                     */
  618. /* this functions returns 1, 2, or 3 depending on which string was received */
  619. /* first                                                                    */
  620. /*--------------------------------------------------------------------------*/
  621. waitfor3:
  622.         parse arg waitstring1 , waitstring2 , waitstring3 , timeout
  623.  
  624.         waitfor_buffer = ''
  625.         done = 0
  626.         curpos = 1
  627.  
  628.         if (remain_buffer = 'REMAIN_BUFFER') then do
  629.                 remain_buffer = ''
  630.         end
  631.  
  632.         do while done = 0
  633.                 if (remain_buffer \= '') then do
  634.                         line = remain_buffer
  635.                         remain_buffer = ''
  636.                 end
  637.                 else do
  638.                         line = slip_com_input(interface)
  639.                 end
  640.  
  641.                 waitfor_buffer = waitfor_buffer || line
  642.                 index1 = pos(waitstring1,waitfor_buffer)
  643.                 index2 = pos(waitstring2,waitfor_buffer)
  644.                 index3 = pos(waitstring3,waitfor_buffer)
  645.  
  646.                 if (index1 > 0) then do
  647.                         remain_buffer = substr(waitfor_buffer,index1+length(waitstring1))
  648.                         waitfor_buffer = delstr(waitfor_buffer,index1+length(waitstring1))
  649.                         stringchosen = 1
  650.                         done = 1
  651.                 end
  652.                 else do
  653.                         if (index2 > 0) then do
  654.                                 remain_buffer = substr(waitfor_buffer,index2+length(waitstring2))
  655.                                 waitfor_buffer = delstr(waitfor_buffer,index2+length(waitstring2))
  656.                                 stringchosen = 2
  657.                                 done = 1
  658.                         end
  659.                         else do
  660.                                 if (index3 > 0) then do
  661.                                         remain_buffer = substr(waitfor_buffer,index3+length(waitstring3))
  662.                                         waitfor_buffer = delstr(waitfor_buffer,index3+length(waitstring3))
  663.                                         stringchosen = 3
  664.                                         done = 1
  665.                                 end
  666.                         end
  667.                 end
  668.  
  669.                 call charout , substr(waitfor_buffer,curpos)
  670.                 curpos = length(waitfor_buffer)+1
  671.         end
  672. return
  673.  
  674.  
  675.  
  676. /*--------------------------------------------------------------------------*/
  677. /*    waitfor2 ( waitstring1 , waitstring2 )                                */
  678. /*..........................................................................*/
  679. /*                                                                          */
  680. /* Waits for the supplied strings to show up in the COM input.  All input   */
  681. /* from the time this function is called until the string shows up in the   */
  682. /* input is accumulated in the "waitfor_buffer" variable.                   */
  683. /*                                                                          */
  684. /*--------------------------------------------------------------------------*/
  685. /* modified to accomodate a second string                                   */
  686. /* this functions returns 1 or 2 depending on which string was received     */
  687. /* first                                                                    */
  688. /*--------------------------------------------------------------------------*/
  689. waitfor2:
  690.         parse arg waitstring1 , waitstring2 , timeout
  691.  
  692.         waitfor_buffer = ''
  693.         done = 0
  694.         curpos = 1
  695.  
  696.         if (remain_buffer = 'REMAIN_BUFFER') then do
  697.                 remain_buffer = ''
  698.         end
  699.  
  700.         do while done = 0
  701.                 if (remain_buffer \= '') then do
  702.                         line = remain_buffer
  703.                         remain_buffer = ''
  704.                 end
  705.                 else do
  706.                         line = slip_com_input(interface)
  707.                 end
  708.  
  709.                 waitfor_buffer = waitfor_buffer || line
  710.                 index1 = pos(waitstring1,waitfor_buffer)
  711.                 index2 = pos(waitstring2,waitfor_buffer)
  712.  
  713.                 if (index1 > 0) then do
  714.                         remain_buffer = substr(waitfor_buffer,index1+length(waitstring1))
  715.                         waitfor_buffer = delstr(waitfor_buffer,index1+length(waitstring1))
  716.                         stringchosen = 1
  717.                         done = 1
  718.                 end
  719.                 else do
  720.                         if (index2 > 0) then do
  721.                                 remain_buffer = substr(waitfor_buffer,index2+length(waitstring2))
  722.                                 waitfor_buffer = delstr(waitfor_buffer,index2+length(waitstring2))
  723.                                 stringchosen = 2
  724.                                 done = 1
  725.                         end
  726.                 end
  727.  
  728.                 call charout , substr(waitfor_buffer,curpos)
  729.                 curpos = length(waitfor_buffer)+1
  730.         end
  731. return
  732.