2018-06-18 17:37:20 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# lang-build.sh - multi-language support script
|
|
|
|
# generate lang_xx.bin (language binary file)
|
|
|
|
#
|
|
|
|
# Input files:
|
2018-06-19 21:18:26 +00:00
|
|
|
# lang_en.txt or lang_en_xx.txt
|
|
|
|
#
|
2018-06-18 17:37:20 +00:00
|
|
|
# Output files:
|
2018-06-19 21:18:26 +00:00
|
|
|
# lang_xx.bin
|
2018-06-18 17:37:20 +00:00
|
|
|
#
|
2018-06-19 21:18:26 +00:00
|
|
|
# Temporary files:
|
|
|
|
# lang_xx.tmp
|
|
|
|
# lang_xx.dat
|
2018-06-18 17:37:20 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
#awk code to format ui16 variables for dd
|
|
|
|
awk_ui16='{ h=int($1/256); printf("\\x%02x\\x%02x\n", int($1-256*h), h); }'
|
|
|
|
|
2018-06-19 21:18:26 +00:00
|
|
|
#startup message
|
|
|
|
echo "lang-build.sh started" >&2
|
|
|
|
|
2018-06-18 17:37:20 +00:00
|
|
|
#exiting function
|
|
|
|
finish()
|
|
|
|
{
|
|
|
|
if [ $1 -eq 0 ]; then
|
2018-06-19 21:18:26 +00:00
|
|
|
echo "lang-build.sh finished with success" >&2
|
2018-06-18 17:37:20 +00:00
|
|
|
else
|
2018-06-19 21:18:26 +00:00
|
|
|
echo "lang-build.sh finished with errors!" >&2
|
2018-06-18 17:37:20 +00:00
|
|
|
fi
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
#returns hexadecial data for lang code
|
2018-06-19 21:18:26 +00:00
|
|
|
lang_code_hex_data()
|
2018-06-18 17:37:20 +00:00
|
|
|
# $1 - language code ('en', 'cz'...)
|
|
|
|
{
|
|
|
|
case "$1" in
|
|
|
|
*en*) echo '\x6e\x65' ;;
|
|
|
|
*cz*) echo '\x73\x63' ;;
|
|
|
|
*de*) echo '\x65\x64' ;;
|
|
|
|
*es*) echo '\x73\x65' ;;
|
|
|
|
*fr*) echo '\x72\x66' ;;
|
|
|
|
*it*) echo '\x74\x69' ;;
|
|
|
|
*pl*) echo '\x6c\x70' ;;
|
|
|
|
esac
|
|
|
|
echo '??'
|
|
|
|
}
|
|
|
|
|
|
|
|
write_header()
|
|
|
|
# $1 - lang
|
|
|
|
# $2 - size
|
|
|
|
# $3 - count
|
|
|
|
# $4 - checksum
|
|
|
|
# $5 - signature
|
|
|
|
{
|
|
|
|
/bin/echo -n -e "\xa5\x5a\xb4\x4b" |\
|
|
|
|
dd of=lang_$1.bin bs=1 count=4 seek=0 conv=notrunc 2>/dev/null
|
|
|
|
/bin/echo -n -e $(echo -n "$(($2))" | awk "$awk_ui16") |\
|
|
|
|
dd of=lang_$1.bin bs=1 count=2 seek=4 conv=notrunc 2>/dev/null
|
|
|
|
/bin/echo -n -e $(echo -n "$(($3))" | awk "$awk_ui16") |\
|
|
|
|
dd of=lang_$1.bin bs=1 count=2 seek=6 conv=notrunc 2>/dev/null
|
|
|
|
/bin/echo -n -e $(echo -n "$(($4))" | awk "$awk_ui16") |\
|
|
|
|
dd of=lang_$1.bin bs=1 count=2 seek=8 conv=notrunc 2>/dev/null
|
2018-06-19 21:18:26 +00:00
|
|
|
/bin/echo -n -e "$(lang_code_hex_data $1)" |\
|
2018-06-18 17:37:20 +00:00
|
|
|
dd of=lang_$1.bin bs=1 count=2 seek=10 conv=notrunc 2>/dev/null
|
|
|
|
sig_h=$(($5 / 65536))
|
|
|
|
/bin/echo -n -e $(echo -n "$sig_h" | awk "$awk_ui16") |\
|
|
|
|
dd of=lang_$1.bin bs=1 count=2 seek=14 conv=notrunc 2>/dev/null
|
|
|
|
sig_l=$(($5 - $sig_h * 65536))
|
|
|
|
/bin/echo -n -e $(echo -n "$sig_l" | awk "$awk_ui16") |\
|
|
|
|
dd of=lang_$1.bin bs=1 count=2 seek=12 conv=notrunc 2>/dev/null
|
|
|
|
}
|
|
|
|
|
2018-06-19 21:18:26 +00:00
|
|
|
generate_binary()
|
|
|
|
# $1 - language code ('en', 'cz'...)
|
2018-06-18 17:37:20 +00:00
|
|
|
{
|
2018-06-19 21:18:26 +00:00
|
|
|
echo "lang="$1 >&2
|
|
|
|
#remove output and temporary files
|
|
|
|
rm -f lang_$1.bin
|
|
|
|
rm -f lang_$1.tmp
|
|
|
|
rm -f lang_$1.dat
|
2018-06-18 17:37:20 +00:00
|
|
|
LNG=$1
|
2019-05-07 10:57:31 +00:00
|
|
|
#check lang dictionary
|
|
|
|
/usr/bin/env python lang-check.py $1
|
2018-06-18 17:37:20 +00:00
|
|
|
#create lang_xx.tmp - different processing for 'en' language
|
2018-06-19 21:18:26 +00:00
|
|
|
if [ "$1" = "en" ]; then
|
2018-06-18 17:37:20 +00:00
|
|
|
#remove comments and empty lines
|
|
|
|
cat lang_en.txt | sed '/^$/d;/^#/d'
|
|
|
|
else
|
|
|
|
#remove comments and empty lines, print lines with translated text only
|
2018-06-19 21:18:26 +00:00
|
|
|
cat lang_en_$1.txt | sed '/^$/d;/^#/d' | sed -n 'n;p'
|
|
|
|
fi | sed 's/^\"\\x00\"$/\"\"/' > lang_$1.tmp
|
2018-06-18 17:37:20 +00:00
|
|
|
#create lang_xx.dat (binary text data file)
|
2018-06-21 16:59:11 +00:00
|
|
|
# cat lang_$1.tmp | sed 's/^\"/\/bin\/echo -e \"/;s/"$/\\x00\"/' > lang_$1.shx
|
2018-06-21 23:27:33 +00:00
|
|
|
cat lang_$1.tmp | sed 's/^\"/\/bin\/echo -e -n \"/;s/"$/\\x00\"/' | sh >lang_$1.dat
|
2018-06-18 17:37:20 +00:00
|
|
|
#calculate number of strings
|
2018-06-19 21:18:26 +00:00
|
|
|
count=$(grep -c '^"' lang_$1.tmp)
|
|
|
|
echo "count="$count >&2
|
2018-06-18 17:37:20 +00:00
|
|
|
#calculate text data offset
|
|
|
|
offs=$((16 + 2 * $count))
|
2018-06-19 21:18:26 +00:00
|
|
|
echo "offs="$offs >&2
|
2018-06-18 17:37:20 +00:00
|
|
|
#calculate text data size
|
2018-06-19 21:18:26 +00:00
|
|
|
size=$(($offs + $(wc -c lang_$1.dat | cut -f1 -d' ')))
|
|
|
|
echo "size="$size >&2
|
2018-06-18 17:37:20 +00:00
|
|
|
#write header with empty signature and checksum
|
2018-06-19 21:18:26 +00:00
|
|
|
write_header $1 $size $count 0x0000 0x00000000
|
2018-06-18 17:37:20 +00:00
|
|
|
#write offset table
|
2018-06-19 21:18:26 +00:00
|
|
|
offs_hex=$(cat lang_$1.tmp | sed 's/^\"//;s/\"$//' |\
|
2018-06-18 17:37:20 +00:00
|
|
|
sed 's/\\x[0-9a-f][0-9a-f]/\./g;s/\\[0-7][0-7][0-7]/\./g;s/\ /\./g' |\
|
2018-06-19 21:18:26 +00:00
|
|
|
awk 'BEGIN { o='$offs';} { h=int(o/256); printf("\\x%02x\\x%02x",int(o-256*h), h); o+=(length($0)+1); }')
|
|
|
|
/bin/echo -n -e "$offs_hex" | dd of=./lang_$1.bin bs=1 seek=16 conv=notrunc 2>/dev/null
|
2018-06-18 17:37:20 +00:00
|
|
|
#write binary text data
|
2018-06-19 21:18:26 +00:00
|
|
|
dd if=./lang_$1.dat of=./lang_$1.bin bs=1 seek=$offs conv=notrunc 2>/dev/null
|
|
|
|
#write signature
|
|
|
|
if [ "$1" != "en" ]; then
|
|
|
|
dd if=lang_en.bin of=lang_$1.bin bs=1 count=4 skip=6 seek=12 conv=notrunc 2>/dev/null
|
|
|
|
fi
|
2018-06-18 17:37:20 +00:00
|
|
|
#calculate and update checksum
|
2018-06-19 21:18:26 +00:00
|
|
|
chsum=$(cat lang_$1.bin | xxd | cut -c11-49 | tr ' ' "\n" | sed '/^$/d' | awk 'BEGIN { sum = 0; } { sum += strtonum("0x"$1); if (sum > 0xffff) sum -= 0x10000; } END { printf("%x\n", sum); }')
|
2018-06-18 17:37:20 +00:00
|
|
|
/bin/echo -n -e $(echo -n $((0x$chsum)) | awk "$awk_ui16") |\
|
2018-06-19 21:18:26 +00:00
|
|
|
dd of=lang_$1.bin bs=1 count=2 seek=8 conv=notrunc 2>/dev/null
|
2018-06-18 17:37:20 +00:00
|
|
|
#remove temporary files
|
2018-06-21 16:59:11 +00:00
|
|
|
# rm -f lang_$1.tmp
|
|
|
|
# rm -f lang_$1.dat
|
2018-06-18 17:37:20 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 21:18:26 +00:00
|
|
|
if [ -z "$1" ]; then set 'all'; fi
|
2018-06-18 17:37:20 +00:00
|
|
|
|
2018-06-19 21:18:26 +00:00
|
|
|
if [ "$1" = "all" ]; then
|
|
|
|
generate_binary 'en'
|
|
|
|
generate_binary 'cz'
|
|
|
|
generate_binary 'de'
|
|
|
|
generate_binary 'es'
|
2018-10-18 11:08:41 +00:00
|
|
|
generate_binary 'fr'
|
2018-06-19 21:18:26 +00:00
|
|
|
generate_binary 'it'
|
|
|
|
generate_binary 'pl'
|
2018-06-18 17:37:20 +00:00
|
|
|
else
|
2018-06-19 21:18:26 +00:00
|
|
|
generate_binary $1
|
2018-06-18 17:37:20 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
finish 0
|