summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorroam <roam@FreeBSD.org>2002-10-02 12:31:10 +0000
committerroam <roam@FreeBSD.org>2002-10-02 12:31:10 +0000
commite474e1f04df3d56ee4471959471e7f9ae34e7cb8 (patch)
tree5508f731308dc3d69528e3771df815ffd5ec04b2 /usr.bin
parent4ab3b5c0e7f470c2a4a31f60fcd78f83f89c5102 (diff)
downloadFreeBSD-src-e474e1f04df3d56ee4471959471e7f9ae34e7cb8.zip
FreeBSD-src-e474e1f04df3d56ee4471959471e7f9ae34e7cb8.tar.gz
Teach ncal(1) about month names specified on the command line.
Reviewed by: -audit Approved by: silence on -audit MFC after: 3 weeks
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ncal/ncal.13
-rw-r--r--usr.bin/ncal/ncal.c24
2 files changed, 24 insertions, 3 deletions
diff --git a/usr.bin/ncal/ncal.1 b/usr.bin/ncal/ncal.1
index 598dbe4..925c2b8 100644
--- a/usr.bin/ncal/ncal.1
+++ b/usr.bin/ncal/ncal.1
@@ -99,7 +99,8 @@ note the year must be fully specified:
will
.Em not
display a calendar for 1989.
-Two parameters denote the month (1 - 12) and year.
+Two parameters denote the month and year; the month is either a number between
+1 and 12, or a full or abbreviated name as specified by the current locale.
.Pp
A year starts on Jan 1.
.Sh SEE ALSO
diff --git a/usr.bin/ncal/ncal.c b/usr.bin/ncal/ncal.c
index e10f45a..4fa3fd4 100644
--- a/usr.bin/ncal/ncal.c
+++ b/usr.bin/ncal/ncal.c
@@ -162,6 +162,7 @@ char *center(char *s, char *t, int w);
void mkmonth(int year, int month, int jd_flag, struct monthlines * monthl);
void mkmonthb(int year, int month, int jd_flag, struct monthlines * monthl);
void mkweekdays(struct weekdays * wds);
+int parsemonth(const char *s);
void printcc(void);
void printeaster(int year, int julian, int orthodox);
void printmonth(int year, int month, int jd_flag);
@@ -306,9 +307,11 @@ main(int argc, char *argv[])
case 2:
if (flag_easter)
usage();
- m = atoi(*argv++);
+ m = parsemonth(*argv++);
if (m < 1 || m > 12)
- errx(EX_USAGE, "month %d not in range 1..12", m);
+ errx(EX_USAGE,
+ "%s is neither a month number (1..12) nor a name",
+ argv[-1]);
/* FALLTHROUGH */
case 1:
y = atoi(*argv++);
@@ -848,3 +851,20 @@ center(char *s, char *t, int w)
sprintf(s, "%.*s%s", (int)(w - strlen(t)) / 2, blanks, t);
return (s);
}
+
+int
+parsemonth(const char *s)
+{
+ int v;
+ char *cp;
+ struct tm tm;
+
+ v = (int)strtol(s, &cp, 10);
+ if (cp != s)
+ return (v);
+ if (strptime(s, "%B", &tm) != NULL)
+ return (tm.tm_mon + 1);
+ if (strptime(s, "%b", &tm) != NULL)
+ return (tm.tm_mon + 1);
+ return (0);
+}
OpenPOWER on IntegriCloud