From d4cb626da245c0d792289f5267eec4b34c281e72 Mon Sep 17 00:00:00 2001 From: Deiz Date: Fri, 9 Oct 2015 20:35:17 -0400 Subject: [PATCH] cal: Track date span independently from months_in_row This fixes a minor issue where cal -n 3 would mirror the spanning behaviour of cal -3 with Gregorian calendars, instead of starting with the current month. Signed-off-by: Deiz --- misc-utils/cal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 6faac5ca29..7441ecfc46 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -232,6 +232,7 @@ struct cal_control { const char *full_month[MONTHS_IN_YEAR]; /* month names */ int colormode; /* day and week number highlight */ int num_months; /* number of requested mounths */ + int span_months; /* span the date */ int months_in_row; /* number of months horizontally in print out */ int weekstart; /* day the week starts, often Sun or Mon */ int weektype; /* WEEK_TYPE_{NONE,ISO,US} */ @@ -276,6 +277,7 @@ int main(int argc, char **argv) static struct cal_control ctl = { .weekstart = SUNDAY, .num_months = 1, /* default is "cal -1" */ + .span_months = 0, .colormode = UL_COLORMODE_UNDEF, .weektype = WEEK_NUM_DISABLED, .day_width = DAY_LEN, @@ -373,6 +375,7 @@ int main(int argc, char **argv) break; case '3': ctl.num_months = 3; + ctl.span_months = 1; ctl.months_in_row = 3; break; case 's': @@ -737,7 +740,7 @@ static void monthly(const struct cal_control *ctl) int32_t year = ctl->req.year; /* cal -3 */ - if (ctl->num_months == 3 && ctl->months_in_row == 3) { + if (ctl->num_months == 3 && ctl->span_months) { if (month == 1){ month = MONTHS_IN_YEAR; year--; -- 2.47.3