Commit 9b12d9d0 authored by Andrew M. Kuchling's avatar Andrew M. Kuchling

Modernize the code a bit:

   use re module
   make chomp() use rstrip()
parent b7878d09
...@@ -18,15 +18,12 @@ ...@@ -18,15 +18,12 @@
import string import string
import sys import sys
import regex import re
from regex_syntax import *
regex.set_syntax(RE_SYNTAX_EGREP)
def main(): def main():
pats = map(chomp, sys.stdin.readlines()) pats = map(chomp, sys.stdin.readlines())
bigpat = '(' + string.joinfields(pats, '|') + ')' bigpat = '(' + '|'.join(pats) + ')'
prog = regex.compile(bigpat) prog = re.compile(bigpat)
for file in sys.argv[1:]: for file in sys.argv[1:]:
try: try:
...@@ -40,11 +37,10 @@ def main(): ...@@ -40,11 +37,10 @@ def main():
if not line: if not line:
break break
lineno = lineno + 1 lineno = lineno + 1
if prog.search(line) >= 0: if prog.search(line):
print "%s:%s:%s" % (file, lineno, line), print "%s:%s:%s" % (file, lineno, line),
def chomp(s): def chomp(s):
if s[-1:] == '\n': return s[:-1] return s.rstrip('\n')
else: return s
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment