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.

MFC after:	14 days
This commit is contained in:
Greg Lehey 2012-11-08 02:55:30 +00:00
parent a012e04865
commit f27de7742d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=242743
2 changed files with 24 additions and 13 deletions

View File

@ -40,7 +40,7 @@
.Op Ar prefix
.Nm
.Op Fl ck
.Ar keyword ...
.Op Ar keyword ...
.Sh DESCRIPTION
The
.Nm
@ -74,8 +74,12 @@ directory.
Print names of all available charmaps.
.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 c
Print the category name for all selected keywords.
If no keywords are selected, print the category name for all defined
keywords.
.El
.Sh IMPLEMENTATION NOTES
The special

View File

@ -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) {
@ -282,13 +280,19 @@ main(int argc, char *argv[])
}
/* process '-c' and/or '-k' */
if (prt_categories || prt_keywords || argc > 0) {
setlocale(LC_ALL, "");
while (argc > 0) {
showdetails(*argv);
argv++;
argc--;
}
if (prt_categories || prt_keywords) {
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);
}
@ -303,7 +307,7 @@ usage(void)
{
printf("Usage: locale [ -a | -m ]\n"
" locale -k list [prefix]\n"
" locale [ -ck ] keyword ...\n");
" locale [ -ck ] [keyword ...]\n");
exit(1);
}
@ -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) {