indent.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2014-2015, Marcus Rohrmoser mobile Software, http://mro.name/me
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without modification, are permitted
  7. # provided that the following conditions are met:
  8. #
  9. # 1. Redistributions of source code must retain the above copyright notice, this list of conditions
  10. # and the following disclaimer.
  11. #
  12. # 2. The software must not be used for military or intelligence or related purposes nor
  13. # anything that's in conflict with human rights as declared in http://www.un.org/en/documents/udhr/ .
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  22. # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. #
  24. if [ ! -e "$UNCRUSTIFY" ] ; then
  25. UNCRUSTIFY=$(which uncrustify | head -n 1)
  26. fi
  27. if [ ! -e "$UNCRUSTIFY" ] ; then
  28. # use most recent
  29. UNCRUSTIFY=$(ls -t /Applications/UniversalIndentGUI*/indenters/uncrustify | head -n 1)
  30. fi
  31. if [ ! -e "$UNCRUSTIFY" ] ; then
  32. echo "I cannot find uncrustify. Please install e.g. from" >&2
  33. echo "\n http://sourceforge.net/projects/uncrustify/files/uncrustify/uncrustify-0.59/uncrustify-0.59-osx-64bit.zip/download" >&2
  34. echo "\n http://universalindent.sourceforge.net/" >&2
  35. echo "\ninto 'Applications', or set" >&2
  36. echo "\n export UNCRUSTIFY=..." >&2
  37. echo "\nto point to the location you installed it to." >&2
  38. exit 1
  39. fi
  40. echo "Found $($UNCRUSTIFY --version) at $UNCRUSTIFY" >&2
  41. cd `dirname $0`/..
  42. if [[ "$@" == "" ]]
  43. then
  44. echo "Got no files on commandline (which is fine), so I'll format those:"
  45. # PROJECT_SOURCE=$(find Classes* -name "*.m" -or -name "*.h")
  46. PROJECT_SOURCE=$(ls *_mro.? */*.h */*.c)
  47. else
  48. PROJECT_SOURCE="$@"
  49. fi
  50. if [[ "$UNCRUSTIFY_OPTS" == "" ]] ; then
  51. UNCRUSTIFY_OPTS="-l C --replace --no-backup -c tools/uncrustify.cfg"
  52. fi
  53. "$UNCRUSTIFY" $UNCRUSTIFY_OPTS $PROJECT_SOURCE 2>&1
  54. for file2indent in $PROJECT_SOURCE ; do
  55. # http://code.google.com/p/core-plot/source/browse/scripts/format_core_plot.sh?spec=svn3daea3e540f8571d6e99b2cbfb832a88f0777d79&r=3daea3e540f8571d6e99b2cbfb832a88f0777d79
  56. # remove spaces before category names to keep Doxygen 1.6.0+ happy
  57. cp -p "$file2indent" .indent.tmp
  58. cat .indent.tmp | sed "s|\(@interface .*\) \((.*)\)|\1\2|g" | sed "s|\(@implementation .*\) \((.*)\)|\1\2|g" > "$file2indent"
  59. touch -r .indent.tmp "$file2indent"
  60. rm .indent.tmp
  61. done