Mercurial > hg > Members > shinya > pyrect
changeset 105:14faa199c3bf
add --regex option (jitgrep). it's useful when grep complex regexp.
author | Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 14 Dec 2010 11:49:59 +0900 |
parents | f228eb779162 |
children | 8102bf4bbec6 |
files | pyrect/jitgrep.py |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/pyrect/jitgrep.py Tue Dec 14 11:07:30 2010 +0900 +++ b/pyrect/jitgrep.py Tue Dec 14 11:49:59 2010 +0900 @@ -11,7 +11,7 @@ def main(argv): myusage = """%prog [--buf-size=size] [--dump] [--CbC] [--time] [--debug] [--cc=compiler] [-c] - [-Olevel] regexp [file..] [--out=file] + [-Olevel] regexp [file..] [--out=file] [--regex=file] [--thread=thread_num] [--filter=algorithm] [--disable-booster] [--functional-transition]""" psr = OptionParser(usage=myusage) @@ -22,6 +22,8 @@ psr.add_option("--cc", action="store", type="string", dest="cc", default="gcc", metavar="FILE", help="Choose compiler (default is gcc).") + psr.add_option("--regex", action="store", type="string", dest="regex", default="", metavar="FILE", + help="Obtain patterns from file.") psr.add_option("-c", action="store_true", dest="compile", default=False , help="compile only.") psr.add_option("--buf-size=size", action="store", type="string", dest="bufsize", default="1M" , help="Set read-buffer size (e.x. 1024, 1024K, 2M)") psr.add_option("--cflags", action="store", type="string", dest="cflags", default="-O3", help="Print compile/matching time.") @@ -38,6 +40,14 @@ (opts, args) = psr.parse_args(argv) + if opts.regex: + fd = open(opts.regex, 'r') + regex = fd.read().rstrip() + fd.close() + if len(args) < 3: + args.append(args[1]) + args[1] = regex + if len(args) < 2: psr.print_usage() return