home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
newfil11.zip
/
NEWFILES.CMD
next >
Wrap
OS/2 REXX Batch file
|
1994-01-23
|
9KB
|
298 lines
/* newfiles.cmd - displays files and their descriptions in the
ALLFILES.TXT when they are newer than the date given on the command line, or
within the number of days given on the command line. This REXX command
file is designed to work ONLY with the OS/2 Shareware BBS's ALLFILES.TXT.
Steve Allen
Altech Computer Services
121 Herta St.
Easley, SC 29640
Jan 94
trace ?i
*/
say ""
say "NEWFILES v1.1 1994"
say "Altech Computer Services" 'fe'x "Steve Allen"
say ""
arg cmpdate newfile /* the "newfile" is optional--has default value */
if cmpdate = "" then
do
call beep_error
say "Usage: newfiles {mm-dd-yy | day_number} [output_file]"
exit(1)
end
call rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
call sysloadfuncs
Jan = 1
Feb = 2
Mar = 3
Apr = 4
May = 5
Jun = 6
Jul = 7
Aug = 8
Sep = 9
Oct = 10
Nov = 11
Dec = 12
/* for each month, set up the number of days in the year that have
passed so far
*/
month.Jan = 0
month.Feb = 31 + month.Jan
month.Mar = 28 + month.Feb
month.Apr = 31 + month.Mar
month.May = 30 + month.Apr
month.Jun = 31 + month.May
month.Jul = 30 + month.Jun
month.Aug = 31 + month.Jul
month.Sep = 31 + month.Aug
month.Oct = 30 + month.Sep
month.Nov = 31 + month.Oct
month.Dec = 30 + month.Nov
/* if they're passing you a date, calculate a "day-number" based
on that date
*/
if pos("-",cmpdate) > 0 | pos("/",cmpdate) > 0 then
cmp_date = calc_days(cmpdate)
else
do
/* if they're passing you a total number of days to "look back",
calculate a "day-number" on that many days back
*/
if datatype(cmpdate,"w") then
cmp_date = calc_days(date(u)) - cmpdate
else
do
call beep_error
say "The number of days given is not numeric. Terminating program."
exit(2)
end
end
ifile = "ALLFILES.TXT" /* the name of the OS/2 shareware file */
iline = ""
oline = ""
linecnt = 0
newfiles_found = 0
if stream(ifile,'c',query exists) = "" then
do
call beep_error
say "ALLFILES.TXT not found. Terminating program."
exit(5)
end
parse var ifile ibase "." iext
if newfile = "" then
ofile = ibase".NEW" /* the default output name */
else
ofile = newfile /* the user's desired output name */
if stream(ofile,'c',query exists) \= "" then
do
rc = SysFileDelete(ofile)
if rc \= 0 then
do
call beep_error
say "Could not delete" ofile". Terminating program."
exit(4)
end
end
oline = center("OS/2 Shareware BBS New Files",79,'*')
call lineout ofile, oline
FileDate = stream(ifile, 'c', 'query datetime')
FileDate = left(FileDate,8)
txt = "ALLFILES.TXT date is" FileDate
oline = center(txt,79)
call lineout ofile, oline
TodaysDayNbr = date('u')
TodaysDayNbr = calc_days(TodaysDayNbr)
FilesDayNbr = calc_days(FileDate)
txt = "Nbr of days searched from today (" || date('u') || ") is" TodaysDayNbr - cmp_date
oline = center(txt,79)
call lineout ofile, oline
call lineout ofile, " "
backspace = '08'x
odometer_msg = "Processing line number "
call charout , odometer_msg
main:
/*----------------------------------------------------------------------------*/
/* Read in all the lines in ALLFILES.TXT, printing the new files as you come */
/* across them. */
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
call read_line
do while lines(ifile) > 0
call get_newfiles
end
call eoj
exit
get_newfiles:
/*----------------------------------------------------------------------------*/
/* If you come across a heading for a particular file section, save it. You */
/* may use it later if you have any new files in that particular section. If */
/* you find a file (denoted by having a period within the first 12 characters)*/
/* see if it's a new file. If so, print it. Otherwise, just read the next */
/* line. */
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
if substr(iline,1,1) = 'cd'x then
do
printed_headings = 'N'
do headnbr = 1 to 8
headarray.headnbr = iline
call read_line
end
end
if pos(".", substr(iline,1,12)) > 0 then
do
if newfile() then
call print_files_lines
else
call read_line
end
else
call read_line
return
newfile:
/*----------------------------------------------------------------------------*/
/* if the files date is newer than the comparison date, indicate that you've */
/* found a new file. */
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
retval = 0
date = substr(iline,20,8)
if substr(date,3,1) = "-" & substr(date,6,1) = "-" then
if calc_days(date) > cmp_date then
do
retval = 1
newfiles_found = newfiles_found + 1
end
return retval
print_files_lines:
/*----------------------------------------------------------------------------*/
/* If you haven't printed the heading yet for this particular section in */
/* which you've found the new file, then print it. Then print all the */
/* description lines for this new file. */
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
if printed_headings = 'N' then
do
printed_headings = 'Y'
do headnbr = 1 to 8
call lineout ofile, headarray.headnbr
end
end
oline = iline
call lineout ofile, oline
call read_line
do while substr(iline,1,1) = ' ' & lines(ifile) > 0
oline = iline
call lineout ofile, oline
call read_line
end
return
read_line:
/*----------------------------------------------------------------------------*/
/* read in a line, letting the user get an idea of how many lines have been */
/* processed so far. */
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
iline = linein(ifile)
linecnt = linecnt + 1
if linecnt // 37 = 0 then
do
j = length(linecnt)
call charout ,linecnt
do k = 1 to j
call charout, backspace
end
end
return
calc_days:
/*----------------------------------------------------------------------------*/
/* calculate a "day number" based on the date passed to you. */
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
arg date_given
if pos("-", date_given) > 0 then
parse var date_given mm "-" dd "-" yy
else
if pos("/", date_given) > 0 then
parse var date_given mm "/" dd "/" yy
else
do
call beep_error
say "Invalid date format! Terminating program."
exit(3)
end
mm = format(mm)
dd = format(dd)
yy = format(yy)
day_number = month.mm + dd + yy*365 /* this is the "day number" */
return(day_number)
beep_error:
/*----------------------------------------------------------------------------*/
/* The big raspberry. */
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
duration = 100
call beep 262, duration
call beep 330, duration
call beep 262, duration
return
eoj:
/*----------------------------------------------------------------------------*/
/* That's all folks! */
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
j = length(odometer_msg)
do k = 1 to j
call charout, backspace
end
oline = center("End of OS/2 Shareware BBS New Files",79,'*')
call lineout ofile, oline
call lineout ofile
say copies(" ",60)
say "Output is" ofile"."
say linecnt "lines processed."
say newfiles_found "new files found."
say " "
exit
return
/* end of newfiles.cmd */