aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2016-10-07 16:02:36 +0200
committerKarel Zak <kzak@redhat.com>2016-10-07 16:02:36 +0200
commit535fd6d2b6b3fec9507b2e435460be317e0485a1 (patch)
tree2e20127a1ca3bdf10dc3297fafdbdf91e4d49814
parente5927d541147dab344d274f02e7c467403883b3f (diff)
downloadutil-linux-535fd6d2b6b3fec9507b2e435460be317e0485a1.tar.gz
cal: support alone month name parameter
For example 'cal August' to print August for the current year. Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--misc-utils/cal.113
-rw-r--r--misc-utils/cal.c10
2 files changed, 16 insertions, 7 deletions
diff --git a/misc-utils/cal.1 b/misc-utils/cal.1
index 2048e95e27..39378cfe2a 100644
--- a/misc-utils/cal.1
+++ b/misc-utils/cal.1
@@ -44,7 +44,7 @@ cal \- display a calendar
.br
.B cal
[options]
-.RI <timestamp>
+.RI <timestamp|monthname>
.SH DESCRIPTION
.B cal
displays a simple calendar. If no arguments are specified, the current
@@ -103,10 +103,13 @@ Specifies the \fIyear\fR to be displayed; note the year must be fully specified:
.B "cal 89"
will not display a calendar for 1989.
.TP
-\fBSingle string parameter (e.g. 'cal tomorrow')\fR
-Specifies \fItimestamp\fR. The special placeholders are accepted when parsing timestamp, "now" may be used to
-refer to the current time, "today", "yesterday", "tomorrow" refer to
-of the current day, the day before or the next day, respectively.
+\fBSingle string parameter (e.g. 'cal tomorrow' or 'cal August')\fR
+Specifies \fItimestamp\fR or a \fImonth name\fR according to the current
+locales.
+.sp
+The special placeholders are accepted when parsing timestamp, "now" may be used
+to refer to the current time, "today", "yesterday", "tomorrow" refer to of the
+current day, the day before or the next day, respectively.
.sp
The relative date specifications are also accepted, in this case "+" is
evaluated to the current time plus the specified time span. Correspondingly, a
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index aaa2943e66..5c56e74805 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -410,10 +410,14 @@ int main(int argc, char **argv)
if (argc == 1 && !isdigit_string(*argv)) {
usec_t x;
+ /* cal <timestamp> */
if (parse_timestamp(*argv, &x) == 0)
now = (time_t) (x / 1000000);
+ /* cal <monthname> */
+ else if ((ctl.req.month = monthname_to_number(&ctl, *argv)) > 0)
+ time(&now); /* this year */
else
- errx(EXIT_FAILURE, _("failed to parse timestamp"));
+ errx(EXIT_FAILURE, _("failed to parse timestamp or unknown month name: %s"), *argv);
argc = 0;
} else
time(&now);
@@ -460,7 +464,8 @@ int main(int argc, char **argv)
case 0:
ctl.req.day = local_time->tm_yday + 1;
ctl.req.year = local_time->tm_year + 1900;
- ctl.req.month = local_time->tm_mon + 1;
+ if (!ctl.req.month)
+ ctl.req.month = local_time->tm_mon + 1;
break;
default:
usage(stderr);
@@ -969,6 +974,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options] [[[day] month] year]\n"), program_invocation_short_name);
+ fprintf(out, _(" %s [options] <timestamp|monthname>\n"), program_invocation_short_name);
fputs(USAGE_SEPARATOR, out);
fputs(_("Display a calendar, or some part of it.\n"), out);