gcc/contrib/check_GNU_style.py
Tom de Vries 75017bb975 check_GNU_style.py: Read stdin if file argument is '-'
2017-05-29  Tom de Vries  <tom@codesourcery.com>

	* check_GNU_style_lib.py (check_GNU_style_file): Treat file argument as
	file handle.  Add and handle file_encoding argument.
	* check_GNU_style.py (main): Handle '-' file argument.  Call
	check_GNU_style_file with file handle as argument.

From-SVN: r248555
2017-05-29 07:31:02 +00:00

44 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
#
# Checks some of the GNU style formatting rules in a set of patches.
# The script is a rewritten of the same bash script and should eventually
# replace the former script.
#
# This file is part of GCC.
#
# GCC is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later
# version.
#
# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>. */
import argparse
import sys
from check_GNU_style_lib import check_GNU_style_file
def main():
parser = argparse.ArgumentParser(description='Check GNU coding style.')
parser.add_argument('file', help = 'File with a patch')
parser.add_argument('-f', '--format', default = 'stdio',
help = 'Display format',
choices = ['stdio', 'quickfix'])
args = parser.parse_args()
filename = args.file
format = args.format
if filename == '-':
check_GNU_style_file(sys.stdin, None, format)
else:
with open(filename, 'rb') as diff_file:
check_GNU_style_file(diff_file, 'utf-8', format)
main()