x86: In ld.so, diagnose missing APX support in APX-only builds
[glibc.git] / localedata / dump-ctype.c
blobb425c572bd7bfa33da13bbb65dc9e10dc7340040
1 /* Dump the character classes and character maps of a locale to a bunch
2 of individual files which can be processed with diff, sed etc.
3 Copyright (C) 2000-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 /* Usage example:
21 $ dump-ctype de_DE.UTF-8
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <wctype.h>
27 #include <locale.h>
28 #include <sys/stat.h>
29 #include <unistd.h>
30 #include <errno.h>
32 static const char *program_name = "dump-ctype";
33 static const char *locale;
35 static const char *class_names[] =
37 "alnum", "alpha", "blank", "cntrl", "digit", "graph", "lower",
38 "print", "punct", "space", "upper", "xdigit"
41 static const char *map_names[] =
43 "tolower", "toupper", "totitle"
46 static void dump_class (const char *class_name)
48 wctype_t class;
49 FILE *f;
50 unsigned int ch;
52 class = wctype (class_name);
53 if (class == (wctype_t) 0)
55 fprintf (stderr, "%s %s: noexistent class %s\n", program_name,
56 locale, class_name);
57 return;
60 f = fopen (class_name, "w");
61 if (f == NULL)
63 fprintf (stderr, "%s %s: cannot open file %s/%s\n", program_name,
64 locale, locale, class_name);
65 exit (1);
68 for (ch = 0; ch < 0x10000; ch++)
69 if (iswctype (ch, class))
70 fprintf (f, "0x%04X\n", ch);
72 if (ferror (f) || fclose (f))
74 fprintf (stderr, "%s %s: I/O error on file %s/%s\n", program_name,
75 locale, locale, class_name);
76 exit (1);
80 static void dump_map (const char *map_name)
82 wctrans_t map;
83 FILE *f;
84 unsigned int ch;
86 map = wctrans (map_name);
87 if (map == (wctrans_t) 0)
89 fprintf (stderr, "%s %s: noexistent map %s\n", program_name,
90 locale, map_name);
91 return;
94 f = fopen (map_name, "w");
95 if (f == NULL)
97 fprintf (stderr, "%s %s: cannot open file %s/%s\n", program_name,
98 locale, locale, map_name);
99 exit (1);
102 for (ch = 0; ch < 0x10000; ch++)
103 if (towctrans (ch, map) != ch)
104 fprintf (f, "0x%04X\t0x%04X\n", ch, towctrans (ch, map));
106 if (ferror (f) || fclose (f))
108 fprintf (stderr, "%s %s: I/O error on file %s/%s\n", program_name,
109 locale, locale, map_name);
110 exit (1);
115 main (int argc, char *argv[])
117 size_t i;
119 if (argc != 2)
121 fprintf (stderr, "Usage: dump-ctype locale\n");
122 exit (1);
124 locale = argv[1];
126 if (setlocale (LC_ALL, locale) == NULL)
128 fprintf (stderr, "%s: setlocale cannot switch to locale %s\n",
129 program_name, locale);
130 exit (1);
133 if (mkdir (locale, 0777) < 0)
135 char buf[100];
136 int save_errno = errno;
138 sprintf (buf, "%s: cannot create directory %s", program_name, locale);
139 errno = save_errno;
140 perror (buf);
141 exit (1);
144 if (chdir (locale) < 0)
146 char buf[100];
147 int save_errno = errno;
149 sprintf (buf, "%s: cannot chdir to %s", program_name, locale);
150 errno = save_errno;
151 perror (buf);
152 exit (1);
155 for (i = 0; i < sizeof (class_names) / sizeof (class_names[0]); i++)
156 dump_class (class_names[i]);
158 for (i = 0; i < sizeof (map_names) / sizeof (map_names[0]); i++)
159 dump_map (map_names[i]);
161 return 0;