Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src add locale(1) utility.



details:   https://anonhg.NetBSD.org/src/rev/568003fca683
branches:  trunk
changeset: 549054:568003fca683
user:      tshiozak <tshiozak%NetBSD.org@localhost>
date:      Fri Jul 04 05:41:49 2003 +0000

description:
add locale(1) utility.
Originally written by Alexey Zelkin <phantom%FreeBSD.org@localhost>.
So, obtained from FreeBSD with gratitude.  (suggested by wiz.)

diffstat:

 distrib/sets/lists/base/mi |    3 +-
 usr.bin/Makefile           |    4 +-
 usr.bin/locale/Makefile    |    7 +
 usr.bin/locale/locale.1    |  108 +++++++
 usr.bin/locale/locale.c    |  655 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 774 insertions(+), 3 deletions(-)

diffs (truncated from 817 to 300 lines):

diff -r 37a85822f3fc -r 568003fca683 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Fri Jul 04 05:21:26 2003 +0000
+++ b/distrib/sets/lists/base/mi        Fri Jul 04 05:41:49 2003 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.417 2003/07/03 15:18:54 wiz Exp $
+# $NetBSD: mi,v 1.418 2003/07/04 05:41:50 tshiozak Exp $
 .                      base-sys-root
 ./altroot              base-sys-root
 ./bin                  base-sys-root
@@ -282,6 +282,7 @@
 ./usr/bin/lessecho     base-util-bin
 ./usr/bin/lesskey      base-util-bin
 ./usr/bin/locate       base-util-bin
+./usr/bin/locale       base-locale-bin
 ./usr/bin/lock         base-util-bin
 ./usr/bin/logger       base-util-bin
 ./usr/bin/login                base-util-bin
diff -r 37a85822f3fc -r 568003fca683 usr.bin/Makefile
--- a/usr.bin/Makefile  Fri Jul 04 05:21:26 2003 +0000
+++ b/usr.bin/Makefile  Fri Jul 04 05:41:49 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.135 2003/06/27 05:21:54 tshiozak Exp $
+#      $NetBSD: Makefile,v 1.136 2003/07/04 05:41:49 tshiozak Exp $
 #      from: @(#)Makefile      8.3 (Berkeley) 1/7/94
 
 .include <bsd.own.mk>
@@ -12,7 +12,7 @@
        from fsplit fstat ftp gcore gencat getconf getopt gprof \
        head hexdump iconv id indent innetgr ipcrm ipcs join jot \
        kdump ktrace ktruss lam last lastcomm ldd leave less \
-       lex locate lock logger login logname look lorder m4 \
+       lex locale locate lock logger login logname look lorder m4 \
        machine mail make man menuc mesg midiplay mixerctl mkcsmapper \
        mkdep mkesdb mkfifo mklocale mkstr mktemp modstat msgc msgs \
        netgroup netstat newsyslog nfsstat nice nl nohup \
