From f27de7742d850e359febdaad2ecdb26c00afa477 Mon Sep 17 00:00:00 2001 From: Greg Lehey Date: Thu, 8 Nov 2012 02:55:30 +0000 Subject: [PATCH] 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 --- usr.bin/locale/locale.1 | 6 +++++- usr.bin/locale/locale.c | 31 +++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/usr.bin/locale/locale.1 b/usr.bin/locale/locale.1 index 144f2802e0f..6e6bf291768 100644 --- a/usr.bin/locale/locale.1 +++ b/usr.bin/locale/locale.1 @@ -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 diff --git a/usr.bin/locale/locale.c b/usr.bin/locale/locale.c index cad3afe71bd..df45f7f23ec 100644 --- a/usr.bin/locale/locale.c +++ b/usr.bin/locale/locale.c @@ -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) {