make_msgs.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. #
  3. echo 'make_msgs.sh'
  4. if [ -e make_msgs.out ]; then rm make_msgs.out; fi
  5. CUSTOM_MENDEL_NAME='Prusa i3 MK3'
  6. calc_charcount()
  7. {
  8. #extract texts for charcount calculation
  9. cat $1 | cut -f$2- -d' ' | sed -E "s/\" \"//g" >_txt.txt_0
  10. #replace printer name
  11. cat _txt.txt_0 | sed -E "s/CUSTOM_MENDEL_NAME/\"$CUSTOM_MENDEL_NAME\"/g" >_txt.txt_1
  12. #replace oct chars with space
  13. cat _txt.txt_1 | sed -E "s/\\\\[0-7]{3}/ /g" >_txt.txt_2
  14. #replace hex chars with space
  15. cat _txt.txt_2 | sed -E "s/\\\\x[0-9A-Fa-f]{2}/ /g" >_txt.txt_3
  16. #replace \" with '
  17. cat _txt.txt_3 | sed -E "s/\\\\\"/'/g" >_txt.txt_4
  18. #replace "_white_space_" with empty sequence - strigs
  19. cat _txt.txt_4 | sed -E "s/\"[ \t]*\"//g" >_txt.txt_5
  20. #replace " and white space at end of line
  21. cat _txt.txt_5 | sed -E "s/\"[ \t]*$/\"/g" >_txt.txt_6
  22. #replace all " with empty sequence
  23. cat _txt.txt_6 | sed -E "s/\"//g" >_txt.txt_7
  24. #calculate charcount
  25. stat -c'%s' _txt.txt_7
  26. rm _txt.txt_*
  27. }
  28. process_language_common()
  29. {
  30. echo -n ' processing language_common.h ...' | tee -a make_msgs.out
  31. #list all defines without '+' prefix from language_common.h
  32. #cat ../Firmware/language_common.h | grep -E "^[+]*define" | sed "s/lenght/length/g" >msgs_common.txt_0
  33. cat ../Firmware/language_common.h | grep -E "^define" | sed "s/lenght/length/g" >msgs_common.txt_0
  34. #replace define and +define
  35. cat msgs_common.txt_0 | sed -E "s/^[+]*define[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\1 c=0 r=0 \2/g" | sort >msgs_common.txt
  36. #calculate msgcount
  37. msgcount=$(grep -c '' msgs_common.txt)
  38. #calculate charcount
  39. charcount=$(calc_charcount msgs_common.txt 4)
  40. #remove tmp files
  41. rm msgs_common.txt_*
  42. echo "ok ($msgcount messages, $charcount characters)" | tee -a make_msgs.out
  43. }
  44. process_language_en()
  45. {
  46. echo -n ' processing language_en.h ...' | tee -a make_msgs.out
  47. #list all defines from language_en.h
  48. cat ../Firmware/language_en.h | grep "^#define" | sed "s/lenght/length/g" >msgs_en.txt_0
  49. #replace #define(length=xx,lines=xx)
  50. cat msgs_en.txt_0 | sed -E "s/^#define\(length=([0-9]*),[ \t]*lines=([0-9]*)\)[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\3 c=\1 r=\2 \4/g" >msgs_en.txt_1
  51. #replace #define(length=xx)
  52. cat msgs_en.txt_1 | sed -E "s/^#define\(length=([0-9]*)\)[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\2 c=\1 r=0 \3/g" >msgs_en.txt_2
  53. #replace #define
  54. cat msgs_en.txt_2 | sed -E "s/^#define[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\1 c=0 r=0 \2/g" | sort >msgs_en.txt
  55. #calculate msgcount
  56. msgcount=$(grep -c '' msgs_en.txt)
  57. #calculate charcount
  58. charcount=$(calc_charcount msgs_en.txt 4)
  59. #remove tmp files
  60. rm msgs_en.txt_*
  61. echo "ok ($msgcount messages, $charcount characters)" | tee -a make_msgs.out
  62. }
  63. process_language_xx()
  64. {
  65. echo -n " processing language_$1.h ..." | tee -a make_msgs.out
  66. #list all defines from language_cz.h
  67. cat "../Firmware/language_$1.h" | grep "^#define" >"msgs_$1.txt_0"
  68. cat "msgs_$1.txt_0" | sed -E "s/^#define[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\1 \2/g" | sort >"msgs_$1.txt"
  69. #calculate msgcount
  70. msgcount=$(grep -c '' "msgs_$1.txt")
  71. #calculate charcount
  72. charcount=$(calc_charcount "msgs_$1.txt" 2)
  73. #remove tmp files
  74. rm "msgs_$1.txt_0"
  75. echo "ok ($msgcount messages, $charcount characters)" | tee -a make_msgs.out
  76. }
  77. process_language_common
  78. process_language_en
  79. process_language_xx cz
  80. process_language_xx de
  81. process_language_xx it
  82. process_language_xx pl
  83. process_language_xx es
  84. echo "step1 finished... press key"
  85. read