diff options
| author | Edwin Groothuis <edwin@FreeBSD.org> | 2009-10-31 06:35:40 +0000 |
|---|---|---|
| committer | Edwin Groothuis <edwin@FreeBSD.org> | 2009-10-31 06:35:40 +0000 |
| commit | 05edd60be4d7d6ca84139790e90a061945904cd3 (patch) | |
| tree | f95c83a65d0a6b89dda89b64c924856b92edaae8 | |
| parent | e22a16d5d30126cdefa97f958dc00766d602b5d8 (diff) | |
Notes
| -rw-r--r-- | include/langinfo.h | 14 | ||||
| -rw-r--r-- | lib/libc/locale/nl_langinfo.c | 6 | ||||
| -rw-r--r-- | lib/libc/stdtime/localtime.c | 11 | ||||
| -rw-r--r-- | usr.bin/locale/locale.1 | 10 | ||||
| -rw-r--r-- | usr.bin/locale/locale.c | 35 |
5 files changed, 66 insertions, 10 deletions
diff --git a/include/langinfo.h b/include/langinfo.h index 59b50f9ce34c..6d6b95f2cc4e 100644 --- a/include/langinfo.h +++ b/include/langinfo.h @@ -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 diff --git a/lib/libc/locale/nl_langinfo.c b/lib/libc/locale/nl_langinfo.c index 9bd508214e4b..26ca02544982 100644 --- a/lib/libc/locale/nl_langinfo.c +++ b/lib/libc/locale/nl_langinfo.c @@ -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 = ""; diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c index e0ed73f7d96f..9fc5f3ee99b7 100644 --- a/lib/libc/stdtime/localtime.c +++ b/lib/libc/stdtime/localtime.c @@ -21,6 +21,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include <sys/types.h> #include <sys/stat.h> +#include <errno.h> #include <fcntl.h> #include <pthread.h> #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); } } diff --git a/usr.bin/locale/locale.1 b/usr.bin/locale/locale.1 index e6b645180787..b2aba5defdbf 100644 --- a/usr.bin/locale/locale.1 +++ b/usr.bin/locale/locale.1 @@ -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 diff --git a/usr.bin/locale/locale.c b/usr.bin/locale/locale.c index a4b6b4001839..cad3afe71bdb 100644 --- a/usr.bin/locale/locale.c +++ b/usr.bin/locale/locale.c @@ -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), |
