Subject: calendar diffs, et. al.
To: None <current-users@NetBSD.ORG>
From: Mason Loring Bliss <mason@acheron.middleboro.ma.us>
List: current-users
Date: 05/11/1998 21:33:05
Hi! I decided to start using the calendar program today. To my dismay, I
noted that the current version doesn't allow individual events to specify
their own "look ahead" dates. (This is a feature I've come to really enjoy
on my Mac. For instance, while a day's notice is sufficient for reminding
me to email a birthday greeting to someone on the net, my friend Erica's
birthday clearly requires fifteen days.)

Below my signature are some diffs I made up after whacking the calendar
program so that it would recognise a simple flag telling it that the
line in question wants a specific number of days' notice. Here's an example
of a simple calendar file done in the format I've chosen:

01/01   Happy New Year. Clean the calendar file.
05/11   Testing 1.
.7.05/11        Testing 2.
05/11   Testing 3.
05/11   Testing 4.
.10.05/15   Testing 5.

The "Testing 2." line is given seven days notice, and the "Testing 5." line
is allotted ten days.

If anyone thinks something like this would be nice to include in the
standard distribution, I can change the format so that it's compatible with
the existing calendar program... I can search for an arbitrary pattern at
the end of each line, or instance. Also, I might include one more bit of
functionality - I might make it so that the program can also, given a
particular year, print out how many years it's been between the year in
question and the present date.

Does this interest anyone? It seems like the current calendar program is
really close to being just right, while lacking a couple bits of essential
functionality.

Thanks in advance for your time and consideration.

-- 
Mason Loring Bliss...mason@acheron.middleboro.ma.us...www.webtrek.com/mason
"In the drowsy dark cave of the mind dreams build their nest with fragments
 dropped from day's caravan."--Rabindranath Tagore...awake ? sleep : dream;

*** calendar.c.old      Thu Apr  2 07:21:39 1998
--- calendar.c  Mon May 11 21:23:01 1998
***************
*** 154,159 ****
--- 154,161 ----
  void
  cal()
  {
+       extern int offset;
+       int offset_save, i, x;
        int printing;
        char *p;
        FILE *fp;
***************
*** 169,174 ****
--- 171,208 ----
                        while ((ch = getchar()) != '\n' && ch != EOF);
                if (buf[0] == '\0')
                        continue;
+
+               /* See if we have an offset marker... */
+               if (buf[0] == '.') {
+                       /* Save the old offset, and grab the new one. */
+                       offset_save = offset;
+                       if (sscanf((char *) (buf + 1), "%i", &offset) != 1) {
+                               offset = offset_save;
+                               continue;
+                       }
+
+                       /* Use the original if it was larger. */
+                       offset = offset_save > offset ? offset_save : offset;
+
+                       /* Find the location of our trailing marker. */
+                       x = sizeof(buf);
+                       for (i = 1; (buf[i] != '.') && (i < x - 1); ++i) ;
+                       x = strlen(buf + ++i);
+
+                       /* Remove the space the new offset marker occupied. */
+                       memmove((void *) buf, (void *) (buf + i), x);
+                       buf[x] = '\0';
+
+                       /* Proceed as normal, with the new offset. */
+                       printing = isnow(buf) ? 1 : 0;
+                       if (printing)
+                               (void)fprintf(fp, "%s\n", buf);
+
+                       /* Restore! */
+                       offset = offset_save;
+                       continue;
+               }
+
                if (buf[0] != '\t')
                        printing = isnow(buf) ? 1 : 0;
                if (printing)