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

From: Greg Reagle <greg.reagle_AT_umbc.edu>
Date: Thu, 8 Jan 2015 14:33:39 -0500

---
 cal.1 |  5 +++++
 cal.c | 11 ++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/cal.1 b/cal.1
index a679350..aebd992 100644
--- a/cal.1
+++ b/cal.1
_AT_@ -29,6 +29,11 @@ of calendars side by side. Each row of calendars contains at most
 .IR columns
 number of calendars. The defaults are obtained using
 .IR localtime (3).
+If
+.IR year
+is given without
+.IR month
+print the whole year, unless overridden by options.
 .SH OPTIONS
 .TP
 .B \-1
diff --git a/cal.c b/cal.c
index 28e58fe..8b04e56 100644
--- a/cal.c
+++ b/cal.c
_AT_@ -122,7 +122,7 @@ main(int argc, char *argv[])
 	fday = 0;
 
 	ncols = 3;
-	nmons = 1;
+	nmons = 0;
 
 	ARGBEGIN {
 	case '1':
_AT_@ -159,6 +159,15 @@ main(int argc, char *argv[])
 		usage();
 	} ARGEND;
 
+	if (nmons == 0) {
+		if (argc == 1) {
+			month = 1;
+			nmons = 12;
+		} else {
+			nmons = 1;
+		}
+	}
+
 	switch (argc) {
 	case 3:
 		day = estrtol(argv[0], 0);
-- 
2.2.1
Received on Thu Jan 08 2015 - 20:33:39 CET

This archive was generated by hypermail 2.3.0 : Thu Jan 08 2015 - 20:36:08 CET