aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/locale
diff options
context:
space:
mode:
authorEric van Gyzen <vangyzen@FreeBSD.org>2016-11-19 02:09:58 +0000
committerEric van Gyzen <vangyzen@FreeBSD.org>2016-11-19 02:09:58 +0000
commit54068d184c9450628989ec6ad20f6d5906778cb9 (patch)
tree20843b3acd3f87bfcc8ad149ebb934d1f79f38c9 /usr.bin/locale
parentfe75b45213a403dc13c2e8a3bef5c83fa3b8225c (diff)
downloadsrc-54068d184c9450628989ec6ad20f6d5906778cb9.tar.gz
src-54068d184c9450628989ec6ad20f6d5906778cb9.zip
locale: fix display of "grouping" and "mon_grouping" values
The "grouping" and "mon_grouping" values are arrays of one-byte integers, not arrays of ASCII characters. Display them in a format similar to GNU and MacOS. MFC after: 3 days Sponsored by: Dell EMC
Notes
Notes: svn path=/head/; revision=308824
Diffstat (limited to 'usr.bin/locale')
-rw-r--r--usr.bin/locale/locale.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/usr.bin/locale/locale.c b/usr.bin/locale/locale.c
index e4409dad4c3b..2c3e61eb529b 100644
--- a/usr.bin/locale/locale.c
+++ b/usr.bin/locale/locale.c
@@ -50,6 +50,7 @@
#include "setlocale.h"
/* Local prototypes */
+char *format_grouping(const char *);
void init_locales_list(void);
void list_charmaps(void);
void list_locales(void);
@@ -488,6 +489,34 @@ showlocale(void)
printf("LC_ALL=%s\n", vval);
}
+char *
+format_grouping(const char *binary)
+{
+ static char rval[64];
+ const char *cp;
+ size_t len;
+
+ rval[0] = '\0';
+ for (cp = binary; *cp != '\0'; ++cp) {
+ char group[sizeof("127;")];
+ snprintf(group, sizeof(group), "%hhd;", *cp);
+ len = strlcat(rval, group, sizeof(rval));
+ if (len >= sizeof(rval)) {
+ len = sizeof(rval) - 1;
+ break;
+ }
+ if (*cp == CHAR_MAX) {
+ break;
+ }
+ }
+
+ /* Remove the trailing ';'. */
+ rval[len - 1] = '\0';
+
+ return (rval);
+}
+
+
/*
* keyword value lookup helper (via localeconv())
*/
@@ -501,7 +530,7 @@ kwval_lconv(int id)
lc = localeconv();
switch (id) {
case KW_GROUPING:
- rval = lc->grouping;
+ rval = format_grouping(lc->grouping);
break;
case KW_INT_CURR_SYMBOL:
rval = lc->int_curr_symbol;
@@ -516,7 +545,7 @@ kwval_lconv(int id)
rval = lc->mon_thousands_sep;
break;
case KW_MON_GROUPING:
- rval = lc->mon_grouping;
+ rval = format_grouping(lc->mon_grouping);
break;
case KW_POSITIVE_SIGN:
rval = lc->positive_sign;