Skip to content

Commit facfe6e

Browse files
committedJun 10, 2015
integrate sorting of includes into astyle.sh/astyle-all.sh/prepare-commit.sh
1 parent a6eb0f5 commit facfe6e

File tree

3 files changed

+81
-23
lines changed

3 files changed

+81
-23
lines changed
 

‎scripts/astyle.sh

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,29 @@ fi
4343

4444
set -e
4545

46-
export ARTISTIC_STYLE_OPTIONS="\
47-
--preserve-date \
48-
--indent-preprocessor \
49-
--brackets=break \
50-
--convert-tabs \
51-
--indent=spaces=2 \
52-
--indent-classes \
53-
--indent-labels \
54-
--indent-namespaces \
55-
--indent-switches \
56-
--one-line=keep-blocks \
57-
--one-line=keep-statements \
58-
--max-instatement-indent=40 \
59-
--min-conditional-indent=-1 \
60-
--suffix=none"
61-
62-
export ARTISTIC_STYLE_OPTIONS="\
63-
$ARTISTIC_STYLE_OPTIONS \
64-
--pad=oper \
65-
--pad=paren-in \
66-
--unpad=paren"
46+
astyleit()
47+
{
48+
scripts/sort_includes.pl "$1"
49+
50+
$ASTYLE \
51+
--preserve-date \
52+
--indent-preprocessor \
53+
--brackets=break \
54+
--convert-tabs \
55+
--indent=spaces=2 \
56+
--indent-classes \
57+
--indent-labels \
58+
--indent-namespaces \
59+
--indent-switches \
60+
--one-line=keep-blocks \
61+
--one-line=keep-statements \
62+
--max-instatement-indent=40 \
63+
--min-conditional-indent=-1 \
64+
--suffix=none \
65+
--pad=oper \
66+
--pad=paren-in \
67+
--unpad=paren "$1"
68+
}
6769

6870
for f in "$@"; do
6971
case "$f" in
@@ -73,7 +75,7 @@ for f in "$@"; do
7375
;;
7476

7577
*.cpp|*.h|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.hpp)
76-
cmd="$ASTYLE $ARTISTIC_STYLE_OPTIONS"
78+
cmd=astyleit
7779
;;
7880

7981
*.ui|*.qgm|*.txt|*.t2t|resources/context_help/*)

‎scripts/prepare-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fi
3131

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

3737
set -e

‎scripts/sort_includes.pl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/perl -i.sortinc -n
2+
###########################################################################
3+
# sort_includes.pl
4+
# ---------------------
5+
# begin : June 2015
6+
# copyright : (C) 2015 by Juergen E. Fischer
7+
# email : jef at norbit dot de
8+
#
9+
###########################################################################
10+
# #
11+
# This program is free software; you can redistribute it and/or modify #
12+
# it under the terms of the GNU General Public License as published by #
13+
# the Free Software Foundation; either version 2 of the License, or #
14+
# (at your option) any later version. #
15+
# #
16+
###########################################################################
17+
18+
# adapted from scripts/sort_includes.sh
19+
20+
use strict;
21+
use warnings;
22+
23+
our %uis;
24+
our %sys;
25+
our %others;
26+
our $sorting;
27+
28+
BEGIN { $sorting = 0; }
29+
END { die "header files not empty" if keys %uis || keys %sys || keys %others; }
30+
31+
if(/^\s*#include/ ) {
32+
if(/"ui_/ ) {
33+
$uis{$_}=1;
34+
} elsif(/</) {
35+
$sys{$_}=1;
36+
} else {
37+
$others{$_}=1;
38+
}
39+
$sorting=1;
40+
next;
41+
}
42+
43+
if( $sorting ) {
44+
print foreach sort keys %uis;
45+
print foreach sort keys %sys;
46+
print foreach sort keys %others;
47+
48+
undef %uis;
49+
undef %sys;
50+
undef %others;
51+
}
52+
53+
54+
$sorting=0;
55+
56+
print;

0 commit comments

Comments
 (0)
Failed to load comments.