ó fc@sYdZddlZddlZddlZd„Zdd„ZedkrUeƒndS(s.Reverse grep. Usage: rgrep [-i] pattern file iÿÿÿÿNcCsAd}d}tjtjddƒ\}}x0|D](\}}|dkr2|tjB}q2q2Wt|ƒdkr}tdƒnt|ƒdkrœtd ƒn|\}}ytj||ƒ}Wn*tjk rê} td t | ƒƒnXyt |ƒ} Wn6t k r3} td t |ƒt | ƒfdƒnX| j ddƒ| jƒ} d} xä| dkr<t| |ƒ} | | } | j | ƒ| j| ƒ}|jd ƒ}~| dkrÏ|d sá|d =qán|d | |d <| dkr|d} |d=nd} |jƒx%|D]}|j|ƒr|GHqqWqYWdS(Ni@iiitis-iisnot enough argumentss"exactly one file argument requiredserror in regular expression: %sscan't open %s: %ss iÿÿÿÿi(tgetopttsystargvtret IGNORECASEtlentusagetcompileterrortstrtopentIOErrortreprtseekttelltNonetmintreadtsplittreversetsearch(tbufsizetreflagstoptstargstotatpatterntfilenametprogtmsgtftpostleftovertsizetbuffertlinestline((s+/usr/lib64/python2.7/Tools/scripts/rgrep.pytmain sR    '           icCs'tjt_|GHtGHtj|ƒdS(N(Rtstderrtstdoutt__doc__texit(Rtcode((s+/usr/lib64/python2.7/Tools/scripts/rgrep.pyR9s t__main__(R*RRRR'Rt__name__(((s+/usr/lib64/python2.7/Tools/scripts/rgrep.pyts    -