From owner-svn-src-stable@freebsd.org Wed Nov 30 18:11:36 2016 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E0629C5DA3E; Wed, 30 Nov 2016 18:11:36 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9475D190B; Wed, 30 Nov 2016 18:11:36 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAUIBZs2065019; Wed, 30 Nov 2016 18:11:35 GMT (envelope-from vangyzen@FreeBSD.org) Received: (from vangyzen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAUIBZ88065018; Wed, 30 Nov 2016 18:11:35 GMT (envelope-from vangyzen@FreeBSD.org) Message-Id: <201611301811.uAUIBZ88065018@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vangyzen set sender to vangyzen@FreeBSD.org using -f From: Eric van Gyzen Date: Wed, 30 Nov 2016 18:11:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r309329 - stable/10/usr.bin/locale X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Nov 2016 18:11:37 -0000 Author: vangyzen Date: Wed Nov 30 18:11:35 2016 New Revision: 309329 URL: https://svnweb.freebsd.org/changeset/base/309329 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/10/usr.bin/locale/locale.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/locale/locale.c ============================================================================== --- stable/10/usr.bin/locale/locale.c Wed Nov 30 14:18:52 2016 (r309328) +++ stable/10/usr.bin/locale/locale.c Wed Nov 30 18:11:35 2016 (r309329) @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,7 @@ #include "setlocale.h" /* Local prototypes */ +char *format_grouping(const char *); void init_locales_list(void); void list_charmaps(void); void list_locales(void); @@ -486,6 +488,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()) */ @@ -499,7 +529,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; @@ -514,7 +544,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;