Thus said Solene Rapenne on Tue, 29 Jan 2019 12:47:57 +0100:
> As I'm not comfortable with calendar(1) code, I don't know if the
> patch breaks some other use. If someone feels confident to read the
> code and import it, that would be nice.
Thanks for the confirmation that it works. I don't believe it will
impact any other use cases other than that -B will not incorrectly give
you extra days.
For completeness, here's a proper patch for both the regress tree and
the calendar program:
Index: calendar.c
===================================================================
RCS file: /home/cvs/src/usr.bin/calendar/calendar.c,v
retrieving revision 1.35
diff -u -p -r1.35 calendar.c
--- calendar.c 7 Dec 2015 18:46:35 -0000 1.35
+++ calendar.c 25 Jan 2019 14:32:37 -0000
@@ -60,7 +60,6 @@ int bodun_always = 0;
int f_dayAfter = 0; /* days after current date */
int f_dayBefore = 0; /* days before current date */
-int f_SetdayAfter = 0; /* calendar invoked with -A */
struct specialev spev[NUMEV];
@@ -101,7 +100,6 @@ main(int argc, char *argv[])
f_dayAfter = strtonum(optarg, 0, INT_MAX, &errstr);
if (errstr)
errx(1, "-A %s: %s", optarg, errstr);
- f_SetdayAfter = 1;
break;
case 'B': /* days before current date */
Index: calendar.h
===================================================================
RCS file: /home/cvs/src/usr.bin/calendar/calendar.h,v
retrieving revision 1.15
diff -u -p -r1.15 calendar.h
--- calendar.h 7 Dec 2015 18:46:35 -0000 1.15
+++ calendar.h 25 Jan 2019 14:32:37 -0000
@@ -103,7 +103,6 @@ void setnnames(void);
extern int f_dayAfter; /* days after current date */
extern int f_dayBefore; /* days before current date */
-extern int f_SetdayAfter; /* calendar invoked with -A */
/* Special events; see also setnnames() in day.c */
/* '=' is not a valid character in a special event name */
Index: day.c
===================================================================
RCS file: /home/cvs/src/usr.bin/calendar/day.c,v
retrieving revision 1.34
diff -u -p -r1.34 day.c
--- day.c 14 Sep 2016 15:09:46 -0000 1.34
+++ day.c 25 Jan 2019 14:32:37 -0000
@@ -166,7 +166,7 @@ settime(time_t *now)
cumdays = daytab[0];
/* Friday displays Monday's events */
offset = tp->tm_wday == 5 ? 3 : 1;
- if (f_SetdayAfter)
+ if (f_dayAfter || f_dayBefore)
offset = 0; /* Except not when range is set explicitly */
header[5].iov_base = dayname;
Index: Makefile
===================================================================
RCS file: /home/cvs/src/regress/usr.bin/calendar/Makefile,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile
--- Makefile 14 Sep 2016 16:11:54 -0000 1.2
+++ Makefile 29 Jan 2019 15:01:02 -0000
@@ -1,6 +1,6 @@
# $OpenBSD: Makefile,v 1.2 2016/09/14 16:11:54 tb Exp $
-FILES?!= ls ${.CURDIR}/*.out
+FILES?!= ls ${.CURDIR}/[0-9]*.out
CALENDAR?= calendar
IN= ${.CURDIR}/in
@@ -14,6 +14,16 @@ ${f:C|.*/||}:
@echo ${*}
@${CALENDAR} -f ${IN} -t ${f:C|.*/||:C/\..*//} | diff -u ${OUT} -
.endfor
+
+REGRESS_TARGETS+=before after
+
+before:
+ @echo ${*}
+ @${CALENDAR} -f ${.CURDIR}/beforeafter.in -t 20190109 -B 5 | diff -U 7
${.CURDIR}/before.out -
+
+after:
+ @echo ${*}
+ @${CALENDAR} -f ${.CURDIR}/beforeafter.in -t 20190111 -A 5 | diff -U 7
${.CURDIR}/after.out -
.PHONY: ${REGRESS_TARGETS}
Index: after.out
===================================================================
RCS file: after.out
diff -N after.out
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ after.out 29 Jan 2019 15:01:02 -0000
@@ -0,0 +1,6 @@
+Jan 11* Friday
+Jan 12* Saturday
+Jan 13* Sunday
+Jan 14* Monday
+Jan 15* Tuesday
+Jan 16* Wednesday
Index: before.out
===================================================================
RCS file: before.out
diff -N before.out
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ before.out 29 Jan 2019 15:01:02 -0000
@@ -0,0 +1,6 @@
+Jan 04* Friday
+Jan 05* Saturday
+Jan 06* Sunday
+Jan 07* Monday
+Jan 08* Tuesday
+Jan 09* Wednesday
Index: beforeafter.in
===================================================================
RCS file: beforeafter.in
diff -N beforeafter.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ beforeafter.in 29 Jan 2019 15:01:02 -0000
@@ -0,0 +1,7 @@
+Sunday Sunday
+Monday Monday
+Tuesday Tuesday
+Wednesday Wednesday
+Thursday Thursday
+Friday Friday
+Saturday Saturday
Thanks,
Andy
--
TAI64 timestamp: 400000005c506bff