Date: Wed, 30 Nov 2016 18:26:22 +0000 (UTC) From: Eric van Gyzen <vangyzen@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r309330 - stable/11/usr.bin/locale Message-ID: <201611301826.uAUIQMTh071606@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: vangyzen Date: Wed Nov 30 18:26:22 2016 New Revision: 309330 URL: https://svnweb.freebsd.org/changeset/base/309330 Log: MFC r308824 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. Sponsored by: Dell EMC Modified: stable/11/usr.bin/locale/locale.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/locale/locale.c ============================================================================== --- stable/11/usr.bin/locale/locale.c Wed Nov 30 18:11:35 2016 (r309329) +++ stable/11/usr.bin/locale/locale.c Wed Nov 30 18:26:22 2016 (r309330) @@ -40,6 +40,7 @@ #include <dirent.h> #include <err.h> +#include <limits.h> #include <locale.h> #include <langinfo.h> #include <stdio.h> @@ -50,6 +51,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 +490,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 +531,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 +546,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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201611301826.uAUIQMTh071606>