2002-10-16 13:17:18 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2003-06-20 11:45:43 +00:00
|
|
|
* Copyright (c) 2002, 2003 Alexey Zelkin <phantom@FreeBSD.org>
|
2002-10-16 13:17:18 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/*
|
2003-06-26 09:07:53 +00:00
|
|
|
* XXX: implement missing era_* (LC_TIME) keywords (require libc &
|
|
|
|
* nl_langinfo(3) extensions)
|
2003-06-20 11:45:43 +00:00
|
|
|
*
|
|
|
|
* XXX: correctly handle reserved 'charmap' keyword and '-m' option (require
|
2012-11-08 23:46:15 +00:00
|
|
|
* localedef(1) implementation). Currently it's handled via
|
2003-06-20 11:45:43 +00:00
|
|
|
* nl_langinfo(CODESET).
|
|
|
|
*/
|
|
|
|
|
2016-04-17 22:42:48 +00:00
|
|
|
#include <sys/param.h>
|
2002-10-16 13:17:18 +00:00
|
|
|
#include <sys/types.h>
|
2019-09-10 15:09:46 +00:00
|
|
|
#include <sys/sbuf.h>
|
2016-04-17 22:42:48 +00:00
|
|
|
|
2002-10-16 13:17:18 +00:00
|
|
|
#include <dirent.h>
|
2003-06-20 11:45:43 +00:00
|
|
|
#include <err.h>
|
2016-11-30 18:34:40 +00:00
|
|
|
#include <limits.h>
|
2002-10-16 13:17:18 +00:00
|
|
|
#include <locale.h>
|
2003-06-20 11:45:43 +00:00
|
|
|
#include <langinfo.h>
|
2002-10-16 13:17:18 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stringlist.h>
|
|
|
|
#include <unistd.h>
|
2003-06-25 23:05:11 +00:00
|
|
|
#include "setlocale.h"
|
2002-10-16 13:17:18 +00:00
|
|
|
|
|
|
|
/* Local prototypes */
|
2019-09-11 15:39:28 +00:00
|
|
|
char *format_grouping(char *);
|
2003-06-20 11:45:43 +00:00
|
|
|
void init_locales_list(void);
|
2003-06-26 11:01:03 +00:00
|
|
|
void list_charmaps(void);
|
2002-10-16 13:17:18 +00:00
|
|
|
void list_locales(void);
|
2003-06-22 08:34:27 +00:00
|
|
|
const char *lookup_localecat(int);
|
2003-06-20 13:23:51 +00:00
|
|
|
char *kwval_lconv(int);
|
2019-09-10 15:09:46 +00:00
|
|
|
int kwval_lookup(const char *, char **, int *, int *, int *);
|
2020-06-13 08:37:24 +00:00
|
|
|
int showdetails(const char *);
|
2009-10-05 07:11:19 +00:00
|
|
|
void showkeywordslist(char *substring);
|
2003-06-20 11:45:43 +00:00
|
|
|
void showlocale(void);
|
2003-06-20 13:23:51 +00:00
|
|
|
void usage(void);
|
2002-10-16 13:17:18 +00:00
|
|
|
|
|
|
|
/* Global variables */
|
|
|
|
static StringList *locales = NULL;
|
|
|
|
|
2016-12-01 17:36:31 +00:00
|
|
|
static int all_locales = 0;
|
|
|
|
static int all_charmaps = 0;
|
|
|
|
static int prt_categories = 0;
|
|
|
|
static int prt_keywords = 0;
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2016-12-01 17:36:31 +00:00
|
|
|
static const struct _lcinfo {
|
2003-06-20 13:23:51 +00:00
|
|
|
const char *name;
|
|
|
|
int id;
|
2002-10-16 13:17:18 +00:00
|
|
|
} lcinfo [] = {
|
2003-06-20 13:23:51 +00:00
|
|
|
{ "LC_CTYPE", LC_CTYPE },
|
|
|
|
{ "LC_COLLATE", LC_COLLATE },
|
2003-06-20 11:45:43 +00:00
|
|
|
{ "LC_TIME", LC_TIME },
|
|
|
|
{ "LC_NUMERIC", LC_NUMERIC },
|
|
|
|
{ "LC_MONETARY", LC_MONETARY },
|
|
|
|
{ "LC_MESSAGES", LC_MESSAGES }
|
2002-10-16 13:17:18 +00:00
|
|
|
};
|
2016-04-17 22:42:48 +00:00
|
|
|
#define NLCINFO nitems(lcinfo)
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/* ids for values not referenced by nl_langinfo() */
|
2019-09-10 15:09:46 +00:00
|
|
|
enum {
|
|
|
|
KW_GROUPING,
|
|
|
|
KW_INT_CURR_SYMBOL,
|
|
|
|
KW_CURRENCY_SYMBOL,
|
|
|
|
KW_MON_DECIMAL_POINT,
|
|
|
|
KW_MON_THOUSANDS_SEP,
|
|
|
|
KW_MON_GROUPING,
|
|
|
|
KW_POSITIVE_SIGN,
|
|
|
|
KW_NEGATIVE_SIGN,
|
|
|
|
KW_INT_FRAC_DIGITS,
|
|
|
|
KW_FRAC_DIGITS,
|
|
|
|
KW_P_CS_PRECEDES,
|
|
|
|
KW_P_SEP_BY_SPACE,
|
|
|
|
KW_N_CS_PRECEDES,
|
|
|
|
KW_N_SEP_BY_SPACE,
|
|
|
|
KW_P_SIGN_POSN,
|
|
|
|
KW_N_SIGN_POSN,
|
|
|
|
KW_INT_P_CS_PRECEDES,
|
|
|
|
KW_INT_P_SEP_BY_SPACE,
|
|
|
|
KW_INT_N_CS_PRECEDES,
|
|
|
|
KW_INT_N_SEP_BY_SPACE,
|
|
|
|
KW_INT_P_SIGN_POSN,
|
|
|
|
KW_INT_N_SIGN_POSN,
|
|
|
|
KW_TIME_DAY,
|
|
|
|
KW_TIME_ABDAY,
|
|
|
|
KW_TIME_MON,
|
|
|
|
KW_TIME_ABMON,
|
|
|
|
KW_TIME_AM_PM
|
|
|
|
};
|
|
|
|
|
2019-09-11 15:39:28 +00:00
|
|
|
enum {
|
|
|
|
TYPE_NUM,
|
|
|
|
TYPE_STR,
|
|
|
|
TYPE_UNQ
|
|
|
|
};
|
|
|
|
|
2019-09-10 15:09:46 +00:00
|
|
|
enum {
|
|
|
|
SRC_LINFO,
|
|
|
|
SRC_LCONV,
|
|
|
|
SRC_LTIME
|
|
|
|
};
|
2003-06-20 11:45:43 +00:00
|
|
|
|
2016-12-01 17:36:31 +00:00
|
|
|
static const struct _kwinfo {
|
2003-06-20 13:23:51 +00:00
|
|
|
const char *name;
|
2019-09-11 15:39:28 +00:00
|
|
|
int type;
|
2003-06-20 13:23:51 +00:00
|
|
|
int catid; /* LC_* */
|
2019-09-10 15:09:46 +00:00
|
|
|
int source;
|
2003-06-20 13:23:51 +00:00
|
|
|
int value_ref;
|
2003-06-22 08:34:27 +00:00
|
|
|
const char *comment;
|
2003-06-20 11:45:43 +00:00
|
|
|
} kwinfo [] = {
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "charmap", TYPE_STR, LC_CTYPE, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
CODESET, "" }, /* hack */
|
|
|
|
|
|
|
|
/* LC_MONETARY - POSIX */
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "int_curr_symbol", TYPE_STR, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_INT_CURR_SYMBOL, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "currency_symbol", TYPE_STR, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_CURRENCY_SYMBOL, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_decimal_point", TYPE_STR, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_MON_DECIMAL_POINT, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_thousands_sep", TYPE_STR, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_MON_THOUSANDS_SEP, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_grouping", TYPE_UNQ, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_MON_GROUPING, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "positive_sign", TYPE_STR, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_POSITIVE_SIGN, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "negative_sign", TYPE_STR, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_NEGATIVE_SIGN, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "int_frac_digits", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_INT_FRAC_DIGITS, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "frac_digits", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_FRAC_DIGITS, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "p_cs_precedes", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_P_CS_PRECEDES, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "p_sep_by_space", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_P_SEP_BY_SPACE, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "n_cs_precedes", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_N_CS_PRECEDES, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "n_sep_by_space", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_N_SEP_BY_SPACE, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "p_sign_posn", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_P_SIGN_POSN, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "n_sign_posn", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_N_SIGN_POSN, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "int_p_cs_precedes", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_INT_P_CS_PRECEDES, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "int_p_sep_by_space", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_INT_P_SEP_BY_SPACE, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "int_n_cs_precedes", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_INT_N_CS_PRECEDES, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "int_n_sep_by_space", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_INT_N_SEP_BY_SPACE, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "int_p_sign_posn", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_INT_P_SIGN_POSN, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "int_n_sign_posn", TYPE_NUM, LC_MONETARY, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_INT_N_SIGN_POSN, "" },
|
|
|
|
|
|
|
|
/* LC_NUMERIC - POSIX */
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "decimal_point", TYPE_STR, LC_NUMERIC, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
RADIXCHAR, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "thousands_sep", TYPE_STR, LC_NUMERIC, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
THOUSEP, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "grouping", TYPE_UNQ, LC_NUMERIC, SRC_LCONV,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_GROUPING, "" },
|
|
|
|
/* LC_NUMERIC - local additions */
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "radixchar", TYPE_STR, LC_NUMERIC, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
RADIXCHAR, "Same as decimal_point (FreeBSD only)" }, /* compat */
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "thousep", TYPE_STR, LC_NUMERIC, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
THOUSEP, "Same as thousands_sep (FreeBSD only)" }, /* compat */
|
|
|
|
|
|
|
|
/* LC_TIME - POSIX */
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abday", TYPE_STR, LC_TIME, SRC_LTIME,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_TIME_ABDAY, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "day", TYPE_STR, LC_TIME, SRC_LTIME,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_TIME_DAY, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon", TYPE_STR, LC_TIME, SRC_LTIME,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_TIME_ABMON, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon", TYPE_STR, LC_TIME, SRC_LTIME,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_TIME_MON, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "d_t_fmt", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
D_T_FMT, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "d_fmt", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
D_FMT, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "t_fmt", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
T_FMT, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "am_pm", TYPE_STR, LC_TIME, SRC_LTIME,
|
2019-09-10 15:09:46 +00:00
|
|
|
KW_TIME_AM_PM, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "t_fmt_ampm", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
T_FMT_AMPM, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "era", TYPE_UNQ, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ERA, "(unavailable)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "era_d_fmt", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ERA_D_FMT, "(unavailable)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "era_d_t_fmt", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ERA_D_T_FMT, "(unavailable)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "era_t_fmt", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ERA_T_FMT, "(unavailable)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "alt_digits", TYPE_UNQ, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALT_DIGITS, "" },
|
|
|
|
/* LC_TIME - local additions */
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abday_1", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABDAY_1, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abday_2", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABDAY_2, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abday_3", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABDAY_3, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abday_4", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABDAY_4, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abday_5", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABDAY_5, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abday_6", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABDAY_6, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abday_7", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABDAY_7, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "day_1", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
DAY_1, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "day_2", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
DAY_2, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "day_3", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
DAY_3, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "day_4", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
DAY_4, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "day_5", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
DAY_5, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "day_6", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
DAY_6, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "day_7", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
DAY_7, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_1", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_1, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_2", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_2, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_3", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_3, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_4", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_4, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_5", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_5, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_6", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_6, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_7", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_7, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_8", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_8, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_9", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_9, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_10", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_10, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_11", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_11, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "abmon_12", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ABMON_12, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_1", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_1, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_2", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_2, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_3", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_3, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_4", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_4, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_5", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_5, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_6", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_6, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_7", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_7, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_8", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_8, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_9", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_9, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_10", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_10, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_11", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_11, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "mon_12", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
MON_12, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_1", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_1, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_2", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_2, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_3", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_3, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_4", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_4, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_5", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_5, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_6", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_6, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_7", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_7, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_8", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_8, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_9", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_9, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_10", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_10, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_11", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_11, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "altmon_12", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
ALTMON_12, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "am_str", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
AM_STR, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "pm_str", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
PM_STR, "(FreeBSD only)" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "d_md_order", TYPE_STR, LC_TIME, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
D_MD_ORDER, "(FreeBSD only)" }, /* local */
|
|
|
|
|
|
|
|
/* LC_MESSAGES - POSIX */
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "yesexpr", TYPE_STR, LC_MESSAGES, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
YESEXPR, "" },
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "noexpr", TYPE_STR, LC_MESSAGES, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
NOEXPR, "" },
|
|
|
|
/* LC_MESSAGES - local additions */
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "yesstr", TYPE_STR, LC_MESSAGES, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
YESSTR, "(POSIX legacy)" }, /* compat */
|
2019-09-11 15:39:28 +00:00
|
|
|
{ "nostr", TYPE_STR, LC_MESSAGES, SRC_LINFO,
|
2019-09-10 15:09:46 +00:00
|
|
|
NOSTR, "(POSIX legacy)" } /* compat */
|
2003-06-20 11:45:43 +00:00
|
|
|
|
|
|
|
};
|
2016-07-30 07:04:46 +00:00
|
|
|
#define NKWINFO (nitems(kwinfo))
|
2003-06-20 11:45:43 +00:00
|
|
|
|
2016-12-01 17:36:31 +00:00
|
|
|
static const char *boguslocales[] = { "UTF-8" };
|
2016-07-30 07:04:46 +00:00
|
|
|
#define NBOGUS (nitems(boguslocales))
|
2004-08-02 12:28:28 +00:00
|
|
|
|
2002-10-16 13:17:18 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2004-01-22 07:23:36 +00:00
|
|
|
int ch;
|
2003-06-22 08:34:27 +00:00
|
|
|
int tmp;
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2009-10-05 07:11:19 +00:00
|
|
|
while ((ch = getopt(argc, argv, "ackms:")) != -1) {
|
2002-10-16 13:17:18 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'a':
|
|
|
|
all_locales = 1;
|
|
|
|
break;
|
2003-06-20 11:45:43 +00:00
|
|
|
case 'c':
|
|
|
|
prt_categories = 1;
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
prt_keywords = 1;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
all_charmaps = 1;
|
2002-10-16 13:17:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
2003-06-20 11:45:43 +00:00
|
|
|
}
|
2002-10-16 13:17:18 +00:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/* validate arguments */
|
|
|
|
if (all_locales && all_charmaps)
|
|
|
|
usage();
|
2012-11-08 02:55:30 +00:00
|
|
|
if ((all_locales || all_charmaps) && argc > 0)
|
2003-06-20 11:45:43 +00:00
|
|
|
usage();
|
|
|
|
if ((all_locales || all_charmaps) && (prt_categories || prt_keywords))
|
|
|
|
usage();
|
|
|
|
|
|
|
|
/* process '-a' */
|
2002-10-16 13:17:18 +00:00
|
|
|
if (all_locales) {
|
|
|
|
list_locales();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/* process '-m' */
|
|
|
|
if (all_charmaps) {
|
2003-06-26 11:01:03 +00:00
|
|
|
list_charmaps();
|
|
|
|
exit(0);
|
2003-06-20 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
2003-06-22 08:34:27 +00:00
|
|
|
/* check for special case '-k list' */
|
|
|
|
tmp = 0;
|
|
|
|
if (prt_keywords && argc > 0)
|
|
|
|
while (tmp < argc)
|
|
|
|
if (strcasecmp(argv[tmp++], "list") == 0) {
|
2009-10-05 07:11:19 +00:00
|
|
|
showkeywordslist(argv[tmp]);
|
2003-06-22 08:34:27 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2012-11-17 23:49:20 +00:00
|
|
|
/* process '-c', '-k', or command line arguments. */
|
|
|
|
if (prt_categories || prt_keywords || argc > 0) {
|
2016-11-18 17:18:05 +00:00
|
|
|
if (prt_keywords || argc > 0)
|
2012-11-08 02:55:30 +00:00
|
|
|
setlocale(LC_ALL, "");
|
2016-11-18 16:48:37 +00:00
|
|
|
if (argc > 0) {
|
2012-11-08 23:46:15 +00:00
|
|
|
while (argc > 0) {
|
2020-06-13 08:37:24 +00:00
|
|
|
if (showdetails(*argv) != 0)
|
|
|
|
exit(EXIT_FAILURE);
|
2012-11-08 23:46:15 +00:00
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
} else {
|
2012-11-08 02:55:30 +00:00
|
|
|
uint i;
|
2016-04-17 22:42:48 +00:00
|
|
|
for (i = 0; i < nitems(kwinfo); i++)
|
2016-12-01 17:36:31 +00:00
|
|
|
showdetails(kwinfo[i].name);
|
2012-11-08 23:46:15 +00:00
|
|
|
}
|
2003-06-20 11:45:43 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no arguments, show current locale state */
|
|
|
|
showlocale();
|
|
|
|
|
2002-10-16 13:17:18 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usage(void)
|
|
|
|
{
|
2003-06-20 11:45:43 +00:00
|
|
|
printf("Usage: locale [ -a | -m ]\n"
|
2012-11-08 23:46:15 +00:00
|
|
|
" locale -k list [prefix]\n"
|
|
|
|
" locale [ -ck ] [keyword ...]\n");
|
2002-10-16 13:17:18 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/*
|
|
|
|
* Output information about all available locales
|
|
|
|
*
|
|
|
|
* XXX actually output of this function does not guarantee that locale
|
|
|
|
* is really available to application, since it can be broken or
|
2012-11-10 06:10:07 +00:00
|
|
|
* inconsistent thus setlocale() will fail. Maybe add '-V' function to
|
2003-06-20 11:45:43 +00:00
|
|
|
* also validate these locales?
|
|
|
|
*/
|
2002-10-16 13:17:18 +00:00
|
|
|
void
|
|
|
|
list_locales(void)
|
|
|
|
{
|
2003-06-20 13:23:51 +00:00
|
|
|
size_t i;
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
init_locales_list();
|
2002-10-16 13:17:18 +00:00
|
|
|
for (i = 0; i < locales->sl_cur; i++) {
|
|
|
|
printf("%s\n", locales->sl_str[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-26 11:05:56 +00:00
|
|
|
/*
|
|
|
|
* qsort() helper function
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
scmp(const void *s1, const void *s2)
|
|
|
|
{
|
2016-12-01 17:36:31 +00:00
|
|
|
return strcmp(*(const char * const *)s1, *(const char * const *)s2);
|
2003-06-26 11:05:56 +00:00
|
|
|
}
|
|
|
|
|
2003-06-26 11:01:03 +00:00
|
|
|
/*
|
|
|
|
* Output information about all available charmaps
|
|
|
|
*
|
|
|
|
* XXX this function is doing a task in hackish way, i.e. by scaning
|
|
|
|
* list of locales, spliting their codeset part and building list of
|
|
|
|
* them.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
list_charmaps(void)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
char *s, *cs;
|
|
|
|
StringList *charmaps;
|
|
|
|
|
|
|
|
/* initialize StringList */
|
|
|
|
charmaps = sl_init();
|
|
|
|
if (charmaps == NULL)
|
|
|
|
err(1, "could not allocate memory");
|
|
|
|
|
|
|
|
/* fetch locales list */
|
|
|
|
init_locales_list();
|
|
|
|
|
|
|
|
/* split codesets and build their list */
|
|
|
|
for (i = 0; i < locales->sl_cur; i++) {
|
|
|
|
s = locales->sl_str[i];
|
|
|
|
if ((cs = strchr(s, '.')) != NULL) {
|
|
|
|
cs++;
|
|
|
|
if (sl_find(charmaps, cs) == NULL)
|
|
|
|
sl_add(charmaps, cs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add US-ASCII, if not yet added */
|
|
|
|
if (sl_find(charmaps, "US-ASCII") == NULL)
|
2016-12-01 17:36:31 +00:00
|
|
|
sl_add(charmaps, strdup("US-ASCII"));
|
2003-06-26 11:01:03 +00:00
|
|
|
|
|
|
|
/* sort the list */
|
|
|
|
qsort(charmaps->sl_str, charmaps->sl_cur, sizeof(char *), scmp);
|
|
|
|
|
|
|
|
/* print results */
|
|
|
|
for (i = 0; i < charmaps->sl_cur; i++) {
|
|
|
|
printf("%s\n", charmaps->sl_str[i]);
|
|
|
|
}
|
|
|
|
}
|
2003-06-20 11:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieve sorted list of system locales (or user locales, if PATH_LOCALE
|
|
|
|
* environment variable is set)
|
|
|
|
*/
|
2002-10-16 13:17:18 +00:00
|
|
|
void
|
2003-06-20 11:45:43 +00:00
|
|
|
init_locales_list(void)
|
2002-10-16 13:17:18 +00:00
|
|
|
{
|
2003-06-20 11:45:43 +00:00
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
2004-08-02 12:28:28 +00:00
|
|
|
size_t i;
|
|
|
|
int bogus;
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/* why call this function twice ? */
|
|
|
|
if (locales != NULL)
|
2002-10-16 13:17:18 +00:00
|
|
|
return;
|
2003-06-20 11:45:43 +00:00
|
|
|
|
|
|
|
/* initialize StringList */
|
|
|
|
locales = sl_init();
|
|
|
|
if (locales == NULL)
|
|
|
|
err(1, "could not allocate memory");
|
|
|
|
|
|
|
|
/* get actual locales directory name */
|
2003-06-25 23:05:11 +00:00
|
|
|
if (__detect_path_locale() != 0)
|
|
|
|
err(1, "unable to find locales storage");
|
2003-06-20 11:45:43 +00:00
|
|
|
|
|
|
|
/* open locales directory */
|
2003-06-25 23:05:11 +00:00
|
|
|
dirp = opendir(_PathLocale);
|
2003-06-20 11:45:43 +00:00
|
|
|
if (dirp == NULL)
|
2003-06-25 23:05:11 +00:00
|
|
|
err(1, "could not open directory '%s'", _PathLocale);
|
2003-06-20 11:45:43 +00:00
|
|
|
|
|
|
|
/* scan directory and store its contents except "." and ".." */
|
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
if (*(dp->d_name) == '.')
|
|
|
|
continue; /* exclude "." and ".." */
|
2004-08-02 12:28:28 +00:00
|
|
|
for (bogus = i = 0; i < NBOGUS; i++)
|
|
|
|
if (strncmp(dp->d_name, boguslocales[i],
|
|
|
|
strlen(boguslocales[i])) == 0)
|
|
|
|
bogus = 1;
|
|
|
|
if (!bogus)
|
|
|
|
sl_add(locales, strdup(dp->d_name));
|
2002-10-16 13:17:18 +00:00
|
|
|
}
|
2003-06-20 11:45:43 +00:00
|
|
|
closedir(dirp);
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2012-11-08 23:46:15 +00:00
|
|
|
/* make sure that 'POSIX' and 'C' locales are present in the list.
|
2003-06-20 11:45:43 +00:00
|
|
|
* POSIX 1003.1-2001 requires presence of 'POSIX' name only here, but
|
2012-11-08 23:46:15 +00:00
|
|
|
* we also list 'C' for constistency
|
|
|
|
*/
|
2003-06-20 11:45:43 +00:00
|
|
|
if (sl_find(locales, "POSIX") == NULL)
|
2016-12-01 17:36:31 +00:00
|
|
|
sl_add(locales, strdup("POSIX"));
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
if (sl_find(locales, "C") == NULL)
|
2016-12-01 17:36:31 +00:00
|
|
|
sl_add(locales, strdup("C"));
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/* make output nicer, sort the list */
|
|
|
|
qsort(locales->sl_str, locales->sl_cur, sizeof(char *), scmp);
|
2002-10-16 13:17:18 +00:00
|
|
|
}
|
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/*
|
|
|
|
* Show current locale status, depending on environment variables
|
|
|
|
*/
|
2002-10-16 13:17:18 +00:00
|
|
|
void
|
2003-06-20 11:45:43 +00:00
|
|
|
showlocale(void)
|
2002-10-16 13:17:18 +00:00
|
|
|
{
|
2003-06-20 13:23:51 +00:00
|
|
|
size_t i;
|
2004-02-02 16:14:02 +00:00
|
|
|
const char *lang, *vval, *eval;
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2004-02-02 16:14:02 +00:00
|
|
|
setlocale(LC_ALL, "");
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2004-02-02 16:14:02 +00:00
|
|
|
lang = getenv("LANG");
|
|
|
|
if (lang == NULL) {
|
2003-06-20 11:45:43 +00:00
|
|
|
lang = "";
|
2004-02-02 16:14:02 +00:00
|
|
|
}
|
|
|
|
printf("LANG=%s\n", lang);
|
2003-06-20 13:23:51 +00:00
|
|
|
/* XXX: if LANG is null, then set it to "C" to get implied values? */
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
for (i = 0; i < NLCINFO; i++) {
|
|
|
|
vval = setlocale(lcinfo[i].id, NULL);
|
|
|
|
eval = getenv(lcinfo[i].name);
|
|
|
|
if (eval != NULL && !strcmp(eval, vval)
|
|
|
|
&& strcmp(lang, vval)) {
|
|
|
|
/*
|
|
|
|
* Appropriate environment variable set, its value
|
2015-10-21 05:37:09 +00:00
|
|
|
* is valid and not overridden by LC_ALL
|
2003-06-20 11:45:43 +00:00
|
|
|
*
|
|
|
|
* XXX: possible side effect: if both LANG and
|
2015-10-21 05:37:09 +00:00
|
|
|
* overridden environment variable are set into same
|
2003-06-20 11:45:43 +00:00
|
|
|
* value, then it'll be assumed as 'implied'
|
|
|
|
*/
|
|
|
|
printf("%s=%s\n", lcinfo[i].name, vval);
|
|
|
|
} else {
|
|
|
|
printf("%s=\"%s\"\n", lcinfo[i].name, vval);
|
|
|
|
}
|
2002-10-16 13:17:18 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 16:14:02 +00:00
|
|
|
vval = getenv("LC_ALL");
|
|
|
|
if (vval == NULL) {
|
|
|
|
vval = "";
|
|
|
|
}
|
|
|
|
printf("LC_ALL=%s\n", vval);
|
2002-10-16 13:17:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 02:09:58 +00:00
|
|
|
char *
|
2019-09-11 15:39:28 +00:00
|
|
|
format_grouping(char *binary)
|
2016-11-19 02:09:58 +00:00
|
|
|
{
|
|
|
|
static char rval[64];
|
|
|
|
const char *cp;
|
2016-12-01 16:54:02 +00:00
|
|
|
size_t roff;
|
|
|
|
int len;
|
2016-11-19 02:09:58 +00:00
|
|
|
|
2019-09-11 15:39:28 +00:00
|
|
|
/*
|
|
|
|
* XXX This check will need to be modified if/when localeconv() is
|
|
|
|
* fixed (PR172215).
|
|
|
|
*/
|
|
|
|
if (*binary == CHAR_MAX)
|
|
|
|
return (binary);
|
|
|
|
|
2016-11-19 02:09:58 +00:00
|
|
|
rval[0] = '\0';
|
2016-12-01 16:54:02 +00:00
|
|
|
roff = 0;
|
2016-11-19 02:09:58 +00:00
|
|
|
for (cp = binary; *cp != '\0'; ++cp) {
|
2016-12-06 15:42:18 +00:00
|
|
|
#if CHAR_MIN != 0
|
2016-12-01 16:54:02 +00:00
|
|
|
if (*cp < 0)
|
|
|
|
break; /* garbage input */
|
2016-12-06 15:42:18 +00:00
|
|
|
#endif
|
2016-12-01 16:54:02 +00:00
|
|
|
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 */
|
2016-11-19 02:09:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 16:54:02 +00:00
|
|
|
/* Truncate at the last successfully snprintf()ed semicolon. */
|
|
|
|
if (roff != 0)
|
|
|
|
rval[roff - 1] = '\0';
|
2016-11-19 02:09:58 +00:00
|
|
|
|
2016-12-01 16:54:02 +00:00
|
|
|
return (&rval[0]);
|
2016-11-19 02:09:58 +00:00
|
|
|
}
|
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/*
|
2019-09-10 15:09:46 +00:00
|
|
|
* keyword value lookup helper for values accessible via localeconv()
|
2003-06-20 11:45:43 +00:00
|
|
|
*/
|
|
|
|
char *
|
|
|
|
kwval_lconv(int id)
|
2002-10-16 13:17:18 +00:00
|
|
|
{
|
2003-06-20 13:23:51 +00:00
|
|
|
struct lconv *lc;
|
|
|
|
char *rval;
|
2003-06-20 11:45:43 +00:00
|
|
|
|
2003-06-20 13:23:51 +00:00
|
|
|
rval = NULL;
|
|
|
|
lc = localeconv();
|
2003-06-20 11:45:43 +00:00
|
|
|
switch (id) {
|
|
|
|
case KW_GROUPING:
|
2016-11-19 02:09:58 +00:00
|
|
|
rval = format_grouping(lc->grouping);
|
2003-06-20 11:45:43 +00:00
|
|
|
break;
|
|
|
|
case KW_INT_CURR_SYMBOL:
|
|
|
|
rval = lc->int_curr_symbol;
|
|
|
|
break;
|
|
|
|
case KW_CURRENCY_SYMBOL:
|
|
|
|
rval = lc->currency_symbol;
|
|
|
|
break;
|
|
|
|
case KW_MON_DECIMAL_POINT:
|
|
|
|
rval = lc->mon_decimal_point;
|
|
|
|
break;
|
|
|
|
case KW_MON_THOUSANDS_SEP:
|
|
|
|
rval = lc->mon_thousands_sep;
|
|
|
|
break;
|
|
|
|
case KW_MON_GROUPING:
|
2016-11-19 02:09:58 +00:00
|
|
|
rval = format_grouping(lc->mon_grouping);
|
2003-06-20 11:45:43 +00:00
|
|
|
break;
|
|
|
|
case KW_POSITIVE_SIGN:
|
|
|
|
rval = lc->positive_sign;
|
|
|
|
break;
|
|
|
|
case KW_NEGATIVE_SIGN:
|
|
|
|
rval = lc->negative_sign;
|
|
|
|
break;
|
|
|
|
case KW_INT_FRAC_DIGITS:
|
|
|
|
rval = &(lc->int_frac_digits);
|
|
|
|
break;
|
|
|
|
case KW_FRAC_DIGITS:
|
|
|
|
rval = &(lc->frac_digits);
|
|
|
|
break;
|
|
|
|
case KW_P_CS_PRECEDES:
|
|
|
|
rval = &(lc->p_cs_precedes);
|
|
|
|
break;
|
|
|
|
case KW_P_SEP_BY_SPACE:
|
|
|
|
rval = &(lc->p_sep_by_space);
|
|
|
|
break;
|
|
|
|
case KW_N_CS_PRECEDES:
|
|
|
|
rval = &(lc->n_cs_precedes);
|
|
|
|
break;
|
|
|
|
case KW_N_SEP_BY_SPACE:
|
|
|
|
rval = &(lc->n_sep_by_space);
|
|
|
|
break;
|
|
|
|
case KW_P_SIGN_POSN:
|
|
|
|
rval = &(lc->p_sign_posn);
|
|
|
|
break;
|
|
|
|
case KW_N_SIGN_POSN:
|
|
|
|
rval = &(lc->n_sign_posn);
|
|
|
|
break;
|
2003-06-26 09:07:53 +00:00
|
|
|
case KW_INT_P_CS_PRECEDES:
|
|
|
|
rval = &(lc->int_p_cs_precedes);
|
|
|
|
break;
|
|
|
|
case KW_INT_P_SEP_BY_SPACE:
|
|
|
|
rval = &(lc->int_p_sep_by_space);
|
|
|
|
break;
|
|
|
|
case KW_INT_N_CS_PRECEDES:
|
|
|
|
rval = &(lc->int_n_cs_precedes);
|
|
|
|
break;
|
|
|
|
case KW_INT_N_SEP_BY_SPACE:
|
|
|
|
rval = &(lc->int_n_sep_by_space);
|
|
|
|
break;
|
|
|
|
case KW_INT_P_SIGN_POSN:
|
|
|
|
rval = &(lc->int_p_sign_posn);
|
|
|
|
break;
|
|
|
|
case KW_INT_N_SIGN_POSN:
|
|
|
|
rval = &(lc->int_n_sign_posn);
|
|
|
|
break;
|
2003-06-20 11:45:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (rval);
|
2002-10-16 13:17:18 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 15:09:46 +00:00
|
|
|
/*
|
|
|
|
* keyword value lookup helper for LC_TIME keywords not accessible
|
|
|
|
* via nl_langinfo() or localeconv()
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
kwval_ltime(int id)
|
|
|
|
{
|
|
|
|
char *rval;
|
|
|
|
struct sbuf *kwsbuf;
|
2019-09-11 16:00:03 +00:00
|
|
|
nl_item i, s_item = 0, e_item = 0;
|
2019-09-10 15:09:46 +00:00
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case KW_TIME_DAY:
|
|
|
|
s_item = DAY_1;
|
|
|
|
e_item = DAY_7;
|
|
|
|
break;
|
|
|
|
case KW_TIME_ABDAY:
|
|
|
|
s_item = ABDAY_1;
|
|
|
|
e_item = ABDAY_7;
|
|
|
|
break;
|
|
|
|
case KW_TIME_MON:
|
|
|
|
s_item = MON_1;
|
|
|
|
e_item = MON_12;
|
|
|
|
break;
|
|
|
|
case KW_TIME_ABMON:
|
|
|
|
s_item = ABMON_1;
|
|
|
|
e_item = ABMON_12;
|
|
|
|
break;
|
|
|
|
case KW_TIME_AM_PM:
|
2019-09-11 15:39:28 +00:00
|
|
|
if (asprintf(&rval, "%s;%s",
|
2019-09-10 15:09:46 +00:00
|
|
|
nl_langinfo(AM_STR),
|
|
|
|
nl_langinfo(PM_STR)) == -1)
|
|
|
|
err(1, "asprintf");
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
kwsbuf = sbuf_new_auto();
|
|
|
|
if (kwsbuf == NULL)
|
|
|
|
err(1, "sbuf");
|
|
|
|
for (i = s_item; i <= e_item; i++) {
|
|
|
|
(void) sbuf_cat(kwsbuf, nl_langinfo(i));
|
|
|
|
if (i != e_item)
|
2019-09-11 15:39:28 +00:00
|
|
|
(void) sbuf_cat(kwsbuf, ";");
|
2019-09-10 15:09:46 +00:00
|
|
|
}
|
|
|
|
(void) sbuf_finish(kwsbuf);
|
|
|
|
rval = strdup(sbuf_data(kwsbuf));
|
|
|
|
if (rval == NULL)
|
|
|
|
err(1, "strdup");
|
|
|
|
sbuf_delete(kwsbuf);
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/*
|
|
|
|
* keyword value and properties lookup
|
|
|
|
*/
|
|
|
|
int
|
2019-09-11 15:39:28 +00:00
|
|
|
kwval_lookup(const char *kwname, char **kwval, int *cat, int *type, int *alloc)
|
2002-10-16 13:17:18 +00:00
|
|
|
{
|
2003-06-20 13:23:51 +00:00
|
|
|
int rval;
|
|
|
|
size_t i;
|
2019-09-11 15:39:28 +00:00
|
|
|
static char nastr[3] = "-1";
|
2003-06-20 11:45:43 +00:00
|
|
|
|
2003-06-20 13:23:51 +00:00
|
|
|
rval = 0;
|
2019-09-10 15:09:46 +00:00
|
|
|
*alloc = 0;
|
2003-06-20 11:45:43 +00:00
|
|
|
for (i = 0; i < NKWINFO; i++) {
|
|
|
|
if (strcasecmp(kwname, kwinfo[i].name) == 0) {
|
|
|
|
rval = 1;
|
|
|
|
*cat = kwinfo[i].catid;
|
2019-09-11 15:39:28 +00:00
|
|
|
*type = kwinfo[i].type;
|
2019-09-10 15:09:46 +00:00
|
|
|
switch (kwinfo[i].source) {
|
|
|
|
case SRC_LINFO:
|
2003-06-20 11:45:43 +00:00
|
|
|
*kwval = nl_langinfo(kwinfo[i].value_ref);
|
2019-09-10 15:09:46 +00:00
|
|
|
break;
|
|
|
|
case SRC_LCONV:
|
2003-06-20 11:45:43 +00:00
|
|
|
*kwval = kwval_lconv(kwinfo[i].value_ref);
|
2019-09-11 15:39:28 +00:00
|
|
|
/*
|
|
|
|
* XXX This check will need to be modified
|
|
|
|
* if/when localeconv() is fixed (PR172215).
|
|
|
|
*/
|
|
|
|
if (**kwval == CHAR_MAX) {
|
|
|
|
if (*type == TYPE_NUM)
|
|
|
|
*type = TYPE_UNQ;
|
|
|
|
*kwval = nastr;
|
|
|
|
}
|
2019-09-10 15:09:46 +00:00
|
|
|
break;
|
|
|
|
case SRC_LTIME:
|
|
|
|
*kwval = kwval_ltime(kwinfo[i].value_ref);
|
|
|
|
*alloc = 1;
|
|
|
|
break;
|
2003-06-20 11:45:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (rval);
|
2002-10-16 13:17:18 +00:00
|
|
|
}
|
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
/*
|
|
|
|
* Show details about requested keyword according to '-k' and/or '-c'
|
|
|
|
* command line options specified.
|
|
|
|
*/
|
2020-06-13 08:37:24 +00:00
|
|
|
int
|
2016-12-01 17:36:31 +00:00
|
|
|
showdetails(const char *kw)
|
2002-10-16 13:17:18 +00:00
|
|
|
{
|
2019-09-11 15:39:28 +00:00
|
|
|
int type, cat, tmpval, alloc;
|
2003-06-20 13:23:51 +00:00
|
|
|
char *kwval;
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2019-09-11 15:39:28 +00:00
|
|
|
if (kwval_lookup(kw, &kwval, &cat, &type, &alloc) == 0) {
|
2020-06-13 08:37:24 +00:00
|
|
|
/* Invalid keyword specified */
|
2009-10-05 07:11:19 +00:00
|
|
|
fprintf(stderr, "Unknown keyword: `%s'\n", kw);
|
2020-06-13 08:37:24 +00:00
|
|
|
return (1);
|
2003-06-20 11:45:43 +00:00
|
|
|
}
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
if (prt_categories) {
|
2016-12-01 17:36:31 +00:00
|
|
|
if (prt_keywords)
|
2012-11-08 02:55:30 +00:00
|
|
|
printf("%-20s ", lookup_localecat(cat));
|
2016-12-01 17:36:31 +00:00
|
|
|
else
|
2012-11-08 23:46:15 +00:00
|
|
|
printf("%-20s\t%s\n", kw, lookup_localecat(cat));
|
2003-06-20 11:45:43 +00:00
|
|
|
}
|
2002-10-16 13:17:18 +00:00
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
if (prt_keywords) {
|
2019-09-11 15:39:28 +00:00
|
|
|
switch (type) {
|
|
|
|
case TYPE_NUM:
|
|
|
|
tmpval = (char)*kwval;
|
2003-06-20 13:23:51 +00:00
|
|
|
printf("%s=%d\n", kw, tmpval);
|
2019-09-11 15:39:28 +00:00
|
|
|
break;
|
|
|
|
case TYPE_STR:
|
|
|
|
printf("%s=\"%s\"\n", kw, kwval);
|
|
|
|
break;
|
|
|
|
case TYPE_UNQ:
|
|
|
|
printf("%s=%s\n", kw, kwval);
|
|
|
|
break;
|
2003-06-20 11:45:43 +00:00
|
|
|
}
|
2002-10-16 13:17:18 +00:00
|
|
|
}
|
|
|
|
|
2003-06-20 11:45:43 +00:00
|
|
|
if (!prt_categories && !prt_keywords) {
|
2019-09-11 15:39:28 +00:00
|
|
|
switch (type) {
|
|
|
|
case TYPE_NUM:
|
|
|
|
tmpval = (char)*kwval;
|
2003-06-20 13:23:51 +00:00
|
|
|
printf("%d\n", tmpval);
|
2019-09-11 15:39:28 +00:00
|
|
|
break;
|
|
|
|
case TYPE_STR:
|
|
|
|
case TYPE_UNQ:
|
|
|
|
printf("%s\n", kwval);
|
|
|
|
break;
|
2003-06-20 11:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-10 15:09:46 +00:00
|
|
|
|
|
|
|
if (alloc)
|
|
|
|
free(kwval);
|
2020-06-13 08:37:24 +00:00
|
|
|
|
|
|
|
return (0);
|
2002-10-16 13:17:18 +00:00
|
|
|
}
|
2003-06-22 08:34:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert locale category id into string
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
lookup_localecat(int cat)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < NLCINFO; i++)
|
|
|
|
if (lcinfo[i].id == cat) {
|
|
|
|
return (lcinfo[i].name);
|
|
|
|
}
|
|
|
|
return ("UNKNOWN");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Show list of keywords
|
|
|
|
*/
|
|
|
|
void
|
2009-10-05 07:11:19 +00:00
|
|
|
showkeywordslist(char *substring)
|
2003-06-22 08:34:27 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
2012-11-10 06:10:07 +00:00
|
|
|
#define FMT "%-20s %-12s %-7s %-20s\n"
|
2003-06-22 08:34:27 +00:00
|
|
|
|
2009-10-05 07:11:19 +00:00
|
|
|
if (substring == NULL)
|
|
|
|
printf("List of available keywords\n\n");
|
|
|
|
else
|
|
|
|
printf("List of available keywords starting with '%s'\n\n",
|
|
|
|
substring);
|
2003-06-22 08:34:27 +00:00
|
|
|
printf(FMT, "Keyword", "Category", "Type", "Comment");
|
|
|
|
printf("-------------------- ------------ ------- --------------------\n");
|
|
|
|
for (i = 0; i < NKWINFO; i++) {
|
2009-10-05 07:11:19 +00:00
|
|
|
if (substring != NULL) {
|
|
|
|
if (strncmp(kwinfo[i].name, substring,
|
|
|
|
strlen(substring)) != 0)
|
|
|
|
continue;
|
|
|
|
}
|
2003-06-22 08:34:27 +00:00
|
|
|
printf(FMT,
|
|
|
|
kwinfo[i].name,
|
|
|
|
lookup_localecat(kwinfo[i].catid),
|
2019-09-11 15:39:28 +00:00
|
|
|
(kwinfo[i].type == TYPE_NUM) ? "number" : "string",
|
2003-06-22 08:34:27 +00:00
|
|
|
kwinfo[i].comment);
|
|
|
|
}
|
|
|
|
}
|