Date: Sat, 14 Sep 2002 20:26:02 +0300 From: Peter Pentchev <roam@ringlet.net> To: freebsd-audit@FreeBSD.org Subject: [CFR] ncal(1): month names on the cmdline Message-ID: <20020914172602.GA1621@straylight.oblivion.bg>
next in thread | raw e-mail | index | archive | help
--TRYliJ5NKNqkz5bu Content-Type: multipart/mixed; boundary="+QahgC5+KEYLbs62" Content-Disposition: inline --+QahgC5+KEYLbs62 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, What do people think about the attached patch, which teaches ncal(1) (and cal(1)) to parse month names if invoked with both a month and year specification? It is not terribly necessary, but it just might turn out to be useful :) Examples: [roam@straylight:v2 ~]$ LANG=3DC ncal August 2002 August 2002 Mo 5 12 19 26 Tu 6 13 20 27 We 7 14 21 28 Th 1 8 15 22 29 Fr 2 9 16 23 30 Sa 3 10 17 24 31 Su 4 11 18 25 [roam@straylight:v2 ~]$ LANG=3DC cal sep 2001 September 2001 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 [roam@straylight:v2 ~]$ (warning: Windows-1251 character set in the following example) [roam@straylight:v2 ~]$ cal =D1=84=D0=B5=D0=B2 2000 =D0=A4=D0=B5=D0=B2=D1=80=D1=83=D0=B0=D1=80=D0=B8 2000 =D0=9D=D0=B4 =D0=9F=D0=BD =D0=92=D1=82 =D0=A1=D1=80 =D0=A7=D1=82 =D0=9F=D1= =82 =D0=A1=D0=B1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [roam@straylight:v2 ~]$ G'luck, Peter --=20 Peter Pentchev roam@ringlet.net roam@FreeBSD.org PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 because I didn't think of a good beginning of it. --+QahgC5+KEYLbs62 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="usr.bin-ncal.patch" Index: src/usr.bin/ncal/ncal.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/ncal/ncal.1,v retrieving revision 1.14 diff -u -r1.14 ncal.1 --- src/usr.bin/ncal/ncal.1 3 Jun 2002 15:02:02 -0000 1.14 +++ src/usr.bin/ncal/ncal.1 14 Sep 2002 10:52:43 -0000 @@ -99,7 +99,8 @@ 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 Index: src/usr.bin/ncal/ncal.c =================================================================== RCS file: /home/ncvs/src/usr.bin/ncal/ncal.c,v retrieving revision 1.17 diff -u -r1.17 ncal.c --- src/usr.bin/ncal/ncal.c 28 Apr 2002 12:25:03 -0000 1.17 +++ src/usr.bin/ncal/ncal.c 14 Sep 2002 10:57:40 -0000 @@ -162,6 +162,7 @@ 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 @@ 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) or a name", + argv[-1]); /* FALLTHROUGH */ case 1: y = atoi(*argv++); @@ -847,4 +850,21 @@ memset(blanks, ' ', sizeof(blanks)); 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); } --+QahgC5+KEYLbs62-- --TRYliJ5NKNqkz5bu Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (FreeBSD) iD8DBQE9g3Eq7Ri2jRYZRVMRAqh+AJ41AeZUEVdVkDqcqSWdz3briZEXyQCfeurU RHBbZER+gwmD5FLUi9Jn3xE= =2mZk -----END PGP SIGNATURE----- --TRYliJ5NKNqkz5bu-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020914172602.GA1621>