home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / newfil11.zip / NEWFILES.CMD next >
OS/2 REXX Batch file  |  1994-01-23  |  9KB  |  298 lines

  1. /* newfiles.cmd - displays files and their descriptions in the
  2. ALLFILES.TXT when they are newer than the date given on the command line, or
  3. within the number of days given on the command line.  This REXX command
  4. file is designed to work ONLY with the OS/2 Shareware BBS's ALLFILES.TXT.
  5.  
  6. Steve Allen
  7. Altech Computer Services
  8. 121 Herta St.
  9. Easley, SC 29640
  10.  
  11. Jan 94
  12. trace ?i
  13. */
  14.  
  15.     say ""
  16.     say "NEWFILES v1.1 1994"
  17.     say "Altech Computer Services" 'fe'x "Steve Allen"
  18.     say ""
  19.  
  20.     arg cmpdate newfile /* the "newfile" is optional--has default value */
  21.  
  22.     if cmpdate = "" then
  23.     do
  24.         call beep_error
  25.         say "Usage: newfiles {mm-dd-yy | day_number} [output_file]"
  26.         exit(1)
  27.     end
  28.  
  29.     call rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
  30.     call sysloadfuncs
  31.  
  32.     Jan = 1
  33.     Feb = 2
  34.     Mar = 3
  35.     Apr = 4
  36.     May = 5
  37.     Jun = 6
  38.     Jul = 7
  39.     Aug = 8
  40.     Sep = 9
  41.     Oct = 10
  42.     Nov = 11
  43.     Dec = 12
  44.  
  45.     /* for each month, set up the number of days in the year that have
  46.        passed so far
  47.     */
  48.     month.Jan = 0 
  49.     month.Feb = 31 + month.Jan
  50.     month.Mar = 28 + month.Feb
  51.     month.Apr = 31 + month.Mar
  52.     month.May = 30 + month.Apr
  53.     month.Jun = 31 + month.May
  54.     month.Jul = 30 + month.Jun
  55.     month.Aug = 31 + month.Jul
  56.     month.Sep = 31 + month.Aug
  57.     month.Oct = 30 + month.Sep
  58.     month.Nov = 31 + month.Oct
  59.     month.Dec = 30 + month.Nov
  60.  
  61.     /* if they're passing you a date, calculate a "day-number" based
  62.        on that date
  63.     */
  64.     if pos("-",cmpdate) > 0 | pos("/",cmpdate) > 0 then
  65.         cmp_date = calc_days(cmpdate)
  66.     else
  67.         do
  68.             /* if they're passing you a total number of days to "look back",
  69.                calculate a "day-number" on that many days back
  70.             */
  71.             if datatype(cmpdate,"w")  then
  72.                 cmp_date = calc_days(date(u)) - cmpdate
  73.             else
  74.                 do
  75.                     call beep_error
  76.                     say "The number of days given is not numeric.  Terminating program."
  77.                     exit(2)
  78.                 end
  79.         end
  80.  
  81.     ifile       = "ALLFILES.TXT"    /* the name of the OS/2 shareware file */
  82.     iline       = ""
  83.     oline       = ""
  84.     linecnt     = 0
  85.     newfiles_found = 0
  86.  
  87.     if stream(ifile,'c',query exists) = "" then
  88.         do 
  89.             call beep_error
  90.             say "ALLFILES.TXT not found.  Terminating program."
  91.             exit(5)
  92.         end
  93.  
  94.     parse var ifile ibase "." iext
  95.  
  96.     if newfile = "" then
  97.         ofile       = ibase".NEW"   /* the default output name */
  98.     else
  99.         ofile = newfile             /* the user's desired output name */
  100.  
  101.     if stream(ofile,'c',query exists) \= "" then
  102.         do 
  103.             rc = SysFileDelete(ofile)
  104.             if rc \= 0 then
  105.                 do
  106.                     call beep_error
  107.                     say "Could not delete" ofile".  Terminating program."
  108.                     exit(4)
  109.                 end
  110.         end
  111.  
  112.     oline = center("OS/2 Shareware BBS New Files",79,'*')
  113.     call lineout ofile, oline      
  114.  
  115.     FileDate = stream(ifile, 'c', 'query datetime')
  116.     FileDate = left(FileDate,8)
  117.     txt = "ALLFILES.TXT date is" FileDate
  118.     oline = center(txt,79)
  119.     call lineout ofile, oline
  120.  
  121.     TodaysDayNbr = date('u')
  122.     TodaysDayNbr = calc_days(TodaysDayNbr)
  123.  
  124.     FilesDayNbr = calc_days(FileDate)
  125.     txt = "Nbr of days searched from today (" || date('u') || ") is" TodaysDayNbr - cmp_date
  126.     oline = center(txt,79)
  127.     call lineout ofile, oline
  128.  
  129.     call lineout ofile, " "
  130.  
  131.     backspace   = '08'x
  132.     odometer_msg = "Processing line number "
  133.     call charout , odometer_msg
  134.  
  135.  
  136. main:
  137. /*----------------------------------------------------------------------------*/
  138. /*  Read in all the lines in ALLFILES.TXT, printing the new files as you come */
  139. /*  across them.                                                              */
  140. /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
  141.     call read_line
  142.     do while lines(ifile) > 0
  143.         call get_newfiles
  144.     end
  145.     call eoj
  146. exit
  147.  
  148.  
  149. get_newfiles:
  150. /*----------------------------------------------------------------------------*/
  151. /* If you come across a heading for a particular file section, save it.  You  */
  152. /* may use it later if you have any new files in that particular section.  If */
  153. /* you find a file (denoted by having a period within the first 12 characters)*/
  154. /* see if it's a new file.  If so, print it.  Otherwise, just read the next   */
  155. /* line.                                                                      */
  156. /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
  157.         if substr(iline,1,1) = 'cd'x then
  158.             do
  159.                 printed_headings = 'N'
  160.                 do headnbr = 1 to 8
  161.                     headarray.headnbr = iline
  162.                     call read_line
  163.                 end
  164.             end
  165.  
  166.         if pos(".", substr(iline,1,12)) > 0 then
  167.             do
  168.                 if newfile() then
  169.                     call print_files_lines
  170.                 else
  171.                     call read_line
  172.             end
  173.         else
  174.             call read_line
  175. return
  176.  
  177.  
  178. newfile:
  179. /*----------------------------------------------------------------------------*/
  180. /*  if the files date is newer than the comparison date, indicate that you've */
  181. /*  found a new file.                                                         */
  182. /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
  183.     retval = 0
  184.     date = substr(iline,20,8)
  185.     if substr(date,3,1) = "-" & substr(date,6,1) = "-" then
  186.         if calc_days(date) > cmp_date then
  187.             do 
  188.                 retval = 1
  189.                 newfiles_found = newfiles_found + 1
  190.             end
  191. return retval
  192.  
  193.  
  194. print_files_lines:
  195. /*----------------------------------------------------------------------------*/
  196. /*  If you haven't printed the heading yet for this particular section in     */
  197. /*  which you've found the new file, then print it.  Then print all the       */
  198. /*  description lines for this new file.                                      */
  199. /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
  200.     if printed_headings = 'N' then
  201.         do
  202.             printed_headings = 'Y'
  203.             do headnbr = 1 to 8
  204.                 call lineout ofile, headarray.headnbr
  205.             end
  206.         end
  207.  
  208.     oline = iline
  209.     call lineout ofile, oline
  210.     call read_line
  211.     do while substr(iline,1,1) =  ' ' & lines(ifile) > 0
  212.         oline = iline
  213.         call lineout ofile, oline
  214.         call read_line
  215.     end
  216. return
  217.  
  218.  
  219. read_line:
  220. /*----------------------------------------------------------------------------*/
  221. /*  read in a line, letting the user get an idea of how many lines have been  */
  222. /*  processed so far.                                                         */
  223. /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
  224.     iline = linein(ifile)
  225.     linecnt = linecnt + 1
  226.  
  227.     if linecnt // 37 = 0 then
  228.         do
  229.             j = length(linecnt)
  230.             call charout ,linecnt
  231.             do k = 1 to j
  232.                 call charout, backspace
  233.             end
  234.         end
  235. return
  236.  
  237.  
  238. calc_days:
  239. /*----------------------------------------------------------------------------*/
  240. /*  calculate a "day number" based on the date passed to you.                 */
  241. /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
  242.     arg date_given
  243.  
  244.     if pos("-", date_given) > 0 then
  245.         parse var date_given mm "-" dd "-" yy
  246.     else
  247.         if pos("/", date_given) > 0 then
  248.             parse var date_given mm "/" dd "/" yy
  249.         else
  250.             do
  251.                 call beep_error
  252.                 say "Invalid date format!  Terminating program."
  253.                 exit(3)
  254.             end
  255.          
  256.     mm = format(mm)
  257.     dd = format(dd)
  258.     yy = format(yy)
  259.  
  260.     day_number = month.mm + dd + yy*365   /* this is the "day number" */
  261. return(day_number)
  262.  
  263.  
  264. beep_error:
  265. /*----------------------------------------------------------------------------*/
  266. /*  The big raspberry.                                                        */
  267. /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
  268.     duration = 100
  269.     call beep 262, duration
  270.     call beep 330, duration
  271.     call beep 262, duration
  272. return
  273.  
  274.  
  275. eoj:
  276. /*----------------------------------------------------------------------------*/
  277. /*  That's all folks!                                                         */
  278. /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
  279.     j = length(odometer_msg)
  280.     do k = 1 to j
  281.         call charout, backspace
  282.     end
  283.  
  284.     oline = center("End of OS/2 Shareware BBS New Files",79,'*')
  285.     call lineout ofile, oline      
  286.     call lineout ofile
  287.  
  288.     say copies(" ",60)
  289.     say "Output is" ofile"."
  290.     say linecnt "lines processed."
  291.     say newfiles_found "new files found."
  292.     say " "
  293.     exit
  294. return
  295.  
  296. /* end of newfiles.cmd */
  297.  
  298.