Skip to content
Permalink
Browse files

integrate sorting of includes into astyle.sh/astyle-all.sh/prepare-co…

…mmit.sh
  • Loading branch information
jef-n committed Jun 10, 2015
1 parent a6eb0f5 commit facfe6ec2c215debe99912c1a342da9bc6b32fec
Showing with 81 additions and 23 deletions.
  1. +24 −22 scripts/astyle.sh
  2. +1 −1 scripts/prepare-commit.sh
  3. +56 −0 scripts/sort_includes.pl
@@ -43,27 +43,29 @@ fi

set -e

export ARTISTIC_STYLE_OPTIONS="\
--preserve-date \
--indent-preprocessor \
--brackets=break \
--convert-tabs \
--indent=spaces=2 \
--indent-classes \
--indent-labels \
--indent-namespaces \
--indent-switches \
--one-line=keep-blocks \
--one-line=keep-statements \
--max-instatement-indent=40 \
--min-conditional-indent=-1 \
--suffix=none"

export ARTISTIC_STYLE_OPTIONS="\
$ARTISTIC_STYLE_OPTIONS \
--pad=oper \
--pad=paren-in \
--unpad=paren"
astyleit()
{
scripts/sort_includes.pl "$1"

$ASTYLE \
--preserve-date \
--indent-preprocessor \
--brackets=break \
--convert-tabs \
--indent=spaces=2 \
--indent-classes \
--indent-labels \
--indent-namespaces \
--indent-switches \
--one-line=keep-blocks \
--one-line=keep-statements \
--max-instatement-indent=40 \
--min-conditional-indent=-1 \
--suffix=none \
--pad=oper \
--pad=paren-in \
--unpad=paren "$1"
}

for f in "$@"; do
case "$f" in
@@ -73,7 +75,7 @@ for f in "$@"; do
;;

*.cpp|*.h|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.hpp)
cmd="$ASTYLE $ARTISTIC_STYLE_OPTIONS"
cmd=astyleit
;;

*.ui|*.qgm|*.txt|*.t2t|resources/context_help/*)
@@ -31,7 +31,7 @@ fi

if [ "$1" = "-c" ]; then
echo "Cleaning..."
find . \( -name "*.prepare" -o -name "*.astyle" -o -name "*.nocopyright" -o -name "astyle.*.diff" -o -name "sha-*.diff" \) -print -delete
find . \( -name "*.prepare" -o -name "*.astyle" -o -name "*.nocopyright" -o -name "astyle.*.diff" -o -name "sha-*.diff" -o -name "*.sortinc" \) -print -delete
fi

set -e
@@ -0,0 +1,56 @@
#!/usr/bin/perl -i.sortinc -n
###########################################################################
# sort_includes.pl
# ---------------------
# begin : June 2015
# copyright : (C) 2015 by Juergen E. Fischer
# email : jef at norbit dot de
#
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################

# adapted from scripts/sort_includes.sh

use strict;
use warnings;

our %uis;
our %sys;
our %others;
our $sorting;

BEGIN { $sorting = 0; }
END { die "header files not empty" if keys %uis || keys %sys || keys %others; }

if(/^\s*#include/ ) {
if(/"ui_/ ) {
$uis{$_}=1;
} elsif(/</) {
$sys{$_}=1;
} else {
$others{$_}=1;
}
$sorting=1;
next;
}

if( $sorting ) {
print foreach sort keys %uis;
print foreach sort keys %sys;
print foreach sort keys %others;

undef %uis;
undef %sys;
undef %others;
}


$sorting=0;

print;

3 comments on commit facfe6e

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids replied Jun 10, 2015

not sure but if run on qgsofflineediting.cpp, it will put spatialiate.h before sqlite3.h and it will cause an error in compilation

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids replied Jun 10, 2015

I suppose this makes my script useless, right?

@jef-n

This comment has been minimized.

Copy link
Member Author

@jef-n jef-n replied Jun 10, 2015

well, I meanwhile changed it to just remove duplicate includes - that should be save - otherwise prepare-commit.sh or astyle-all.sh could break stuff.

Please sign in to comment.
You can’t perform that action at this time.