make_source.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/sh
  2. # make_source.sh - step3 - replace old source files and generate new
  3. if [ -e ./source ]; then
  4. echo 'folder ./source already exists.'
  5. read
  6. exit
  7. fi
  8. #create target folder
  9. echo 'creating target folder...'
  10. mkdir ./source
  11. #list all source files except *language*
  12. files=$(ls ../Firmware/*.c* | grep -v 'language'; ls ../Firmware/*.h | grep -v 'language' )
  13. #copy original source files to target folder
  14. echo 'copying files...'
  15. cp $files ./source/
  16. #list all source files in target folder
  17. files=$(ls ./source/*.c*; ls ./source/*.h )
  18. #replace source - internatinalized messages used once with _i("TEXT")
  19. echo 'processing msgs_en_used_once.txt'
  20. cat msgs_en_used_once.txt | sed "s/\\\\/\\\\\\\\/g;s/\//\\\\\\\\\//g" | while read name cols rows text; do
  21. comment="$name $cols $rows"
  22. if sed -i -E "s/(.*)(\b$name\b)(.*)$/\1_i\($text\)\3\/\/\/\/$comment/g" $files; then
  23. echo "$name OK"
  24. else
  25. echo "$name NG!"
  26. fi
  27. done | tee replace_en.out
  28. #replace source - not internatinalized messages used once with _n("TEXT")
  29. echo 'processing msgs_common_used_once.txt'
  30. cat msgs_common_used_once.txt | sed "s/\\\\/\\\\\\\\/g;s/\//\\\\\\\\\//g" | while read name cols rows text; do
  31. comment="$name $cols $rows"
  32. if sed -i -E "s/(.*)(\b$name\b)(.*)$/\1_n\($text\)\3\/\/\/\/$comment/g" $files; then
  33. echo "$name OK"
  34. else
  35. echo "$name NG!"
  36. fi
  37. done | tee replace_common.out
  38. #messages used twice or more will be listed in messages.h and messages.c.
  39. cp ./src/messages.h ./source/
  40. cp ./src/messages.c ./source/
  41. echo '//internationalized messages' | tee -a ./source/messages.h >> ./source/messages.c
  42. cat msgs_en_used_more.txt | sed 's/\\/\\\\/g' | while read msg cols rows text; do
  43. comment="$cols $rows"
  44. echo "extern const char $msg[];" >> ./source/messages.h
  45. echo "const char $msg[] PROGMEM_I1 = ISTR("$text"); ////$comment" >> ./source/messages.c
  46. echo "$msg"
  47. done
  48. echo '//not internationalized messages' | tee -a ./source/messages.h >> ./source/messages.c
  49. cat msgs_common_used_more.txt | sed 's/\\/\\\\/g' | while read msg cols rows text; do
  50. comment="$cols $rows"
  51. echo "extern const char $msg[];" >> ./source/messages.h
  52. echo "const char $msg[] PROGMEM_N1 = "$text"; ////$comment" >> ./source/messages.c
  53. echo "$msg"
  54. done
  55. #copy new source files
  56. cp ./src/language.h ./source/
  57. cp ./src/language.c ./source/
  58. cp ./src/config.h ./source/
  59. #replace line with declaration in Marlin_main.cpp
  60. sed -i -E "s/^(unsigned char lang_selected = 0;)/\/\/\1/" ./source/Marlin_main.cpp
  61. echo "step3 finished... press key"
  62. read
  63. exit