home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / chang09m.zip / autochanx.cmd < prev    next >
OS/2 REXX Batch file  |  1995-08-29  |  4KB  |  122 lines

  1. /*
  2.  
  3.    AUTOCHANX.CMD
  4.  
  5.    This is used to call CHANX (the news-exchange program) with the date that
  6.    CHANX was last called, so that only recent news is received.
  7.  
  8. */
  9.  
  10. /* User settable constants for the Program */
  11.  
  12. ChangiPIDSpec   = 'D:\APPS\NEWS\CHANGI.PID'     /* Location of CHANGI.PID, when present */
  13. ChanxFileSpec   = 'D:\APPS\NEWS\CHANX.EXE'      /* Location of CHANX.EXE */
  14. HostNewsAddress = 'news.dircon.co.uk'           /* Name of the news server */
  15. Groups          = 'D:\APPS\NEWS\NEWSRC'         /* Name of file specifying which groups */
  16.                                                 /* to collect */
  17. MaxDays         = 2                             /* Maximum number of days to collect */
  18.                                                 /* Should not exceed 27 */
  19. /* Internal constants */
  20.  
  21. MonthDays.1     = 31                            /* How many days in each month */
  22. MonthDays.2     = 28
  23. MonthDays.3     = 31
  24. MonthDays.4     = 30
  25. MonthDays.5     = 31
  26. MonthDays.6     = 30
  27. MonthDays.7     = 31
  28. MonthDays.8     = 31
  29. MonthDays.9     = 30
  30. MonthDays.10    = 31
  31. MonthDays.11    = 30
  32. MonthDays.12    = 31
  33.  
  34. /* Load the system functions (REXXUTIL) */
  35.  
  36. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  37. call SysLoadFuncs
  38.  
  39. /* Check to see if Changi the NNTP news server is running, by checking for the */
  40. /* existence of the CHANGI.PID file. Changi must be running for Chanx to work. */
  41.  
  42. if STREAM( ChangiPIDSpec, 'c', 'Query exists' )=='' then
  43. do
  44.         say "The Changi NNTP news server must be running for CHANX to work."
  45.         say "If Changi is running, then check the setting of the ChangiPIDSpec"
  46.         say "variable in the REXX script. The current value of ChangiPIDSpec"
  47.         say "is '"ChangiPIDSpec"'"
  48.         exit
  49. end
  50.  
  51. /* The date command, Date('Based') returns the number of days since 01 January 0001 */
  52. /* This makes it easy to get the difference between dates, in days */
  53. /* Date('Ordered') returns the date in the form YY/MM/DD */
  54.  
  55. TodayBased   = Date('Based')                    /* Get the Current Date */
  56. TodayOrdered = Date('Ordered')
  57. TodayTime    = Time()
  58.  
  59. /* Get the last date that CHANX was called from an extended file attribute in */
  60. /* CHANX.EXE */
  61.  
  62. result  = SysGetEA( ChanxFileSpec, 'LASTRUN_ORDERED', 'LastOrdered' )
  63. result  = SysGetEA( ChanxFileSpec, 'LASTRUN_TIME', 'LastTime' ) + result
  64. result  = SysGetEA( ChanxFileSpec, 'LASTRUN_BASED', 'LastBased' ) + result
  65.  
  66. if (result \= 0) | (LastOrdered=='') then
  67. do
  68.         say "Could not read extended attributes LASTRUN_BASED and LASTRUN_SORTED"
  69.         say "from file '"ChanxFileSpec"'. Assuming that this is the first"
  70.         say "time you are running this script."
  71.  
  72.         /* Default action is to collect the last MaxDays lot of news */
  73.  
  74.         LastBased = 0
  75.         LastTime = '000000'
  76.         LastSorted = ' '
  77. end
  78.  
  79. /*
  80.    If more than MaxDays have passed since the last collection of news, then
  81.    collect only the last MaxDays lot of news.
  82. */
  83.  
  84. if (TodayBased - LastBased > MaxDays) then
  85. do
  86.         PARSE VAR TodayOrdered Year '/' Month '/' Day
  87.  
  88.         /* Subtract MaxDays from Today's date */
  89.  
  90.         Day = Day - MaxDays
  91.         if Day <= 0 then
  92.         do
  93.                 Month = Month - 1;
  94.                 if Month <= 0 then do
  95.                         Month = 12
  96.                         Year = Year - 1
  97.                 end
  98.                 Day = MonthDays.Month - MaxDays;
  99.         end
  100.  
  101.         LastSorted = Year''Month''Day
  102.         LastTime   = TodayTime
  103. end
  104. else do
  105.         PARSE VAR LastOrdered Year '/' Month '/' Day
  106.         LastSorted = Year''Month''Day
  107. end
  108.  
  109. /* Split the time into hour minute and second portions */
  110.  
  111. PARSE VAR LastTime Hour ':' Minute ':' Seconds
  112.  
  113. /* Call chanx with the appropriate parameters, remove the say to perform the function */
  114.  
  115. ChanxFileSpec HostNewsAddress Groups LastSorted Hour''Minute''Seconds
  116.  
  117. /* Update Chanx's Extended Attributes */
  118.  
  119. result  = SysPutEA( ChanxFileSpec, 'LASTRUN_ORDERED', TodayOrdered )
  120. result  = SysPutEA( ChanxFileSpec, 'LASTRUN_TIME', TodayTime ) + result
  121. result  = SysPutEA( ChanxFileSpec, 'LASTRUN_BASED', TodayBased ) + result
  122.