Advertisement
puneet

astyle-aslkimia.sh

Jul 10th, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # apply alkimia coding style (kdelibs coding style with 2 spaces
  4. # indentation) to all c, cpp and header files
  5. # in and below the current directory
  6. #
  7. # the coding style is defined in http://techbase.kde.org/Policies/Kdelibs_Coding_Style
  8. #
  9. # requirements: installed astyle
  10.  
  11. IFS=:
  12. for path in $PATH; do
  13. if test -x $path/astyle; then
  14. # determine version of AStyle
  15. VER=`$path/astyle --version 2>&1 | cut -d' ' -f4`
  16.  
  17. # there was an option change between 1.22 and 1.23
  18. # we default to the newer version here as this is the future
  19. case $VER in
  20. 1.2[1-2])
  21. PAD="pad=oper"
  22. UNPAD="unpad=paren"
  23. ONELINE="one-line=keep-statements"
  24. ;;
  25. *)
  26. PAD="pad-oper"
  27. UNPAD="unpad-paren"
  28. ONELINE="keep-one-line-statements"
  29. ;;
  30. esac
  31.  
  32. # run astyle with options on the set of files
  33. find . -path \*/build -prune -o -type f \( -name \*.c -or -name \*.cpp -or -name \*.h \) -exec $path/astyle --indent=spaces=2 --brackets=linux \
  34. --indent-labels --${PAD} --${UNPAD} \
  35. --${ONELINE} --convert-tabs \
  36. --indent-switches --indent-cases \
  37. --indent-preprocessor {} \;
  38.  
  39. # process the same set of files to replace "foreach(" with "foreach ("
  40. find . -path \*/build -prune -o -type f \( -name \*.c -or -name \*.cpp -or -name \*.h \) | while read a; do
  41. if test ! -d $a; then
  42. sed -e "s/foreach(/foreach (/" $a > $a.tmp
  43. diff $a $a.tmp > /dev/null
  44. if test $? -ne 0; then
  45. echo "formatted "$a
  46. mv $a.tmp $a
  47. else
  48. echo "unchanged* "$a
  49. rm $a.tmp
  50. fi
  51. fi
  52. done
  53.  
  54. exit $?
  55. fi
  56. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement