I237 Riistvaralähedane programmerimine 2016
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

49 lines
1.3 KiB

  1. #!/bin/bash
  2. # Simple script for code formatting in 1tbs
  3. # See http://astyle.sourceforge.net/astyle.html for syntax and defaults
  4. MINPARAMS=1
  5. ORIG_SUFFIX=orig
  6. if [ $# -lt "$MINPARAMS" ]
  7. then
  8. echo "This script needs C source files passed as arguments"
  9. echo "USAGE: format-code.sh src/main.c src/somecode.c ..."
  10. exit 1
  11. fi
  12. #
  13. for FILE in "$@"
  14. do
  15. RESULT="$(astyle --style=1tbs \
  16. --indent-col1-comments \
  17. --break-blocks \
  18. --pad-oper \
  19. --pad-header \
  20. --delete-empty-lines \
  21. --add-brackets \
  22. --convert-tabs \
  23. --max-code-length=80 \
  24. --break-after-logical \
  25. --mode=c \
  26. --suffix=.$ORIG_SUFFIX \
  27. --lineend=linux \
  28. $FILE)"
  29. # if file unchanged print unchanged result message
  30. if [[ "$RESULT" = Unchanged* ]]
  31. then
  32. echo "$RESULT"
  33. fi
  34. # if file formatted print result and renamed file name
  35. if [[ "$RESULT" = Formatted* ]]
  36. then
  37. echo "$RESULT"
  38. echo "Original code was preserved in file $FILE.$ORIG_SUFFIX"
  39. fi
  40. done
  41. exit 0