Browse Source

Add astyle code formatter usage script and change .gitignore to exclude astyle preserved files

tags/lab02
Silver Kits 3 years ago
parent
commit
5abb360450
2 changed files with 51 additions and 0 deletions
  1. +3
    -0
      .gitignore
  2. +48
    -0
      tooling/format-code.sh

+ 3
- 0
.gitignore View File

@@ -1,6 +1,9 @@
# Build artefacts
bin/*

# astyle formatter preserved files
*.orig

#
# Templates from https://github.com/github/gitignore
#

+ 48
- 0
tooling/format-code.sh View File

@@ -0,0 +1,48 @@
#!/bin/bash

# Simple script for code formatting in 1tbs
# See http://astyle.sourceforge.net/astyle.html for syntax and defaults

MINPARAMS=1
ORIG_SUFFIX=orig

if [ $# -lt "$MINPARAMS" ]
then
echo "This script needs C source files passed as arguments"
echo "USAGE: format-code.sh src/main.c src/somecode.c ..."
exit 1
fi

#
for FILE in "$@"
do
RESULT="$(astyle --style=1tbs \
--indent-col1-comments \
--break-blocks \
--pad-oper \
--pad-header \
--delete-empty-lines \
--add-brackets \
--convert-tabs \
--max-code-length=80 \
--break-after-logical \
--mode=c \
--suffix=.$ORIG_SUFFIX \
--lineend=linux \
$FILE)"

# if file unchanged print unchanged result message
if [[ "$RESULT" = Unchanged* ]]
then
echo "$RESULT"
fi

# if file formatted print result and renamed file name
if [[ "$RESULT" = Formatted* ]]
then
echo "$RESULT"
echo "Original code was preserved in file $FILE.$ORIG_SUFFIX"
fi
done

exit 0

Loading…
Cancel
Save