svn commit: r250905 - stable/9/usr.bin/locale

Greg Lehey grog at FreeBSD.org
Wed May 22 07:52:42 UTC 2013


Author: grog
Date: Wed May 22 07:52:41 2013
New Revision: 250905
URL: http://svnweb.freebsd.org/changeset/base/250905

Log:
  MFH revisions 242743 to 243202:
  
  Make parameters to -c and -k options optional.  If no parameters are
  supplied, print information for all keywords.
  
  Improve output of -c option, in particular in conjunction with -k
  option.
  
  Complete man page.
  
  Add comment on standards conformity.

Modified:
  stable/9/usr.bin/locale/locale.1
  stable/9/usr.bin/locale/locale.c
Directory Properties:
  stable/9/usr.bin/locale/   (props changed)

Modified: stable/9/usr.bin/locale/locale.1
==============================================================================
--- stable/9/usr.bin/locale/locale.1	Wed May 22 05:43:14 2013	(r250904)
+++ stable/9/usr.bin/locale/locale.1	Wed May 22 07:52:41 2013	(r250905)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.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 @@ will respect the
 .Ev PATH_LOCALE
 environment variable, and use it instead of the system's default locale
 directory.
-.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.
+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.
 .El
 .Sh IMPLEMENTATION NOTES
 The special
@@ -89,6 +93,17 @@ a prefix string can be defined to limit 
 .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: stable/9/usr.bin/locale/locale.c
==============================================================================
--- stable/9/usr.bin/locale/locale.c	Wed May 22 05:43:14 2013	(r250904)
+++ stable/9/usr.bin/locale/locale.c	Wed May 22 07:52:41 2013	(r250905)
@@ -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 @@ struct _lcinfo {
 	{ "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 @@ struct _kwinfo {
 	  "(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 @@ main(int argc, char *argv[])
 	/* 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 @@ main(int argc, char *argv[])
 				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 @@ void
 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 @@ init_locales_list(void)
 	}
 	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 @@ showdetails(char *kw)
 	}
 
 	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 @@ showkeywordslist(char *substring)
 {
 	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 svn-src-stable-9 mailing list