Skip to content

Commit

Permalink
unify_includes.pl:
Browse files Browse the repository at this point in the history
* renamed from sort_includes.pl
* don't destroy order just remove duplicate includes
* run after astyle
  • Loading branch information
jef-n committed Jun 10, 2015
1 parent d077a16 commit 49286b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
4 changes: 2 additions & 2 deletions scripts/astyle.sh
Expand Up @@ -45,8 +45,6 @@ set -e

astyleit()
{
scripts/sort_includes.pl "$1"

$ASTYLE \
--preserve-date \
--indent-preprocessor \
Expand All @@ -65,6 +63,8 @@ astyleit()
--pad=oper \
--pad=paren-in \
--unpad=paren "$1"

scripts/unify_includes.pl "$1"
}

for f in "$@"; do
Expand Down
39 changes: 11 additions & 28 deletions scripts/sort_includes.pl → scripts/unify_includes.pl
@@ -1,6 +1,6 @@
#!/usr/bin/perl -i.sortinc -n
###########################################################################
# sort_includes.pl
# unify_includes.pl
# ---------------------
# begin : June 2015
# copyright : (C) 2015 by Juergen E. Fischer
Expand All @@ -20,39 +20,22 @@
use strict;
use warnings;

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

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;
END { die "header files not empty" if @inc; }

if( /^\s*#include/ ) {
push @inc, $_ unless exists $inc{$_};
$inc{$_}=1;
next unless eof;
}

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

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

if( %inc ) {
print foreach @inc;
undef %inc;
undef @inc;
last if eof;
}

$sorting=0;

print;

0 comments on commit 49286b3

Please sign in to comment.