VirtualBox

source: kBuild/vendor/grep/current/gnulib-tests/locale.c

Last change on this file was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1/* Program that prints the names of the categories of the current locale.
2 Copyright (C) 2019-2021 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2019. */
18
19#include <config.h>
20
21#include <locale.h>
22#include <stdio.h>
23#include <stdlib.h>
24
25/* We want to use the system's setlocale() function here, not the gnulib
26 override. */
27#undef setlocale
28
29/* Specification:
30 <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/locale.html>
31 Here we implement only the invocation without any command-line options. */
32
33static const char *
34defaulted_getenv (const char *variable)
35{
36 const char *value = getenv (variable);
37 return (value != NULL ? value : "");
38}
39
40static void
41print_category (int category, const char *variable)
42{
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);
47 else
48 printf ("%s=\"%s\"\n", variable, setlocale (category, NULL));
49}
50
51int
52main (void)
53{
54 setlocale (LC_ALL, "");
55
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");
63#ifdef LC_PAPER
64 print_category (LC_PAPER, "LC_PAPER");
65#endif
66#ifdef LC_NAME
67 print_category (LC_NAME, "LC_NAME");
68#endif
69#ifdef LC_ADDRESS
70 print_category (LC_ADDRESS, "LC_ADDRESS");
71#endif
72#ifdef LC_TELEPHONE
73 print_category (LC_TELEPHONE, "LC_TELEPHONE");
74#endif
75#ifdef LC_MEASUREMENT
76 print_category (LC_MEASUREMENT, "LC_MEASUREMENT");
77#endif
78#ifdef LC_IDENTIFICATION
79 print_category (LC_IDENTIFICATION, "LC_IDENTIFICATION");
80#endif
81
82 printf ("LC_ALL=%s\n", defaulted_getenv ("LC_ALL"));
83
84 return 0;
85}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette