X-Git-Url: https://git.treefish.org/fex.git/blobdiff_plain/cdeb354c4dbb11b683f9f8c5db2861f3dc572c61..refs/heads/master:/bin/fpg?ds=inline diff --git a/bin/fpg b/bin/fpg index 5f2f751..7e616bd 100755 --- a/bin/fpg +++ b/bin/fpg @@ -2,7 +2,7 @@ # # Programname: fpg - Frams' Perl grep # Author: framstag@rus.uni-stuttgart.de -# Copyright: GPL +# Licence: Perl Artistic # # History: # 2003-02-27 Framstag initial version @@ -18,13 +18,16 @@ # -n ==> -S, new -n option # 2008-10-14 Framstag added option -M # 2008-11-23 Framstag added option -~ +# 2016-06-12 Framstag option -o respects (match) use Getopt::Std; use Term::ReadLine; use locale; -sub usage { - die <30 and not /\\w/' script #See "perldoc perlre" for help on regular expressions. -} -$0 =~ s:.*/::; -$| = 1; $maxlen = 0; @@ -67,10 +67,15 @@ $opt_S = 4; $opt_x = $opt_X = ''; $opt_R = "\n"; -usage() if !getopts('hirvlLFMopscQen~S:R:C:x:X:') or $opt_h and not @ARGV; +getopts('hirvlLFMopscQen~S:R:C:x:X:') or die $usage; + +if ($opt_h) { + print $usage; + exit; +} unless ($opt_Q) { - $exp = shift or usage(); + $exp = shift or die $usage; } if ($opt_C and ($opt_l or $opt_L or $opt_s or $opt_v or $opt_p or $opt_M)) { @@ -129,7 +134,7 @@ sub scan { } else { $exp =~ s/([\@\$\%\^\&\*\(\)\+\[\]\{\}\\\|\.\?])/\\$1/g if $opt_F; $exp = '(?i)'.$exp if $opt_i; - $exp = '(?s)'.$exp if $opt_p or $opt_R; + $exp = '(?s)'.$exp if $opt_p or $opt_R ne "\n"; #? $exp =~ s/\.\*\*/[.\n]*/g; } @@ -277,12 +282,19 @@ sub grepf { else { $n++ while /$exp/omg } } else { if ($opt_o) { - my $m = ''; - while (s/($exp)//) { - $n++; - $m .= "$1\n"; + if ($exp =~ /\([^?]+\)/) { + if (/$exp/) { + $n++; + $_ = "$1\n"; + } + } else { + my $m = ''; + while (s/($exp)//) { + $n++; + $m .= "$1\n"; + } + $_ = $m; } - $_ = $m; } elsif ($opt_Q) { $n += s/($exp)/$B$1$N/mg; } else {