[Midnightbsd-cvs] src [11506] trunk/usr.bin/locale/locale.c: sync locale with freebsd.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jul 7 13:45:25 EDT 2018
Revision: 11506
http://svnweb.midnightbsd.org/src/?rev=11506
Author: laffer1
Date: 2018-07-07 13:45:24 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
sync locale with freebsd.
Modified Paths:
--------------
trunk/usr.bin/locale/Makefile
trunk/usr.bin/locale/locale.1
trunk/usr.bin/locale/locale.c
Property Changed:
----------------
trunk/usr.bin/locale/locale.1
Modified: trunk/usr.bin/locale/Makefile
===================================================================
--- trunk/usr.bin/locale/Makefile 2018-07-07 17:44:49 UTC (rev 11505)
+++ trunk/usr.bin/locale/Makefile 2018-07-07 17:45:24 UTC (rev 11506)
@@ -1,7 +1,7 @@
# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/locale/Makefile 310041 2016-12-13 23:10:35Z vangyzen $
PROG= locale
-WARNS?= 3
CFLAGS+= -I${.CURDIR}/../../lib/libc/locale
.include <bsd.prog.mk>
Modified: trunk/usr.bin/locale/locale.1
===================================================================
--- trunk/usr.bin/locale/locale.1 2018-07-07 17:44:49 UTC (rev 11505)
+++ trunk/usr.bin/locale/locale.1 2018-07-07 17:45:24 UTC (rev 11506)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\"
.\" Copyright (c) 2003 Alexey Zelkin <phantom at FreeBSD.org>
.\" All rights reserved.
@@ -23,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/locale/locale.1 243202 2012-11-17 23:52:38Z grog $
.\"
.Dd November 18, 2012
.Dt LOCALE 1
Property changes on: trunk/usr.bin/locale/locale.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/locale/locale.c
===================================================================
--- trunk/usr.bin/locale/locale.c 2018-07-07 17:44:49 UTC (rev 11505)
+++ trunk/usr.bin/locale/locale.c 2018-07-07 17:45:24 UTC (rev 11506)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002, 2003 Alexey Zelkin <phantom at FreeBSD.org>
* All rights reserved.
@@ -23,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/locale/locale.c 310041 2016-12-13 23:10:35Z vangyzen $
*/
/*
@@ -38,6 +39,7 @@
#include <sys/types.h>
#include <dirent.h>
#include <err.h>
+#include <limits.h>
#include <locale.h>
#include <langinfo.h>
#include <stdio.h>
@@ -48,13 +50,14 @@
#include "setlocale.h"
/* Local prototypes */
+char *format_grouping(const char *);
void init_locales_list(void);
void list_charmaps(void);
void list_locales(void);
const char *lookup_localecat(int);
char *kwval_lconv(int);
-int kwval_lookup(char *, char **, int *, int *);
-void showdetails(char *);
+int kwval_lookup(const char *, char **, int *, int *);
+void showdetails(const char *);
void showkeywordslist(char *substring);
void showlocale(void);
void usage(void);
@@ -62,13 +65,12 @@
/* Global variables */
static StringList *locales = NULL;
-int all_locales = 0;
-int all_charmaps = 0;
-int prt_categories = 0;
-int prt_keywords = 0;
-int more_params = 0;
+static int all_locales = 0;
+static int all_charmaps = 0;
+static int prt_categories = 0;
+static int prt_keywords = 0;
-struct _lcinfo {
+static const struct _lcinfo {
const char *name;
int id;
} lcinfo [] = {
@@ -106,7 +108,7 @@
#define KW_INT_P_SIGN_POSN (KW_ZERO+21)
#define KW_INT_N_SIGN_POSN (KW_ZERO+22)
-struct _kwinfo {
+static const struct _kwinfo {
const char *name;
int isstr; /* true - string, false - number */
int catid; /* LC_* */
@@ -220,7 +222,7 @@
};
#define NKWINFO (sizeof(kwinfo)/sizeof(kwinfo[0]))
-const char *boguslocales[] = { "UTF-8" };
+static const char *boguslocales[] = { "UTF-8" };
#define NBOGUS (sizeof(boguslocales)/sizeof(boguslocales[0]))
int
@@ -281,8 +283,9 @@
/* process '-c', '-k', or command line arguments. */
if (prt_categories || prt_keywords || argc > 0) {
+ if (prt_keywords || argc > 0)
+ setlocale(LC_ALL, "");
if (argc > 0) {
- setlocale(LC_ALL, "");
while (argc > 0) {
showdetails(*argv);
argv++;
@@ -291,7 +294,7 @@
} else {
uint i;
for (i = 0; i < sizeof (kwinfo) / sizeof (struct _kwinfo); i++)
- showdetails ((char *)kwinfo [i].name);
+ showdetails(kwinfo[i].name);
}
exit(0);
}
@@ -336,7 +339,7 @@
static int
scmp(const void *s1, const void *s2)
{
- return strcmp(*(const char **)s1, *(const char **)s2);
+ return strcmp(*(const char * const *)s1, *(const char * const *)s2);
}
/*
@@ -373,7 +376,7 @@
/* add US-ASCII, if not yet added */
if (sl_find(charmaps, "US-ASCII") == NULL)
- sl_add(charmaps, "US-ASCII");
+ sl_add(charmaps, strdup("US-ASCII"));
/* sort the list */
qsort(charmaps->sl_str, charmaps->sl_cur, sizeof(char *), scmp);
@@ -432,10 +435,10 @@
* we also list 'C' for constistency
*/
if (sl_find(locales, "POSIX") == NULL)
- sl_add(locales, "POSIX");
+ sl_add(locales, strdup("POSIX"));
if (sl_find(locales, "C") == NULL)
- sl_add(locales, "C");
+ sl_add(locales, strdup("C"));
/* make output nicer, sort the list */
qsort(locales->sl_str, locales->sl_cur, sizeof(char *), scmp);
@@ -466,10 +469,10 @@
&& strcmp(lang, vval)) {
/*
* Appropriate environment variable set, its value
- * is valid and not overriden by LC_ALL
+ * is valid and not overridden by LC_ALL
*
* XXX: possible side effect: if both LANG and
- * overriden environment variable are set into same
+ * overridden environment variable are set into same
* value, then it'll be assumed as 'implied'
*/
printf("%s=%s\n", lcinfo[i].name, vval);
@@ -485,6 +488,36 @@
printf("LC_ALL=%s\n", vval);
}
+char *
+format_grouping(const char *binary)
+{
+ static char rval[64];
+ const char *cp;
+ size_t roff;
+ int len;
+
+ rval[0] = '\0';
+ roff = 0;
+ for (cp = binary; *cp != '\0'; ++cp) {
+#if CHAR_MIN != 0
+ if (*cp < 0)
+ break; /* garbage input */
+#endif
+ len = snprintf(&rval[roff], sizeof(rval) - roff, "%u;", *cp);
+ if (len < 0 || (unsigned)len >= sizeof(rval) - roff)
+ break; /* insufficient space for output */
+ roff += len;
+ if (*cp == CHAR_MAX)
+ break; /* special termination */
+ }
+
+ /* Truncate at the last successfully snprintf()ed semicolon. */
+ if (roff != 0)
+ rval[roff - 1] = '\0';
+
+ return (&rval[0]);
+}
+
/*
* keyword value lookup helper (via localeconv())
*/
@@ -498,7 +531,7 @@
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;
@@ -513,7 +546,7 @@
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;
@@ -573,7 +606,7 @@
* keyword value and properties lookup
*/
int
-kwval_lookup(char *kwname, char **kwval, int *cat, int *isstr)
+kwval_lookup(const char *kwname, char **kwval, int *cat, int *isstr)
{
int rval;
size_t i;
@@ -601,7 +634,7 @@
* command line options specified.
*/
void
-showdetails(char *kw)
+showdetails(const char *kw)
{
int isstr, cat, tmpval;
char *kwval;
@@ -616,9 +649,9 @@
}
if (prt_categories) {
- if (prt_keywords)
+ if (prt_keywords)
printf("%-20s ", lookup_localecat(cat));
- else
+ else
printf("%-20s\t%s\n", kw, lookup_localecat(cat));
}
More information about the Midnightbsd-cvs
mailing list