find_msgs.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. #
  3. echo 'find_msgs.sh'
  4. #list all source files from source folder except *language* files
  5. files=$(ls ../Firmware/*.c* | grep -v 'language'; ls ../Firmware/*.h | grep -v 'language'; )
  6. echo ' processing msgs_en.txt and msgs_common.txt...'
  7. #msgs=$(cat msgs_en.txt | cut -f 1 -d' ')
  8. msgs=$(cat msgs_en.txt msgs_common.txt | cut -f 1 -d' ')
  9. #msgs=$(cat msgs_common.txt | cut -f 1 -d' ')
  10. echo "$msgs" | while read msg; do
  11. echo -n "$msg "
  12. found=$(grep -c -E "\b$msg\b" $files | sed "/:0$/d;s/.*:/+/g")
  13. echo $(("0"$found))
  14. done | tee msgs_usage.txt_0
  15. cat msgs_usage.txt_0 | sort -k2 -n >msgs_usage.txt
  16. rm msgs_usage.txt_0
  17. #list messages that are not used
  18. msgs=$(cat msgs_usage.txt | grep " 0$" | cut -f1 -d' ')
  19. #make regular expression from the list - replace spaces with '\b|\b' (match whole words)
  20. msgs='\b'$(echo $msgs | sed "s/ /\\\b\\\|\\\b/g")'\b'
  21. #grep unused messages
  22. cat msgs_en.txt | grep "$msgs" > msgs_en_unused.txt
  23. cat msgs_common.txt | grep "$msgs" > msgs_common_unused.txt
  24. #list messages used once
  25. msgs=$(cat msgs_usage.txt | grep " 1$" | cut -f1 -d' ')
  26. #make regular expression from the list - replace spaces with '\b|\b' (match whole words)
  27. msgs='\b'$(echo $msgs | sed "s/ /\\\b\\\|\\\b/g")'\b'
  28. #grep unused messages
  29. cat msgs_en.txt | grep "$msgs" > msgs_en_used_once.txt
  30. cat msgs_common.txt | grep "$msgs" > msgs_common_used_once.txt
  31. #list messages used once more (exclude unused and used once)
  32. msgs=$(cat msgs_usage.txt | grep -v " 0$" | grep -v " 1$" | cut -f1 -d' ')
  33. #make regular expression from the list - replace spaces with '\b|\b' (match whole words)
  34. msgs='\b'$(echo $msgs | sed "s/ /\\\b\\\|\\\b/g")'\b'
  35. #grep unused messages
  36. cat msgs_en.txt | grep "$msgs" > msgs_en_used_more.txt
  37. cat msgs_common.txt | grep "$msgs" > msgs_common_used_more.txt
  38. echo "step2 finished... press key"
  39. read
  40. exit