4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-19 04:49:25 +08:00
newlib-cygwin/winsup/cygwin/linux-locale-helpers/fetch-lc-def-codesets-from-linux
Corinna Vinschen 5011c8cc48 Cygwin: fetch-lc-def-codesets-from-linux: fix locale name handling
As the former call to `locale -av' has the unwanted side effect
to shorten the locale name to <= 15 chars, don't use it.  Use
`locale -a' instead and fetch the codeset from another call to
`locale' for each locale.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-26 20:14:54 +01:00

26 lines
725 B
Bash
Executable File

#!/bin/bash
(
cat <<-EOF
/* This struct of default codesets has been generated by fetching
locale data from a Linux system using $(rpm -q glibc | head -1) on $(date +%F) */
struct default_codeset_t
{
const char *locale;
const char *codeset;
} default_codeset[] =
{
EOF
locale -a | \
awk '{
if ( index ($1, "_") == 0 ) next # No aliases
if ( index ($1, ".") > 0 ) next # No explicit codesets
locale = $1
cmd = "LC_CTYPE=" locale " locale -ck LC_CTYPE | grep charmap"
cmd | getline codeset
codeset = gensub (/charmap="(.*)"/, "\\1", 1, codeset)
codeset = gensub (/BIG5.*/, "BIG5", 1, codeset);
printf " { \"%s\", \"%s\" },\n", locale, codeset;
}'
echo "};"
) > lc_def_codesets.h