-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
astyle.sh
executable file
·161 lines (141 loc) · 4.6 KB
/
astyle.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env bash
###########################################################################
# astyle.sh
# ---------------------
# Date : August 2008
# Copyright : (C) 2008 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. #
# #
###########################################################################
# sort by version option
SV=V
if [[ "$OSTYPE" == *bsd* ]] || [[ "$OSTYPE" =~ darwin* ]]; then
SV=n
fi
min_version="3"
astyle_version_check() {
[ $(printf "$($1 --version 2>/dev/null | cut -d ' ' -f4)\\n$min_version" | sort -${SV} | head -n1) = "$min_version" ]
}
for ASTYLE in ${QGISSTYLE} $(dirname "$0")/qgisstyle $(dirname "$0")/RelWithDebInfo/qgisstyle astyle
do
if type -p "$ASTYLE" >/dev/null; then
if astyle_version_check "$ASTYLE"; then
break
fi
fi
ASTYLE=
done
if [ -z "$ASTYLE" ]; then
echo "qgisstyle / astyle not found - please install astyle >= $min_version or enable WITH_ASTYLE in cmake and build" >&2
exit 1
fi
if type -p tput >/dev/null; then
elcr="$ASTYLEPROGRESS$(tput el)$(tput cr)"
else
elcr="$ASTYLEPROGRESS \\r"
fi
if ! type -p flip >/dev/null; then
if type -p dos2unix >/dev/null; then
flip() {
dos2unix -q -k "$2"
}
else
echo "flip not found" >&2
echo "Try:"
if [[ -f /etc/fedora-release ]]; then
echo " dnf install dos2unix";
elif [[ -f /etc/debian_version ]]; then
echo " apt install flip";
else
echo " installing flip or dos2unix from your package manager";
fi
flip() {
:
}
fi
fi
if ! type -p autopep8 >/dev/null; then
echo "autopep8 not found" >&2
echo "Try:"
if [[ -f /etc/fedora-release ]]; then
echo " dnf install python3-autopep8";
elif [[ -f /etc/debian_version ]]; then
echo " apt install python3-autopep8";
else
echo " installing python3-autopep8 from your package manager";
fi
autopep8() {
:
}
fi
ASTYLEOPTS=$(dirname "$0")/astyle.options
# when using `qgisstyle` built alongside QGIS (on windows),
# convert path to options file
if [ $ASTYLE != "astyle" ] ; then
if type -p cygpath >/dev/null; then
ASTYLEOPTS="$(cygpath -w "$ASTYLEOPTS")"
fi
if type -p wslpath >/dev/null; then
ASTYLEOPTS="$(wslpath -a -w "$ASTYLEOPTS")"
fi
fi
set -e
astyleit() {
$ASTYLE --options="$ASTYLEOPTS" "$1"
modified=$1.unify_includes_modified
cp "$1" "$modified"
perl -i.sortinc -n scripts/unify_includes.pl "$modified"
scripts/doxygen_space.py "$modified"
diff "$1" "$modified" >/dev/null || mv "$modified" "$1"
rm -f "$modified"
}
for f in "$@"; do
case "$f" in
external/libdxfrw/*|external/untwine/*|external/qwt*|external/o2/*|external/odbccpp/*|external/qt-unix-signals/*|external/rtree/*|external/astyle/*|external/kdbush/*|external/PDF4QT/*|external/poly2tri/*|external/wintoast/*|external/qt3dextra-headers/*|external/lazperf/*|external/meshOptimizer/*|external/mapbox-vector-tile/*|external/pdal_wrench/*|external/tinygltf/*|python/ext-libs/*|ui_*.py|*.astyle|src/core/providers/gdal/gdal_minmax_element.hpp|src/core/providers/gdal/gdal_priv_templates.hpp|tests/testdata/*|editors/*)
echo -ne "$f skipped $elcr"
continue
;;
*.cpp|*.h|*.c|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.hpp|*.mm)
if [ -x "$f" ]; then
chmod a-x "$f"
fi
cmd=astyleit
;;
*.ui|*.qgm|*.txt)
cmd=:
;;
*.py)
#cmd="autopep8 --in-place --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701"
echo -ne "Formatting $f $elcr"
cmd="autopep8 --in-place --ignore=E261,E265,E402,E501"
;;
*.sip)
cmd="perl -i.prepare -pe 's/[\\r\\t ]+$//; s#^(\\s*)/\\*[*!]\\s*([^\\s*].*)\\s*\$#\$1/** \\u\$2\\n#;'"
;;
*)
echo -ne "$f skipped $elcr"
continue
;;
esac
if ! [ -f "$f" ]; then
echo "$f not found" >&2
continue
fi
if [[ -f $f && $(head -c 3 "$f") == $'\xef\xbb\xbf' ]]; then
mv "$f" "$f".bom
tail -c +4 "$f".bom > "$f"
echo "removed BOM from $f"
fi
modified=$f.flip_modified
cp "$f" "$modified"
flip -ub "$modified"
diff "$f" "$modified" >/dev/null || mv "$modified" "$f"
rm -f "$modified"
eval "$cmd '$f'"
done