]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cal: Track date span independently from months_in_row
authorDeiz <silverwraithii@gmail.com>
Sat, 10 Oct 2015 00:35:17 +0000 (20:35 -0400)
committerDeiz <silverwraithii@gmail.com>
Sat, 10 Oct 2015 00:35:17 +0000 (20:35 -0400)
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 <silverwraithii@gmail.com>
misc-utils/cal.c

index 6faac5ca29e2814a3f43f53078801bff3a1f3d28..7441ecfc46120a747613dea32a257ce63d2770f9 100644 (file)
@@ -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--;