<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package trad;

=head1 Name

Package trad - a perl Module for naif translation

=head1  Synopsis

   use trad;

=head1  Description

=cut


BEGIN{
use Exporter;
@ISA   = (Exporter);
@EXPORT= qw(t_trad t_dict t_fdesc);
$status="sdd";			# sem dicionário definido
undef $proc_desc;
%trat_desc=("INTERACT" =&gt; sub { my $p=shift;
				   open(I,"/dev/tty");
				   print "Como traduzir $p?\n";
				   $r=&lt;I&gt;;
				   chop($r);
				   close(I);
				   $trad::dic{$p}=$r;
				   $r},
	    "PREFIX" =&gt; sub { "##".shift });
}

=head2 Setting dictionary(s)

In order to define the list of dictionaries to be used, call

   ...

A ordem dos argumentos (dicionários) na funç~ao t_dict 
n~ao é comutativa.  

=cut

sub t_dict {
	@ld = @_;
	for (@ld) {
		open (D, $_) or die("Can't open $_\n");
		while (&lt;D&gt;) {
			chomp;
			($a,$b) = split("=",$_);
			$dic{$a}=$b
		}
		close(D);
	}
	$status = "cdd";	# com dicionário definido
}			

sub t_trad {
	my $s = '='.shift;
	for($s)
	{
	 while(/=/){
		s/=($dont_touch|[.;!?0-9{}\s-]+)/$1=/;
		if(/=(\w+( \w+){2})/ &amp;&amp; defined $dic{$1})
		{
		 $p=$1;
		 s/=$p/$dic{$p}=/;
		}
		elsif(/=(\w+ \w+)/ &amp;&amp; defined $dic{$1})
		{
		 $p=$1;
		 s/=$p/$dic{$p}=/;
		}
		elsif(/=(\w+)/)
		{
		 s/=(\w+)/p_p($1)."="/e;
		}
		elsif(/=\s*$/)
		{
		 s/=//;
		}
		else {s/=(.)/$1=/;}
	}
    }
  $s;
}

sub p_p {			# processa palavra
	my $p = shift;
	if (exists $dic{$p} ) {
		$dic{$p};
	} 
	elsif (exists $dic{lcfirst $p}) {
		ucfirst $dic{lcfirst $p};
	}
	elsif (exists $dic{ucfirst $p}) {
		lcfirst $dic{ucfirst $p};
	}
	else {	
		proc_desc($p);
	}
}

sub proc_desc {
	my $p = shift;
	if (defined $proc_desc) {
		&amp;{$proc_desc}($p)
	}
	else { "#$p" }
}

sub t_fdesc { my $a=shift;
	if(ref($a) eq "CODE") {$proc_desc=$a;}
	else {$proc_desc=$trat_desc{$a};}
}

=head2 Text not to be touched

=cut

1;
</pre></body></html>