From 129b3ccedb2677a51988b322a92fefdf0ba2466e Mon Sep 17 00:00:00 2001 From: Jesse Ogle Date: Thu, 20 Jun 2013 11:23:44 -0400 Subject: [PATCH 1/6] Simplified isleap() --- cal.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cal.c b/cal.c index f1ba10d..54c27de 100644 --- a/cal.c +++ b/cal.c @@ -94,15 +94,7 @@ dayofweek(int year, int month, int day, int fday) static bool isleap(int year) { - bool leap = false; - - if(year % 4 == 0) - leap = true; - if(year % 100 == 0) - leap = false; - if(year % 400 == 0) - leap = true; - return leap; + return year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ); } -- 1.8.3.1 From 9a018ca70a427d482ac5d2378b5e3820f4a75690 Mon Sep 17 00:00:00 2001 From: Jesse Ogle Date: Thu, 20 Jun 2013 11:24:57 -0400 Subject: [PATCH 2/6] Converted spaces to tabs --- cal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cal.c b/cal.c index 54c27de..8fbbfcb 100644 --- a/cal.c +++ b/cal.c @@ -28,8 +28,8 @@ drawcal(int year, int month, int day, int ncols, int nmons, int fday) int row = 0; char *days[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", }; - if(!ncols) - ncols = nmons; + if(!ncols) + ncols = nmons; while(nmons > 0) { last = MIN(nmons, ncols); for(i = 0; i < last; i++) { -- 1.8.3.1 From 274cefb228b06d3588530d408a641c397c53a275 Mon Sep 17 00:00:00 2001 From: Jesse Ogle Date: Thu, 20 Jun 2013 11:28:14 -0400 Subject: [PATCH 3/6] Fixed -3 option replaced month -= 1 in -3 option so that multiple -3 switches would not keep decrementing the month. --- cal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cal.c b/cal.c index 8fbbfcb..cfca715 100644 --- a/cal.c +++ b/cal.c @@ -129,7 +129,7 @@ main(int argc, char *argv[]) break; case '3': nmons = 3; - month -= 1; + month = ltime->tm_mon; if(month == 0) { month = 12; year--; -- 1.8.3.1 From 48027b5bfa46814239735fb07b2c9e0b900c3343 Mon Sep 17 00:00:00 2001 From: Jesse Ogle Date: Thu, 20 Jun 2013 11:32:24 -0400 Subject: [PATCH 4/6] Fixed year assignment in -3 option Switch -3 now does a reassignment and not a decrement to prevent multiple switches from possibly messing up the year. --- cal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cal.c b/cal.c index cfca715..946f6fb 100644 --- a/cal.c +++ b/cal.c @@ -132,7 +132,7 @@ main(int argc, char *argv[]) month = ltime->tm_mon; if(month == 0) { month = 12; - year--; + year = ltime->tm_year + 1900 - 1; } break; case 'c': -- 1.8.3.1 From c9199ceb9728cfc810a354eb956b7df67b8ccc5a Mon Sep 17 00:00:00 2001 From: Jesse Ogle Date: Thu, 20 Jun 2013 11:49:49 -0400 Subject: [PATCH 5/6] Cleaned up usage() and man --- cal.1 | 16 ++++++++++------ cal.c | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cal.1 b/cal.1 index a679350..0abdc38 100644 --- a/cal.1 +++ b/cal.1 @@ -13,7 +13,7 @@ cal \- print calendar .RB [ \-f .IR firstday ] .RB [ \-n -.IR nmonths ] +.IR number ] .RB [ [ [ .IR day ] .IR month ] @@ -25,9 +25,11 @@ and .IR year print .IR number -of calendars side by side. Each row of calendars contains at most +of calendars in rows. Each row of calendars contains at most .IR columns -number of calendars. The defaults are obtained using +number of calendars. Setting +.IR columns +to 0 prints all calendars in a single row. The defaults are obtained using .IR localtime (3). .SH OPTIONS .TP @@ -49,12 +51,14 @@ Print a calendar of the current year. .BI \-c " columns" Print .IR columns -number of calendars in a row. The default is 3. +number of calendars per row. The default is 3. .TP .BI \-f " firstday" Specify the first day of the week. 0 is Sunday and 6 is Saturday. .TP -.BI \-n " nmonths" -Specify the number months to print. The default is 1. +.BI \-n " number" +Specify the +.IR number +months to print. The default is 1. .SH SEE ALSO .IR localtime (3) diff --git a/cal.c b/cal.c index 946f6fb..8001069 100644 --- a/cal.c +++ b/cal.c @@ -102,7 +102,7 @@ static void usage(void) { eprintf("usage: %s [-1] [-3] [-m] [-s] [-y] [-c columns]" - " [-f firstday] [-n nmonths] [ [ [day] month] year]\n", + " [-f firstday] [-n number] [ [ [day] month] year]\n", argv0); } -- 1.8.3.1 From ebe17fff1d1cbbeb0e931e07c470e0de5b456da6 Mon Sep 17 00:00:00 2001 From: Jesse Ogle Date: Thu, 20 Jun 2013 11:54:17 -0400 Subject: [PATCH 6/6] space to tab --- cal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cal.c b/cal.c index 8001069..a781f9c 100644 --- a/cal.c +++ b/cal.c @@ -94,7 +94,7 @@ dayofweek(int year, int month, int day, int fday) static bool isleap(int year) { - return year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ); + return year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ); } -- 1.8.3.1