home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************/
- /* Events.rexx */
- /* A reminder for events through the year */
- /* Cedric BEUST (beust@taloa.unice.fr), Oct 91 */
- /* This program is in public domain */
- /* */
- /* The entries in the file 's:.eventsconfig' look like this: */
- /* 01 nov 91,5, Foo's birthday */
- /* --------- - ----------------------------------------- */
- /* | | | */
- /* | | +-> A comment that will be displayed */
- /* | +---------> Warn how many days BEFORE the event */
- /* +--------> The event */
- /* */
- /* A valid entry is one that starts with a numeric. Any other is a comment */
- /* The menus are self-explanatory... */
- /* This program is meant to be inserted in your startup-sequence (or */
- /* you user-startup). It is not very robust but this can be easily fixed */
- /* (I started to write it yesterday...) */
- /* Before doing any operation on the configfile, it is copied to */
- /* 's:.eventsconfig.old' */
- /* */
- /* Syntax: events [-n] */
- /* -n: Display next event to come */
- /* */
- /***************************************************************************/
-
- arg options
- closesteventdays = 10000
-
- /* Files used */
- configfile = "s:.eventsconfig"
- tmpfilefrom = 't:event.tmp'
- tmpfileto = 't:event.new'
-
- /* Copy the config file for lock considerations */
- address command
- "copy " configfile tmpfileto
-
- /* Try to read the configuration file */
- if ~open(file, configfile, 'Read') then do
- say "Can't open configuration file " configfile ". Exiting..."
- exit 10
- end
-
- /* Calculate how many days there has been for current date */
- currentdays = convertToDays(date('Normal'))
-
- /* Check out each event in the config file */
- do until eof(file)
- line = readln(file)
- parse value line with date "," delay "," comment
- parse var date dd mmm yy
- if datatype(dd, 'Numeric') then
- do
- eventdays = convertToDays(date)
- if index(options, '-N') then
- /* We only display the closest event, so we check if this one is closer than */
- /* the previous one */
- do
- if (eventdays - currentdays < closesteventdays) then
- do
- closesteventdays = eventdays - currentdays
- closestevent = line
- end
- end
- else if (eventdays - currentdays <= delay & eventdays - currentdays > 0) then
- do
-
- /* This event is due, display an appropriate message */
- call displayEvent(line)
- end
- end
- end
-
- if index(options, '-N') then
- do
- parse var closestevent date "," delay "," comment
- howmanyleft = convertToDays(date) - convertToDays(date('Normal'))
- say "Next event: <" || strip(comment) || "> on " || date || " (in " || howmanyleft || " days)"
- say "You will be warned " || delay || " days before"
- end
- call close(file)
-
- /* Update the configuration file */
- "copy " tmpfileto configfile
- return 0
-
- /***************************************************************************/
-
- displayEvent:
- /* An event is due, display its comment in a window */
- arg line
-
- parse var line date "," delay "," comment
-
- windev = "CON:1/1/639/199/ ** EVENT **"
-
- if ~open('console',windev) then
- do
- say "Couldn't open" windev
- exit /* Window for all activity */
- end
-
-
- /* Put some colors in the menu... */
- nexttimekey = 'T'
- nextmonthkey = 'M'
- nextyearkey = 'Y'
- ndayskey = 'N'
- deletekey = 'D'
-
- nexttimecode = '1B'x || '[33m' || nexttimekey || '1B'x || '[32m'
- nextmonthcode = '1B'x || '[33m' || nextmonthkey || '1B'x || '[32m'
- nextyearcode = '1B'x || '[33m' || nextyearkey || '1B'x || '[32m'
- ndayscode = '1B'x || '[33m' || ndayskey || '1B'x || '[32m'
- deletecode = '1B'x || '[33m' || deletekey || '1B'x || '[32m'
-
- howmanyleft = convertToDays(date) - convertToDays(date('Normal'))
- call writeln('console', "")
- call writeln('console', 'In' howmanyleft 'days' || '1B'x || '[33m' || ' (' || date || ')')
- call writeln('console', "")
- call writeln('console', '1B'x || '[31m' || (center(comment,75)))
- call writeln('console', '1B'x || '[32m')
- call writeln('console', "")
- call writeln('console', center("Now what?",75))
- call writeln('console', " Remind next " || nexttimecode || ")ime")
- call writeln('console', " Remind again next " || nextmonthcode || ")onth")
- call writeln('console', " Remind again next " || nextyearcode || ")ear")
- call writeln('console', " Remind again in " || ndayscode || ") days")
- call writeln('console', " " || deletecode || ")elete this entry")
- call writeln('console', "")
- call writech('console'," -> ")
-
- valid = 0
- do while valid = 0
- do
- answer = readln('console')
- select
- when answer = 't' then do valid = 1; end
- when answer = 'm' then do forgetEntry('m',line); valid = 1; end
- when answer = 'y' then do forgetEntry('y',line); valid = 1; end
- when answer = 'd' then do deleteEntry(line); valid = 1; end
- when answer = 'n' then do remindNDays(line); valid = 1; end
- otherwise valid = 1 /* default: remind next time */
- end
-
- end
- call close('console')
- return 0
-
- /***************************************************************************/
- forgetEntry:
- /* Forget entry till next year, month or time */
- /* 'whenagain' is a letter saying what part must be increased */
-
- arg whenagain, line
-
- parse value line with date "," delay "," comment
-
- months.1 = 'Jan'; months.2 = 'Feb'; months.3 = 'Mar'; months.4 = 'Apr'
- months.5 = 'May'; months.6 = 'Jun'; months.7 = 'Jul'; months.8 = 'Aug'
- months.9 = 'Sep'; months.10 = 'Oct'; months.11 = 'Nov'; months.12 = 'Dec'
- months.13 = 'Jan'
-
- months.jan = 1; months.feb = 2; months.mar = 3; months.apr = 4
- months.may = 5; months.jun = 6; months.jul = 7; months.aug = 8
- months.sep = 9; months.oct = 10; months.nov = 11 ; months.dec = 12
-
- parse var date dd mmm yy
- select
- when whenagain = 'Y' then
- do
- yy = yy + 1
- modifiedline = dd || " " || mmm || " " || yy || ","
- modifiedline = modifiedline || delay || "," || comment
- end
- when whenagain = 'M' then
- do
- mm = months.mmm + 1
- newmonth = months.mm
- if newmonth = 'Jan' then
- do
- yy = yy + 1
- newmonth = 'Jan '
- end
- modifiedline = dd || " " || newmonth || yy || ","
- modifiedline = modifiedline || delay || "," || comment
- end
- otherwise
- do
- say "Unexpected value " whenagain
- whenagain = 'T'
- end
- end
- if whenagain ~= 'T' then /* we don't do anything if it's T */
- call modifyLine(line, modifiedline)
-
- return 0
-
- /***************************************************************************/
- deleteEntry:
- /* Delete this entry from the config file */
- /* Save the old file in 's:.eventsconfig.old' */
-
- arg line
-
- call modifyLine(line,"")
- return 0
-
- /***************************************************************************/
- remindNDays:
- /* Ask the user in how many days they want to be reminded again */
-
- arg line
-
- parse value line with date "," delay "," comment
- answer = -1
-
- howmanyleft = convertToDays(date) - convertToDays(date('Normal'))
-
- call writeln('console','')
- do while answer < 0 | answer > delay
- call writech('console', "In how many days shall I remind you again ? (0-" || howmanyleft || ") ")
-
- answer = readln('console')
- end
-
- modifiedline = date || "," || (howmanyleft - answer) || "," || comment
- call modifyLine(line, modifiedline)
-
- return 0
-
- /***************************************************************************/
- modifyLine:
- /* Replace in the configline the oldline by the newline */
- arg oldline, newline
-
- parse value oldline with date "," delay "," comment
-
- address command
- "copy " configfile configfile'.old'
- "copy " configfile tmpfilefrom
-
- /* Open both files. No checking, they *ought* to be there! */
- s = open(to, tmpfileto, 'Write')
- s = open(from, tmpfilefrom, 'Read')
-
- linein = readln(from)
- do while ~eof(from)
- if index(upper(linein), upper(comment)) = 0 then
- do
- call writeln(to, linein)
- end
- else
- do
- call writeln(to, newline)
- end
- linein = readln(from)
- end
- call close(to)
- call close(from)
- return 0
-
- /***************************************************************************/
- convertToDays: procedure
- /* Date is 'dd mmm yy'. Return number of days since time 0 */
- arg date
-
- parse var date dd mmm year
-
- /* Set up the months table - from names to numbers, */
- months. = 0; months.jan = 1; months.feb = 2; months.mar = 3
- months.apr = 4; months.may = 5; months.jun = 6; months.jul = 7
- months.aug = 8; months.sep = 9; months.oct = 10; months.nov = 11
- months.dec = 12
-
- /* and now from numbers to days/month & print names */
- months.1.days = 31; months.2.days = 1 /* Fixed later */
- months.3.days = 31; months.4.days = 30; months.5.days = 31
- months.6.days = 30; months.7.days = 31; months.8.days = 31
- months.9.days = 30; months.10.days = 31; months.11.days = 30
- months.12.days = 31 /* Not needed, but here for completeness */
-
- if (year < 100) then yy = 1900 + year
- else yy = year
- if (yy // 4 = 0 & yy // 100 ~= 0) then months.2.days = 29 /* a leap year */
- else months.2.days = 28
- mmm = upper(left(mmm,3))
- themonth = months.mmm
-
- /* summonth is the number of days in the previous months */
- summonth = 0
- do i = 1 to themonth - 1
- summonth = summonth + months.i.days
- end
-
- return (yy - 1) * 365 + summonth +dd
-
-