home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / OS2SHKWQ.ZIP / OS2SHARE.CMD
OS/2 REXX Batch file  |  1992-11-29  |  11KB  |  314 lines

  1. /*-------------------------------------------------------------------*/
  2. /* Log onto Pete Norloff's ShareWare BBS, upload pending KWQ REPs,   */
  3. /* download KWQ mail, once a day download Pete's Os2New.zip          */
  4. /*                                                                   */
  5. /* The script assumes your settings on the board are:                */
  6. /*             expert toggled on, and protocol=Zmodem                */
  7. /*                                                                   */
  8. /* Timeouts are set assuming a reasonable number of new messages.    */
  9. /* If your last message in each forum isn't reasonable current,      */
  10. /* you'll time out.                                                  */
  11. /*                                                                   */
  12. /* This script assumes you have set the PmComm32 memo field to a     */
  13. /* string that consists of "First name", "Last Name", and "Password" */
  14. /* separated by white space.  Example:                               */
  15. /*                                                                   */
  16. /*                    Ron Hester mysecretpassword                    */
  17. /*                                                                   */
  18. /* Be sure to the the "File Specs" below for your own system.        */
  19. /*-------------------------------------------------------------------*/
  20.  
  21. Signal ON SYNTAX NAME SYNTAX_ERROR
  22.  
  23. Parse arg port portname screen_handle dde_output dde_input semaphore
  24. Parse source . . fn .
  25.  
  26. /* File Specs */
  27. Reply_File="D:\PmComm\HostUp\Os2Share.rep" /* Packet to upload */
  28. Capture_File="D:\PmComm\Capture\Os2Share.txt" /* Capture file */
  29. Os2New="D:\PmComm\Files\Os2New.zip"
  30.  
  31. /* Constants */
  32. cr     = '0D'x
  33. crlf   = '0A0D'x
  34. ctrl_K = '0B'x
  35. esc    = '1B'x
  36.  
  37. /* Environment Switches */
  38. dcds  = 1    /* modem supports dcd */
  39. quiet = 0    /* change to 1 to disable audible alarms at suitable points */
  40. debug = 0    /* change to 1 to activate some debugging stuff */
  41.  
  42. Call RxFuncAdd "Init_32dll","RxPmC32","Init_32dll"
  43. Call Init_32dll
  44. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  45. Call SysLoadFuncs
  46.  
  47. Call Clear
  48. Call Alarm
  49. If debug then Call Put_s 'Executing' fn '...'||crlf,screen_handle
  50.  
  51. DownLoad_New=stream(Os2New,'c','query exists')=''
  52. if \Download_New then
  53.   do
  54.     parse value stream(Os2New,'c','query datetime') with FDate ' ' .
  55.     Download_New=Fdate\=translate(date('U'),'-','/')
  56.   end
  57. Download_New=DownLoad_New & time('h')>4
  58. if debug then Call Put_s crlf"DownLoad_New="DownLoad_New||crlf,screen_handle
  59.  
  60. Call get_dial_memo dde_output,dde_input
  61. parse var Result First_Name Last_Name Password
  62.  
  63. Call Read_timeout '20000',port
  64. Do Forever
  65.    If dcds then Call Connected
  66.    Call Wait_fore "andle:",,        /*  1 */
  67.                   "irst name",,     /*  2 */
  68.                   "ast name",,      /*  3 */
  69.                   " name",,         /*  4 */
  70.                   "assword",,       /*  5 */
  71.                   "ape",,           /*  6 */
  72.                   ",n]?",,          /*  7 */
  73.                   "graphics (",,    /*  8 */
  74.                   "olor?",,         /*  9 */
  75.                   "onStop:",,       /* 10 */
  76.                   "anguage #",,     /* 11 */
  77.                   "First Name",,    /* 12 */
  78.         port,screen_handle
  79.    Match=Result
  80.    Call Flush
  81.    If debug then Call Put_s crlf"Match="Match||crlf,screen_handle
  82.    Select
  83.       When Match=1 then Call Put_s CS_Handle||cr,port
  84.       When Match=2 then Call Put_s First_Name||cr,port
  85.       When Match=3 then Call Put_s Last_Name||cr,port
  86.       When Match=4 then Call Put_s First_Name";"Last_Name||cr,port
  87.       When Match=5 then
  88.          Do
  89.             Call Put_s Password||cr,port
  90.             Leave
  91.          End
  92.       When Match=6 then
  93.          Do
  94.             Call Put_s esc,port
  95.             Call Sleep "250"
  96.             Call Put_s esc,port
  97.          End
  98.       When Match=7 | Match=8 | Match=9 then Call Put_s "y"cr,port
  99.       When Match=10 then Call Put_s "n"cr,port
  100.       When Match=11 then Call Put_s cr,port
  101.       When Match=12 then Call Put_s NewWareBBS";"Password||cr,port
  102.       When Match=0 then
  103.          Do
  104.             Call Alarm
  105.             If dcds then Call Connected
  106.             Call Put_s crlf"Unexpected timeout, script is exiting"crlf,screen_handle
  107.             Call Alarm
  108.             Exit /* If no match, go manual */
  109.          End
  110.       Otherwise Call Put_s cflf"Unexpected Match="Match" encountered and ignored"crlf,screen_handle
  111.  
  112.    End
  113. End
  114.  
  115. Call Read_timeout '90000',port
  116. Do Forever
  117.    If dcds then Call Connected
  118.    Call Wait_fore " to continue ",,      /*  1 */
  119.                   " to continue?",,      /*  2 */
  120.                   "inue?",,              /*  3 */
  121.                   "ins updated",,        /*  4 */
  122.                   "ort scan.",,          /*  5 */
  123.                   "xecute ?",,           /*  6 */
  124.                   " go...",,             /*  7 */
  125.                   "k for mail",,         /*  8 */
  126.                   "k for new files",,    /*  9 */
  127.                   "ate to search from",, /* 10 */
  128.                   "MAIN:",,              /* 11 */
  129.                   "ain:",,               /* 12 */
  130.                   "ommand?",,            /* 13 */
  131.                   "nter = ",,            /* 14 */
  132.                   "earching",,           /* 15 */
  133.                   "ore [",,              /* 16 */
  134.                   "*)NextArea]:",,       /* 17 */
  135.         port,screen_handle
  136.    Match=Result
  137.    If Match\=5 & Match\=6 & Match\=7 & Match\=11 & Match\=12,
  138.     & Match\=13 & Match\=15 & Match\=17 then
  139.      Call Flush
  140.    if debug then Call Put_s crlf"Match="Match||crlf,screen_handle
  141.    Select
  142.       When Match=9 then
  143.         do
  144.           If DownLoad_New then
  145.             do
  146.               Call Put_s cr,port
  147.               Call Capture_on Capture_File,dde_output,dde_input
  148.             end
  149.           else
  150.             Call Put_s "n",port
  151.         end
  152.       When Match=1 | Match=10 | Match=14 then Call Put_s cr,port
  153.       When Match=3 | Match=8 | Match=16 then Call Put_s "n",port
  154.       When Match=2 | Match=4 | Match=17 then Call Put_s "n"cr,port
  155.       When Match=5 then Nop  /* Call Put_s ctrl_K,port */  /* Suppress mail notification? */
  156.       When Match=6 | Match=7 | Match=11 | Match=12 | Match=13 then Leave
  157.       When Match=15 then nop /* allow more time for new files scan */
  158.       When Match=0 then
  159.          Do
  160.             If dcds then Call Connected
  161.             Call Alarm
  162.             Call Put_s crlf"Unexpected timeout, script is exiting"crlf,screen_handle
  163.             Call Alarm
  164.             Exit /* If no match, go manual */
  165.          End
  166.       Otherwise Call Put_s cflf"Unexpected Match="Match" encountered and ignored"crlf,screen_handle
  167.    End
  168. End
  169.  
  170. If DownLoad_New then
  171.   Call Capture_off dde_output,dde_input
  172.  
  173. Call Put_s "o",port
  174. Call Wait_fore "READER:",port,screen_handle
  175. Call Flush
  176. If dcds then Call Connected
  177. if stream(Reply_File,'c','query exists')\='' then
  178.   do
  179.     Call put_s "u",port
  180.     Call wait_fore "cancel",port,screen_handle
  181.     Call Flush
  182.     Call zmodem_send Reply_File,dde_output,dde_input
  183.     Call Flush
  184.     Call wait_fore "READER:",port,screen_handle
  185.     Call Flush
  186.     Call SysFileDelete Reply_File
  187.   end
  188. Call put_s "d",port
  189. Call wait_fore "QWK format",,
  190.                "READER:",,
  191.      port,screen_handle
  192. Match=Result
  193. Call Flush
  194. If dcds then Call Connected
  195. Select
  196.   When Match=1 then
  197.     do
  198.       Call put_s cr,port
  199.       Call wait_fore "to abort:",port,screen_handle
  200.       Call Flush
  201.       Call put_s cr,port
  202.       Call wait_fore "to cancel.",port,screen_handle
  203.       Call zmodem_receive dde_output,dde_input
  204.       Call Read_timeout '120000',port
  205.       Call wait_fore "READER:",port,screen_handle
  206.       Call Flush
  207.     end
  208.   When Match=2 then
  209.     nop
  210.   Othewise
  211.     Exit
  212. End
  213.  
  214. Call Read_timeout '90000',port
  215.  
  216. If Download_New then
  217.   do
  218.     Call SysFileDelete Os2New
  219.     Call put_s "m",port
  220.     Call wait_fore ":",port,screen_handle
  221.     Call put_s "f",port
  222.     Call wait_fore ":",port,screen_handle
  223.     Call put_s "d",port
  224.     Call wait_fore ":",port,screen_handle
  225.     Call put_s "Os2New"cr,port
  226.     Call wait_fore ":",port,screen_handle
  227.     Call put_s "/g"cr,port
  228.     Call wait_fore "to cancel.",port,screen_handle
  229.     Call Flush
  230.     Call zmodem_receive dde_output,dde_input
  231.   end
  232. Else
  233.   do
  234.     Call put_s "g",port
  235.     Call wait_fore "nnect",port,screen_handle
  236.     Call Flush
  237.     Call put_s cr,port
  238.     Call wait_fore "rloff",port,screen_handle
  239.     Call Flush
  240.     Call put_s cr,port
  241.   End
  242.  
  243. If Debug then Call Put_s crlf"Script has completed"crlf||crlf,screen_handle
  244. Call Alarm
  245. Exit 0
  246.  
  247. /* Clear Screen Routine                                              */
  248. Clear: procedure expose screen_handle
  249.  
  250. Call put_s "1b5b324a"x,screen_handle
  251. Return
  252.  
  253.  
  254. /* A Procedure to see if the modem supports DCD and if see if we     */
  255. /* have a connection, if not then DROP the DTR and then RAISE the    */
  256. /* DTR again ...                                                     */
  257. Connected: procedure expose port crlf screen_handle
  258.  
  259. Call DCD port
  260. If result \= 1 then
  261.    Do
  262.      Call Beep 40,900
  263.      Call Put_s 'Carrier lost, script is terminating'||crlf,screen_handle
  264.      Call Drop_DTR port
  265.      Call Raise_DTR port
  266.      Exit
  267.    End
  268. Return
  269.  
  270. /* speedy NBC noise, courtesy of Dr. Scott Mack */
  271. Alarm: procedure expose quiet
  272.  
  273. If quiet then return
  274. CALL BEEP 196,350
  275. CALL BEEP 330,500
  276. CALL BEEP 262,650
  277. return
  278.  
  279. /*
  280.    Read and display any characters that were in the receive buffer at the time our wait_fore
  281.    hit a match.  Do this since the match might not have been at the end of the string we are going
  282.    to respond to, so we want the accompanying characters to be processed and displayed.  Don't
  283.    loop until get_ch fails, just in case we've matched something in the middle of a continuous
  284.    transmission that won't expect a response at this point.
  285. */
  286.  
  287. Flush: procedure expose port screen_handle crlf
  288.  
  289. Do while char_avail(port)>0
  290.    Call Put_s Get_ch(port),screen_handle
  291. End
  292. return
  293.  
  294. /* Standard handler for SIGNAL on ERROR, will help in the debugging  */
  295. syntax_error:
  296. fp = filespec("path",fn)
  297. fd = filespec("drive",fn)
  298. errormsg='REXX error' rc 'in line' sigl':' errortext(rc)
  299. errorfile = fd||fp||"SCRIPT.ERR"
  300. rc = lineout(errorfile,date() time() fn '-' errormsg)
  301. rc = lineout(errorfile,date() time() fn '-' sourceline(sigl))
  302. Exit 8
  303.  
  304. /*
  305. If debug then
  306.    Do
  307.       fp = filespec("path",fn)
  308.       fd = filespec("drive",fn)
  309.       capfile = fd||fp||"Debug.err"
  310.       call capture_on capfile,dde_output,dde_input
  311.    End
  312. If debug then Call capture_off dde_output,dde_input
  313. */
  314.