astyle.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. ###########################################################################
  3. # astyle.sh
  4. # ---------------------
  5. # Date : August 2008
  6. # Copyright : (C) 2008 by Juergen E. Fischer
  7. # Email : jef at norbit dot de
  8. ###########################################################################
  9. # #
  10. # This program is free software; you can redistribute it and/or modify #
  11. # it under the terms of the GNU General Public License as published by #
  12. # the Free Software Foundation; either version 2 of the License, or #
  13. # (at your option) any later version. #
  14. # #
  15. ###########################################################################
  16. for ASTYLE in ${OPJSTYLE} $(dirname $0)/opjstyle $(dirname $0)/RelWithDebInfo/opjstyle
  17. do
  18. if type -p $ASTYLE >/dev/null; then
  19. break
  20. fi
  21. ASTYLE=
  22. done
  23. if [ -z "$ASTYLE" ]; then
  24. echo "opjstyle not found - please enable WITH_ASTYLE in cmake and build it" >&2
  25. exit 1
  26. fi
  27. if type -p tput >/dev/null; then
  28. elcr="$ASTYLEPROGRESS$(tput el)$(tput cr)"
  29. else
  30. elcr="$ASTYLEPROGRESS \r"
  31. fi
  32. if ! type -p flip >/dev/null; then
  33. if type -p dos2unix >/dev/null; then
  34. flip() {
  35. dos2unix -k $2
  36. }
  37. else
  38. echo "flip not found" >&2
  39. flip() {
  40. :
  41. }
  42. fi
  43. fi
  44. if ! type -p autopep8 >/dev/null; then
  45. echo "autopep8 not found" >&2
  46. autopep8() {
  47. :
  48. }
  49. fi
  50. ASTYLEOPTS=$(dirname $0)/astyle.options
  51. if type -p cygpath >/dev/null; then
  52. ASTYLEOPTS="$(cygpath -w $ASTYLEOPTS)"
  53. fi
  54. set -e
  55. astyleit() {
  56. $ASTYLE --options="$ASTYLEOPTS" "$1"
  57. #modified=$1.unify_includes_modified
  58. #cp "$1" "$modified"
  59. #scripts/unify_includes.pl "$modified"
  60. #scripts/doxygen_space.pl "$modified"
  61. #diff "$1" "$modified" >/dev/null || mv "$modified" "$1"
  62. #rm -f "$modified"
  63. }
  64. for f in "$@"; do
  65. case "$f" in
  66. thirdparty/*)
  67. echo -ne "$f skipped $elcr"
  68. continue
  69. ;;
  70. *.cpp|*.h|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.hpp)
  71. if [ -x "$f" ]; then
  72. chmod a-x "$f"
  73. fi
  74. cmd=astyleit
  75. ;;
  76. *.py)
  77. #cmd="autopep8 --in-place --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701"
  78. echo -ne "Formatting $f $elcr"
  79. cmd="autopep8 --in-place --ignore=E261,E265,E402,E501"
  80. ;;
  81. *)
  82. echo -ne "$f skipped $elcr"
  83. continue
  84. ;;
  85. esac
  86. if ! [ -f "$f" ]; then
  87. echo "$f not found" >&2
  88. continue
  89. fi
  90. if [[ -f $f && `head -c 3 $f` == $'\xef\xbb\xbf' ]]; then
  91. mv $f $f.bom
  92. tail -c +4 $f.bom > $f
  93. echo "removed BOM from $f"
  94. fi
  95. modified=$f.flip_modified
  96. cp "$f" "$modified"
  97. flip -ub "$modified"
  98. diff "$f" "$modified" >/dev/null || mv "$modified" "$f"
  99. rm -f "$modified"
  100. eval "$cmd '$f'"
  101. done