2
2
3
3
# Script to run astyle on the code
4
4
#
5
- # Usage: /path/to/run_astyle.sh
5
+ # Usage: /path/to/run_astyle.sh [ -v ASTYLE_VER]
6
6
#
7
+ # - If -v ASTYLE_VER is specified, that version of astyle is run from
8
+ # ~/astyle.local (whether or not it's there!). Use install_astyle.sh
9
+ # to install a new version.
10
+
7
11
# Note: the script must be run from the root directory of the xrdp repository
8
12
9
13
INSTALL_ROOT=~ /astyle.local
10
- ASTYLE_FROM_XRDP=$INSTALL_ROOT /3.4.12/usr/bin/astyle
11
14
MIN_ASTYLE_VER=" 3.1"
12
15
13
16
# ----------------------------------------------------------------------------
14
17
# U S A G E
15
18
# ----------------------------------------------------------------------------
16
19
usage ()
17
20
{
18
- echo " ** Usage: $0 "
19
- echo " e.g. $0 "
21
+ echo " ** Usage: $0 [ -v version] "
22
+ echo " e.g. $0 -v 3.4.12 "
20
23
} >&2
21
24
22
25
# ----------------------------------------------------------------------------
23
26
# M A I N
24
27
# ----------------------------------------------------------------------------
28
+ # Figure out ASTYLE setting, if any. Currently '-v' must be the first
29
+ # argument on the command line.
30
+ case " $1 " in
31
+ -v) # Version is separate parameter
32
+ if [ $# -ge 2 ]; then
33
+ ASTYLE=" $INSTALL_ROOT /$2 /usr/bin/astyle"
34
+ shift 2
35
+ else
36
+ echo " ** ignoring '-v' with no arg" >&2
37
+ shift 1
38
+ fi
39
+ ;;
40
+ -v* ) # Version is in same parameter
41
+ # ${parameter#word} is not supported by classic Bourne shell,
42
+ # but it is on bash, dash, etc. If it doesn't work on your shell,
43
+ # don't use this form!
44
+ ASTYLE=" $INSTALL_ROOT /${1# -v} /usr/bin/astyle"
45
+ shift 1
46
+ esac
47
+
48
+ if [ -z " $ASTYLE " ]; then
49
+ ASTYLE=astyle
50
+ fi
51
+
25
52
if [ $# -ne 0 ]; then
26
53
usage
27
54
exit 1
28
55
fi
29
56
30
- # check if the built-in astyle meets the minimum requrements
31
- ASTYLE_FROM_OS_VER_OUTPUT=` astyle --version | grep " Artistic Style Version" | cut -d' ' -f4`
32
57
33
- ASTYLE=" "
34
- ERROR_MESSAGE=" "
35
- if [ ! -z " $ASTYLE_FROM_OS_VER_OUTPUT " ]; then
36
- # astyle is installed, so check if it's version meets the minimum requirements
37
- LOWEST_VERSION=` echo -e " $MIN_ASTYLE_VER \n$ASTYLE_FROM_OS_VER_OUTPUT " | sort -V | head -n1`
38
- if [ " $MIN_ASTYLE_VER " = " $LOWEST_VERSION " ]; then
39
- ASTYLE=astyle
40
- else
58
+ # check if the selected astyle meets the minimum requrements
59
+ ASTYLE_VER_OUTPUT=` $ASTYLE --version 2> /dev/null | grep " Artistic Style Version" | cut -d' ' -f4`
60
+
61
+ if [ ! -z " $ASTYLE_VER_OUTPUT " ]; then
62
+ # Check the version meets the minimum requirements
63
+ LOWEST_VERSION=` { echo " $MIN_ASTYLE_VER " ; echo " $ASTYLE_VER_OUTPUT " ; } | sort -V | head -n1`
64
+ if [ " $MIN_ASTYLE_VER " != " $LOWEST_VERSION " ]; then
41
65
ERROR_MESSAGE=" The version of astyle installed does not meet the minimum version requirement: >= $MIN_ASTYLE_VER "
42
66
fi
43
- else
67
+ elif [ " $ASTYLE " = astyle ] ; then
44
68
ERROR_MESSAGE=" astyle is not installed on the system path"
45
- fi
46
-
47
- if [ -z " $ASTYLE " ]; then
48
- # astyle from the os is invlid, fallback to the xrdp version if it is installed
49
- if [ -x " $ASTYLE_FROM_XRDP " ]; then
50
- ASTYLE=" $ASTYLE_FROM_XRDP "
51
- ERROR_MESSAGE=" "
52
- else
53
- ERROR_MESSAGE=" ${ERROR_MESSAGE} \nastyle $MIN_ASTYLE_VER is not installed at the expected path: $ASTYLE_FROM_XRDP "
54
- fi
69
+ else
70
+ ERROR_MESSAGE=" Can't find $ASTYLE "
55
71
fi
56
72
57
73
if [ ! -z " $ERROR_MESSAGE " ]; then
58
- echo " $ERROR_MESSAGE "
74
+ echo " $ERROR_MESSAGE " >&2
59
75
exit 1
60
76
fi
61
77
62
78
if [ ! -f " astyle_config.as" ]; then
63
- echo " $0 must be run from the root xrdp repository directory which "
64
- echo " contains the 'astyle_config.as' file."
79
+ echo " $0 must be run from the root xrdp repository directory which " >&2
80
+ echo " contains the 'astyle_config.as' file." >&2
65
81
exit 2
66
82
fi
67
83
@@ -72,3 +88,5 @@ ASTYLE_FLAGS="--options=astyle_config.as --exclude=third_party ./\*.c ./\*.h"
72
88
echo " Command: $ASTYLE $ASTYLE_FLAGS "
73
89
" $ASTYLE " $ASTYLE_FLAGS
74
90
}
91
+
92
+ exit $?
0 commit comments