#!/usr/bin/perl use Getopt::Long; use jspell; jspell_dict("port"); GetOptions("f=s","t"); if ($opt_f) { @exp = split(/[ \n]+/, `cat $opt_f`) ; } else { @exp = split(/[ \n]+/, shift(@ARGS)); @ARGS = (); } eval "sub accao { for (\@_) " . pop(@exp) . "}\n" ; print $! if $@; $s='(?:[ ]*)'; $s2='(?:[ ]+)'; @x=(); @a=(); for (@exp) { # while($_ = shift) { print; 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 $@; while(<>){ # if ($v) {print &x($_) ;} # elsif ($awk) {&accao( &y($_)); } # else {for $w (&y($_)) {print "$w\n";} } &accao( &y($_)); } 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 ; }