diff -r 37a85822f3fc -r 568003fca683 usr.bin/locale/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/locale/Makefile   Fri Jul 04 05:41:49 2003 +0000
@@ -0,0 +1,7 @@
+# $NetBSD: Makefile,v 1.1 2003/07/04 05:41:50 tshiozak Exp $
+# FreeBSD: src/usr.bin/locale/Makefile,v 1.4 2003/06/25 23:05:11 phantom Exp
+
+PROG = locale
+WARNS ?= 1
+
+.include <bsd.prog.mk>
diff -r 37a85822f3fc -r 568003fca683 usr.bin/locale/locale.1
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/locale/locale.1   Fri Jul 04 05:41:49 2003 +0000
@@ -0,0 +1,108 @@
+.\" $NetBSD: locale.1,v 1.1 2003/07/04 05:41:50 tshiozak Exp $
+.\"
+.\" Copyright (c) 2003 Alexey Zelkin <phantom%FreeBSD.org@localhost>
+.\" All rights reserved.
+.\" 
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\" 
+.\" FreeBSD: src/usr.bin/locale/locale.1,v 1.3 2003/06/26 11:01:03 phantom Exp
+.\"
+.Dd July 4, 2003
+.Dt LOCALE 1
+.Os
+.Sh NAME
+.Nm locale
+.Nd get locale-specific information
+.Sh SYNOPSIS
+.Nm
+.Op Fl a | Fl m
+.Nm
+.Op Fl ck
+.Op Ar keyword ...
+.Sh DESCRIPTION
+The
+.Nm
+utility is supposed to provide most locale specific information to
+the standard output.
+.Pp
+When
+.Nm
+is invoked without arguments it will print out summary of current
+locale environment depending on environment variable settings and
+internal status. 
+.Pp
+When
+.Nm
+is invoked with arguments and no options specified it will print out
+.Em keyword Ns No 's
+value determined using current locale settings.
+.Pp
+The following options are available:
+.Bl -tag -width indent 
+.It Fl a
+Write names of all available locales.
+While looking for locales
+.Nm
+will respect
+.Ev PATH_LOCALE
+environment variable, and use it instead of system default locale
+directory.
+.It Fl m
+Write names of all available charmaps.
+.It Fl k
+Write the name and value of the selected keywords.
+.It Fl c
+Write the category name for the selected keywords.
+.El
+.Sh IMPLEMENTATION DETAILS
+Special (FreeBSD / NetBSD specific) keyword
+.Ar list
+can be used to retrieve human readable list of available keywrods.
+.Sh DIAGNOSTICS
+The
+.Nm
+utility exits 0 on success, and >0 if an error occurs.
+.Sh BUGS
+Since
+.Nx
+does not support
+.Em charmap Ns No s
+in their
+.Em POSIX
+meaning
+.Nm
+emulates
+.Ar m
+option via CODESETs listing of all available locales.
+.Sh HISTORY
+.Nm
+first appeared in
+.Nx 2.0 .
+.Sh AUTHORS
+This implementation of
+.Nm
+was originally written by Alexey Zelkin <phantom%FreeBSD.org@localhost> for
+.Fx .
+.Sh STANDARDS
+.Nm
+conforms to 
+.St -p1003.1-2001 .
diff -r 37a85822f3fc -r 568003fca683 usr.bin/locale/locale.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/locale/locale.c   Fri Jul 04 05:41:49 2003 +0000
@@ -0,0 +1,655 @@
+/*     $NetBSD: locale.c,v 1.1 2003/07/04 05:41:50 tshiozak Exp $      */
+
+/*-
+ * Copyright (c) 2002, 2003 Alexey Zelkin <phantom%FreeBSD.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * FreeBSD: src/usr.bin/locale/locale.c,v 1.10 2003/06/26 11:05:56 phantom Exp
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: locale.c,v 1.1 2003/07/04 05:41:50 tshiozak Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * XXX: implement missing era_* (LC_TIME) keywords (require libc &
+ *     nl_langinfo(3) extensions)
+ *
+ * XXX: correctly handle reserved 'charmap' keyword and '-m' option (require
+ *      localedef(1) implementation).  Currently it's handled via
+ *     nl_langinfo(CODESET).
+ */
+
+#include <sys/types.h>
+#include <dirent.h>
+#include <err.h>
+#include <locale.h>
+#include <langinfo.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+#include <unistd.h>
+
+/* Local prototypes */
+void   init_locales_list(void);
+void   list_charmaps(void);
+void   list_locales(void);
+const char *lookup_localecat(int);
+char   *kwval_lconv(int);
+int    kwval_lookup(char *, char **, int *, int *);
+void   showdetails(char *);
+void   showkeywordslist(void);
+void   showlocale(void);
+void   usage(void);
+
+/* Global variables */
+static StringList *locales = NULL;
+extern char *_PathLocale;
+
+int    all_locales = 0;
+int    all_charmaps = 0;
+int    prt_categories = 0;
+int    prt_keywords = 0;
+int    more_params = 0;
+
+struct _lcinfo {
+       const char      *name;
+       int             id;
+} lcinfo [] = {
+       { "LC_CTYPE",           LC_CTYPE },
+       { "LC_COLLATE",         LC_COLLATE },
+       { "LC_TIME",            LC_TIME },
+       { "LC_NUMERIC",         LC_NUMERIC },
+       { "LC_MONETARY",        LC_MONETARY },
+       { "LC_MESSAGES",        LC_MESSAGES }
+};
+#define NLCINFO (sizeof(lcinfo)/sizeof(lcinfo[0]))
+
+/* ids for values not referenced by nl_langinfo() */
+#define        KW_ZERO                 10000
+#define        KW_GROUPING             (KW_ZERO+1)
+#define KW_INT_CURR_SYMBOL     (KW_ZERO+2)
+#define KW_CURRENCY_SYMBOL     (KW_ZERO+3)
+#define KW_MON_DECIMAL_POINT   (KW_ZERO+4)
+#define KW_MON_THOUSANDS_SEP   (KW_ZERO+5)
+#define KW_MON_GROUPING        (KW_ZERO+6)
+#define KW_POSITIVE_SIGN       (KW_ZERO+7)
+#define KW_NEGATIVE_SIGN       (KW_ZERO+8)
+#define KW_INT_FRAC_DIGITS     (KW_ZERO+9)
+#define KW_FRAC_DIGITS                 (KW_ZERO+10)
+#define KW_P_CS_PRECEDES       (KW_ZERO+11)
+#define KW_P_SEP_BY_SPACE      (KW_ZERO+12)
+#define KW_N_CS_PRECEDES       (KW_ZERO+13)
+#define KW_N_SEP_BY_SPACE      (KW_ZERO+14)
+#define KW_P_SIGN_POSN                 (KW_ZERO+15)
+#define KW_N_SIGN_POSN                 (KW_ZERO+16)
+#define KW_INT_P_CS_PRECEDES   (KW_ZERO+17)
+#define KW_INT_P_SEP_BY_SPACE  (KW_ZERO+18)
+#define KW_INT_N_CS_PRECEDES   (KW_ZERO+19)
+#define KW_INT_N_SEP_BY_SPACE  (KW_ZERO+20)
+#define KW_INT_P_SIGN_POSN     (KW_ZERO+21)
+#define KW_INT_N_SIGN_POSN     (KW_ZERO+22)
+
+struct _kwinfo {
+       const char      *name;
+       int             isstr;          /* true - string, false - number */
+       int             catid;          /* LC_* */
+       int             value_ref;
+       const char      *comment;
+} kwinfo [] = {
+       { "charmap",            1, LC_CTYPE,    CODESET, "" },  /* hack */
+
+       { "decimal_point",      1, LC_NUMERIC,  RADIXCHAR, "" },
+       { "thousands_sep",      1, LC_NUMERIC,  THOUSEP, "" },
+       { "grouping",           1, LC_NUMERIC,  KW_GROUPING, "" },
+       { "radixchar",          1, LC_NUMERIC,  RADIXCHAR,
+         "Same as decimal_point (BSD only)" },                 /* compat */
+       { "thousep",            1, LC_NUMERIC,  THOUSEP,
+         "Same as thousands_sep (BSD only)" },                 /* compat */
+
+       { "int_curr_symbol",    1, LC_MONETARY, KW_INT_CURR_SYMBOL, "" },
+       { "currency_symbol",    1, LC_MONETARY, KW_CURRENCY_SYMBOL, "" },
+       { "mon_decimal_point",  1, LC_MONETARY, KW_MON_DECIMAL_POINT, "" },
+       { "mon_thousands_sep",  1, LC_MONETARY, KW_MON_THOUSANDS_SEP, "" },
+       { "mon_grouping",       1, LC_MONETARY, KW_MON_GROUPING, "" },



Home | Main Index | Thread Index | Old Index