style.py (4761:4bb357497886) style.py (4781:59a75bd0ddf4)
1#! /usr/bin/env python
2# Copyright (c) 2007 The Regents of The University of Michigan
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 37 unchanged lines hidden (view full) ---

46 'hpp' : "C++",
47 'C' : "C++",
48 'H' : "C++",
49 'i' : "swig",
50 'py' : "python",
51 's' : "asm",
52 'S' : "asm",
53 'isa' : "isa" }
1#! /usr/bin/env python
2# Copyright (c) 2007 The Regents of The University of Michigan
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 37 unchanged lines hidden (view full) ---

46 'hpp' : "C++",
47 'C' : "C++",
48 'H' : "C++",
49 'i' : "swig",
50 'py' : "python",
51 's' : "asm",
52 'S' : "asm",
53 'isa' : "isa" }
54whitespace_types = ('C', 'C++', 'swig', 'python', 'asm', 'isa')
55format_types = ( 'C', 'C++' )
56
57def file_type(filename):
58 extension = filename.split('.')
59 extension = len(extension) > 1 and extension[-1]
60 return lang_types.get(extension, None)
61
54def file_type(filename):
55 extension = filename.split('.')
56 extension = len(extension) > 1 and extension[-1]
57 return lang_types.get(extension, None)
58
59whitespace_types = ('C', 'C++', 'swig', 'python', 'asm', 'isa')
60def whitespace_file(filename):
61 if file_type(filename) in whitespace_types:
62 return True
63
64 if filename.startswith("SCons"):
65 return True
66
67 return False
68
69format_types = ( 'C', 'C++' )
70def format_file(filename):
71 if file_type(filename) in format_types:
72 return True
73
74 return False
75
62def checkwhite_line(line):
63 match = lead.search(line)
64 if match and match.group(1).find('\t') != -1:
65 return False
66
67 match = trail.search(line)
68 if match:
69 return False
70
71 return True
72
73def checkwhite(filename):
76def checkwhite_line(line):
77 match = lead.search(line)
78 if match and match.group(1).find('\t') != -1:
79 return False
80
81 match = trail.search(line)
82 if match:
83 return False
84
85 return True
86
87def checkwhite(filename):
74 if file_type(filename) not in whitespace_types:
88 if not whitespace_file(filename)
75 return
76
77 try:
78 f = file(filename, 'r+')
79 except OSError, msg:
80 print 'could not open file %s: %s' % (filename, msg)
81 return
82

--- 13 unchanged lines hidden (view full) ---

96 newline += line[i:]
97 break
98
99 line = newline
100
101 return line.rstrip() + '\n'
102
103def fixwhite(filename, tabsize, fixonly=None):
89 return
90
91 try:
92 f = file(filename, 'r+')
93 except OSError, msg:
94 print 'could not open file %s: %s' % (filename, msg)
95 return
96

--- 13 unchanged lines hidden (view full) ---

110 newline += line[i:]
111 break
112
113 line = newline
114
115 return line.rstrip() + '\n'
116
117def fixwhite(filename, tabsize, fixonly=None):
104 if file_type(filename) not in whitespace_types:
118 if not whitespace_file(filename)
105 return
106
107 try:
108 f = file(filename, 'r+')
109 except OSError, msg:
110 print 'could not open file %s: %s' % (filename, msg)
111 return
112

--- 41 unchanged lines hidden (view full) ---

154''' % (self.toolong, self.toolong80, self.trailwhite, self.leadtabs,
155 self.badcontrol, self.cret)
156
157 def __nonzero__(self):
158 return self.toolong or self.toolong80 or self.leadtabs or \
159 self.trailwhite or self.badcontrol or self.cret
160
161def validate(filename, stats, verbose, exit_code):
119 return
120
121 try:
122 f = file(filename, 'r+')
123 except OSError, msg:
124 print 'could not open file %s: %s' % (filename, msg)
125 return
126

--- 41 unchanged lines hidden (view full) ---

168''' % (self.toolong, self.toolong80, self.trailwhite, self.leadtabs,
169 self.badcontrol, self.cret)
170
171 def __nonzero__(self):
172 return self.toolong or self.toolong80 or self.leadtabs or \
173 self.trailwhite or self.badcontrol or self.cret
174
175def validate(filename, stats, verbose, exit_code):
162 if file_type(filename) not in format_types:
176 if not format_file(filename):
163 return
164
165 def msg(lineno, line, message):
166 print '%s:%d>' % (filename, lineno + 1), message
167 if verbose > 2:
168 print line
169
170 def bad():

--- 220 unchanged lines hidden ---
177 return
178
179 def msg(lineno, line, message):
180 print '%s:%d>' % (filename, lineno + 1), message
181 if verbose > 2:
182 print line
183
184 def bad():

--- 220 unchanged lines hidden ---