#!/usr/bin/perl -s if ($h){ print 'nlgrep [-tag] [-f=prg] [exp] < filename option : -tag etiquetar o texto pondo "{" "}" nos padroes encontrados -f=prg expressao a procurar contida no ficheiro prg '; exit; } if ($f) { print "-f\n"; $file = $f; @exp = split(/[ \n]+/, `cat $file`) ; } else { print "+f\n"; @exp = @ARGS; @ARGS = (); } use jspell; jspell_dict("port"); $s='(?:[ ]*)'; $s2='(?:[ ]+)'; @x=(); @a=(); for (@exp) { # while($_ = shift) { ... } if ( /\{\}/) {@x = (@x, '(?:\b\w+|[.,;!?])');} elsif ( /\{.*?\}/) {@x = (@x, '(\b\w+|[.,;!?])'); @a = (@a,'ok('.$& . ',fea($'. ++$i .'))' );} else {s/\(/(?:/g; @x = (@x,'\b'. $_); } } eval "sub x { my \$z=shift; if (\$z =~ /" . join('${s}' , @x) . '/){ if('. join( ' and ',@a). ") { return \$`. \"{\$&}\" . &x(\$') ;} else { (\$x1,\$x2,\$x3)=(\$`,\$&,\$'); if(\$x2 =~/$s2/) {return \$x1. \$`. \$& . &x(\$'.\$x3) ;} else {return \$x1. \$x2. &x(\$x3) ;} } } else { return \$z } }\n" ; print $! if $@; eval "sub y { my \$z=shift; if (\$z =~ /" . join('${s}' , @x) . '/){ if('. join( ' and ',@a). ") { return (\"\$&\" , &y(\$')) ;} else { (\$x1,\$x2,\$x3)=(\$`,\$&,\$'); if(\$x2 =~/$s2/) {return (&y(\$'.\$x3)) ;} else {return (&y(\$x3)) ;} } } else { return (); } }\n" ; print $! if $@; #print "....\n"; while(<>){ if ($tag) {print &x($_) ;} else {for $w (&y($_)) {print "$w\n";} } } sub ok{ my ($a,@b)=@_; for $x (@b){ $ok = 1 ; for $c (keys %$a) { $ok=0 if $a->{$c} ne $x->{$c}; } return 1 if $ok; } return 0 ; }