util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] cal: honor num_months when only a year argument
@ 2018-01-22 20:05 J William Piggott
  2018-01-22 20:07 ` [PATCH 2/2] cal: do not set months_in_row with -3 option J William Piggott
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: J William Piggott @ 2018-01-22 20:05 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


I don't know if this was an oversight or an overzealous
interpretation of POSIX. Just in case, I'll address the
POSIX possibility. POSIX description for cal(1) says:

  If only the year operand is given, cal shall produce a
  calendar for all twelve months in the given calendar year.

It also says that cal(1) has no options, so in that context
if an option is given then it should be expected to override
POSIX behavior.

Before patched all of these command displayed a full year:
cal -1 2020
cal -3 2020
cal -n6 2020

Patched the number of months options are honored.

This patch also fixes the -1 option which was a no-op.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
 misc-utils/cal.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 5a6364a27..8a715d94c 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -267,7 +267,6 @@ int main(int argc, char **argv)
 	static struct cal_control ctl = {
 		.reform_year = DEFAULT_REFORM_YEAR,
 		.weekstart = SUNDAY,
-		.num_months = 1,		/* default is "cal -1" */
 		.span_months = 0,
 		.colormode = UL_COLORMODE_UNDEF,
 		.weektype = WEEK_NUM_DISABLED,
@@ -363,7 +362,7 @@ int main(int argc, char **argv)
 
 		switch(ch) {
 		case '1':
-			/* default */
+			ctl.num_months = 1;
 			break;
 		case '3':
 			ctl.num_months = 3;
@@ -536,7 +535,8 @@ int main(int argc, char **argv)
 
 	if (yflag || Yflag) {
 		ctl.gutter_width = 3;
-		ctl.num_months = MONTHS_IN_YEAR;
+		if (!ctl.num_months)
+			ctl.num_months = MONTHS_IN_YEAR;
 		if (yflag) {
 			ctl.req.start_month = 1;	/* start from Jan */
 			ctl.header_year = 1;		/* print year number */
@@ -549,6 +549,9 @@ int main(int argc, char **argv)
 	else if (!ctl.months_in_row)
 		ctl.months_in_row = 1;
 
+	if (!ctl.num_months)
+		ctl.num_months = 1;		/* display at least one month */
+
 	if (yflag || Yflag)
 		yearly(&ctl);
 	else

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-01-30 12:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-22 20:05 [PATCH 1/2] cal: honor num_months when only a year argument J William Piggott
2018-01-22 20:07 ` [PATCH 2/2] cal: do not set months_in_row with -3 option J William Piggott
2018-01-24 13:25   ` Karel Zak
2018-01-24 12:54 ` [PATCH 1/2] cal: honor num_months when only a year argument Karel Zak
2018-01-24 15:22   ` J William Piggott
2018-01-24 14:24 ` Ruediger Meier
2018-01-24 15:33   ` Ruediger Meier
2018-01-30 10:44   ` Karel Zak
2018-01-30 12:05     ` Ruediger Meier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).