lang-check.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/sh
  2. #
  3. # lang_check.sh - multi-language support script
  4. # check lang_xx.bin (language binary file)
  5. #
  6. # Input files:
  7. # lang_$1.bin
  8. # lang_en.txt or lang_en_$1.txt
  9. #
  10. #
  11. #set 'cz'
  12. #dictionary txt file
  13. fn_t=lang_en_$1.txt
  14. if [ "$1" = "en" ]; then fn_t=lang_en.txt; fi
  15. #binary file to check
  16. fn_b=lang_$1.bin
  17. #check txt dictionary file
  18. echo -n "dictionary file: $fn_t"
  19. if [ -e $fn_t ]; then echo " - OK"; else echo " - Not found!"; exit 1; fi
  20. #create lang_xx.tmp - different processing for 'en' language
  21. if [ "$1" = "en" ]; then
  22. #remove comments and empty lines
  23. cat lang_en.txt | sed '/^$/d;/^#/d'
  24. else
  25. #remove comments and empty lines, print lines with translated text only
  26. cat lang_en_$1.txt | sed '/^$/d;/^#/d' | sed -n 'n;p'
  27. fi | sed 's/^\"\\x00\"$/\"\"/' > lang_$1.tmp
  28. count_txt=$(grep -c '^"' lang_$1.tmp)
  29. echo -n "language bin file: $fn_b"
  30. if [ -e $fn_b ]; then echo " - OK"; else echo " - Not found!"; exit 1; fi
  31. #read header and convert to hex
  32. header=$(dd if=$fn_b bs=1 count=16 2>/dev/null | xxd | cut -c11-49 | sed 's/\([0-9a-f][0-9a-f]\)[\ ]*/\1 /g')
  33. echo "header='$header'"
  34. magic=0x$(echo $header | tr -d ' ' | cut -c1-8)
  35. echo "magic='$magic'"
  36. size=$(echo $header | tr -d ' ' | cut -c9-12)
  37. size=0x${size:2:2}${size:0:2}
  38. echo "size='$size' ($(($size)))"
  39. count=$(echo $header | tr -d ' ' | cut -c13-16)
  40. count=0x${count:2:2}${count:0:2}
  41. echo "count='$count' ($(($count)))"
  42. o=0
  43. l=0
  44. #create lang_xx_1.tmp (temporary text file from binary data)
  45. (dd if=$fn_b bs=1 count=$((2*$count)) skip=16 2>/dev/null | xxd | cut -c11-49 | tr ' ' "\n" |\
  46. sed 's/\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)/\2\1 /g;/^$/d'; printf "%04x\n" $(($size)) ) |\
  47. while read offs; do
  48. if [ $o -ne 0 ]; then
  49. l=$((0x$offs - $o))
  50. echo -n '"'
  51. dd if=$fn_b bs=1 count=$((l-1)) skip=$o 2>/dev/null
  52. echo '"'
  53. fi
  54. o=$((0x$offs))
  55. done > lang_$1_1.tmp
  56. #create lang_xx_2.tmp (temporary text file from dictionary)
  57. cat lang_$1.tmp | sed 's/^\"/printf \"\\x22/;s/"$/\\x22\\x0a\"/' | sh >lang_$1_2.tmp
  58. #compare temporary files
  59. diff lang_$1_2.tmp lang_$1_2.tmp >lang_$1_check.dif
  60. dif=$(cat lang_$1_check.dif)
  61. if [ -z "$dif" ]; then
  62. echo 'binary data OK'
  63. else
  64. echo 'binary data NG!'
  65. fi
  66. read
  67. exit