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-2023 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/>. */
21 $ dump-ctype de_DE.UTF-8
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
)
52 class = wctype (class_name
);
53 if (class == (wctype_t) 0)
55 fprintf (stderr
, "%s %s: noexistent class %s\n", program_name
,
60 f
= fopen (class_name
, "w");
63 fprintf (stderr
, "%s %s: cannot open file %s/%s\n", program_name
,
64 locale
, locale
, class_name
);
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
);
80 static void dump_map (const char *map_name
)
86 map
= wctrans (map_name
);
87 if (map
== (wctrans_t) 0)
89 fprintf (stderr
, "%s %s: noexistent map %s\n", program_name
,
94 f
= fopen (map_name
, "w");
97 fprintf (stderr
, "%s %s: cannot open file %s/%s\n", program_name
,
98 locale
, locale
, map_name
);
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
);
115 main (int argc
, char *argv
[])
121 fprintf (stderr
, "Usage: dump-ctype locale\n");
126 if (setlocale (LC_ALL
, locale
) == NULL
)
128 fprintf (stderr
, "%s: setlocale cannot switch to locale %s\n",
129 program_name
, locale
);
133 if (mkdir (locale
, 0777) < 0)
136 int save_errno
= errno
;
138 sprintf (buf
, "%s: cannot create directory %s", program_name
, locale
);
144 if (chdir (locale
) < 0)
147 int save_errno
= errno
;
149 sprintf (buf
, "%s: cannot chdir to %s", program_name
, locale
);
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
]);