2018-02-05 13:38:02 +01:00
|
|
|
#!/usr/bin/env bash
|
2015-06-09 17:06:12 +02:00
|
|
|
###########################################################################
|
|
|
|
# sort_include.sh
|
|
|
|
# ---------------------
|
|
|
|
# Date : June 2015
|
|
|
|
# Copyright : (C) 2015 by Denis Rouzaud
|
|
|
|
# Email : denis.rouzaud@gmail.com
|
|
|
|
###########################################################################
|
|
|
|
# #
|
|
|
|
# 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. #
|
|
|
|
# #
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
|
|
|
|
# this sorts and remove duplicates in #include in src and tests folders
|
|
|
|
# sorts includes in <...> before "..."
|
|
|
|
# keep #include "ui_..." on top of list
|
|
|
|
# can skip includes if an order should be kept
|
2015-06-24 09:08:52 +02:00
|
|
|
# can exclude directories (hard-copies of external libraries)
|
2015-06-09 17:06:12 +02:00
|
|
|
|
|
|
|
SORTING=false
|
2015-06-10 11:07:29 +02:00
|
|
|
FILE1="sort_include_1.tmp"
|
|
|
|
FILE2="sort_include_2.tmp"
|
|
|
|
FILE3="sort_include_3.tmp"
|
2015-06-09 17:06:12 +02:00
|
|
|
|
|
|
|
# files not to be sorted (leads to compile errors otherwise)
|
|
|
|
DoNotSort="(sqlite3.h)|(spatialite.h)"
|
|
|
|
|
|
|
|
for file in $(find . \
|
2015-06-10 11:07:29 +02:00
|
|
|
! -path "./python/ext-libs/*" \
|
2018-06-28 23:30:32 +02:00
|
|
|
! -path "./external/astyle/*" \
|
|
|
|
! -path "./external/qwtpolar-*" \
|
|
|
|
! -path "./external/qspatialite/*" \
|
2015-06-10 11:07:29 +02:00
|
|
|
-regex "./src/\(.+/\)*.*\.\(h\|cpp\)" -type f \
|
|
|
|
-or -regex "./tests/\(.+/\)*.*\.\(h\|cpp\)" -type f )
|
2015-06-09 17:06:12 +02:00
|
|
|
do
|
|
|
|
echo "$file"
|
|
|
|
touch $FILE1
|
|
|
|
while IFS= read -r line
|
|
|
|
do
|
|
|
|
if [[ "$line" =~ ^[[:space:]]*"#"include ]] && [[ ! "$line" =~ $DoNotSort ]]; then
|
|
|
|
if ! $SORTING; then
|
|
|
|
touch $FILE2
|
|
|
|
touch $FILE3
|
|
|
|
fi
|
|
|
|
SORTING=true
|
|
|
|
if [[ "$line" =~ ^"#"include[[:space:]]*\"ui_ ]]; then
|
|
|
|
echo "$line" >> $FILE1 # keep ui_ on top of list
|
|
|
|
elif [[ "$line" =~ ^"#"include[[:space:]]*\<[^[:space:]]+\> ]]; then
|
2015-06-10 11:07:29 +02:00
|
|
|
echo "$line" >> $FILE2 # include <...>
|
2015-06-09 17:06:12 +02:00
|
|
|
else
|
2015-06-10 11:07:29 +02:00
|
|
|
echo "$line" >> $FILE3 # include "..."
|
2015-06-09 17:06:12 +02:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
if $SORTING; then
|
|
|
|
sort -u $FILE2 >> $FILE1
|
|
|
|
sort -u $FILE3 >> $FILE1
|
|
|
|
rm -f $FILE2 $FILE3
|
|
|
|
SORTING=false
|
|
|
|
fi
|
|
|
|
echo "$line" >> $FILE1
|
|
|
|
fi
|
|
|
|
done < "$file"
|
2015-06-10 11:07:29 +02:00
|
|
|
if $SORTING; then
|
|
|
|
sort -u $FILE2 >> $FILE1
|
|
|
|
sort -u $FILE3 >> $FILE1
|
|
|
|
SORTING=false
|
|
|
|
fi
|
2018-06-21 12:49:45 +10:00
|
|
|
mv $FILE1 "$file"
|
2015-06-10 11:07:29 +02:00
|
|
|
rm -f $FILE1 $FILE2 $FILE3
|
2015-06-09 17:06:12 +02:00
|
|
|
done
|
|
|
|
|