check_GNU_style.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. #
  3. # Checks some of the GNU style formatting rules in a set of patches.
  4. # The script is a rewritten of the same bash script and should eventually
  5. # replace the former script.
  6. #
  7. # This file is part of GCC.
  8. #
  9. # GCC is free software; you can redistribute it and/or modify it under
  10. # the terms of the GNU General Public License as published by the Free
  11. # Software Foundation; either version 3, or (at your option) any later
  12. # version.
  13. #
  14. # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  15. # WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. # for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with GCC; see the file COPYING3. If not see
  21. # <http://www.gnu.org/licenses/>. */
  22. import argparse
  23. import sys
  24. from check_GNU_style_lib import check_GNU_style_file
  25. def main():
  26. parser = argparse.ArgumentParser(description='Check GNU coding style.')
  27. parser.add_argument('file', help = 'File with a patch')
  28. parser.add_argument('-f', '--format', default = 'stdio',
  29. help = 'Display format',
  30. choices = ['stdio', 'quickfix'])
  31. args = parser.parse_args()
  32. filename = args.file
  33. format = args.format
  34. if filename == '-':
  35. check_GNU_style_file(sys.stdin, None, format)
  36. else:
  37. with open(filename, 'rb') as diff_file:
  38. check_GNU_style_file(diff_file, 'utf-8', format)
  39. main()