Thus said "Todd C. Miller" on Thu, 24 Jan 2019 10:06:59 -0700:
> On 24 Jan 2019 08:19:00 -0700, "Andy Bradford" wrote: > It looks like
> currently if -A is used the Friday handling is > disabled, so the
> following patch also disables it when -B is used.
>
> I think that's the correct approach.
Regarding the proposed patch, would it be better simply to remove the
extra variable and rely on the values of f_dayAfter or f_dayBefore? As
in:
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;
Oh and how about some regression:
? after.out
? before.out
? beforeafter.in
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 25 Jan 2019 15:18:56 -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 20190109 -A 2 | diff -U 7
${.CURDIR}/after.out -
.PHONY: ${REGRESS_TARGETS}
Here is beforeafter.in:
Sunday Sunday
Monday Monday
Tuesday Tuesday
Wednesday Wednesday
Thursday Thursday
Friday Friday
Saturday Saturday
Here is before.out:
Jan 04* Friday
Jan 05* Saturday
Jan 06* Sunday
Jan 07* Monday
Jan 08* Tuesday
Jan 09* Wednesday
And here is after.out:
Jan 09* Wednesday
Jan 10* Thursday
Jan 11* Friday
Thanks,
Andy
--
TAI64 timestamp: 400000005c4b29dc