diff --git a/uncrustify-kf5 b/uncrustify-kf5 --- a/uncrustify-kf5 +++ b/uncrustify-kf5 @@ -1,6 +1,6 @@ #!/bin/sh -# Apply KF5 coding style to all c, cpp and header files in and below the current directory +# Apply KF5, Qt or custom coding style to all c, cpp and header files in and below the current directory # # The coding style is defined in http://techbase.kde.org/Policies/Kdelibs_Coding_Style # @@ -13,24 +13,66 @@ # Documentation of the uncrustify options at http://uncrustify.sourceforge.net/default.cfg # +help() { + echo "`basename $0` [--qt] [--commit] - Apply KF5, Qt or custom coding style to all c, cpp and header files in and below the current directory" + echo "Simply chdir to the directory containing your code and run this program." + echo + echo "Options:" + echo " --qt - use Qt style (default is KDE Frameworks 5 style, which could be overriden by a file uncrustify.cfg in the current directory)" + echo " --commit - commit changes" + echo " --ignore-connects - do not reformat connects" + echo + echo +} + +qt=0 +commit=0 +no_slots=1 +until [ -z "$1" ]; do + case $1 in + --qt) + qt=1 + ;; + --commit) + commit=1 + ;; + --ignore-connects) + ignore_connects=1 + ;; + *) + help + exit 1 + ;; + esac + shift +done + files=`find -type f -name '*.c' -or -name '*.cpp' -or -name '*.cc' -or -name '*.h'` if [ -z "$files" ]; then # nothing to do exit 0 fi -if test -z "$QT_NORMALIZE_TOOL"; then +if test -z "$QT_NORMALIZE_TOOL" && test "$ignore_connects" == "0"; then echo "Please export QT_NORMALIZE_TOOL=/qtrepotools/util/normalize/normalize" exit 1 fi -# Change this to uncrustify-qt.cfg to reformat Qt code (TODO: command-line option?) -cfgfile=uncrustify-kf5.cfg - -cfg=`qtpaths --locate-file GenericDataLocation uncrustify/$cfgfile` -if test -z "$cfg"; then - echo "Config file uncrustify/$cfgfile not found in prefix/share (GenericDataLocation). Check that XDG_DATA_DIRS contains the install prefix for kde-dev-scripts." - exit 1 +cfg=uncrustify.cfg +if ! test -f "$cfg"; then + if test "$qt" == "1"; then + cfgfile=uncrustify-qt.cfg + else + cfgfile=uncrustify-kf5.cfg + fi + cfg=`qtpaths --locate-file GenericDataLocation uncrustify/$cfgfile` + if test -z "$cfg"; then + cfg=$(dirname $0)/$cfgfile + if ! test -f "$cfg"; then + echo "Config file uncrustify/$cfgfile not found in prefix/share (GenericDataLocation) or $(dirname $0). Check that XDG_DATA_DIRS contains the install prefix for kde-dev-scripts." + exit 1 + fi + fi fi uncrustify --no-backup -c "$cfg" $files @@ -78,10 +120,12 @@ EOF # Normalize signals/slots -$QT_NORMALIZE_TOOL --modify . +if test -n "$QT_NORMALIZE_TOOL" && test "$ignore_connects" == "1"; then + $QT_NORMALIZE_TOOL --modify . +fi -# TODO: add command-line option to trigger this -# It's not wanted when working on a fix -#git commit -q -a -m "Code reformatted using kde-dev-scripts/astyle-kdelibs. -#Use git blame -w `git rev-parse --short HEAD` to show authorship as it was before this commit." +if test "$commit" == "1"; then + git commit -q -a -m "Code reformatted using kde-dev-scripts/`basename $0`" +fi +#Use git blame -w `git rev-parse --short HEAD` to show authorship as it was before this commit."