1 /* Program that prints the names of the categories of the current locale.
2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2019. */
25 /* We want to use the system's setlocale() function here, not the gnulib
30 <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/locale.html>
31 Here we implement only the invocation without any command-line options. */
34 defaulted_getenv (const char *variable
)
36 const char *value
= getenv (variable
);
37 return (value
!= NULL
? value
: "");
41 print_category (int category
, const char *variable
)
43 const char *value
= defaulted_getenv (variable
);
44 if (value
[0] != '\0' && defaulted_getenv ("LC_ALL")[0] == '\0')
45 /* The variable is set in the environment and not overridden by LC_ALL. */
46 printf ("%s=%s\n", variable
, value
);
48 printf ("%s=\"%s\"\n", variable
, setlocale (category
, NULL
));
54 setlocale (LC_ALL
, "");
56 printf ("LANG=%s\n", defaulted_getenv ("LANG"));
57 print_category (LC_CTYPE
, "LC_CTYPE");
58 print_category (LC_NUMERIC
, "LC_NUMERIC");
59 print_category (LC_TIME
, "LC_TIME");
60 print_category (LC_COLLATE
, "LC_COLLATE");
61 print_category (LC_MONETARY
, "LC_MONETARY");
62 print_category (LC_MESSAGES
, "LC_MESSAGES");
64 print_category (LC_PAPER
, "LC_PAPER");
67 print_category (LC_NAME
, "LC_NAME");
70 print_category (LC_ADDRESS
, "LC_ADDRESS");
73 print_category (LC_TELEPHONE
, "LC_TELEPHONE");
76 print_category (LC_MEASUREMENT
, "LC_MEASUREMENT");
78 #ifdef LC_IDENTIFICATION
79 print_category (LC_IDENTIFICATION
, "LC_IDENTIFICATION");
82 printf ("LC_ALL=%s\n", defaulted_getenv ("LC_ALL"));