home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ACTSCLOK.ZIP / ACTSCLOK.CMD next >
OS/2 REXX Batch file  |  1992-10-28  |  16KB  |  360 lines

  1. /* REXX */
  2. /********************************************************************************/
  3. /*                                                                              */
  4. /* Program: ACTSCLOK.CMD - set system date and time from Automatic              */
  5. /*              Computer Time Service (ACTS) maintained by the                  */
  6. /*              National Institute of Standards                                 */
  7. /*                                                                              */
  8. /* Version: 1.0 - October, 1992                                                 */
  9. /*                                                                              */
  10. /* Author:  Chuck Giglia, Delaware Valley OS/2 Users Group                      */
  11. /*          1129 Webster Drive, Wilmington, Delaware 19803                      */
  12. /*          Compuserve: 72317,3704                                              */
  13. /*                                                                              */
  14. /* Acknowledgements:                                                            */
  15. /*          Many thanks to Jerry am Ende of the Delaware Valley OS/2            */
  16. /*          Users Group for his enthusiasm toward REXX which piqued             */
  17. /*          my interest in improving on his TIMESET.CMD routine.                */
  18. /*          Also, I appreciate the design ideas I got from John                 */
  19. /*          Deurbrouck in the October 27, 1992 issue of PC Magazine.            */
  20. /*          His program was a bit flashier, but it was written for              */
  21. /*          Windows in C and I didn't think this problem needed a               */
  22. /*          graphical solution.                                                 */
  23. /*                                                                              */
  24. /*          I hope you can use this routine to your advantage, but I            */
  25. /*          provide no warrantees nor do I guarantee that it performs           */
  26. /*          any useful function.                                                */
  27. /*                                                                              */
  28. /*          Your feedback or ideas for improvement are appreciated.             */
  29. /*                                                                              */
  30. /* Product Description                                                          */
  31. /*      ACTSCLOK.CMD is an OS/2 REXX command file which sets the System Date    */
  32. /*      and Time of the invoking computer to the current date and time from     */
  33. /*      the Automated Computer Time Service (ACTS) maintained by the National   */
  34. /*      Institute of Standards. The ACTS returns Greenwich Mean Time (GMT),     */
  35. /*      so ACTSCLOK.CMD provides for handling a positive or negative offset     */
  36. /*      from GMT and allows the user to enable or disable Daylight Saving       */
  37. /*      Time (DST) adjustment.                                                  */
  38. /*                                                                              */
  39. /* Usage is:                                                                    */
  40. /*       ACTSCLOK <offset> <dstIndicator> <comPort> <PhoneNumber> <dialPrefix>  */
  41. /*              <offset>       = Minutes from GMT (i.e. EST = -300).            */
  42. /*                              The default is -300                             */
  43. /*              <dstIndicator> = Adjust for DST? (Y or N). The default is Y     */
  44. /*              <comPort>      = COM port to use (COM1, COM2, etc.). The        */
  45. /*                              default is COM1                                 */
  46. /*              <PhoneNumber>  = Area code and phone number of the ACTS.        */
  47. /*                              The default is 303-494-4774.                    */
  48. /*              <dialPrefix>   = Any dialing prefixes or codes required to dial */
  49. /*                              the ACTS. The default is 1, (the comma causes   */
  50. /*                              the modem to pause briefly before continuing)   */
  51. /*                                                                              */
  52. /*      Individual command line arguments may be forced to use the default by   */
  53. /*      coding an exclamation point (!) in that argument's position. For example*/
  54. /*      to accept all defaults except the COM port and dialling prefix, use:    */
  55. /*                                                                              */
  56. /*                      ACTSCLOK ! ! COM2 ! 9,                                  */
  57. /*                                                                              */
  58. /*      This example will set the system clock to 300 minutes before GMT during */
  59. /*      Standard Time or 240 minutes before GMT during Daylight Saving Time.    */
  60. /*      The system will use COM2 to dial 9,303-494-4774 to connect to the ACTS. */
  61. /*                                                                              */
  62. /********************************************************************************/
  63.  
  64. /* Initialize Defaults and Control Variables and Perform Startup Processing     */
  65.  
  66.  
  67. dDialPrefix = "1,"              /* default dialing prefix   */
  68.  
  69. dPhoneNumber = "303-494-4774"   /* default telephone number */
  70.  
  71. dOffset = -300                  /* default minutes from GMT.*/
  72.                                 /* This is a signed whole   */
  73.                                 /* number (-300 is 5 hours  */
  74.                                 /* earlier than Greenwich   */
  75.                                 /* Mean Time - i.e. Eastern */
  76.                                 /* Standard Time in the USA)*/
  77.  
  78. dDSTIndicator = "Y"             /* default DST indicator.   */
  79.                                 /* "Y" means adjust for DST */
  80.                                 /* "N" means don't adjust   */
  81.  
  82. dCOMPort = "COM1"               /* defualt COM port         */
  83.  
  84. crLf = X2C("0D0A")
  85.  
  86. busyRetrys = 10                 /* number of times to redial*/
  87.                                 /* if busy or no answer     */
  88.  
  89. attemptNum = 1                  /* dial attempt counter     */
  90.  
  91. argTester = ""                  /* used to determine if     */
  92.                                 /* there are any arguments  */
  93.  
  94. connectLimit = 30               /* number of seconds to wait*/
  95.                                 /* for ACTS to answer       */
  96.  
  97. minutesPerDay = 24 * 60         /* used to determine if we  */
  98.                                 /* have adjusted the time   */
  99.                                 /* over a day boundary      */
  100.  
  101. daysPerMonth.1 = 31             /* load array of number of  */
  102. daysPerMonth.2 = 28             /* days in each month       */
  103. daysPerMonth.3 = 31             
  104. daysPerMonth.4 = 30             /* NOTE: the value for      */
  105. daysPerMonth.5 = 31             /* February will be adjusted*/
  106. daysPerMonth.6 = 30             /* later in the logic if    */
  107. daysPerMonth.7 = 31             /* this is a leap year      */
  108. daysPerMonth.8 = 31
  109. daysPerMonth.9 = 30
  110. daysPerMonth.10 = 31
  111. daysPerMonth.11 = 30
  112. daysPerMonth.12 = 31
  113.  
  114. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  115.  
  116. /* Get and Process any User-Supplied Arguements                                 */
  117.  
  118. PARSE UPPER ARG uOffset uDSTIndicator uCOMPort uPhoneNumber uDialPrefix
  119.  
  120. argTester = uOffset||uDSTIndicator||uCOMPort||uPhoneNumber||uDialPrefix
  121.  
  122. IF argTester == "?" | argTester == "" then do
  123.  
  124.      SAY " "
  125.      SAY "ACTSCLOK.CMD is an OS/2 REXX command file which sets the System Date "
  126.      SAY "     and Time of the invoking computer to the current date and time from "
  127.      SAY "     the Automated Computer Time Service (ACTS) maintained by the National "
  128.      SAY "     Institute of Standards. The ACTS returns Greenwich Mean Time (GMT), "
  129.      SAY "     so ACTSCLOK.CMD provides for handling a positive or negative offset "
  130.      SAY "     from GMT and allows the user to enable or disable Daylight Saving "
  131.      SAY "     Time (DST) adjustment."
  132.      SAY " "
  133.      "@pause"
  134.      SAY " "
  135.      SAY "Usage is: ACTSCLOK <offset> <dstIndicator> <comPort> <PhoneNumber> <dialPrefix>"
  136.      SAY "     <offset>       = Minutes from GMT (i.e. EST = -300). The default is -300"
  137.      SAY "     <dstIndicator> = Adjust for DST? (Y or N). The default is Y"
  138.      SAY "     <comPort>      = COM port to use (COM1, COM2, etc.). The default is COM1"
  139.      SAY "     <PhoneNumber>  = Area code and phone number of the ACTS. The default"
  140.      SAY "                         is 303-494-4774."
  141.      SAY "     <dialPrefix>   = Any dialing prefixes or codes required to dial"
  142.      SAY "                         the ACTS. The default is 1, (the comma"
  143.      SAY "                         causes the modem to pause briefly before "
  144.      SAY "                         continuing)"
  145.      SAY " "
  146.      "@pause"
  147.      SAY " "
  148.      SAY "      Individual command line arguments may be forced to use the default by "
  149.      SAY "      coding an exclamation point (!) in that argument's position. For example "
  150.      SAY "      to accept all defaults except the COM port and dialling prefix, use: "
  151.      SAY " "
  152.      SAY "                      ACTSCLOK ! ! COM2 ! 9, "
  153.      SAY " "
  154.      SAY "      This example will set the system clock to 300 minutes before GMT during "
  155.      SAY "      Standard Time or 240 minutes before GMT during Daylight Saving Time. "
  156.      SAY "      The system will use COM2 to dial 9,303-494-4774 to connect to the ACTS. "
  157.      SAY " "
  158.      "@pause"
  159.      SAY " "
  160.      exit
  161.      
  162. end  /* Do */
  163.  
  164. IF uOffset == "" | uOffset == "!" then
  165.      offset = dOffset
  166. else
  167.      offset = uOffset
  168.  
  169. IF uDSTIndicator == "" | uDSTIndicator == "!" then
  170.      dstIndicator = dDSTIndicator
  171. else
  172.      dstIndicator = uDSTIndicator
  173.  
  174. IF uCOMPort == "" | uCOMPort == "!" then
  175.      comPort = dCOMPort
  176. else
  177.      comPort = uCOMPort
  178.  
  179. IF uPhoneNumber == "" | uPhoneNumber == "!" then
  180.      phoneNumber = dPhoneNumber
  181. else
  182.      phoneNumber = uPhoneNumber
  183.  
  184. IF uDialPrefix == "" | uDialPrefix == "!" then
  185.      dialPrefix = dDialPrefix
  186. else
  187.      dialPrefix = uDialPrefix
  188.  
  189. dialSequence = dialPrefix||phoneNumber
  190.  
  191. /* Open the COM Port and Set the Communications Parameters                      */
  192.  
  193. state = STREAM(comPort, "C", "OPEN")
  194. "@MODE" comPort":1200,E,7,1 > NUL"
  195.  
  196. needToRetry = "Y"                       /* make sure we enter loop at least once */
  197. DO WHILE attemptNum <= busyRetrys & needToRetry = "Y"
  198.  
  199.         SAY " "
  200.         SAY " "
  201.         SAY "Preparing to dial" dialSequence "on" comPort
  202.         SAY "GMT Offset is" offset "minutes"
  203.         SAY "DST Switch is" dstIndicator
  204.         SAY " "
  205.         SAY "Dialing Attempt Number" attemptNum
  206.         SAY " "
  207.  
  208.         /* Dial the ACTS                                                        */
  209.  
  210.         SAY "Dialing . . ."
  211.         SAY " "
  212.  
  213.         startTimer = time('R')          /* reset the elapsed time clock */
  214.         CALL LINEOUT comPort, "ATDT"dialSequence||crLf
  215.  
  216.         /* Bypass first line of help information by grabbing                    */
  217.         /* the first couple lines of output from the ACTS                       */
  218.         /* and throwing them away                                               */
  219.  
  220.         needToRetry = "N"
  221.         dataBuffer = ""
  222.         DO WHILE POS("*", dataBuffer) == 0 & POS("#", dataBuffer) == 0
  223.  
  224.              dataBuffer = dataBuffer||CHARIN(comPort)
  225.              IF POS("BUSY", dataBuffer) <> 0 then do    /* Handle busy condition */
  226.                 SAY "Busy!"
  227.                 needToRetry = "Y"
  228.              end  /* Do */
  229.  
  230.              if time('E') > connectLimit then do        /* Handle no answer condition */
  231.                 say "No Response"
  232.                 needToRetry = "Y"
  233.              end  /* Do */
  234.  
  235.              if needToRetry = "Y" then do
  236.                 CALL LINEOUT comPort, crLf crLf crLf
  237.                 CALL LINEOUT comPort, "ATH"||crLf
  238.                 CALL LINEOUT comPort, "ATH"||crLf
  239.                 CALL LINEOUT comPort, "ATH"||crLf
  240.                 SAY " "
  241.                 attemptNum = attemptNum + 1
  242.                 say "Waiting . . ."
  243.                 SAY " "
  244.                 call SysSleep 5
  245.                 LEAVE
  246.              end  /* Do */
  247.  
  248.         END /* DO WHILE POS("*", dataBuffer) == 0 & POS("#", dataBuffer) == 0 */
  249.  
  250. END /* DO WHILE attemptNum <= busyRetrys & needToRetry = "Y" */
  251.  
  252. IF attemptNum > busyRetrys then do
  253.         SAY " "
  254.         SAY "No response from ACTS after" busyRetrys "attempts"
  255.         SAY "Please try again later"
  256.         SAY " "
  257.         EXIT
  258. END
  259.  
  260. dataBuffer = ""
  261. DO WHILE POS("UTC", dataBuffer) == 0
  262.  
  263.      dataBuffer = dataBuffer||CHARIN(comPort)
  264.  
  265. END
  266.  
  267. CALL LINEOUT comPort, crLf crLf crLf
  268. CALL LINEOUT comPort, "ATH"||crLf                      /* Hang up */
  269. CALL LINEOUT comPort, "ATH"||crLf                      /* Hang up */
  270. CALL LINEOUT comPort, "ATH"||crLf                      /* Hang up */
  271.  
  272. tate = STREAM(comPort, "C", "CLOSE")
  273.  
  274. PARSE VAR dataBuffer . ymdDate timeOfDay dstStatus .
  275.  
  276. /* Interpret the date retrieved from the ACTS */
  277.  
  278. currentYear = LEFT(ymdDate, 2)
  279. currentMonth = SUBSTR(ymdDate, 4, 2)
  280. currentDay = RIGHT(ymdDate, 2)
  281.  
  282. if currentYear // 4 == 0 then             /* check for leap year */
  283.         daysPerMonth.2 = 29
  284.  
  285. /* Determine if we should adjust for Daylight Savings Time (DST)                */
  286. /*   The DST indicator returned in the data will be 00 if we are                */
  287. /*   on Standard Time or 99 to 51 if we are on Standard Time, but               */
  288. /*   approaching DST.                                                           */
  289. /*   This indicator will be 50 if we are on DST or 49 to 01 if we               */
  290. /*   are on DST but approaching Standard Time.                                  */
  291.  
  292. IF dstIndicator == "Y" then
  293.         IF dstStatus <= "50" & dstStatus >= "01" then    /* we're on DST */
  294.                 offset = offset + 60
  295.  
  296. /* Interpret then convert the time to minutes to simplify adjustment            */
  297.  
  298. currentHours = LEFT(timeOfDay, 2)
  299. currentMinutes = SUBSTR(timeOfDay, 4, 2)
  300. currentSeconds = RIGHT(timeOfDay, 2)
  301.  
  302. timeInMinutes = (currentHours * 60) + currentMinutes
  303.  
  304. /* Now, adjust the time and extract the date and time in a                      */
  305. /* form suitable for setting the system clock                                   */
  306.  
  307. adjustedTime = timeInMinutes + offset
  308.  
  309. /* make adjustments if we have crossed a date boundary (i.e. crossed into       */
  310. /* yesterday or into tomorrow)                                                  */
  311.  
  312. select          
  313.  
  314.    when adjustedTime < 0 then do                /* we backed into yesterday */
  315.         adjustedTime = minutesPerDay + adjustedTime
  316.         currentDay = currentDay - 1
  317.         IF currentDay < 1 then
  318.                 currentMonth = currentMonth - 1
  319.         IF currentMonth < 1 then do
  320.                 currentYear = currentYear - 1
  321.                 currentMonth = 12 + currentMonth
  322.                 currentDay = daysPerMonth.currentMonth
  323.         end    /* do */
  324.    end    /* when do */
  325.  
  326.    when adjustedTime > minutesPerDay then do    /* we crossed into tomorrow */
  327.         adjustedTime = adjustedTime - minutesPerDay
  328.         currentDay = currentDay + 1
  329.         if currentDay > daysPerMonth.currentMonth then do
  330.                 currentDay = currentDay - daysPerMonth.currentMonth
  331.                 currentMonth = currentMonth + 1
  332.         end    /* do */
  333.         if currentMonth > 12 then do
  334.                 currentMonth = currentMonth - 12
  335.                 currentYear = currentYear + 1
  336.         end    /* do */
  337.    end    /* when do */
  338.  
  339.    otherwise                                    /* we're still on today */
  340.         nop
  341.  
  342. end  /* select */
  343.  
  344. currentHours = adjustedTime % 60
  345. currentMinutes = adjustedTime // 60
  346.  
  347. /* Finally, Set the system date and time on this PC                             */
  348. /*      NOTE: This version assumes US date format (mm-dd-yy)                    */
  349.  
  350. "@DATE" currentMonth"-"currentDay"-"currentYear
  351. "@TIME" currentHours":"currentMinutes":"currentSeconds
  352.  
  353. SAY " "
  354. SAY " "
  355. SAY "New Time" TIME() "and Date" DATE()
  356. SAY " "
  357. SAY " "
  358.  
  359. exit
  360.