]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cal: support abbreviated month names
authorKarel Zak <kzak@redhat.com>
Fri, 7 Oct 2016 14:10:28 +0000 (16:10 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Oct 2016 14:10:28 +0000 (16:10 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/cal.1
misc-utils/cal.c

index 39378cfe2af5a4cb0fd54fe1005e9290ae4d1c40..162916fe97865d3267867d0b3343c5b99920fd29 100644 (file)
@@ -50,8 +50,8 @@ cal \- display a calendar
 displays a simple calendar.  If no arguments are specified, the current
 month is displayed.
 .sp
-The \fImonth\fR may be specified as a number (1-12) or as a month name according
-to the current locales.
+The \fImonth\fR may be specified as a number (1-12), as a month name or as an
+abbreviated month name according to the current locales.
 .SH OPTIONS
 .TP
 \fB\-1\fR, \fB\-\-one\fR
@@ -104,7 +104,7 @@ Specifies the \fIyear\fR to be displayed; note the year must be fully specified:
 will not display a calendar for 1989.
 .TP
 \fBSingle string parameter (e.g. 'cal tomorrow' or 'cal August')\fR
-Specifies \fItimestamp\fR or a \fImonth name\fR according to the current
+Specifies \fItimestamp\fR or a \fImonth name\fR (or abbreviated name) according to the current
 locales.
 .sp
 The special placeholders are accepted when parsing timestamp, "now" may be used
index 5c56e748055c29a698ff5324d37b340b670a6a62..5e7b356c8fa178641153d54a8096b30e3887c51d 100644 (file)
@@ -203,6 +203,8 @@ struct cal_request {
 
 struct cal_control {
        const char *full_month[MONTHS_IN_YEAR]; /* month names */
+       const char *abbr_month[MONTHS_IN_YEAR]; /* abbreviated month names */
+
        int colormode;                  /* day and week number highlight */
        int num_months;                 /* number of requested monts */
        int span_months;                /* span the date */
@@ -548,16 +550,31 @@ static void init_monthnames(struct cal_control *ctl)
                ctl->full_month[i] = nl_langinfo(MON_1 + i);
 }
 
+static void init_abbr_monthnames(struct cal_control *ctl)
+{
+       size_t i;
+
+       if (ctl->abbr_month[0] != '\0')
+               return;         /* already initialized */
+
+       for (i = 0; i < MONTHS_IN_YEAR; i++)
+               ctl->abbr_month[i] = nl_langinfo(ABMON_1 + i);
+}
+
 static int monthname_to_number(struct cal_control *ctl, const char *name)
 {
        size_t i;
 
        init_monthnames(ctl);
-
        for (i = 0; i < MONTHS_IN_YEAR; i++)
                if (strcasecmp(ctl->full_month[i], name) == 0)
                        return i + 1;
 
+       init_abbr_monthnames(ctl);
+       for (i = 0; i < MONTHS_IN_YEAR; i++)
+               if (strcasecmp(ctl->abbr_month[i], name) == 0)
+                       return i + 1;
+
        return -EINVAL;
 }