#!/net/u/1/f/fdc/kermit/wermit + # Requires C-Kermit 9.0.304 Dev.06 or later. # In the first line above: # replace the string after the '!' with the path of C-Kermit on your computer. # Give this file execute permission. # Put the remind.txt file (help text) in same directory with this script. # # Kermit script that does most of what the Solaris 'remind' program did, # displays upcoming events and reminders the from ~/.remind file. # Unlike the original program this one lists dates in chronological order # and highlights events for TODAY and TOMORROW. # # Illustrates some of C-Kermit's date-handling functions. # # fdc - Sat Jan 16 20:07:18 2016 # Updated: # Sat Feb 6 09:12:57 2016 for Locale-ized output and fix help. # Mon Jul 3 07:45:26 2017 to write report to .remind.today and type it. # Wed Sep 19 19:35:44 2018 Added ANNUAL for birthdays and anniversaries # Sun Jan 12 10:10:29 2020 to add countdown option: # use "countdown" instead of "date" and result shows how many days from now. # def xx fwrite /line \%o \%1 dcl \&a[1000] # Array for dated lines dcl \&b[1000] # Parallel array with numeric dates .version = 1.02 # Version of this script .versiondate = 2018/09/19 # Date of this version .remindfile = ~/.remind # Data file .helpfile := \v(cmdfile).txt # Help text file .outfile := ~/.remind.today # Output file if def \%1 { # Command-line args if ( equ \%1 -h || equ \%1 help ) { # Only '-h' and 'help' are accepted. if exist \m(helpfile) { type /page \m(helpfile) # Show help text exit 0 } else { echo "?Help file \m(helpfile) not found" echo "Visit http://kermitproject.org/remind.html for details." exit 1 } } else if exist \%1 { # Alternative data file for testing .remindfile := \%1 show mac remindfile } else { echo "Usage: remind OR remind -h for help" # otherwise give usage msg. exit } } if not exist \m(remindfile) { # Check that data file exists echo "?\m(remindfile) not found" echo "~/.remind file required" echo "Type 'remind -h' for help" exit 1 } fopen /read \%c \m(remindfile) # Open data file if fail exit fopen /write \%o \m(outfile) # Open output file if fail exit .fuzz = 365 # Initialize Fuzz to 1 year .today := \fword(\v(date),1) # Date of month of today .i = 0 # Index for arrays xx xx "---------------------------------" xx {Today is \fupper(\fdayname(\v(date))) \fcvtdate(,2)} while not \f_eof(\%c) { # Loop through .remind file .countdown = 0 # Reset 'countdown' for this entry fread /line /trim \%c line # Read a line if fail break if not def line continue # Blank line - skip .c := \s(line[1:1]) # First character in nonblank line if \findex(\m(c),{;#}) continue # Comment line - skip .w1 := \fword(\m(line),1) # First word in line .w2 := \fword(\m(line),2,\32,ALL) # Second word in line .\%x ::= \findex(\m(w1),\m(line)) + \flen(\m(w1)) + 1 # Where text starts .\%y ::= \findex(\m(w2),\m(line)) + \flen(\m(w2)) + 1 .text := \s(line[\%y]) # Extract the text to be displayed switch \m(w1) { :monthday # Day of month if equ \m(w2) \m(today) xx {Day \m(w2) of each month: \m(text)} break :weekday # Day of week if equ \m(w2) \fdayname(,0) xx {Every \m(w2): \m(text)} break :annual # Annual event .w2 := \m(w2)-\v(year) # Append this year and fall through :countdown :date # Specific date if equ "\m(w1)" "countdown" .countdown = 1 if > \fcmpdates(\m(w2),TODAY+\m(fuzz)d) 0 { # Too far in future? continue } if > \fcmpdates(\m(w2),TODAY) -1 { incr i # Count this event if > i \fdim(&a) { # If array is full make it bigger array resize &a \fdim(&a)+100 array resize &b \fdim(&b)+100 } # Add event to result arrays .\&b[i] := \fcvtdate(\m(w2),3): \m(text) # Numeric date for sorting .w3 := \fword(\fcvtdate(\m(w2),2),1,\32) # Convert to locale if == \fcmpdates(\m(w2),TODAY) 0 { # w2 = date .w2 := \frpad(TODAY\7\7,13) \m(w3) } else if == \fcmpdates(\m(w2),TODAY+1d) 0 { .w2 := \frpad(TOMORROW,11) \m(w3) } else { .w2 := \frpad(\fdayname(\m(w3),0),11,) \m(w3) if countdown { .text := \m(text) (today \fdiffdates(\m(w3),today)) } } .\&a[i] := \m(w2): \m(text) # Date for display } break :fuzz # How many days in the future to show .fuzz := \m(w2) break :default # Other xx {UNKNOWN: \m(w1)} } } fclose \%c # Close the .remind file # Sort the results that have specific dates. # Remove the empty array elements, otherwise sort moves them to the top. # if i { # If we have anything to show... .n := \m(i) # How many items array resize &b n # Remove unused part of array array sort &b &a # Sort in chronological order for i 1 n 1 { # Show results xx {\&a[i]} } } xx "---------------------------------" xx fclose \%o type /page \m(outfile) exit ; Local Variables: ; comment-column:40 ; comment-start:"# " ; End: