indent.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2015 Marcus Rohrmoser http://mro.name/me. All rights reserved.
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. if [ ! -e "$UNCRUSTIFY" ] ; then
  19. UNCRUSTIFY=$(which uncrustify | head -n 1)
  20. fi
  21. if [ ! -e "$UNCRUSTIFY" ] ; then
  22. # use most recent
  23. UNCRUSTIFY=$(ls -t /Applications/UniversalIndentGUI*/indenters/uncrustify | head -n 1)
  24. fi
  25. if [ ! -e "$UNCRUSTIFY" ] ; then
  26. echo "I cannot find uncrustify. Please install e.g. from" >&2
  27. echo "\n http://sourceforge.net/projects/uncrustify/files/uncrustify/uncrustify-0.59/uncrustify-0.59-osx-64bit.zip/download" >&2
  28. echo "\n http://universalindent.sourceforge.net/" >&2
  29. echo "\ninto 'Applications', or set" >&2
  30. echo "\n export UNCRUSTIFY=..." >&2
  31. echo "\nto point to the location you installed it to." >&2
  32. exit 1
  33. fi
  34. echo "Found $($UNCRUSTIFY --version) at $UNCRUSTIFY" >&2
  35. cd `dirname $0`/..
  36. if [[ "$@" == "" ]]
  37. then
  38. echo "Got no files on commandline (which is fine), so I'll format those:"
  39. PROJECT_SOURCE=$(find Sha* \( -name "*.m" -or -name "*.c" -or -name "*.h" \) ; find Today \( -name "*.m" -or -name "*.c" -or -name "*.h" \) )
  40. else
  41. PROJECT_SOURCE="$@"
  42. fi
  43. if [[ "$UNCRUSTIFY_OPTS" == "" ]] ; then
  44. UNCRUSTIFY_OPTS="-l OC --replace --no-backup -c tools/uncrustify.cfg"
  45. fi
  46. "$UNCRUSTIFY" $UNCRUSTIFY_OPTS $PROJECT_SOURCE 2>&1
  47. for file2indent in $PROJECT_SOURCE ; do
  48. # http://code.google.com/p/core-plot/source/browse/scripts/format_core_plot.sh?spec=svn3daea3e540f8571d6e99b2cbfb832a88f0777d79&r=3daea3e540f8571d6e99b2cbfb832a88f0777d79
  49. # remove spaces before category names to keep Doxygen 1.6.0+ happy
  50. cp -p "$file2indent" .indent.tmp
  51. cat .indent.tmp | sed "s|\(@interface .*\) \((.*)\)|\1\2|g" | sed "s|\(@implementation .*\) \((.*)\)|\1\2|g" > "$file2indent"
  52. touch -r .indent.tmp "$file2indent"
  53. rm .indent.tmp
  54. done