#!/usr/bin/perl # 日本語コンソール版 NDTP 簡易クライアント # Copyright (C) 1998- Yoshizumi Endo, ABSOLUTELY NO WARRANTY, Ver 0.1 # This program may be distributed under the terms of the GNU General # Public License. # 使用法: # # プロンプト dict> で、 # 'L' 利用可能な辞書の一覧を表示します。 # 'S ' 番号 の辞書を選択します。 # 'O' 選択中の辞書の奥書 (著作権) を表示します。 # 'C ' フレーム を転送し表示します。 # 'Q' 終了 # 'その他の単語' その単語を検索し、指定のページャで表示します。 # use Socket; $host = localhost; # ndtpd サーバのあるマシン $dic = 2; # 起動時に選択する辞書の番号 $pager = "/usr/bin/less"; # 検索結果を表示するためのページャ $tmp = "/tmp/dic.tmp"; # ページャが利用するテンポラリファイル # 初期設定等 &setup; &setdic($dic); # コマンド while (!$quit) { print "dict> "; $com = ; chomp $com; if ($com eq 'Q') {exit;} elsif ($com eq '') {©right;} elsif ($com eq 'O') {©right;} elsif ($com eq 'L') {&list;} elsif ($com =~ /^S/) {&setdic($com);} elsif ($com =~ /^C/) {&content($com);} else {$search = $com ; &search;} } # 辞書サーバへの接続 sub setup { socket(SOCK, &PF_INET, &SOCK_STREAM, 0) || die "ソケットが確立できません。\n"; ($addr) = (gethostbyname($host))[4] || die "ホスト $host が見つかりません。\n"; $sockaddr = pack('S n a4 x8', $AF_INET, 2010, $addr); connect(SOCK,$sockaddr) || die "辞書サーバに接続できません。\n"; $| = 1; select(SOCK); $| = 1; select(STDOUT); } # 辞書のセット sub setdic { $_[0] =~ s/[S ]//g; print SOCK "L$_[0]\n"; $a = ; if ($a ne "\$\*\n") { print STDERR "辞書がセットできませんでした。\n"; return; } else { ©right; } } # 検索 sub search { local @item, $p; print "検索中"; print SOCK "Pa$search\n"; $a = ; while (($a = ) ne "\$\$\n") { $p++; if ($p % 2){print ".";} chomp $a; push (@item, $a); } if (@item eq 0){ print ": $search は見つかりませんでした。\n\n"; return; } print " done.\n"; # 項目表示 &flame(@item); } # 指定のフレームを表示する。 sub flame { @item = @_; print "読込中"; open(OUTPUT,"> $tmp" ); for ($i=0; $i<@item; $i=$i+2) { print "."; print SOCK "S$item[$i+1]\n"; print OUTPUT "■"; $a = ; while (($a = ) ne "\$\$\n") { # $a =~ s/<[0-9a-z:]*>//g; # 整形 print OUTPUT $a; } } close(OUTPUT); print " done.\n\n"; &pager; } # コンテンツの表示 sub content { $_[0] =~ s/[C ]//g; $flame[0] = "C"; $flame[1] = $_[0]; &flame(@flame); } # 辞書一覧 sub list { print SOCK "T\n"; while (($a = ) ne "\$\*\n") { print $a; } } # 著作権表示 sub copyright { print SOCK "I\n"; $a = ; while (($a = ) ne "\$\$\n") { if ( $a =~ /OK/ ){ @copyflame = split(" ",$a); } } print SOCK "S$copyflame[1]:0\n"; $a = ; while (($a = ) ne "\$\$\n") { print $a; } } # ページャの起動 sub pager { $child_pid = fork; if ($child_pid==0) { #child exec ("$pager $tmp" ); } elsif ($child_pid != 0) { wait; } }