From owner-svn-src-stable@FreeBSD.ORG Sat Oct 31 06:35:40 2009 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F186B106566B; Sat, 31 Oct 2009 06:35:40 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DD65E8FC16; Sat, 31 Oct 2009 06:35:40 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n9V6Ze6g071323; Sat, 31 Oct 2009 06:35:40 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n9V6ZewN071320; Sat, 31 Oct 2009 06:35:40 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200910310635.n9V6ZewN071320@svn.freebsd.org> From: Edwin Groothuis Date: Sat, 31 Oct 2009 06:35:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r198704 - in stable/8: include lib/libc lib/libc/gen lib/libc/locale lib/libc/stdio lib/libc/stdtime lib/libc/string usr.bin/locale X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2009 06:35:41 -0000 Author: edwin Date: Sat Oct 31 06:35:40 2009 New Revision: 198704 URL: http://svn.freebsd.org/changeset/base/198704 Log: MFCs of r197764, r197765, r197766, r197847: Modified locale(1) to be able to show the altmon_X fields and the [cxX]_fmt's. Also modify the "-k list" option to display only fields with a certain prefix. Add the comment "(FreeBSD only)" to the altmonth_x keywords Modified: stable/8/include/ (props changed) stable/8/include/langinfo.h stable/8/lib/libc/ (props changed) stable/8/lib/libc/gen/ (props changed) stable/8/lib/libc/locale/nl_langinfo.c stable/8/lib/libc/stdio/asprintf.c (props changed) stable/8/lib/libc/stdtime/ (props changed) stable/8/lib/libc/stdtime/localtime.c stable/8/lib/libc/string/ffsll.c (props changed) stable/8/lib/libc/string/flsll.c (props changed) stable/8/lib/libc/string/wcpcpy.c (props changed) stable/8/lib/libc/string/wcpncpy.c (props changed) stable/8/usr.bin/locale/ (props changed) stable/8/usr.bin/locale/locale.1 stable/8/usr.bin/locale/locale.c Modified: stable/8/include/langinfo.h ============================================================================== --- stable/8/include/langinfo.h Fri Oct 30 23:33:06 2009 (r198703) +++ stable/8/include/langinfo.h Sat Oct 31 06:35:40 2009 (r198704) @@ -114,6 +114,20 @@ typedef __nl_item nl_item; #define D_MD_ORDER 57 /* month/day order (local extension) */ #endif +/* standalone months forms for %OB */ +#define ALTMON_1 58 +#define ALTMON_2 59 +#define ALTMON_3 60 +#define ALTMON_4 61 +#define ALTMON_5 62 +#define ALTMON_6 63 +#define ALTMON_7 64 +#define ALTMON_8 65 +#define ALTMON_9 66 +#define ALTMON_10 67 +#define ALTMON_11 68 +#define ALTMON_12 69 + __BEGIN_DECLS char *nl_langinfo(nl_item); __END_DECLS Modified: stable/8/lib/libc/locale/nl_langinfo.c ============================================================================== --- stable/8/lib/libc/locale/nl_langinfo.c Fri Oct 30 23:33:06 2009 (r198703) +++ stable/8/lib/libc/locale/nl_langinfo.c Sat Oct 31 06:35:40 2009 (r198704) @@ -93,6 +93,12 @@ nl_langinfo(nl_item item) case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12: ret = (char*) __get_current_time_locale()->mon[_REL(ABMON_1)]; break; + case ALTMON_1: case ALTMON_2: case ALTMON_3: case ALTMON_4: + case ALTMON_5: case ALTMON_6: case ALTMON_7: case ALTMON_8: + case ALTMON_9: case ALTMON_10: case ALTMON_11: case ALTMON_12: + ret = (char*) + __get_current_time_locale()->alt_month[_REL(ALTMON_1)]; + break; case ERA: /* XXX: need to be implemented */ ret = ""; Modified: stable/8/lib/libc/stdtime/localtime.c ============================================================================== --- stable/8/lib/libc/stdtime/localtime.c Fri Oct 30 23:33:06 2009 (r198703) +++ stable/8/lib/libc/stdtime/localtime.c Sat Oct 31 06:35:40 2009 (r198704) @@ -21,6 +21,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include #include +#include #include #include #include "private.h" @@ -1413,13 +1414,16 @@ const time_t * const timep; static pthread_mutex_t localtime_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_key_t localtime_key = -1; struct tm *p_tm; + int r; if (__isthreaded != 0) { if (localtime_key < 0) { _pthread_mutex_lock(&localtime_mutex); if (localtime_key < 0) { - if (_pthread_key_create(&localtime_key, free) < 0) { + if ((r = _pthread_key_create(&localtime_key, + free)) != 0) { _pthread_mutex_unlock(&localtime_mutex); + errno = r; return(NULL); } } @@ -1512,13 +1516,16 @@ const time_t * const timep; static pthread_mutex_t gmtime_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_key_t gmtime_key = -1; struct tm *p_tm; + int r; if (__isthreaded != 0) { if (gmtime_key < 0) { _pthread_mutex_lock(&gmtime_mutex); if (gmtime_key < 0) { - if (_pthread_key_create(&gmtime_key, free) < 0) { + if ((r = _pthread_key_create(&gmtime_key, + free)) != 0) { _pthread_mutex_unlock(&gmtime_mutex); + errno = r; return(NULL); } } Modified: stable/8/usr.bin/locale/locale.1 ============================================================================== --- stable/8/usr.bin/locale/locale.1 Fri Oct 30 23:33:06 2009 (r198703) +++ stable/8/usr.bin/locale/locale.1 Sat Oct 31 06:35:40 2009 (r198704) @@ -35,8 +35,12 @@ .Nm .Op Fl a | m .Nm -.Op Fl ck -.Op Ar keyword ... +.Fl k +.Ic list +.Op Ar prefix +.Nm +.Op Fl ck +.Ar keyword ... .Sh DESCRIPTION The .Nm @@ -79,6 +83,8 @@ The special specific) keyword .Cm list can be used to retrieve the human readable list of all available keywords. +If so, +a prefix string can be defined to limit the amount of keywords returned. .Sh EXIT STATUS .Ex -std .Sh SEE ALSO Modified: stable/8/usr.bin/locale/locale.c ============================================================================== --- stable/8/usr.bin/locale/locale.c Fri Oct 30 23:33:06 2009 (r198703) +++ stable/8/usr.bin/locale/locale.c Sat Oct 31 06:35:40 2009 (r198704) @@ -55,7 +55,7 @@ const char *lookup_localecat(int); char *kwval_lconv(int); int kwval_lookup(char *, char **, int *, int *); void showdetails(char *); -void showkeywordslist(void); +void showkeywordslist(char *substring); void showlocale(void); void usage(void); @@ -190,6 +190,18 @@ struct _kwinfo { { "abmon_10", 1, LC_TIME, ABMON_10, "" }, { "abmon_11", 1, LC_TIME, ABMON_11, "" }, { "abmon_12", 1, LC_TIME, ABMON_12, "" }, + { "altmon_1", 1, LC_TIME, ALTMON_1, "(FreeBSD only)" }, + { "altmon_2", 1, LC_TIME, ALTMON_2, "(FreeBSD only)" }, + { "altmon_3", 1, LC_TIME, ALTMON_3, "(FreeBSD only)" }, + { "altmon_4", 1, LC_TIME, ALTMON_4, "(FreeBSD only)" }, + { "altmon_5", 1, LC_TIME, ALTMON_5, "(FreeBSD only)" }, + { "altmon_6", 1, LC_TIME, ALTMON_6, "(FreeBSD only)" }, + { "altmon_7", 1, LC_TIME, ALTMON_7, "(FreeBSD only)" }, + { "altmon_8", 1, LC_TIME, ALTMON_8, "(FreeBSD only)" }, + { "altmon_9", 1, LC_TIME, ALTMON_9, "(FreeBSD only)" }, + { "altmon_10", 1, LC_TIME, ALTMON_10, "(FreeBSD only)" }, + { "altmon_11", 1, LC_TIME, ALTMON_11, "(FreeBSD only)" }, + { "altmon_12", 1, LC_TIME, ALTMON_12, "(FreeBSD only)" }, { "era", 1, LC_TIME, ERA, "(unavailable)" }, { "era_d_fmt", 1, LC_TIME, ERA_D_FMT, "(unavailable)" }, { "era_d_t_fmt", 1, LC_TIME, ERA_D_T_FMT, "(unavailable)" }, @@ -217,7 +229,7 @@ main(int argc, char *argv[]) int ch; int tmp; - while ((ch = getopt(argc, argv, "ackm")) != -1) { + while ((ch = getopt(argc, argv, "ackms:")) != -1) { switch (ch) { case 'a': all_locales = 1; @@ -265,7 +277,7 @@ main(int argc, char *argv[]) if (prt_keywords && argc > 0) while (tmp < argc) if (strcasecmp(argv[tmp++], "list") == 0) { - showkeywordslist(); + showkeywordslist(argv[tmp]); exit(0); } @@ -290,7 +302,8 @@ void usage(void) { printf("Usage: locale [ -a | -m ]\n" - " locale [ -ck ] name ...\n"); + " locale -k list [prefix]\n" + " locale [ -ck ] keyword ...\n"); exit(1); } @@ -594,6 +607,7 @@ showdetails(char *kw) * invalid keyword specified. * XXX: any actions? */ + fprintf(stderr, "Unknown keyword: `%s'\n", kw); return; } @@ -639,16 +653,25 @@ lookup_localecat(int cat) * Show list of keywords */ void -showkeywordslist(void) +showkeywordslist(char *substring) { size_t i; #define FMT "%-20s %-12s %-7s %-20s\n" - printf("List of available keywords\n\n"); + if (substring == NULL) + printf("List of available keywords\n\n"); + else + printf("List of available keywords starting with '%s'\n\n", + substring); printf(FMT, "Keyword", "Category", "Type", "Comment"); printf("-------------------- ------------ ------- --------------------\n"); for (i = 0; i < NKWINFO; i++) { + if (substring != NULL) { + if (strncmp(kwinfo[i].name, substring, + strlen(substring)) != 0) + continue; + } printf(FMT, kwinfo[i].name, lookup_localecat(kwinfo[i].catid),