NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/41945: calendar(1) doesn't recognize days of the week correctly sometimes



The following reply was made to PR bin/41945; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: Thomas Klausner <wiz%netbsd.org@localhost>
Cc: "Jeremy C. Reed" <reed%reedmedia.net@localhost>,
        NetBSD bugtracking <gnats-bugs%netbsd.org@localhost>
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week 
correctly sometimes 
Date: Wed, 21 Oct 2009 17:05:49 +0700

     Date:        Tue, 20 Oct 2009 21:54:58 +0200
     From:        Thomas Klausner <wiz%NetBSD.org@localhost>
     Message-ID:  <20091020195458.GE13087%danbala.tuwien.ac.at@localhost>
 
   | Sounds good, thanks!
 
 OK, here's a replacement patch - this is just for (most of the) parsing
 bugs that you mentioned, and those from Jeremy Reed's message
        http://mail-index.netbsd.org/tech-userlevel/2008/05/05/msg000543.html
 which was reporting essentially the same set of bugs.
 
 This is just for the calendar line parser bugs, no changes to the
 way cpp is invoked yet, so expecting
        #include "file"
 to find "file" in the same directory as the calendar file, except
 bu fluke (the calendar file is in the "right place") is still not
 going to work, but it is possible to
        #include <stdio.h>
 and that "works" ...    Still no idea why you wouldn't have gotten an
 error message if the file you included wasn't found, unless a file of
 the same name did exist somewhere that calendar would look (unless it
 happens to have canendar style lines in it, referencing a bogus file
 is mostly just silently ignored).
 
 There's one bug mentioned in Jeremy's mail that this doesn't fix, because
 fixing that one is a significantly bigger change than I have time for
 right now.
 
 That is ...
        5) Multiple entries for same day or missed:
 
        tx:work$ calendar -d 0504 -f /home/reed/calendar.test
        *Monday         *Monday
        Wednesday       Today is Wednesday
        *Wednesday      *Wednesday
        **              **
 
        See my other Wednesday entry in calendar.test above.
 
 The "missing" entry from the calendar file given was
 
        Wednesday       Wednesday
 
 It isn't missed because it is a duplicate, but because it starts with
 two day names, and that just confuses the parser, if the line had been
 
        Wednesday       is Wednesday
 
 or something, it would have worked just fine (well, subject to the other
 bugs that exist anyway - that line shouldn't have apepared in that test
 at all, as 0504 (in 2008 when the message was sent) was a Sunday.  But
 when Wednesday lines should be printed, it would be.
 
 This patch doesn't attempt to fix that, or various other "unusual"
 formats for calendar type lines that cause strange things to happen.
 
 I am going to send a message to netbsd-users about another possible
 change that might be needed, to ask for what people think.
 
 kre
 
 ps; this patch is based upon src/usr.bin/calendar/calendar.c from
 current as it is today (1.47).   Discard my earlier versions in this PR.
 
 --- /release/current/usr/src/usr.bin/calendar/calendar.c       2008-09-30 
12:51:41.000000000 +0700
 +++ calendar.c 2009-10-21 16:26:26.000000000 +0700
 @@ -63,6 +63,13 @@
  
  #include "pathnames.h"
  
 +      /* flags used by calendar file parser */
 +#define       F_ISMONTH       0x01
 +#define       F_ISDAY         0x02
 +#define       F_ISDOW         0x04
 +#define       F_WILDMONTH     0x10
 +#define       F_WILDDAY       0x20
 +
  static unsigned short lookahead = 1;
  static unsigned short weekend = 2;
  static char *fname = NULL;
 @@ -247,18 +254,13 @@
        int v1;
        int v2;
  
 -#define       F_ISMONTH       0x01
 -#define       F_ISDAY         0x02
 -#define F_WILDMONTH   0x04
 -#define F_WILDDAY     0x08
 -
        flags = 0;
  
        /* didn't recognize anything, skip it */
        if (!(v1 = getfield(endp, &endp, &flags)))
                return false;
  
 -      if (flags & F_ISDAY || v1 > 12) {
 +      if ((flags & (F_ISDAY|F_ISDOW)) || v1 > 12) {
                /* found a day */
                day = v1;
                /* if no recognizable month, assume wildcard ('*') month */
 @@ -295,10 +297,17 @@
        if (flags & F_WILDMONTH && flags & F_ISDAY && day == tp->tm_mday)
                return true;
  
 +      if (flags & F_WILDMONTH && flags & F_ISDOW && day == tp->tm_wday + 1)
 +              return true;
 +
        if (flags & F_ISMONTH && flags & F_WILDDAY && month == tp->tm_mon + 1)
                return true;
  
 -      if (flags & F_ISDAY)
 +      if (flags & F_ISMONTH && flags & F_ISDOW && month == tp->tm_mon + 1 &&
 +          day == tp->tm_wday + 1)
 +              return true;
 +
 +      if (flags & F_ISDOW)
                day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7);
        day = cumdays[month] + day;
  
 @@ -343,17 +352,20 @@
                *endp = p;
                return val;
        }
 -      for (start = p; *p != '\0' && isalpha((unsigned char)*++p); /*EMPTY*/)
 +      for (start = p; *p != '\0' && isalpha((unsigned char)*p); p++)
                continue;
 -      savech = *p;
 -      *p = '\0';
 -      if ((val = getmonth(start)) != 0)
 -              *flags |= F_ISMONTH;
 -      else if ((val = getday(start)) != 0)
 -              *flags |= F_ISDAY;
 -      else {
 -              *p = savech;
 -              return 0;
 +      if (p != start) {
 +              savech = *p;
 +              *p = '\0';
 +              if ((val = getmonth(start)) != 0)
 +                      *flags |= F_ISMONTH;
 +              else if ((val = getday(start)) != 0)
 +                      *flags |= F_ISDOW;
 +              else {
 +                      *p = savech;
 +                      *endp = start;
 +                      return 0;
 +              }
        }
        for (*p = savech; FLDCHAR(*p); ++p)
                continue;
 
 


Home | Main Index | Thread Index | Old Index