chk_ifdef.sh 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. #
  3. # check the propper syntax of C preprocessor directives.
  4. # for example:
  5. #if defined key_traldf_c3d && key_traldf_smag
  6. # is not good and should be
  7. #if defined key_traldf_c3d && defined key_traldf_smag
  8. #
  9. # use: go to TOOLS/MISCELLANEOUS/ and simply execute:
  10. # ./chk_ifdef.sh
  11. #
  12. set -u
  13. #
  14. grep -r "^ *#if" ../../NEMO | grep -v "~:" > tmp$$ # get each lines of the code starting with #if
  15. grep -r "^ *#elif" ../../NEMO | grep -v "~:" >> tmp$$ # get each lines of the code starting with #elif
  16. #
  17. for ll in $( seq 1 $( cat tmp$$ | wc -l ) ) # for each of these lines
  18. do
  19. lll=$( sed -n -e "${ll}p" tmp$$ )
  20. nbdef=$( echo $lll | grep -o defined | wc -l ) # number of occurences of "defined"
  21. nband=$( echo $lll | grep -o "&&" | wc -l ) # number of occurences of "&&"
  22. nbor=$( echo $lll | grep -o "||" | wc -l ) # number of occurences of "||"
  23. [ $nbdef -ne $(( $nband + $nbor + 1 )) ] && echo $lll # print bad line
  24. done
  25. rm -f tmp$$
  26. #
  27. # add other basic tests
  28. #
  29. grep -ir ":,:.*ji,jj" * | grep -v "~:"
  30. grep -ir "ji,jj.*:,:" * | grep -v "~:"