diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2013-06-16 15:09:04 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2013-06-16 15:09:04 +0000 |
commit | cac793a33f4280e29571adc5dd71fcb33dc985e5 (patch) | |
tree | 05d4c753ffcfd5b3aa31c374d5f17d5b24b1fdbd /usr.bin/locale | |
parent | 79112e2f4a9f44cc9fb327c2811a13056c2ba81d (diff) |
Improve locale(1) output formatting.
Quote LC_* variables "that are not set in the environment or are
overridden by LC_ALL" when printing them, and just print an empty string
for LC_ALL if it is unset.
With input and ok from guenther@ stsp@
Diffstat (limited to 'usr.bin/locale')
-rw-r--r-- | usr.bin/locale/locale.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/usr.bin/locale/locale.c b/usr.bin/locale/locale.c index 5671c2f774e..381ce2230b9 100644 --- a/usr.bin/locale/locale.c +++ b/usr.bin/locale/locale.c @@ -1,4 +1,4 @@ -/* $OpenBSD: locale.c,v 1.2 2013/06/05 14:56:45 stsp Exp $ */ +/* $OpenBSD: locale.c,v 1.3 2013/06/16 15:09:03 jca Exp $ */ /* * Copyright (c) 2013 Stefan Sperling <stsp@openbsd.org> * @@ -32,20 +32,28 @@ struct category_name { { LC_NUMERIC, "LC_NUMERIC" }, { LC_TIME, "LC_TIME" }, { LC_MESSAGES, "LC_MESSAGES" }, - { LC_ALL, "LC_ALL" }, { 0, NULL}, }; void show_current_locale() { - char *lang = getenv("LANG"); + char *lang, *lc_all; int i; + lang = getenv("LANG"); + lc_all = getenv("LC_ALL"); + printf("LANG=%s\n", lang ? lang : ""); - for (i = 0; categories[i].name != NULL; i++) - printf("%s=%s\n", categories[i].name, - setlocale(categories[i].category, NULL)); + for (i = 0; categories[i].name != NULL; i++) { + if (lc_all == NULL && getenv(categories[i].name)) + printf("%s=%s\n", categories[i].name, + getenv(categories[i].name)); + else + printf("%s=\"%s\"\n", categories[i].name, + setlocale(categories[i].category, NULL)); + } + printf("LC_ALL=%s\n", lc_all ? lc_all : ""); } const char * const some_locales[] = { @@ -53,8 +61,7 @@ const char * const some_locales[] = { "C.UTF-8", "POSIX", "POSIX.UTF-8", - "Pig.ISO8859-1", - "Pig.UTF-8", + "Pig", "ar_SD.UTF-8", "ar_SY.UTF-8", "bg_BG.CP1251", |