indent.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2010-2015, Marcus Rohrmoser mobile Software
  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 MROGeometry* \( -name "*.m" -or -name "*.c" -or -name "*.h" \) -and -not -name "*Parser.m")
  46. else
  47. PROJECT_SOURCE="$@"
  48. fi
  49. if [[ "$UNCRUSTIFY_OPTS" == "" ]] ; then
  50. UNCRUSTIFY_OPTS="-l OC --replace --no-backup -c tools/uncrustify.cfg"
  51. fi
  52. "$UNCRUSTIFY" $UNCRUSTIFY_OPTS $PROJECT_SOURCE 2>&1
  53. for file2indent in $PROJECT_SOURCE ; do
  54. # http://code.google.com/p/core-plot/source/browse/scripts/format_core_plot.sh?spec=svn3daea3e540f8571d6e99b2cbfb832a88f0777d79&r=3daea3e540f8571d6e99b2cbfb832a88f0777d79
  55. # remove spaces before category names to keep Doxygen 1.6.0+ happy
  56. cp -p "$file2indent" .indent.tmp
  57. cat .indent.tmp | sed "s|\(@interface .*\) \((.*)\)|\1\2|g" | sed "s|\(@implementation .*\) \((.*)\)|\1\2|g" > "$file2indent"
  58. touch -r .indent.tmp "$file2indent"
  59. rm .indent.tmp
  60. done