Cygwin: fetch-lc-def-codesets-from-linux: speed up

Drop shell read loop in favor of performing the locale output
evaluation inside a single awk invocation.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2023-02-25 20:15:53 +01:00
parent 6e6111671a
commit a31d4039d0
1 changed files with 12 additions and 34 deletions

View File

@ -10,39 +10,17 @@
} default_codeset[] = } default_codeset[] =
{ {
EOF EOF
while read line locale -av | \
do awk '/^locale:/{
locale=$(echo "${line}" | awk '/^locale:/{ print $2; }') if ( index ($2, "_") == 0 ) next # No aliases
if [ -z "${locale}" ] if ( index ($2, ".") > 0 ) next # No explicit codesets
then locale=$2;
continue }
fi /codeset/ {
# No aliases if ( length (locale) == 0 ) next
idx=$(expr index "${locale}" '_') codeset = gensub (/BIG5.*/, "BIG5", 1, $3);
if [ "${idx}" -eq 0 ] printf " { \"%s\", \"%s\" },\n", locale, codeset;
then locale = "";
continue }'
fi
# No explicit codesets
idx=$(expr index "${locale}" '.')
if [ "${idx}" -ne 0 ]
then
continue
fi
while read line2
do
codeset=$(echo "${line2}" | awk '/codeset/{ print $3; }')
if [ -n "${codeset}" ]
then
# Translate into internal codeset names. */
case "${codeset}" in
BIG5*) codeset="BIG5";;
*) ;;
esac
printf " { \"%s\", \"%s\" },\n" "${locale}" "${codeset}"
break
fi
done
done <<<$(locale -av)
echo "};" echo "};"
) > lc_def_codesets.h ) > lc_def_codesets.h