Teach ncal(1) about month names specified on the command line.
Reviewed by: -audit Approved by: silence on -audit MFC after: 3 weeks
This commit is contained in:
parent
e31d11c36a
commit
ac6d1c224f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=104369
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user