[Midnightbsd-cvs] src [9412] trunk/usr.bin/locale: Make parameters to -c and -k options optional.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Mar 4 16:45:58 EST 2017
Revision: 9412
http://svnweb.midnightbsd.org/src/?rev=9412
Author: laffer1
Date: 2017-03-04 16:45:58 -0500 (Sat, 04 Mar 2017)
Log Message:
-----------
Make parameters to -c and -k options optional.
Modified Paths:
--------------
trunk/usr.bin/locale/locale.1
trunk/usr.bin/locale/locale.c
Modified: trunk/usr.bin/locale/locale.1
===================================================================
--- trunk/usr.bin/locale/locale.1 2017-03-04 21:44:58 UTC (rev 9411)
+++ trunk/usr.bin/locale/locale.1 2017-03-04 21:45:58 UTC (rev 9412)
@@ -25,7 +25,7 @@
.\"
.\" $MidnightBSD$
.\"
-.Dd November 1, 2005
+.Dd November 18, 2012
.Dt LOCALE 1
.Os
.Sh NAME
@@ -40,7 +40,7 @@
.Op Ar prefix
.Nm
.Op Fl ck
-.Ar keyword ...
+.Op Ar keyword ...
.Sh DESCRIPTION
The
.Nm
@@ -70,12 +70,16 @@
.Ev PATH_LOCALE
environment variable, and use it instead of the system's default locale
directory.
+.It Fl c
+Print the category name for all selected keywords.
+If no keywords are selected, print the category name for all defined
+keywords.
+.It Fl k
+Print the names and values of all selected keywords.
+If no keywords are selected, print the names and values of all defined
+keywords.
.It Fl m
Print names of all available charmaps.
-.It Fl k
-Print the names and values of all selected keywords.
-.It Fl c
-Print the category name for all selected keywords.
.El
.Sh IMPLEMENTATION NOTES
The special
@@ -89,6 +93,17 @@
.Ex -std
.Sh SEE ALSO
.Xr setlocale 3
+.Sh STANDARDS
+The
+.Nm
+utility conforms to
+.St -p1003.1-2004 .
+The
+.Ev LC_CTYPE ,
+.Ev LC_MESSAGES
+and
+.Ev NLSPATH
+environment variables are not interpreted.
.Sh BUGS
Since
.Fx
Modified: trunk/usr.bin/locale/locale.c
===================================================================
--- trunk/usr.bin/locale/locale.c 2017-03-04 21:44:58 UTC (rev 9411)
+++ trunk/usr.bin/locale/locale.c 2017-03-04 21:45:58 UTC (rev 9412)
@@ -31,7 +31,7 @@
* nl_langinfo(3) extensions)
*
* XXX: correctly handle reserved 'charmap' keyword and '-m' option (require
- * localedef(1) implementation). Currently it's handled via
+ * localedef(1) implementation). Currently it's handled via
* nl_langinfo(CODESET).
*/
@@ -79,32 +79,32 @@
{ "LC_MONETARY", LC_MONETARY },
{ "LC_MESSAGES", LC_MESSAGES }
};
-#define NLCINFO (sizeof(lcinfo)/sizeof(lcinfo[0]))
+#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)
+#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;
@@ -218,7 +218,7 @@
"(POSIX legacy)" } /* compat */
};
-#define NKWINFO (sizeof(kwinfo)/sizeof(kwinfo[0]))
+#define NKWINFO (sizeof(kwinfo)/sizeof(kwinfo[0]))
const char *boguslocales[] = { "UTF-8" };
#define NBOGUS (sizeof(boguslocales)/sizeof(boguslocales[0]))
@@ -253,12 +253,10 @@
/* validate arguments */
if (all_locales && all_charmaps)
usage();
- if ((all_locales || all_charmaps) && argc > 0)
+ if ((all_locales || all_charmaps) && argc > 0)
usage();
if ((all_locales || all_charmaps) && (prt_categories || prt_keywords))
usage();
- if ((prt_categories || prt_keywords) && argc <= 0)
- usage();
/* process '-a' */
if (all_locales) {
@@ -281,13 +279,19 @@
exit(0);
}
- /* process '-c' and/or '-k' */
+ /* process '-c', '-k', or command line arguments. */
if (prt_categories || prt_keywords || argc > 0) {
- setlocale(LC_ALL, "");
- while (argc > 0) {
- showdetails(*argv);
- argv++;
- argc--;
+ if (argc > 0) {
+ setlocale(LC_ALL, "");
+ while (argc > 0) {
+ showdetails(*argv);
+ argv++;
+ argc--;
+ }
+ } else {
+ uint i;
+ for (i = 0; i < sizeof (kwinfo) / sizeof (struct _kwinfo); i++)
+ showdetails ((char *)kwinfo [i].name);
}
exit(0);
}
@@ -302,8 +306,8 @@
usage(void)
{
printf("Usage: locale [ -a | -m ]\n"
- " locale -k list [prefix]\n"
- " locale [ -ck ] keyword ...\n");
+ " locale -k list [prefix]\n"
+ " locale [ -ck ] [keyword ...]\n");
exit(1);
}
@@ -423,10 +427,10 @@
}
closedir(dirp);
- /* make sure that 'POSIX' and 'C' locales are present in the list.
+ /* make sure that 'POSIX' and 'C' locales are present in the list.
* POSIX 1003.1-2001 requires presence of 'POSIX' name only here, but
- * we also list 'C' for constistency
- */
+ * we also list 'C' for constistency
+ */
if (sl_find(locales, "POSIX") == NULL)
sl_add(locales, "POSIX");
@@ -612,7 +616,10 @@
}
if (prt_categories) {
- printf("%s\n", lookup_localecat(cat));
+ if (prt_keywords)
+ printf("%-20s ", lookup_localecat(cat));
+ else
+ printf("%-20s\t%s\n", kw, lookup_localecat(cat));
}
if (prt_keywords) {
@@ -657,7 +664,7 @@
{
size_t i;
-#define FMT "%-20s %-12s %-7s %-20s\n"
+#define FMT "%-20s %-12s %-7s %-20s\n"
if (substring == NULL)
printf("List of available keywords\n\n");
More information about the Midnightbsd-cvs
mailing list