diff options
Diffstat (limited to 'lib/grep.py')
| -rw-r--r-- | lib/grep.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/lib/grep.py b/lib/grep.py index 66eb08d..210f9f0 100644 --- a/lib/grep.py +++ b/lib/grep.py @@ -4,29 +4,29 @@ import regexp import string def grep(expr, filename): - prog = regexp.compile(expr) - fp = open(filename, 'r') - lineno = 0 - while 1: - line = fp.readline() - if not line: break - lineno = lineno + 1 - res = prog.exec(line) - if res: - #print res - start, end = res[0] - if line[-1:] = '\n': line = line[:-1] - prefix = string.rjust(`lineno`, 3) + ': ' - print prefix + line - if 0: - line = line[:start] - if '\t' not in line: - prefix = ' ' * (len(prefix) + start) - else: - prefix = ' ' * len(prefix) - for c in line: - if c <> '\t': c = ' ' - prefix = prefix + c - if start = end: prefix = prefix + '\\' - else: prefix = prefix + '^'*(end-start) - print prefix + prog = regexp.compile(expr) + fp = open(filename, 'r') + lineno = 0 + while 1: + line = fp.readline() + if not line: break + lineno = lineno + 1 + res = prog.exec(line) + if res: + #print res + start, end = res[0] + if line[-1:] = '\n': line = line[:-1] + prefix = string.rjust(`lineno`, 3) + ': ' + print prefix + line + if 0: + line = line[:start] + if '\t' not in line: + prefix = ' ' * (len(prefix) + start) + else: + prefix = ' ' * len(prefix) + for c in line: + if c <> '\t': c = ' ' + prefix = prefix + c + if start = end: prefix = prefix + '\\' + else: prefix = prefix + '^'*(end-start) + print prefix |
