File: format_code.sh

package info (click to toggle)
freerdp2 2.0.0~git20190204.1.2693389a+dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 22,772 kB
  • sloc: ansic: 307,908; xml: 1,676; sh: 770; perl: 231; makefile: 158; python: 65
file content (42 lines) | stat: -rwxr-xr-x 1,194 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

ASTYLE=$(which astyle)

if [ ! -x $ASTYLE ]; then
  echo "No astyle found in path, please install."
  exit 1
fi

# Need at least astyle 2.03 due to bugs in older versions
# indenting headers with extern "C"
STR_VERSION=$($ASTYLE --version 2>&1)
VERSION=$(echo $STR_VERSION | cut -d ' ' -f4)
MAJOR_VERSION=$(echo $VERSION | cut -d'.' -f1)
MINOR_VERSION=$(echo $VERSION | cut -d'.' -f2)

if [ "$MAJOR_VERSION" -lt "2" ];
then
  echo "Your version of astyle($VERSION) is too old, need at least 2.03"
  exit 1
elif [ "$MAJOR_VERSION" -eq "2" ];
then
  if [ "$MINOR_VERSION" -lt "3" ];
  then
    echo "Your version of astyle($VERSION) is too old, need at least 2.03"
    exit 1
  fi
fi

if [ $# -le 0 ]; then
  echo "Usage:"
  echo -e "\t$0 <file1> [<file2> ...]"
  exit 2
fi

$ASTYLE --lineend=linux --mode=c --indent=tab=4 --pad-header --pad-oper --style=allman --min-conditional-indent=0 \
        --indent-switches --indent-cases --indent-preprocessor -k1 --max-code-length=100 \
        --indent-col1-comments --delete-empty-lines --break-closing-brackets \
        --align-pointer=type --indent-labels -xe --break-after-logical \
        --unpad-paren --break-blocks $@

exit $?