Commit 72f72d64 authored by Tatsuya Kinoshita's avatar Tatsuya Kinoshita

Adding upstream version 0.5.1

parent adc0f0ac
XXMakefile
Makefile
config.cache
config.log
config.status
config.h
config.param
funcname.tab
funcname.c
funcname1.h
funcname2.h
functable.c
tagtable.c
inflate
mktable
w3m
w3mbookmark
w3mhelperpanel
w3mimgdisplay
version.c
w3mhelp-lynx_en.html
w3mhelp-lynx_ja.html
w3mhelp-w3m_en.html
w3mhelp-w3m_ja.html
posubst
This diff is collapsed.
#!/usr/bin/perl
$WGET = "wget";
$SCRIPT_NAME = $ENV{'SCRIPT_NAME'} || $0;
$CGI = "file://$SCRIPT_NAME";
$_ = $QUERY_STRING = $ENV{"QUERY_STRING"};
$UserAgent = "Monazilla/1.00 (w3m/2ch.cgi)";
if (/subback.html$/) {
&subback();
exit;
}
s@/(\d+)(/([^/]*))?$@/$1@ || exit;
my $datnum = $1;
$label = $3;
$cgi = "$CGI?$_";
s@^http://([^/]+)/test/read.cgi/([^/]+)/@$1/$2/dat/@ || exit;
$subback = "$CGI?http://$1/$2/subback.html";
$bbs = $2;
if ($ENV{REQUEST_METHOD} eq "POST") {
&post();
exit;
}
$_ .= ".dat";
$dat = "http://$_";
$tmp = $ENV{"HOME"} . "/.w3m2ch/$_";
$dat =~ s/([^\w\/.\:\-])/\\$1/g;
$tmp =~ s/([^\w\/.\:\-])/\\$1/g;
($dir = $tmp) =~ s@/[^/]+$@@;
$cmd = "mkdir -p $dir; $WGET -c -U \"$UserAgent\" -O $tmp $dat >/dev/null 2>&1";
system $cmd;
$lines = (split(" ", `wc $tmp`))[0];
$lines || exit;
@ARGV = ($tmp);
if ($label =~ /^l(\d+)/) {
$start = $lines - $1 + 1;
if ($start < 1) {
$start = 1;
}
$end = $lines;
} elsif ($label =~ /^(\d+)-(\d+)/) {
$start = $1;
$end = $2;
} elsif ($label =~ /^(\d+)-/) {
$start = $1;
$end = $start + 100 - 1;
} elsif ($label =~ /^(\d+)/) {
$start = $1;
$end = $1;
} else {
$start = 1;
$end = $lines;
}
$head = "<a href=\"$subback\">■掲示板に戻る■</a>\n";
$head .= "<a href=\"$cgi/\">全部</a>\n";
for (0 .. ($lines - 1) / 100) {
$n = $_ * 100 + 1;
$head .= "<a href=\"$cgi/$n-\">$n-</a>\n";
}
$head .= "<a href=\"$cgi/l50\">最新50</a>\n";
print <<EOF;
Content-Type: text/html
EOF
$i = 1;
while (<>) {
s/\r?\n$//;
($name, $mail, $date, $_, $title) = split(/\<\>/);
if ($i == 1) {
if (!$title) {
print <<EOF;
このスレッドは過去ログ倉庫に格納されています。
<p>
<a href="$QUERY_STRING">$QUERY_STRING</a>
EOF
unlink($tmp);
exit
}
print <<EOF;
<title>$title</title>
$head
<p>$title</p>
<dl>
EOF
}
if ($mail) {
$name = "<a href=\"mailto:$mail\">$name</a>";
}
s@http://ime.nu/@http://@g;
s@(h?ttp:)([#-~]+)@"<a href=\"" . &link("http:$2") . "\">$1$2</a>"@ge;
s@(ftp:[#-~]+)@<a href="$1">$1</a>@g;
s@<a href="../test/read.cgi/\w+/\d+/@<a href="$cgi/@g;
if ($i == 1 || ($i >= $start && $i <= $end)) {
print <<EOF;
<dt><a name="$i">$i</a> :$name:$date
<dd>
$_
<p>
EOF
}
$i++;
}
print <<EOF;
</dl>
<hr>
<form method=POST action="$cgi"><input type=submit value="書き込む" name=submit> 名前: <input name=FROM size=19> E-mail<font size=1> (省略可) </font>: <input name=mail size=19><br><textarea rows=5 cols=70 wrap=off name=MESSAGE></textarea><input type=hidden name=bbs value=$bbs><input type=hidden name=key value=$datnum><input type=hidden name=time value=@{[time]}></form></body></html>
EOF
sub link {
local($_) = @_;
if (m@/test/read.cgi/@) {
return "$CGI?$_";
}
return $_;
}
sub subback {
$dat = $_;
s@http://@@ || exit;
$tmp = $ENV{"HOME"} . "/.w3m2ch/$_";
$dat =~ s/([^\w\/.\:\-])/\\$1/g;
$tmp =~ s/([^\w\/.\:\-])/\\$1/g;
($dir = $tmp) =~ s@/[^/]+$@@;
$cmd = "mkdir -p $dir; $WGET -O $tmp $dat >/dev/null 2>&1";
system $cmd;
print <<EOF;
Content-Type: text/html
EOF
@ARGV = ($tmp);
while (<>) {
if (/<base href="([^"]+)"/) {
$base = $1;
} elsif ($base) {
s@^<a href="@<a href="$CGI?$base@;
}
print;
}
unlink($tmp);
}
sub post {
my $debug = 0;
$| = 1;
use IO::Socket;
my @POST = <>;
$QUERY_STRING =~ m@^http://([^/]+)@;
my $host = $1;
my $sock = IO::Socket::INET->new("$host:80") or die;
# retrieve posting cookie; this may not work
print "Content-Type: text/html\n\n";
print $sock
"HEAD /test/bbs.cgi HTTP/1.1\n",
"Host: $host\n",
"Connection: keep-alive\n",
"\n";
my $posting_cookie = undef;
while (<$sock>) {
print if ($debug);
s/[\n\r]+$//;
last if (/^$/);
if (/^set-cookie:.*(PON=[^;]+)/i) {
$posting_cookie = $1;
}
}
#$sock = IO::Socket::INET->new("$host:80") or die;
my $submit =
"POST /test/bbs.cgi HTTP/1.1\n" .
"Host: $host\n" .
"Accept-Language: ja\n" .
"User-Agent: $UserAgent\n" .
"Referer: $QUERY_STRING\n" .
"Cookie: $posting_cookie; NAME=nobody; MAIL=sage\n" .
"Content-Length: " . length(join("", @POST)) . "\n" .
"\n@POST";
print $sock $submit or die;
print "\n-- POSTed contents --\n${submit}\n-- POSTed contents --\n"
if ($debug);
my $chunked = 0;
while (<$sock>) {
s/[\n\r]*$//;
last if (/^$/);
$chunked = 1 if (/^transfer-encoding:\s*chunked/i);
}
my $post_response = "";
while (<$sock>) {
if ($chunked) {
s/[ \r\n]*$//;
my $len = hex($_);
$len > 0 or last;
read($sock, $_, $len);
<$sock>; #skip empty line at the end of chunk.
}
$post_response .= $_;
}
$post_response =~ s/<META content=(\d+);URL=(\S+) http-equiv=refresh>/<META content=$1;URL=$cgi http-equiv=refresh>/im;
print $post_response;
exit;
}
2ch.cgi
[w3m-dev 03635] 2ch.cgi
2ch の dat を直読みする local CGI です。
w3m file:/cgi-bin/2ch.cgi?http://pc.2ch.net/test/read.cgi/unix/1035755937/
wget の差分転送(-c)を使います。
読んだ dat は ~/.w3m2ch/ 以下に保存します。
書き込みはできません。
smb.cgi
[w3m-dev 03634] smb.cgi
SMB にアクセスする local CGI です。
nmblookup,smbclient を使うので sabma がインストールされている
必要があります。
パスワードは、
1) ~/.w3m/smb にパスワードが設定されており、
smbclient の -A オプションを使えるなら
smbclient -A ~/.w3m/smb として渡します。
2) 環境変数 PASSWD_FILE (パスワードのみのファイル)が設定
されている場合は、環境変数 PASSWD_FILE を使います。
3) ~/.w3m/smb にパスワードが設定されていれば、
環境変数 PASSWD_FD を使って標準入力経由で渡します。
どちらにせよ、あまり良い事ではないので SMB(CIFS)プロトコルを
喋る版を希望。
google.cgi
[w3m-dev 03625] keymap key SEARCH string
html2latex
HTMLの文書をLaTeX に変換します.Rubyスクリプトです.不完全です.
ある程度の役には立つかもしれません.
使用法
html2latex file.html > file.tex
ここに置いてある理由
makeref のための部品取りです :-)
makeref
HTMLの文書を読み,アンカーに番号を振ります.番号を振った文書を
標準出力に書き出し,最後にその一覧を出力します.Ruby スクリプトです.
使用法
makeref [-url base_url] [file]
-url: 文書のURLを指定します.リンクの一覧を出すときに,そのURLを
補完するために使います.
バグ
HTMLの記述ミス( &lt; ではなく < を使う,&... の最後に ; を付けない
等)があると,悲惨な結果になることがあります.
半角カナ(JIS X-0201カナ)に対応していません.
htmldump
URL からHTML文書を読み,アンカーに番号を振って整形し,標準出力に
書き出します.
使用法
dumphtml [URL]
URL を省略すると,$WWW_HOME の内容を読みます.
バグ
URL の指す文書がHTMLでなかった場合,かわいそうなことになります.
makeref を使っているので,makeref がうまく処理できない文書の表示
は変になります.
2ch.cgi
[w3m-dev 03635] 2ch.cgi
localcgi to read 2ch dat directly
w3m file:/cgi-bin/2ch.cgi?http://pc.2ch.net/test/read.cgi/unix/1035755937/
It uses wget -c.
`dat' files are recorded under ~/w3m2ch/.
You can not post.
smb.cgi
[w3m-dev 03634] smb.cgi
localcgi to access SMB.
Since it uses nmblookup, smbclient, you should install samba.
Password can be passed to smbclient:
1) When the password is set by contents of ~/.w3m/smb and
-A option available, `smbclient -A ~/.w3m/smb' is used.
2) When the environment variable PASSWD_FILE, it is used.
3) When the password is set by contents of ~/.w3m/smb,
the password is passed via standrad I/O using
the environment variable PASSWD_FD.
google.cgi
[w3m-dev 03625] keymap key SEARCH string
html2latex
Convert HTML document into LaTeX. Ruby script. incomplete.
Usage:
html2latex file.html > file.tex
Why this script is here?
To exploit code for makeref. :-)
makeref
Read HTML document and number the anchors. Print numbered document
into standard output and append reference index. Ruby script.
Usage:
makeref [-u] [-url base_url] [file]
-url: Specify URL of the document. It is used to complete link
in the document.
-u: Append URL after each anchor, instead of reference number.
Bugs
If there are any error in HTML (unbalanced < , character entity
without ; , etc.), output will be miserable.
htmldump
Read HTML document from URL, number the anchors and format it,
and output it on standard output.
Usage
htmldump [-u] [URL]
-u: Append URL after each anchor, instead of reference number.
If URL is omitted, $WWW_HOME is used instead.
Bugs
It assumes that the document on URL is HTML.
As it uses makeref to number the anchor, it can't handle any document
makeref can't handle.
#!/usr/bin/perl
# keymap "x \\" GOTO file:/$LIB/backslash_to_slash.cgi
$_ = $ENV{W3M_CURRENT_LINK} || exit;
s@\\@/@g;
print <<EOF;
Location: $_
EOF
#!/usr/bin/perl
# ~/.w3m/urimethodmap
# e: file:/cgi-bin/goodict.cgi?%s
# w: file:/cgi-bin/goodict.cgi?%s
# j: file:/cgi-bin/goodict.cgi?%s
use NKF;
#$mode = 0; # substring
$mode = 1; # perfect match
#$mode = 3; # search body text
$url = "http://dictionary.goo.ne.jp";
$_ = $ENV{"QUERY_STRING"};
if (/^e:/) {
$kind = 'ej';
} elsif (/^w:/) {
$kind = 'je';
} elsif (/^j:/) {
$kind = 'jn';
}
s@^[ewjs]:@@ && s@^//@@ && s@/$@@;
if ($_) {
s/\+/ /g;
s/%([\da-f][\da-f])/pack('C', hex($1))/egi;
$_ = nkf("-e", $_);
s/[\000-\040\+:#?&%<>"\177-\377]/sprintf('%%%02X', unpack('C', $&))/eg;
$url .= "/search.php?MT=$_&kind=$kind&mode=$mode";
} else {
$input = "w3m-control: GOTO_LINK";
}
print <<EOF;
w3m-control: GOTO $url
w3m-control: DELETE_PREVBUF
w3m-control: SEARCH \\[
w3m-control: MOVE_RIGHT
${input}
EOF
#!/usr/bin/perl
# ~/.w3m/urimethodmap
# g: file:/cgi-bin/google.cgi?%s
# google: file:/cgi-bin/google.cgi?%s
$url = "http://www.google.com/";
$_ = $ENV{"QUERY_STRING"};
s@^g(oogle)?:@@ && s@^//@@ && s@/$@@;
if ($_) {
s/\+/ /g;
s/%([\da-f][\da-f])/pack('C', hex($1))/egi;
s/[\000-\040\+:#?&%<>"\177-\377]/sprintf('%%%02X', unpack('C', $&))/eg;
$url .= "search?q=$_&hl=ja&lr=lang_ja&ie=EUC-JP";
} else {
$input = "w3m-control: GOTO_LINK";
}
print <<EOF;
w3m-control: GOTO $url
w3m-control: DELETE_PREVBUF
w3m-control: SEARCH \\[
w3m-control: MOVE_RIGHT
${input}
EOF
This diff is collapsed.
#!/bin/sh
OPT=
if [ $# -gt 0 -a $1 = "-u" ]; then
OPT=-u
shift
fi
if [ $# = 0 ]; then
URL=$WWW_HOME
else
URL=$1
fi
w3m -dump_source $URL | makeref $OPT -url $URL | w3m -dump -F -T text/html
#!/usr/local/bin/ruby
# HTML reference generator
# by A.Ito 1999/3/30
require 'kconv'
###########################################################################
class URL
attr 'scheme'
attr 'host'
attr 'port'
attr 'file'
attr 'label'
def initialize(str)
if /([a-zA-Z+\-]+):(.*)/ =~ str then
@scheme = $1
str = $2
else
@scheme = 'unknown'
end
hostpart = ''
if %r'//([^/]*)(/.*)' =~ str then
hostpart = $1
str = $2
elsif %r'//([^/]*)$' =~ str then
hostpart = str
str = ''
end
if hostpart != '' then
if /(.*):(\d+)/ =~ hostpart then
@host = $1
@port = $2
else
@host = hostpart
@port = ''
end
else
@host = @port = ''
end
if /(.*)#(.*)/ =~ str then
@file = $1
@label = $2
else
@file = str
@label = ''
end
end
def to_s
s = "#{@scheme}:"
if s == 'news' or s == 'mailto' then
return s+@file
end
s += "//"+@host
s += ":"+@port if @port.size > 0
s += @file
s += "#"+@label if @label.size > 0
s
end
def complete(current)
@scheme = current.scheme if @scheme == 'unknown'
@port = current.port if @host == '' and @port == ''
@host = current.host if @host == ''
unless @file =~ %r'^/' then
@file = File.expand_path(File.dirname(current.file)+'/'+@file)
end
self
end
end
class Tag
def initialize(str)
if str =~ /<(.+)>/ then
str = $1
end
tags = str.split
@tagname = tags.shift.downcase
@vals = {}
tags.each do |t|
if t =~ /=/ then
tn,tv = t.split(/\s*=\s*/,2)
tv.sub!(/^"/,"")
tv.sub!(/"$/,"")
@vals[tn.downcase] = tv
else
@vals[t.downcase] = TRUE
end
end
end
def tagname
return @tagname
end
def each
@vals.each do |k,v|
yield k,v
end
end
def switch(k)
return @vals[k]
end
def to_s
if tagname =~ /!--/ then
return ''
end
t = "<"+tagname
if @vals.size == 0 then