home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / haotd1_1.zip / WEATHER.CMD < prev    next >
OS/2 REXX Batch file  |  1995-10-12  |  12KB  |  355 lines

  1. /*  This REXX script will log you onto the FedWorld BBS and download */
  2. /*  a set of weather maps in GIF format */
  3. /*  by: Sam Shipley, Hilgraeve Inc. */
  4. /*  $Revision: 1.14 $  */
  5. /*  $Date: 1995/09/21 09:44:26 $  */
  6.  
  7. /*  Text within slashes and asterisks (like this line) are comments. */
  8. /*  Parse the command line for arguments passed to this program */
  9. PARSE ARG pipename
  10.  
  11. /******* Register external functions with REXX *****************************/
  12. CALL RxFuncAdd 'haLoadFuncs', 'HA_AUTO', 'RxhaLoadFuncs'
  13. CALL haLoadFuncs
  14.  
  15. signal on failure name CLEANUP
  16. signal on halt name CLEANUP
  17. signal on syntax name CLEANUP
  18.  
  19. /************  Process only if link with HyperACCESS was successful ********/
  20. scripthandle = haInitialize(1, pipename) 
  21. IF scripthandle <> 0 THEN
  22.     DO
  23.  
  24. /******************** Initialize useful variables **************************/
  25.     cr = '0D'x
  26.     lf = '0A'x
  27.     nul = '00'x
  28.     ErrMsg1 = "The BBS has displayed some unexpected text at line "
  29.     ErrMsg2 = " of the script.  The script will attempt to recover."
  30.     ErrMsg3 = "Try calling again.  If you still have problems check the"
  31.     ErrMsg4 = " Hilgraeve BBS for a revised script."
  32.     crlf = '0D'x||'0A'x
  33.     returnvalue = 0
  34.     MWSret = 0
  35.     NameCnt = 0
  36.     MapName = ''
  37.     NameVal = ''
  38.     Mname = ''
  39.     Mcompany = ''
  40.     Maddress = ''
  41.     Mcity = ''
  42.     Mphone = ''
  43.     password = ''
  44.     ErrCnt = 0
  45.     RegisterData = haGetNameString(scripthandle, 256,'RegBuf')
  46.     parse var RegBuf Name (crlf) Company (crlf) Address (crlf) City (crlf) State (crlf) Zip (crlf) Country
  47.     City = City || "," || State || "  " || Zip    
  48.     
  49. /****** Routine to check if this is a first time call to FedWorld BBS ******/
  50.     
  51.     ret = haGetRuntimeValue(scripthandle, 1, 0, 128, 'NameVal')
  52.     /*  If user has logged in using this script and has stored their name
  53.         in the runtime values then NameVal will have a length greater than
  54.         0 */
  55.     
  56.     IF LENGTH(NameVal) > 0 THEN DO
  57.         CALL StandardLogin
  58.     END
  59.     ELSE DO
  60.         CALL NewUser
  61.     END
  62.     DO i = 1 TO 3  /* Send some carriage returns to clear any unwanted messages */
  63.         returnvalue = haTypeText(scripthandle, 0, cr)
  64.         ret = haWaitForActivity(scripthandle, 5000)
  65.     END /* DO i = 1 TO 3 */
  66. /*** We'll now start making the selections to download the weather Maps ****/
  67. /* Check to see if one of the runtime values contains a map name  */
  68.     DO i = 10 TO 19
  69.         returnvalue = haGetSessionDataString(scripthandle, i, 14, 'MapName')
  70.         IF LENGTH(MapName) > 0 THEN LEAVE
  71.     END
  72.     IF LENGTH(MapName) > 0 THEN 
  73.         DO
  74.             returnvalue = haTypeText(scripthandle, 0, '/go satimgs'||cr)
  75.             CALL GetMaps
  76.         END
  77.     CALL Cleanup
  78. END
  79.  
  80. /*********************** Subroutine section ********************************/
  81.  
  82. NewUser:
  83.  
  84. /******************* Start of opening screen *******************************/
  85.  
  86.     IF returnvalue >= 0 THEN DO
  87.         returnvalue = haWaitForString(scripthandle, 1, '"NEW":  ', 600000)
  88.         CALL ChkRtnVal
  89.     END
  90.     IF returnvalue >= 0 THEN
  91.         returnvalue = haTypeText(scripthandle, 0, 'new'||cr)
  92.     IF returnvalue >= 0 THEN DO
  93.         returnvalue = haWaitForPrompt(scripthandle, 1, 'continue', 300, 5000)
  94.         CALL ChkRtnVal
  95.     END
  96.     IF returnvalue >= 0 THEN
  97.         returnvalue = haTypeText(scripthandle, 0, cr)
  98.  
  99. /************** BBS prompt to ask about ANSI graphics  *********************/
  100.  
  101.     IF returnvalue >= 0 THEN
  102.         returnvalue = haWaitForPrompt(scripthandle, 1, '[1D'||'1B'x'[37m', 300, 12000)
  103.     IF returnvalue >= 0 THEN
  104.         returnvalue = haTypeText(scripthandle, 0, 'N'||cr)
  105.    
  106. /************ Start logging in as a new user *******************************/
  107.     DO UNTIL MWSret >= 8
  108.         MWSret = haWaitForString(scripthandle, 9, 'tted!)'nul'if none:'nul'Box):'nul'ZIP):'nul'U.S.):'nul'the day:'nul'0 to 3:'nul'to use:'nul'verification'nul||nul, 180000)
  109.         CALL ChkRtnVal
  110.         SELECT
  111.  
  112. /************* Get user name and pass to FedWorld BBS **********************/
  113.             WHEN MWSret = 0 THEN
  114.                 DO
  115.                     IF NameCnt = 0 THEN DO
  116.                         returnvalue = haGetRuntimeValue(scripthandle, 1, 1, 128, 'NameVal')
  117.                         returnvalue = haTypeText(scripthandle, 0, NameVal||cr)
  118.                         returnvalue = haSetRuntimeValue(scripthandle, 1, NameVal)
  119.                         NameCnt = NameCnt + 1
  120.                     END
  121.                     ELSE DO
  122.                         returnvalue = haMessageBox(scripthandle, 'NAME IN USE!!','Please change name slightly and press OK', 128, 'Mname', 1)
  123.                         returnvalue = haTypeText(scripthandle, 0, Mname||cr)
  124.                         returnvalue = haSetRuntimeValue(scripthandle, 1, Mname)
  125.                     END
  126.                 END
  127.  
  128. /*************** Get Company Name and pass to FedWorld BBS *****************/
  129.             WHEN MWSret = 1 THEN
  130.                 DO
  131.                     IF LENGTH(Company) > 0 THEN
  132.                         DO
  133.                             returnvalue = haTypeText(scripthandle, 0, Company||cr)
  134.                         END
  135.                         ELSE DO
  136.                             returnvalue = haMessageBox(scripthandle, 'Company','Please enter your company name, press enter for none', 128, 'Mcompany', 1)
  137.                             returnvalue = haTypeText(scripthandle, 0, Mcompany||cr)
  138.                         END
  139.  
  140.                 END
  141.  
  142. /************ Get street address and pass to FedWorld BBS ******************/
  143.             WHEN MWSret = 2 THEN
  144.                 DO
  145.                     IF LENGTH(Address) >= 5 THEN
  146.                         DO
  147.                         returnvalue = haTypeText(scripthandle, 0, Address||cr)
  148.                     END
  149.                     ELSE DO
  150.                         returnvalue = haMessageBox(scripthandle, 'Address','Please enter your address and press OK', 128, 'Maddress', 1)
  151.                         returnvalue = haTypeText(scripthandle, 0, Maddress||cr)
  152.                     END
  153.                 END
  154.  
  155. /************* Get City, ST & Zip Code and pass to FedWorld BBS  ***********/
  156.             WHEN MWSret = 3 THEN
  157.                 DO
  158.                     IF LENGTH(City) >= 7 THEN
  159.                         DO
  160.                             returnvalue = haTypeText(scripthandle, 0, City||cr)
  161.                         END
  162.                         ELSE DO
  163.                             returnvalue = haMessageBox(scripthandle, 'City, State & Zip','Please enter your City, St and Postal Code then press OK', 128, 'Mcity', 1)
  164.                             returnvalue = haTypeText(scripthandle, 0, Mcity||cr)
  165.                         END
  166.  
  167.                 END
  168.  
  169. /*************** Enter Country  ********************************************/
  170.             WHEN MWSret = 4 THEN
  171.                 DO
  172.                     IF LENGTH(Country) >= 2 THEN
  173.                         DO
  174.                             returnvalue = haTypeText(scripthandle, 0, Country)
  175.                         END
  176.                 END
  177.  
  178. /*************** Enter Daytime phone ***************************************/
  179.             WHEN MWSret = 5 THEN 
  180.                 DO
  181.                     returnvalue = haMessageBox(scripthandle, 'Phone Number','Please enter your daytime phone number and press OK', 128, 'Mphone', 1)
  182.                     returnvalue = haTypeText(scripthandle, 0, Mphone||cr)
  183.                 END
  184.  
  185. /************** Enter type of computer *************************************/
  186.             WHEN MWSret = 6 THEN
  187.                 returnvalue = haTypeText(scripthandle, 0, '1'||cr)
  188.  
  189. /************** Enter Password *********************************************/
  190.             WHEN MWSret = 7 THEN
  191.                 DO
  192.                     returnvalue = haGetRuntimeValue(scripthandle, 3, 1, 128, 'password')
  193.                     returnvalue = haTypeText(scripthandle, 0, password||cr)
  194.                     returnvalue = haSetRuntimeValue(scripthandle, 3, password)
  195.                 END
  196.  
  197. /************** Verify Passowrd ********************************************/
  198.             WHEN MWSret = 8 THEN
  199.                 DO
  200.                     returnvalue = haTypeText(scripthandle, 0, password||cr)
  201.                 END
  202.  
  203. /************ Some other value has been returned - this is an error ********/            
  204.             OTHERWISE LEAVE
  205.         END /* SELECT */
  206.     END /* DO UNTIL */
  207.  
  208. /* The rest will be answered with default answers to get to the main menu  */
  209.     IF returnvalue >= 0 THEN DO
  210.         returnvalue = haWaitForString(scripthandle, 1, 'sword...', 5000)
  211.         CALL ChkRtnVal
  212.     END
  213.     IF returnvalue >= 0 THEN
  214.         returnvalue = haTypeText(scripthandle, 0, cr)
  215.     IF returnvalue >= 0 THEN DO
  216.         returnvalue = haWaitForString(scripthandle, 1, '(Y/N)? ', 5000)
  217.         CALL ChkRtnVal
  218.     END
  219.     IF returnvalue >= 0 THEN
  220.         returnvalue = haTypeText(scripthandle, 0, 'n'||cr)
  221.     returnvalue = 0
  222. RETURN
  223.  
  224. StandardLogin:
  225.     returnvalue = 0
  226.     IF returnvalue >= 0 THEN DO
  227.         returnvalue = haWaitForString(scripthandle, 1, '"NEW":  ', 600000)
  228.         CALL ChkRtnVal
  229.     END
  230.     IF returnvalue >= 0 THEN
  231.         returnvalue = haGetRuntimeValue(scripthandle, 1, 1, 128, 'NameVal')
  232.     IF returnvalue >= 0 THEN
  233.         returnvalue = haTypeText(scripthandle, 0, NameVal || cr)
  234.     IF returnvalue >= 0 THEN DO
  235.         returnvalue = haWaitForString(scripthandle, 1, 'Password>  ', 5000)
  236.         CALL ChkRtnVal
  237.     END
  238.     IF returnvalue >= 0 THEN
  239.         returnvalue = haGetRuntimeValue(scripthandle, 3, 1, 128, 'PassVal') >= 0 THEN
  240.     IF returnvalue >= 0 THEN DO
  241.         returnvalue = haTypeText(scripthandle, 0, PassVal||cr)
  242.         returnvalue = haSetRuntimeValue(scripthandle, 3, PassVal)
  243.     END
  244.     DO UNTIL MWSret >= 1
  245.         MWSret = haWaitForString(scripthandle, 2, 'RETURN to continue'nul' (Y/N)? 'nul||nul, 20000)
  246.         SELECT
  247.             WHEN MWSret = 0 THEN
  248.                 returnvalue = haTypeText(scripthandle, 0, cr)
  249.             WHEN MWSret = 1 THEN 
  250.                 returnvalue = haTypeText(scripthandle, 0, 'n'||cr)
  251.             OTHERWISE LEAVE
  252.         END /* SELECT  */
  253.     END /* DO UNTIL  */
  254.     MWSret = 0
  255.     returnvalue = 0
  256. RETURN
  257.  
  258. GetMaps:
  259.  
  260. /******** Get the maps for downloading from the runtime values *************/
  261. /*  GetMaps processes the list of files from the runtime values that the 
  262.     user selected with the MAPSELEC.CMD script which runs before the connection
  263.     is started. */
  264.     IF returnvalue >= 0 THEN DO
  265.         returnvalue = haWaitForString(scripthandle, 1, 'help: ', 5000)
  266.         CALL ChkRtnVal
  267.     END
  268.     IF returnvalue >= 0 THEN
  269.         returnvalue = haTypeText(scripthandle, 0, 'p'||cr)
  270.     IF returnvalue >= 0 THEN DO
  271.         returnvalue = haWaitForString(scripthandle, 1, 'exit: ', 5000)
  272.         CALL ChkRtnVal
  273.     END
  274.     IF returnvalue >= 0 THEN
  275.         returnvalue = haTypeText(scripthandle, 0, 'p'||cr)
  276.     IF returnvalue >= 0 THEN DO
  277.         returnvalue = haWaitForString(scripthandle, 1, 'RETURN: ', 5000)
  278.         CALL ChkRtnVal
  279.     END
  280.     IF returnvalue >= 0 THEN
  281.         returnvalue = haTypeText(scripthandle, 0, 'z'||cr)
  282.     IF returnvalue >= 0 THEN DO
  283.         returnvalue = haWaitForString(scripthandle, 1, 'mplete? ', 5000)
  284.         CALL ChkRtnVal
  285.     END
  286.     IF returnvalue >= 0 THEN
  287.         returnvalue = haTypeText(scripthandle, 0, 'n'||cr)
  288.     IF returnvalue >= 0 THEN DO
  289.         returnvalue = haWaitForString(scripthandle, 1, 'to exit: ', 5000)
  290.         CALL ChkRtnVal
  291.     END
  292.     IF returnvalue >= 0 THEN
  293.         returnvalue = haTypeText(scripthandle, 0, 'x'||cr)
  294.     IF returnvalue >= 0 THEN
  295.        returnvalue =  haSetXferProtocol(scripthandle, 2, 2)
  296.     Map. = ''
  297.     DO i = 10 TO 19
  298.         returnvalue = haGetSessionDataString(scripthandle, i, 14, 'Map.'i)
  299.     END
  300.     IF returnvalue >= 0 THEN
  301.         DO i = 10 TO 19
  302.             IF LENGTH(Map.i) > 1 THEN
  303.                 DO  /* Start download of file */
  304.                     IF returnvalue >= 0 THEN
  305.                         returnvalue = haTypeText(scripthandle, 0, 'D'||cr)
  306.                     IF returnvalue >= 0 THEN
  307.                         returnvalue = haWaitForString(scripthandle, 1, 'help', 12000)
  308.                     returnvalue = haTypeText(scripthandle, 0, Map.i||cr)
  309.                     IF returnvalue >= 0 THEN
  310.                         returnvalue = haWaitForString(scripthandle, 1, 'continue', 1000000)
  311.                     IF returnvalue >= 0 THEN
  312.                         returnvalue = haTypeText(scripthandle, 0, cr)
  313.                 END  /* End download of file */
  314.         END /* i = 10 TO 19 loop */
  315.  
  316. /***************** End the session and disconnect **************************/
  317.  
  318.     IF returnvalue >= 0 THEN DO
  319.         returnvalue = haWaitForString(scripthandle, 1, 'for help: ', 5000)
  320.         CALL ChkRtnVal
  321.     END
  322.     IF returnvalue >= 0 THEN
  323.         returnvalue = haTypeText(scripthandle, 0, '/go logoff'||cr)
  324.     IF returnvalue >= 0 THEN DO
  325.         returnvalue = haWaitForString(scripthandle, 1, '(Y/N)? ', 5000)
  326.         CALL ChkRtnVal
  327.     END
  328.     IF returnvalue >= 0 THEN
  329.         returnvalue = haTypeText(scripthandle, 0, 'Y'||cr)
  330. RETURN
  331.  
  332.  
  333. CLEANUP:
  334.     ret = haDisconnectSession(scripthandle)
  335.     CALL haTerminate scripthandle
  336.     DROP pipename
  337.     DROP scripthandle
  338.     CALL haDropFuncs
  339. EXIT
  340.  
  341. ChkRtnVal:
  342.     retval = haGetConnectionStatus
  343.     IF retval == 3 THEN CALL Cleanup
  344.     IF returnvalue < 0 THEN DO
  345.         IF ErrCnt = 0 THEN DO
  346.             ErrCnt = 1
  347.             returnvalue = haMessageBox(scripthandle, 'Error', ErrMsg1||sigl||ErrMsg2, 0, null, 1)
  348.         END
  349.         ELSE DO
  350.             returnvalue = haMessageBox(scripthandle, 'Unrecoverable Error', ErrMsg3||ErrMsg4, 0, null, 1)
  351.             CALL Cleanup
  352.         END        
  353.     END
  354. RETURN    
  355.