Re: misleading error message in cal
On Tue, Jan 24, 2023 at 09:39:05PM -0300, Lucas de Sena wrote: > > hi. > > > > the trouble is, openbsd supports a single month name argument to cal(1): > > > > $ cal jan > > > > the ability is non-standard, but is documented as such. > > > > so our SYNOPSIS is correct and this proposal, as far as i can see, > > incorrect. > > > > jmc > > Indeed, my proposed SYNOPSIS ignores the month name exception. > Sorry for that. > > On the proposed patch for cal.c; do you think that it is correct > and that the issue on the misleading error message is valid? > that one's not my department. sorry. jmc
Re: misleading error message in cal
> hi. > > the trouble is, openbsd supports a single month name argument to cal(1): > > $ cal jan > > the ability is non-standard, but is documented as such. > > so our SYNOPSIS is correct and this proposal, as far as i can see, > incorrect. > > jmc Indeed, my proposed SYNOPSIS ignores the month name exception. Sorry for that. On the proposed patch for cal.c; do you think that it is correct and that the issue on the misleading error message is valid?
Re: misleading error message in cal
On Tue, Jan 24, 2023 at 07:13:49AM -0300, Lucas de Sena wrote: > On 2023-01-24, Lucas de Sena wrote: > > (nitpick) > > While I'm at it, here's a patch for the SYNOPSIS section of the manual: > > > Index: usr.bin/cal/cal.1 > === > RCS file: /cvs/src/usr.bin/cal/cal.1,v > retrieving revision 1.32 > diff -u -p -r1.32 cal.1 > --- usr.bin/cal/cal.1 31 Mar 2022 17:27:24 - 1.32 > +++ usr.bin/cal/cal.1 24 Jan 2023 10:09:46 - > @@ -42,8 +42,10 @@ > .Sh SYNOPSIS > .Nm cal > .Op Fl jmwy > +.Oo > .Op Ar month > -.Op Ar year > +.Ar year > +.Oc > .Sh DESCRIPTION > .Nm > displays a simple calendar. > hi. the trouble is, openbsd supports a single month name argument to cal(1): $ cal jan the ability is non-standard, but is documented as such. so our SYNOPSIS is correct and this proposal, as far as i can see, incorrect. jmc
Re: misleading error message in cal
On 2023-01-24, Lucas de Sena wrote: > (nitpick) While I'm at it, here's a patch for the SYNOPSIS section of the manual: Index: usr.bin/cal/cal.1 === RCS file: /cvs/src/usr.bin/cal/cal.1,v retrieving revision 1.32 diff -u -p -r1.32 cal.1 --- usr.bin/cal/cal.1 31 Mar 2022 17:27:24 - 1.32 +++ usr.bin/cal/cal.1 24 Jan 2023 10:09:46 - @@ -42,8 +42,10 @@ .Sh SYNOPSIS .Nm cal .Op Fl jmwy +.Oo .Op Ar month -.Op Ar year +.Ar year +.Oc .Sh DESCRIPTION .Nm displays a simple calendar.
misleading error message in cal
(nitpick) When invoked with a single argument and this argument is not a number, cal(1) thinks it is a month name and calls parsemonth() on it. If this non-numeric argument is not a valid month name, it exit with the following error message: > invalid month: use 1-12 or a name That error message is OK when invoking cal(1) like this > cal le_month 2023 "le_month" is indeed an invalid month name. However, invoking cal(1) like this: > cal le_month warns the same error message: > invalid month: use 1-12 or a name A 1-12 number there is interpreted as a year number, not as a month. The errx(3) call in parsemonth() is not necessary, for its return value is already checked when parsemonth() is called. I then removed the call to errx(3) and just returned 0, which is checked against by the caller. Index: usr.bin/cal/cal.c === RCS file: /cvs/src/usr.bin/cal/cal.c,v retrieving revision 1.30 diff -u -p -r1.30 cal.c --- usr.bin/cal/cal.c 9 Oct 2015 01:37:06 - 1.30 +++ usr.bin/cal/cal.c 24 Jan 2023 04:16:42 - @@ -196,7 +196,7 @@ main(int argc, char *argv[]) case 2: month = parsemonth(*argv++); if (!month) - errx(1, "Unable to parse month"); + errx(1, "invalid month: use 1-12 or a name"); /* FALLTHROUGH */ case 1: if (argc == 1 && !isdigit((unsigned char)*argv[0])) { @@ -559,6 +559,6 @@ parsemonth(const char *s) v = tm.tm_mon + 1; } if (v <= 0 || v > 12) - errx(1, "invalid month: use 1-12 or a name"); + return 0; return (v); }