132 ('python', r'.*\.(py|cgi)$', pyfilters, pypats), |
132 ('python', r'.*\.(py|cgi)$', pyfilters, pypats), |
133 ('test script', r'(.*/)?test-[^.~]*$', testfilters, testpats), |
133 ('test script', r'(.*/)?test-[^.~]*$', testfilters, testpats), |
134 ('c', r'.*\.c$', cfilters, cpats), |
134 ('c', r'.*\.c$', cfilters, cpats), |
135 ] |
135 ] |
136 |
136 |
137 if len(sys.argv) == 1: |
137 if __name__ == "__main__": |
138 check = glob.glob("*") |
138 if len(sys.argv) == 1: |
139 else: |
139 check = glob.glob("*") |
140 check = sys.argv[1:] |
140 else: |
|
141 check = sys.argv[1:] |
141 |
142 |
142 for f in check: |
143 for f in check: |
143 for name, match, filters, pats in checks: |
144 for name, match, filters, pats in checks: |
144 fc = 0 |
145 fc = 0 |
145 if not re.match(match, f): |
146 if not re.match(match, f): |
146 continue |
147 continue |
147 pre = post = open(f).read() |
148 pre = post = open(f).read() |
148 if "no-" + "check-code" in pre: |
149 if "no-" + "check-code" in pre: |
|
150 break |
|
151 for p, r in filters: |
|
152 post = re.sub(p, r, post) |
|
153 # print post # uncomment to show filtered version |
|
154 z = enumerate(zip(pre.splitlines(), post.splitlines(True))) |
|
155 for n, l in z: |
|
156 if "check-code" + "-ignore" in l[0]: |
|
157 continue |
|
158 lc = 0 |
|
159 for p, msg in pats: |
|
160 if re.search(p, l[1]): |
|
161 if not lc: |
|
162 print "%s:%d:" % (f, n + 1) |
|
163 print " > %s" % l[0] |
|
164 print " %s" % msg |
|
165 lc += 1 |
|
166 fc += 1 |
|
167 if fc == 15: |
|
168 print " (too many errors, giving up)" |
|
169 break |
149 break |
170 break |
150 for p, r in filters: |
|
151 post = re.sub(p, r, post) |
|
152 # print post # uncomment to show filtered version |
|
153 z = enumerate(zip(pre.splitlines(), post.splitlines(True))) |
|
154 for n, l in z: |
|
155 if "check-code" + "-ignore" in l[0]: |
|
156 continue |
|
157 lc = 0 |
|
158 for p, msg in pats: |
|
159 if re.search(p, l[1]): |
|
160 if not lc: |
|
161 print "%s:%d:" % (f, n + 1) |
|
162 print " > %s" % l[0] |
|
163 print " %s" % msg |
|
164 lc += 1 |
|
165 fc += 1 |
|
166 if fc == 15: |
|
167 print " (too many errors, giving up)" |
|
168 break |
|
169 break |
|