#!/usr/bin/perl
#
# Dicionário Eletrônico - 21/04/2002
# fabiano@seng.com.br
#
# Português: http://www.priberam.pt/DLPO
# Inglês: http://www.m-w.com
# Tradução: http://babelfish.altavista.com
use strict;
use IO::Socket;
use Getopt::Std;
my (
$host, $port, $erro, $sock, $opt, $palavra, $get, $linha, $resultado, $tmp, $ok,
%args, @temp,
);
getopts("i:p:n:r:",\%args);
print "Dicionario Eletronico\n";
if ($args{i}) {
&opt_i;
} elsif ($args{p}) {
&opt_p;
} elsif ($args{n}) {
&opt_n;
} elsif ($args{r}) {
&opt_r;
} else {
&usage;
}
sub opt_i {
($palavra, $erro, $host, $port, $ok) = ($args{i}, 1, "12.129.203.38", 80, 1);
print "\n Opcao: Ingles (".$palavra.")\n ----------------------------------------------\n";
$palavra =~ s/ +/+/g;
&conecta;
if ($erro) {
$get = "GET /cgi-bin/dictionary?va=".$palavra." HTTP/1.0\n\n";
print $sock $get;
@temp = <$sock>;
for ($tmp=0;$tmp<=$#temp;$tmp++) {
if ($temp[$tmp] =~ /Pronunciation/) {
while ($ok) {
$resultado = $temp[$tmp];
$resultado =~ s/<(.*?)>//g;
$resultado =~ s/<//g;
$resultado =~ s/\n//g;
print " ".$resultado."\n";
if ($resultado =~ /Date:/) {
$tmp++;
$resultado = $temp[$tmp];
$resultado =~ s/
/\n /g;
$resultado =~ s/<(.*?)>//g;
$resultado =~ s/<//g;
print " ".$resultado;
$ok = 0;
}
$tmp++;
}
}
}
if ($ok) {
foreach $linha (@temp) {
if ($linha =~ /\/cgi-bin\/dictionary\?va=/) {
(undef, $resultado) = split(/>/,$linha);
($resultado, undef) = split(/,$resultado);
$resultado =~ s/\n//;
print " - ".$resultado."\n";
}
}
}
close($sock);
} else {
print " Erro ao conectar!\n";
}
}
sub opt_p {
($palavra, $erro, $host, $port, $tmp) = ($args{p}, 1, "193.126.1.131", 80, 1);
print "\n Opcao: Portugues (".$palavra.")\n ----------------------------------------------\n";
$palavra =~ s/ +/+/g;
&conecta;
if ($erro) {
$get = "GET /scripts/dlpouniv.dll?Command&search_value=".$palavra." HTTP/1.0\n\n";
print $sock $get;
foreach $linha (<$sock>) {
if ($linha =~ /<\/a>\r/) {
($resultado, undef) = split(/,$linha);
$resultado =~ s/\n//;
print " - ".$resultado."\n";
$tmp = 0;
} elsif ($linha =~ /red/) {
(undef, $resultado) = split(/<\/font>