home *** CD-ROM | disk | FTP | other *** search
Wrap
/* $VER: EZCrond by Jim Hines v3.016 ©1995-1998 All Rights Reserved ** Thanks must go to Gene Heskett for his help in coding some functions. ** */ csi = '9b'x Ital = csi'3m' bold = csi'1m' norm = csi'0m' black = csi'31m' white = csi'32m' blue = csi'33m' LF = '0a'x /* LINEFEED */ VER = 'EZCronD v3.016' /* Version String */ yearpre = left(date('S'), 2) /* Year Prefix */ SIGNAL ON ERROR SIGNAL ON IOERR SIGNAL ON SYNTAX SIGNAL ON HALT OPTIONS FAILAT 20 OPTIONS RESULTS if ~show('L','rexxsupport.library') then call addlib('rexxsupport.library',0,-30) if ~exists('EZCron:prefs/config.prefs') then configfile = 't:cron.config' else do call open('configprefs', 'EZCron:Prefs/config.prefs', 'R') configfile = readln('configprefs') call close('configprefs') end if ~exists('env:EZCStartTime') then do call open(startinfo, 'env:EZCStartTime', 'W') call writeln(startinfo, date(USA) time()) call writeln(startinfo, VER) call close(startinfo) end if exists('s:cron.config') then address command 'copy s:cron.config' configfile else do call rtezrequest('A config file does NOT exist.'||LF||'Use EZCron to create one.', "Okay",'EZCronD Error',) exit end if showlist('P', 'EZCROND') then do say 'Exiting EZCron... This may take several seconds.' address 'EZCROND' STOP exit end else call startrtn() exit /* =======LOOP== */ startrtn: call readprefsfiles() call parseconfig() do i = 1 to event.0 if event.i.time = 'startup' then do if event.i.sfx ~= '-' then do address command 'run' prefs.6 event.i.sfx end if event.i.command = 'TEXTREMINDER' then address command 'run <>NIL: rx ezcron:rexx/Reminder.rexx' event.i.txt else address command 'run >NIL:' event.i.command event.i.pargs end end call openport('EZCROND') say VER say '©1995-98 Jim Hines' if showlist('P', 'EZCRONPREFS') then address 'EZCRONPREFS' refresh /* =======PARSE CONFIG FILE & TIMER SECTION == */ do forever sec = right(time('N'),2) /* get seconds */ sec2 = 60 - sec /* 60 (seconds) minus sec) */ delayvar = sec2 * 50 /* sec2 x 50 ticks or 1 second sets the delay time */ call delay(delayvar) /* 3000 would be equal to 1 minute */ pkt = getpkt('EZCROND') if pkt ~= '0000 0000'x then call aport(pkt) clock = left(time(), 5) /* 22:58 */ date = Date('USA') /* 08/04/92 */ date2 = Date('S') /* 19920804 */ date3 = Date(W, date2, 'S') /* Friday */ call parseconfig() do i = 1 to event.0 parse var clock ahrs ':' amin /* Actual Hrs and Mins */ ahrs1 = left(ahrs, 1) ahrs2 = right(ahrs, 1) amin1 = left(amin, 1) amin2 = right(amin, 1) parse var date amm'/'add'/'ayy /* Actual mm dd yy */ amm1 = left(amm, 1) amm2 = right(amm, 1) add1 = left(add, 1) add2 = right(add, 1) ayy1 = left(ayy, 1) ayy2 = right(ayy, 1) timescount = 1 /* Get multi-times fields */ if pos('|', event.i.time, 1) > 0 then do readline = event.i.time do while pos('|', readline) > 0 a = pos('|', readline) readline = right(readline, length(readline) - a) timescount = timescount + 1 end end do t = 1 to timescount parse var event.i.time event.i.time.t '|' event.i.time end do t = 1 to timescount parse var event.i.time.t ehrs.t':'emin.t /* Event Hrs and Mins */ if pos('#', event.i.time.t, 1) > 0 then do ehrs1.t = left(ehrs.t, 1) ehrs2.t = right(ehrs.t, 1) emin1.t = left(emin.t, 1) emin2.t = right(emin.t, 1) end end datescount = 1 /* Get multi-date fields */ if pos('|', event.i.date, 1) > 0 then do readline = event.i.date do while pos('|', readline) > 0 a = pos('|', readline) readline = right(readline, length(readline) - a) datescount = datescount + 1 end end do t = 1 to datescount parse var event.i.date event.i.date.t '|' event.i.date end do t = 1 to datescount parse var event.i.date.t emm.t'/'edd.t'/'eyy.t if pos('#', event.i.date.t, 1) > 0 then do emm1.t = left(emm.t, 1) emm2.t = right(emm.t, 1) edd1.t = left(edd.t, 1) edd2.t = right(edd.t, 1) eyy1.t = left(eyy.t, 1) eyy2.t = right(eyy.t, 1) end end parse var event.i.startdate sdmm'/'sddd'/'sdyy /* Event Startdate mm dd yy */ if pos('#', event.i.startdate, 1) > 0 then do sdmm1 = left(sdmm, 1) sdmm2 = right(sdmm, 1) sddd1 = left(sddd, 1) sddd2 = right(sddd, 1) sdyy1 = left(sdyy, 1) sdyy2 = right(sdyy, 1) end parse var event.i.enddate edmm'/'eddd'/'edyy /* Event Enddate mm dd yy */ if pos('#', event.i.enddate, 1) > 0 then do edmm1 = left(edmm, 1) edmm2 = right(edmm, 1) eddd1 = left(eddd, 1) eddd2 = right(eddd, 1) edyy1 = left(edyy, 1) edyy2 = right(edyy, 1) end /* ======= Misc Routines == */ if event.i.pargs = '-' then event.i.pargs = '' if event.i.sfx = '-' then event.i.sfx = '' if event.i.txt = '-' then event.i.txt = '' /* ======= Date Routines == */ do t = 1 to datescount /* Days of Week */ if event.i.date.t = 'sun' & date3 = 'Sunday' then event.i.date.t = date if event.i.date.t = 'mon' & date3 = 'Monday' then event.i.date.t = date if event.i.date.t = 'tue' & date3 = 'Tuesday' then event.i.date.t = date if event.i.date.t = 'wed' & date3 = 'Wednesday' then event.i.date.t = date if event.i.date.t = 'thu' & date3 = 'Thursday' then event.i.date.t = date if event.i.date.t = 'fri' & date3 = 'Friday' then event.i.date.t = date if event.i.date.t = 'sat' & date3 = 'Saturday' then event.i.date.t = date /* WildCard Support */ if pos('#', event.i.date.t, 1) > 0 then do if emm1.t = '#' then emm1.t = amm1 if emm2.t = '#' then emm2.t = amm2 if edd1.t = '#' then edd1.t = add1 if edd2.t = '#' then edd2.t = add2 if eyy1.t = '#' then eyy1.t = ayy1 if eyy2.t = '#' then eyy2.t = ayy2 event.i.date.t = emm1.t||emm2.t'/'edd1.t||edd2.t'/'eyy1.t||eyy2.t end /* Third Friday, 2nd Tues, etc routine */ if pos('every', event.i.date.t, 1) > 0 then do parse var event.i.date.t var1 '_' num '_' dow /* every 2 wed */ del3 = date(n) /* 20 Apr 88 */ parse var del3 del1 cm del2 drop del1 del2 /* dont even need them */ if cm = 'Jan' then cm = 31;if cm = 'Feb' then cm = 28 /* Will need to be changed for leap */ if cm = 'Mar' then cm = 31;if cm = 'Apr' then cm = 30 if cm = 'May' then cm = 31;if cm = 'Jun' then cm = 30 if cm = 'Jul' then cm = 31;if cm = 'Aug' then cm = 31 if cm = 'Sep' then cm = 30;if cm = 'Oct' then cm = 31 if cm = 'Nov' then cm = 30;if cm = 'Dec' then cm = 31 countvar = 0 do z = 1 to cm currdate = date(s) /* 19951221 year month day */ yearmonth = left(currdate, 6) /* 199512 year month */ if z < 10 then do zdate = yearmonth'0'z /* 19951201 Add the 0 back for single digit days*/ newz = '0'z end else do zdate = yearmonth''z /* 19951231 */ newz = z end myday = Date(W, zdate, 'S') /* Friday */ myday = left(myday, 3) /* Fri */ myday = translate(myday, 'abcdefghijklmnopqrstuvwxyz',, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') /* fri */ if myday = dow then countvar = countvar + 1 if myday = dow & countvar = num then do year = left(zdate, 4) /* 1995 */ year2 = right(year, 2) /* 95 */ month = right(zdate, 4) /* 1221 */ month2 = left(month, 2) /* 12 */ event.i.date.t = month2'/'newz'/'year2 leave end end end end /* ======= Time Routine == */ do t = 1 to timescount if pos('#', event.i.time.t, 1) > 0 then do if ehrs1.t = '#' then ehrs1.t = ahrs1 if ehrs2.t = '#' then ehrs2.t = ahrs2 if emin1.t = '#' then emin1.t = amin1 if emin2.t = '#' then emin2.t = amin2 event.i.time.t = ehrs1.t||ehrs2.t':'emin1.t||emin2.t end end /* ======= Time Range routine == */ do t = 1 to timescount if event.i.rng1 ~= '--:--' & event.i.rng2 ~= '--:--' then do strng = event.i.rng1 parse var strng sthrs':'stmin if pos('#', strng, 1) > 0 then do sthrs1 = left(sthrs, 1) sthrs2 = right(sthrs, 1) stmin1 = left(stmin, 1) stmin2 = right(stmin, 1) if sthrs1 = '#' then sthrs1 = ahrs1 if sthrs2 = '#' then sthrs2 = ahrs2 if stmin1 = '#' then stmin1 = amin1 if stmin2 = '#' then stmin2 = amin2 sthrs = sthrs1||sthrs2 stmin = stmin1||stmin2 end strngdrop = 60 * sthrs strng = strngdrop + stmin endrng = event.i.rng2 parse var endrng edhrs':'edmin if pos('#', endrng, 1) > 0 then do edhrs1 = left(edhrs, 1) edhrs2 = right(edhrs, 1) edmin1 = left(edmin, 1) edmin2 = right(edmin, 1) if edhrs1 = '#' then edhrs1 = ahrs1 if edhrs2 = '#' then edhrs2 = ahrs2 if edmin1 = '#' then edmin1 = amin1 if edmin2 = '#' then edmin2 = amin2 edhrs = edhrs1||edhrs2 edmin = edmin1||edmin2 end edrngdrop = 60 * edhrs edrng = edrngdrop + edmin currtim = time(m) /* current time in minutes since midnight */ a = 0 if (strng > edrng) & ((currtim < strng) & (currtim > edrng)) then event.i.time.t = 0 if (strng < edrng) & ((currtim < strng) | (currtim > edrng)) then event.i.time.t = 0 drop strng sthrs sthrs2 sthrs2 stmin stmin1 stmin2 endrng edhrs edhrs1 edhrs2 edmin edmin1 edmin2 currtim end end /* ======= Date Range Routine == */ if event.i.startdate ~= '--/--/--' & event.i.enddate ~= '--/--/--' then do if pos('#', event.i.startdate, 1) > 0 | pos('#', event.i.enddate, 1) > 0 then do /* Start Range */ if sdmm1 = '#' then sdmm1 = amm1 if sdmm2 = '#' then sdmm2 = amm2 if sddd1 = '#' then sddd1 = add1 if sddd2 = '#' then sddd2 = add2 if sdyy1 = '#' then sdyy1 = ayy1 if sdyy2 = '#' then sdyy2 = ayy2 event.i.startdate = sdmm1||sdmm2'/'sddd1||sddd2'/'sdyy1||sdyy2 /* End Range */ if edmm1 = '#' then edmm1 = amm1 if edmm2 = '#' then edmm2 = amm2 if eddd1 = '#' then eddd1 = add1 if eddd2 = '#' then eddd2 = add2 if edyy1 = '#' then edyy1 = ayy1 if edyy2 = '#' then edyy2 = ayy2 event.i.enddate = edmm1||edmm2'/'eddd1||eddd2'/'edyy1||edyy2 end a = b = 0 sdt = event.i.startdate edt = event.i.enddate parse var sdt tmm'/'tdd'/'tyy sdt = date(c, yearpre''tyy''tmm''tdd, S) /* # days since Jan 1st, 1900 */ parse var edt tmm'/'tdd'/'tyy edt = date(c,yearpre||tyy||tmm||tdd, S) currdt = date(usa) parse var currdt tmm'/'tdd'/'tyy currdt = date(c, yearpre||tyy||tmm||tdd, S) a = 0 do t = 1 to datescount if (sdt < edt) & (currdt < sdt) then event.i.date.t = 0 /* This may need reworked! */ if (sdt > edt) & (currdt > edt) then event.i.date.t = 0 end drop sdt edt currdt tmm tdd tyy end /* ======= Final Routine == */ do t = 1 to datescount if event.i.date.t = date then do event.i.date = event.i.date.t leave end end do t = 1 to timescount if event.i.time.t = clock then do event.i.time = event.i.time.t leave end end if event.i.txt = '' & event.i.time = clock & event.i.date = date & event.i.run = '0' then do address command 'run >NIL:' event.i.command event.i.pargs end else if event.i.time = clock & event.i.date = date & event.i.run = '1' then do address command event.i.command event.i.pargs end if event.i.time = clock & event.i.date = date & event.i.txt ~= "" then do address command 'run rx <>nil: ezcron:rexx/Reminder.rexx' event.i.txt /*This calls the external rexx proggy for the event display */ if showlist(h,SPEAK) then do address command 'echo' '"'event.i.txt'"' '>speak:' end end if event.i.time = clock & event.i.date = date & event.i.sfx ~= '' then address command 'run >nil:' prefs.6 event.i.sfx end /* end of 'do i = 1 to event.0' */ end /* end of do forever */ /* ======== Arexx Port Message Check == */ aport: cmd = getarg(Pkt) if cmd = 'STOP' then do call reply(Pkt, 0) call exiting() end parseconfig: event. = 0 if ~open(cronfile, configfile,'READ') then exit 20 errors = 0 do until eof(cronfile) /* Grab the line, parse the event and ignore the comments */ linein = readln(cronfile) parse var linein line ';' parse var line line '!' next = event.0 + 1 parse var line event.next.command','event.next.pargs','event.next.time',', event.next.date','event.next.startdate','event.next.enddate',', event.next.rng1','event.next.rng2','event.next.sfx','event.next.txt',', event.next.run','event.next.desc',' event.next.date = translate(event.next.date, 'abcdefghijklmnopqrstuvwxyz',, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') /* TRANSLATES THE DATE TO LOWERCASE IF NOT NUMERIC */ event.next.time = translate(event.next.time, 'abcdefghijklmnopqrstuvwxyz',, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') /* TRANSLATES THE TIME TO LOWERCASE IF NOT NUMERIC */ select when event.next.command = "" then iterate when event.next.command = "" then do errors = 1 iterate end otherwise event.0 = next end end call close(cronfile) return readprefsfiles: if exists('EZCron:prefs/EZCron.prefs') then do call open('ezconfig','EZCron:Prefs/EZCron.prefs','R') do i = 1 to 7 prefs.i = readln('ezconfig') end call close('ezconfig') end else do prefs.6 = 'c:play16' end return syntax: ioerr: error: errorrc = RC if ~show('L','rexxreqtools.library') then call addlib('rexxsupport.library',0,-30) call rtezrequest('EZCronD has exited with an error in event'||LF||event.i.command||LF||'Line' SIGL ERRORTEXT(errorrc),'Okay!','**EZCronD Fatal Error**','rt_reqpos = reqpos_centerscr rtez_flags=ezreqf_centertext',) call exiting() exiting: call closeport('EZCROND') if showlist('P', 'EZCRONPREFS') then address 'EZCRONPREFS' refresh address command 'avail flush >NIL:' exit