+++ /dev/null
-#! /usr/bin/env python\r
-\r
-# 1) Regular Expressions Test\r
-#\r
-# Read a file of (extended per egrep) regular expressions (one per line),\r
-# and apply those to all files whose names are listed on the command line.\r
-# Basically, an 'egrep -f' simulator. Test it with 20 "vt100" patterns\r
-# against a five /etc/termcap files. Tests using more elaborate patters\r
-# would also be interesting. Your code should not break if given hundreds\r
-# of regular expressions or binary files to scan.\r
-\r
-# This implementation:\r
-# - combines all patterns into a single one using ( ... | ... | ... )\r
-# - reads patterns from stdin, scans files given as command line arguments\r
-# - produces output in the format <file>:<lineno>:<line>\r
-# - is only about 2.5 times as slow as egrep (though I couldn't run\r
-# Tom's test -- this system, a vanilla SGI, only has /etc/terminfo)\r
-\r
-import string\r
-import sys\r
-import re\r
-\r
-def main():\r
- pats = map(chomp, sys.stdin.readlines())\r
- bigpat = '(' + '|'.join(pats) + ')'\r
- prog = re.compile(bigpat)\r
-\r
- for file in sys.argv[1:]:\r
- try:\r
- fp = open(file, 'r')\r
- except IOError, msg:\r
- print "%s: %s" % (file, msg)\r
- continue\r
- lineno = 0\r
- while 1:\r
- line = fp.readline()\r
- if not line:\r
- break\r
- lineno = lineno + 1\r
- if prog.search(line):\r
- print "%s:%s:%s" % (file, lineno, line),\r
-\r
-def chomp(s):\r
- return s.rstrip('\n')\r
-\r
-if __name__ == '__main__':\r
- main()\r