2021-05-08 19:53:32 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Script to run astyle on the code
|
|
|
|
#
|
2024-02-12 13:03:56 +03:00
|
|
|
# Usage: /path/to/run_astyle.sh [ -v ASTYLE_VER]
|
2021-05-08 19:53:32 +03:00
|
|
|
#
|
2024-02-12 13:03:56 +03:00
|
|
|
# - If -v ASTYLE_VER is specified, that version of astyle is run from
|
|
|
|
# ~/astyle.local (whether or not it's there!). Use install_astyle.sh
|
|
|
|
# to install a new version.
|
|
|
|
|
2021-05-08 19:53:32 +03:00
|
|
|
# Note: the script must be run from the root directory of the xrdp repository
|
|
|
|
|
|
|
|
INSTALL_ROOT=~/astyle.local
|
|
|
|
MIN_ASTYLE_VER="3.1"
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# U S A G E
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
usage()
|
|
|
|
{
|
2024-02-12 13:03:56 +03:00
|
|
|
echo "** Usage: $0 [ -v version]"
|
|
|
|
echo " e.g. $0 -v 3.4.12"
|
2021-05-08 19:53:32 +03:00
|
|
|
} >&2
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# M A I N
|
|
|
|
# ----------------------------------------------------------------------------
|
2024-02-12 13:03:56 +03:00
|
|
|
# Figure out ASTYLE setting, if any. Currently '-v' must be the first
|
|
|
|
# argument on the command line.
|
|
|
|
case "$1" in
|
|
|
|
-v) # Version is separate parameter
|
|
|
|
if [ $# -ge 2 ]; then
|
|
|
|
ASTYLE="$INSTALL_ROOT/$2/usr/bin/astyle"
|
|
|
|
shift 2
|
|
|
|
else
|
|
|
|
echo "** ignoring '-v' with no arg" >&2
|
|
|
|
shift 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
-v*) # Version is in same parameter
|
|
|
|
# ${parameter#word} is not supported by classic Bourne shell,
|
|
|
|
# but it is on bash, dash, etc. If it doesn't work on your shell,
|
|
|
|
# don't use this form!
|
|
|
|
ASTYLE="$INSTALL_ROOT/${1#-v}/usr/bin/astyle"
|
|
|
|
shift 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -z "$ASTYLE" ]; then
|
|
|
|
ASTYLE=astyle
|
|
|
|
fi
|
|
|
|
|
2021-05-08 19:53:32 +03:00
|
|
|
if [ $# -ne 0 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2024-02-12 13:03:56 +03:00
|
|
|
# check if the selected astyle meets the minimum requrements
|
|
|
|
ASTYLE_VER_OUTPUT=`$ASTYLE --version 2>/dev/null | grep "Artistic Style Version" | cut -d' ' -f4`
|
|
|
|
|
|
|
|
if [ ! -z "$ASTYLE_VER_OUTPUT" ]; then
|
|
|
|
# Check the version meets the minimum requirements
|
|
|
|
LOWEST_VERSION=`{ echo "$MIN_ASTYLE_VER" ; echo "$ASTYLE_VER_OUTPUT"; } | sort -V | head -n1`
|
|
|
|
if [ "$MIN_ASTYLE_VER" != "$LOWEST_VERSION" ]; then
|
2021-05-08 19:53:32 +03:00
|
|
|
ERROR_MESSAGE="The version of astyle installed does not meet the minimum version requirement: >= $MIN_ASTYLE_VER "
|
|
|
|
fi
|
2024-02-12 13:03:56 +03:00
|
|
|
elif [ "$ASTYLE" = astyle ]; then
|
2021-05-08 19:53:32 +03:00
|
|
|
ERROR_MESSAGE="astyle is not installed on the system path"
|
2024-02-12 13:03:56 +03:00
|
|
|
else
|
|
|
|
ERROR_MESSAGE="Can't find $ASTYLE"
|
2021-05-08 19:53:32 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$ERROR_MESSAGE" ]; then
|
2024-02-12 13:03:56 +03:00
|
|
|
echo "$ERROR_MESSAGE" >&2
|
2021-05-08 19:53:32 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "astyle_config.as" ]; then
|
2024-02-12 13:03:56 +03:00
|
|
|
echo "$0 must be run from the root xrdp repository directory which " >&2
|
|
|
|
echo "contains the 'astyle_config.as' file." >&2
|
2021-05-08 19:53:32 +03:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2023-04-03 11:38:01 +03:00
|
|
|
ASTYLE_FLAGS="--options=astyle_config.as --exclude=third_party ./\*.c ./\*.h"
|
2021-05-08 19:53:32 +03:00
|
|
|
|
|
|
|
# Display the astyle version and command for debugging
|
|
|
|
"$ASTYLE" --version && {
|
2022-09-03 03:50:56 +03:00
|
|
|
echo "Command: $ASTYLE $ASTYLE_FLAGS"
|
2021-05-08 19:53:32 +03:00
|
|
|
"$ASTYLE" $ASTYLE_FLAGS
|
|
|
|
}
|
2024-02-12 13:03:56 +03:00
|
|
|
|
|
|
|
exit $?
|