namazu-ml(avocado)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
silly client for namazu
- From: Hajime BABA <baba@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 6 Feb 1998 20:23:59 +0900
- X-ml-name: namazu
- X-mail-count: 00128
馬場@京大宇宙物理 です。
(主にDoc-CDのことが前提にあるのですが)、UNIX で httpd をインストー
ルしていないなどの理由で CGI 経由でない検索を行う場合、
% namazu -h keyword > result.html
% netscape result.html
という二段階でなければブラウズできないのですが、それすら面倒くさい
という人のためのクライアントbnamazu を作りました。と言っても、凝っ
たことは何もしていなくて、上の二段階を自動でやるだけの事で、見たら
笑ってしまうような作りなので、多くを期待しないで下さい。(^_^;)
% bnamazu keyword
% bnamazu -b lynx keyword
% bnamazu -b lynx -n keyword
くらいかな。試すとしたら。
こんなのより、namazu.elの方が256倍完成度が高いので、明らかに
namazu.elを勧める方が良いのですが、muleを使わない人もいるだろうし、
という事でちょっといじってみたのです。
Tcl/Tk や X の場合は、&get_query() 部分をそれ相当に書き換えればそ
れでいいんじゃないかなあ。一時ファイルが残ってしまうという根本的欠
点がありますが、まあそこはそれ。部品取りにでも使ってください。
--
馬場 肇 ( Hajime BABA ) E-mail: baba@xxxxxxxxxxxxxxxxxxxxxx
京都大学理学部宇宙物理学教室 博士課程一回生
--
#!/usr/bin/perl
#
# bnamazu -- query via "namazu", and browse the result.
#
# Copyright (C) 1998 Hajime BABA. All rights reserved.
#
# Usage: bnamazu [-h] [-n] [-b browser] [options] [query...]
#
# -h Show usage.
# -n Open new window when you browse.
# -b browser Specify browser you want to use.
# (default: Netscape)
#
# Other options without -h, -n and -b are for namazu.
# Now available: [-f conf] [-s] [-l] [-e]
#
#
$debug = 1;
$prog = "bnamazu";
# definitions
$namazu = "namazu";
$namazu_opt = "-a -h"; # default option
if (defined($ENV{"BNAMAZUTMPDIR"})) {
$tmpdir = $ENV{"BNAMAZUTMPDIR"};
} elsif (defined($ENV{"TMPDIR"})) {
$tmpdir = $ENV{"TMPDIR"};
} else {
$tmpdir = "/tmp";
}
$results_html = "$tmpdir/$prog$$.html";
# programs
$rm = "/bin/rm -f";
$xterm = "kterm";
# browsers
$netscape = "netscape";
$lynx = "lynx";
$mosaic = "xmosaic";
$mmm = "mmm";
$more = "less";
$default_browser = "netscape";
# subroutines
require("getopts.pl");
sub usage {
print(stderr "Usage: $prog [-h] [-n] [-b browser] [options] [query...]\n");
exit 0;
}
sub parse_options {
# Getopts('hb:f:slean:w:');
Getopts('hnb:f:sle');
&usage if (defined($opt_h));
$newwindow = $opt_n if (defined($opt_n));
$browser = $opt_b if (defined($opt_b));
$namazu_opt .= " -f $opt_f" if (defined($opt_f));
$namazu_opt .= " -s" if (defined($opt_s));
$namazu_opt .= " -l" if (defined($opt_l));
$namazu_opt .= " -e" if (defined($opt_e));
# If we include '-a' within $namazu_opt as a default option,
# both options '-n' and '-w' are meaningless.
# $namazu_opt .= " -a" if (defined($opt_a));
# $namazu_opt .= " -n $opt_n" if (defined($opt_n));
# $namazu_opt .= " -w $opt_w" if (defined($opt_w));
}
sub get_query {
local($query);
if ($#ARGV == -1) { # no args
print("Input query: ");
$query = <STDIN>;
chop($query);
} else {
$query = join(" ", @ARGV);
$query = "\"$query\""; # brace with ""
}
$query;
}
sub exec_browser {
local($browser, $url) = @_;
$browser = $default_browser if (! defined($browser));
if ($browser =~ /netscape/i) {
$netscape_lockfile = "$ENV{\"HOME\"}/.netscape/lock";
# if exists symbolic link
if ( -l $netscape_lockfile ) {
# browse result to running netscape.
if ($newwindow) {
$browse_cmd = "$netscape -noraise -remote 'openURL($url,new-window)'";
} else {
$browse_cmd = "$netscape -remote 'openURL($url)'";
}
} else {
# invoke new netscape as a background process.
$browse_cmd = "$netscape $url &";
}
} elsif ($browser =~ /lynx/i) {
if ($newwindow) {
# invoke new terminal window as a background process.
$browse_cmd = "$xterm -e $xterm_opt $lynx $url &";
} else {
$browse_cmd = "$lynx $url";
}
} elsif ($browser =~ /mosaic/i) {
# This is untested. It doesn't work well probably. (;_;)
$browse_cmd = "$mosaic $url";
} elsif ($browser =~ /mmm/i) {
# This is untested. It doesn't work well probably. (;_;)
$browse_cmd = "$mmm $url";
} else {
# if unknown browser, show raw html... (;_;)
$browse_cmd = "$more $url";
}
# $browse_cmd .= "; $rm $url"; # mmm... X-(
# go!
print("$browse_cmd\n") if $debug;
exec($browse_cmd);
# not reached.
}
# main routine
sub main {
&parse_options();
$query = &get_query();
# invoke namazu via /bin/sh.
$query_cmd = "$namazu $namazu_opt $query > $results_html 2> /dev/null";
print("$query_cmd\n") if $debug;
system($query_cmd);
if ($?) {
print(stderr "$namazu: unknown error: $?\n");
exit 1;
}
# browse the result !
&exec_browser($browser, $results_html);
}
&main();
exit 0; # not reached.
## EOF