Merge with head.
--HG-- extra : convert_revision : 3c1ff2585c9b20649792344b4180f6d82cef9c1b
This commit is contained in:
commit
fe46e28b14
5 changed files with 65 additions and 50 deletions
|
@ -51,14 +51,28 @@ lang_types = { 'c' : "C",
|
||||||
's' : "asm",
|
's' : "asm",
|
||||||
'S' : "asm",
|
'S' : "asm",
|
||||||
'isa' : "isa" }
|
'isa' : "isa" }
|
||||||
whitespace_types = ('C', 'C++', 'swig', 'python', 'asm', 'isa')
|
|
||||||
format_types = ( 'C', 'C++' )
|
|
||||||
|
|
||||||
def file_type(filename):
|
def file_type(filename):
|
||||||
extension = filename.split('.')
|
extension = filename.split('.')
|
||||||
extension = len(extension) > 1 and extension[-1]
|
extension = len(extension) > 1 and extension[-1]
|
||||||
return lang_types.get(extension, None)
|
return lang_types.get(extension, None)
|
||||||
|
|
||||||
|
whitespace_types = ('C', 'C++', 'swig', 'python', 'asm', 'isa')
|
||||||
|
def whitespace_file(filename):
|
||||||
|
if file_type(filename) in whitespace_types:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if filename.startswith("SCons"):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
format_types = ( 'C', 'C++' )
|
||||||
|
def format_file(filename):
|
||||||
|
if file_type(filename) in format_types:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def checkwhite_line(line):
|
def checkwhite_line(line):
|
||||||
match = lead.search(line)
|
match = lead.search(line)
|
||||||
if match and match.group(1).find('\t') != -1:
|
if match and match.group(1).find('\t') != -1:
|
||||||
|
@ -71,7 +85,7 @@ def checkwhite_line(line):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def checkwhite(filename):
|
def checkwhite(filename):
|
||||||
if file_type(filename) not in whitespace_types:
|
if not whitespace_file(filename):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -101,7 +115,7 @@ def fixwhite_line(line, tabsize):
|
||||||
return line.rstrip() + '\n'
|
return line.rstrip() + '\n'
|
||||||
|
|
||||||
def fixwhite(filename, tabsize, fixonly=None):
|
def fixwhite(filename, tabsize, fixonly=None):
|
||||||
if file_type(filename) not in whitespace_types:
|
if not whitespace_file(filename):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -159,7 +173,7 @@ class ValidationStats(object):
|
||||||
self.trailwhite or self.badcontrol or self.cret
|
self.trailwhite or self.badcontrol or self.cret
|
||||||
|
|
||||||
def validate(filename, stats, verbose, exit_code):
|
def validate(filename, stats, verbose, exit_code):
|
||||||
if file_type(filename) not in format_types:
|
if not format_file(filename):
|
||||||
return
|
return
|
||||||
|
|
||||||
def msg(lineno, line, message):
|
def msg(lineno, line, message):
|
||||||
|
@ -376,9 +390,10 @@ if __name__ == '__main__':
|
||||||
fixwhite(filename, tabsize)
|
fixwhite(filename, tabsize)
|
||||||
elif command == 'chkwhite':
|
elif command == 'chkwhite':
|
||||||
for filename in args:
|
for filename in args:
|
||||||
line = checkwhite(filename)
|
for line,num in checkwhite(filename):
|
||||||
if line:
|
print 'invalid whitespace: %s:%d' % (filename, num)
|
||||||
print 'invalid whitespace at %s:%d' % (filename, line)
|
if verbose:
|
||||||
|
print '>>%s<<' % line[:-1]
|
||||||
elif command == 'chkformat':
|
elif command == 'chkformat':
|
||||||
stats = ValidationStats()
|
stats = ValidationStats()
|
||||||
for filename in files:
|
for filename in files:
|
||||||
|
|
Loading…
Reference in a new issue