diff options
author | Deiz | 2015-10-10 02:39:02 +0200 |
---|---|---|
committer | Deiz | 2015-10-10 02:39:02 +0200 |
commit | ccf3dd50ce70bb915a42a037d99fac9fcd282bf1 (patch) | |
tree | 1c88ab1509502ceaaf6dab36a9355ece77ad2968 /misc-utils/cal.c | |
parent | cal: Track date span independently from months_in_row (diff) | |
download | kernel-qcow2-util-linux-ccf3dd50ce70bb915a42a037d99fac9fcd282bf1.tar.gz kernel-qcow2-util-linux-ccf3dd50ce70bb915a42a037d99fac9fcd282bf1.tar.xz kernel-qcow2-util-linux-ccf3dd50ce70bb915a42a037d99fac9fcd282bf1.zip |
cal: Add --span option
This allows the date spanning behaviour of -3 to be used with other
month ranges.
Signed-off-by: Deiz <silverwraithii@gmail.com>
Diffstat (limited to 'misc-utils/cal.c')
-rw-r--r-- | misc-utils/cal.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 7441ecfc4..62c5818dc 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -297,6 +297,7 @@ int main(int argc, char **argv) {"monday", no_argument, NULL, 'm'}, {"julian", no_argument, NULL, 'j'}, {"months", required_argument, NULL, 'n'}, + {"span", no_argument, NULL, 'S'}, {"year", no_argument, NULL, 'y'}, {"week", optional_argument, NULL, 'w'}, {"color", optional_argument, NULL, OPT_COLOR}, @@ -365,7 +366,7 @@ int main(int argc, char **argv) ctl.weekstart = (wfd + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % DAYS_IN_WEEK; } #endif - while ((ch = getopt_long(argc, argv, "13mjn:sywYVh", longopts, NULL)) != -1) { + while ((ch = getopt_long(argc, argv, "13mjn:sSywYVh", longopts, NULL)) != -1) { err_exclusive_options(ch, longopts, excl, excl_st); @@ -398,6 +399,9 @@ int main(int argc, char **argv) ctl.num_months = strtou32_or_err(optarg, _("invalid month argument")); break; + case 'S': + ctl.span_months = 1; + break; case 'w': if (optarg) { ctl.req.week = strtos32_or_err(optarg, @@ -736,16 +740,18 @@ static void cal_output_months(struct cal_month *month, const struct cal_control static void monthly(const struct cal_control *ctl) { struct cal_month m1,m2,m3, *m; - int i, rows, month = ctl->req.start_month ? ctl->req.start_month : ctl->req.month; + int i, rows, new_month, month = ctl->req.start_month ? ctl->req.start_month : ctl->req.month; int32_t year = ctl->req.year; - /* cal -3 */ - if (ctl->num_months == 3 && ctl->span_months) { - if (month == 1){ - month = MONTHS_IN_YEAR; + /* cal -3, cal -Y --span, etc. */ + if (ctl->span_months) { + new_month = month - ctl->num_months / 2; + if (new_month < 1) { + month = new_month + MONTHS_IN_YEAR; year--; - } else - month--; + } + else + month = new_month; } m1.next = (ctl->months_in_row > 1) ? &m2 : NULL; @@ -958,6 +964,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out) fputs(_(" -1, --one show only a single month (default)\n"), out); fputs(_(" -3, --three show three months spanning the date\n"), out); fputs(_(" -n, --months <num> show num months starting with date's month\n"), out); + fputs(_(" -S, --span span the date when displaying multiple months\n"), out); fputs(_(" -s, --sunday Sunday as first day of week\n"), out); fputs(_(" -m, --monday Monday as first day of week\n"), out); fputs(_(" -j, --julian output Julian dates\n"), out); |