format.sh 640 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/sh
  2. #
  3. # format.sh
  4. #
  5. # run clang-format on each .c & .h file
  6. #
  7. # assumes git tree is clean when reporting status
  8. if [ -z "${CLANG_FORMAT}" ]; then
  9. CLANG_FORMAT=clang-format
  10. fi
  11. a=`git ls-files '*.h' '*.c'`
  12. for x in $a; do
  13. if [ $x != "config_in.h" ]; then
  14. $CLANG_FORMAT -i -style=file $x
  15. fi
  16. done
  17. m=`git ls-files -m`
  18. if [ -n "$m" ]; then
  19. v=`$CLANG_FORMAT -version`
  20. echo "Fromatting required when checking with $v"
  21. echo
  22. echo "The following files required formatting:"
  23. for f in $m; do
  24. echo $f
  25. done
  26. if [ "$1" = "-d" ]; then
  27. echo
  28. git diff
  29. fi
  30. exit 1
  31. fi
  32. exit 0