make_msgs.sh 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "../lang_backup/language_$1.h" | sed "s/[ \t]*\+//;s/^\+ #/#/;s/^\+#/#/" | grep -E "^#define" >"msgs_$1.txt_0"
  68. cat "msgs_$1.txt_0" | sed "s/(length = [0-9]*)//" | sed "s/(length = [0-9]*, lines = [0-9]*)//" > "msgs_$1.txt_1"
  69. cat "msgs_$1.txt_1" | sed -E "s/^#define[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\1 \2/g" | sort >"msgs_$1.txt"
  70. #calculate msgcount
  71. msgcount=$(grep -c '' "msgs_$1.txt")
  72. #calculate charcount
  73. charcount=$(calc_charcount "msgs_$1.txt" 2)
  74. #remove tmp files
  75. rm "msgs_$1.txt_0"
  76. rm "msgs_$1.txt_1"
  77. echo "ok ($msgcount messages, $charcount characters)" | tee -a make_msgs.out
  78. }
  79. #process_language_common
  80. #process_language_en
  81. #process_language_xx cz
  82. process_language_xx de
  83. #process_language_xx it
  84. #process_language_xx pl
  85. #process_language_xx es
  86. echo "make_msgs.sh finished... press key"
  87. read