Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Jan 2002 13:30:02 -0800 (PST)
From:      David Taylor <davidt@yadt.co.uk>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/34497: calendar(1) does not understand calendars
Message-ID:  <200201312130.g0VLU2d96837@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/34497; it has been noted by GNATS.

From: David Taylor <davidt@yadt.co.uk>
To: wilko@FreeBSD.org
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: bin/34497: calendar(1) does not understand calendars
Date: Thu, 31 Jan 2002 21:24:00 +0000

 --cNdxnHkX5QqsyA0e
 Content-Type: text/plain; charset=iso-8859-15
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Thu, 31 Jan 2002, wilko@FreeBSD.org wrote:
 >=20
 > >Number:         34497
 > >Category:       bin
 > >Synopsis:       calendar(1) does not understand calendars
 >=20
 > >Description:
 >=20
 > 	calendar(1) does not understand calendars, has 33 days in=20
 >  	January for example.
 >=20
 > >How-To-Repeat:
 >=20
 > Given the following calendar file:
 >=20
 > Thursday        BAR
 > Friday 		FOO
 > Saturday	DUH
 >=20
 > running calendar displays:
 >=20
 > Jan 31* BAR
 > Jan 32* FOO
 > Jan 33* DUH
 >=20
 > When run on Thu Jan 31 20:32:12 CET 2002
 >=20
 > January with 33 days appears slightly odd.
 >=20
 
 Yeah, it does.
 
 For some reason, I was bored and decided to look at the source to see if I
 could fix it.  I regret that move now :)
 
 First thing I noticed was the code for the -a option (to run as root, and
 loop through every user's calendar:
 
                 while ((pw =3D getpwent()) !=3D NULL) {
                         (void)setegid(pw->pw_gid);
                         (void)initgroups(pw->pw_name, pw->pw_gid);
                         (void)seteuid(pw->pw_uid);
                         if (!chdir(pw->pw_dir))
                                 cal();
                         (void)seteuid(0);
                 }
 
 Which helpfully casts the return value of setegid()/seteuid()/etc to
 (void) and ignores it, so if there _is_ an error, it will just read the
 user-definable calendar file (which can include arbitrary files) as
 root...  not sure that's a good idea.
 
 I was going to submit a patch for that along with a fix for the original
 problem, until I decided there was no way I was fixing the original
 problem.
 
 The code is rather weird and obfusciated, but I managed to create a fix
 for the specific problem reported, but that doesn't stop '2002-01-33'
 being misinterpreted, along with other problems that cropped up....
 
 The easiest way I can see to fix it (instead of adding yet more horrible
 code to an already messy program) would be to change the design from:
 
 for each entry in calendar file:
 	Assign date to entry.
 	If date is within user-specified range of dates to display:
 		Display date
 	endif
 loop
 
 (which currently results in assigning 'Jan 32' to 'Friday', and also means
 if you have something to do every Thursday (e.g. clean car, or something),
 and ask for every entry for the next 60 days, you will only get one 'clean
 car' entry, instead of 8 or 9)
 
 to
 
 for each date in user-specified range:
 	for each entry in calendar file:
 		if entry could represent current date:
 			Display date
 		endif
 	loop
 loop
 
 Thus, you'd have the date 'Feb 01' and the entry 'Thursday', and just have
 to check if 'Feb 01' is 'Thursday'.
 
 However, I don't have enough time to write a calendar(1) replacement from
 scratch..
 
 Personally, if I was a committer, I'd rip calendar(1) out of the cvs
 repo. :)   [although that may explain why i'm not a committer :)].
 
 Is there a similar program anywhere in /usr/ports?  I can see various
 replacements for cal(1), and a few programs that appear to be X-versions
 of calendar(1), but nothing that claims to be a better console version of
 calendar(1).  Bah.
 
 --=20
 David Taylor
 davidt@yadt.co.uk
 "The future just ain't what it used to be"
 
 --cNdxnHkX5QqsyA0e
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.6 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iD8DBQE8WbXvfIqKXSsJ/xERAnv/AJ9LiGkUiKRSdEvfPMgfepdt64TGdACfa7oG
 UzHO9enfjAXK5fTfz4SLFFQ=
 =+sv/
 -----END PGP SIGNATURE-----
 
 --cNdxnHkX5QqsyA0e--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200201312130.g0VLU2d96837>