summaryrefslogtreecommitdiffstats
path: root/misc-utils/cal.c
diff options
context:
space:
mode:
authorKarel Zak2016-10-07 16:10:28 +0200
committerKarel Zak2016-10-07 16:10:28 +0200
commitc8805632003c8fb39d8ebf9c921e9c1a90bfa52a (patch)
treee31e87c9c92c3516be10153e749db96a2eca384b /misc-utils/cal.c
parentcal: support alone month name parameter (diff)
downloadkernel-qcow2-util-linux-c8805632003c8fb39d8ebf9c921e9c1a90bfa52a.tar.gz
kernel-qcow2-util-linux-c8805632003c8fb39d8ebf9c921e9c1a90bfa52a.tar.xz
kernel-qcow2-util-linux-c8805632003c8fb39d8ebf9c921e9c1a90bfa52a.zip
cal: support abbreviated month names
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/cal.c')
-rw-r--r--misc-utils/cal.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 5c56e7480..5e7b356c8 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -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;
}