#!/usr/local/bin/perl
#
# Perlサーバを使った辞書引き
#
require 'clientserver.pl';
require "getopts.pl";
&Getopts('p');
$repeat = $opt_p;
$pat = shift;
exit if !$opt_p && !$pat;
&clientopen(5678,'CLIENTSOCK'); # サーバとの接続
if($repeat){
$| = 1;
open(tty,"/dev/tty");
while(1){
print "英和> ";
$pat = <tty>;
last if $pat eq '';
chop($pat);
&lookup($pat);
}
print "\n";
}
else {
&lookup($pat);
}
sub lookup {
local($pat) = @_;
print CLIENTSOCK "$pat\n"; # サーバに検索依頼
$ret = <CLIENTSOCK>; # 検索結果取得
chop($ret);
$ret =~ s/\r/\n/g;
print $ret;
}