Adding upstream version 0.5.1

This commit is contained in:
Tatsuya Kinoshita
2011-05-04 16:05:14 +09:00
parent adc0f0ac3c
commit 72f72d64a4
403 changed files with 329486 additions and 0 deletions

204
Bonus/2ch.cgi Executable file
View File

@@ -0,0 +1,204 @@
#!/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\"><3E><><EFBFBD>f<EFBFBD><66><EFBFBD>‚ɖ߂遡</a>\n";
$head .= "<a href=\"$cgi/\"><3E>S<EFBFBD><53></a>\n";
for (0 .. ($lines - 1) / 100) {
$n = $_ * 100 + 1;
$head .= "<a href=\"$cgi/$n-\">$n-</a>\n";
}
$head .= "<a href=\"$cgi/l50\"><3E>ŐV50</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;
<EFBFBD><EFBFBD><EFBFBD>̃X<EFBFBD><EFBFBD><EFBFBD>b<EFBFBD>h<EFBFBD>͉ߋ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD>q<EFBFBD>ɂɊi<EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>Ă<EFBFBD><C482>܂<EFBFBD><DC82>B
<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> <20>F$name<6D>F$date
<dd>
$_
<p>
EOF
}
$i++;
}
print <<EOF;
</dl>
<hr>
<form method=POST action="$cgi"><input type=submit value="<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" name=submit> <20><><EFBFBD>O<EFBFBD>F <input name=FROM size=19> E-mail<font size=1> (<28>ȗ<EFBFBD><C897><EFBFBD>) </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;
}

80
Bonus/README Normal file
View File

@@ -0,0 +1,80 @@
2ch.cgi
[w3m-dev 03635] 2ch.cgi
2ch <20><> dat <20><>ľ<EFBFBD>ɤߤ<C9A4><DFA4><EFBFBD> local CGI <20>Ǥ<EFBFBD><C7A4><EFBFBD>
w3m file:/cgi-bin/2ch.cgi?http://pc.2ch.net/test/read.cgi/unix/1035755937/
wget <20>κ<EFBFBD>ʬž<CAAC><C5BE>(-c)<29><><EFBFBD>Ȥ<EFBFBD><C8A4>ޤ<EFBFBD><DEA4><EFBFBD>
<20>ɤ<EFBFBD><C9A4><EFBFBD> dat <20><> ~/.w3m2ch/ <20>ʲ<EFBFBD><CAB2><EFBFBD><EFBFBD><EFBFBD>¸<EFBFBD><C2B8><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD>
<20>񤭹<EFBFBD><F1A4ADB9>ߤϤǤ<CFA4><C7A4>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD>
smb.cgi
[w3m-dev 03634] smb.cgi
SMB <20>˥<EFBFBD><CBA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> local CGI <20>Ǥ<EFBFBD><C7A4><EFBFBD>
nmblookup,smbclient <20><><EFBFBD>Ȥ<EFBFBD><C8A4>Τ<EFBFBD> sabma <20><><EFBFBD><EFBFBD><EFBFBD>󥹥ȡ<F3A5B9A5><C8A1><EFBFBD><EBA4B5><EFBFBD>Ƥ<EFBFBD><C6A4><EFBFBD>
ɬ<>פ<EFBFBD><D7A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD>
<20>ѥ<EFBFBD><D1A5><EFBFBD>ɤϡ<C9A4>
1) ~/.w3m/smb <20>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E8A1A2><EFBFBD>ޤ<EFBFBD><DEA4>ɤ<EFBFBD><C9A4><EFBFBD><EFBFBD>ǤϤʤ<CFA4><CAA4>Τ<EFBFBD> SMB(CIFS)<29>ץ<EFBFBD><D7A5>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD>Ǥ<EFBFBD><C7A4><EFBFBD>˾<EFBFBD><CBBE>
google.cgi
[w3m-dev 03625] keymap key SEARCH string
html2latex
HTML<4D><4C>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD>LaTeX <20><><EFBFBD>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD>Ruby<62><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ץȤǤ<C8A4><C7A4><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>Ǥ<EFBFBD><C7A4><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>٤<EFBFBD><D9A4><EFBFBD><EFBFBD>ˤ<EFBFBD>Ω<EFBFBD>Ĥ<EFBFBD><C4A4><EFBFBD><E2A4B7><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD>ˡ
html2latex file.html > file.tex
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4>Ƥ<EFBFBD><C6A4><EFBFBD><EFBFBD><EFBFBD>ͳ
makeref <20>Τ<EFBFBD><CEA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>Ǥ<EFBFBD> :-)
makeref
HTML<4D><4C>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD><EFBFBD>ɤߡ<C9A4><DFA1><EFBFBD><EFBFBD>󥫡<EFBFBD><F3A5ABA1><EFB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<C3A4><C6A4><EFBFBD><EFBFBD>Τǡ<CEA4>makeref <20><><EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǥ<EFBFBD><C7A4>ʤ<EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>
<20><><EFBFBD>Ѥˤʤ<CBA4><CAA4>ޤ<EFBFBD><DEA4><EFBFBD>

77
Bonus/README.eng Normal file
View File

@@ -0,0 +1,77 @@
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.

9
Bonus/backslash_to_slash.cgi Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/perl
# keymap "x \\" GOTO file:/$LIB/backslash_to_slash.cgi
$_ = $ENV{W3M_CURRENT_LINK} || exit;
s@\\@/@g;
print <<EOF;
Location: $_
EOF

38
Bonus/goodict.cgi Executable file
View File

@@ -0,0 +1,38 @@
#!/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

25
Bonus/google.cgi Executable file
View File

@@ -0,0 +1,25 @@
#!/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

517
Bonus/html2latex Executable file
View File

@@ -0,0 +1,517 @@
#!/usr/local/bin/ruby
#
# HTML to LaTeX converter
# by A. Ito, 16 June, 1997
#
require 'kconv'
# configuration
def gif2eps(giffile,epsfile)
cmd = "convert #{giffile} #{epsfile}"
STDERR.print cmd,"\n"
system cmd
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
end
class TokenStream
TAG_START = ?<
TAG_END = ?>
AMP_START = ?&
AMP_END = ?;
AMP_REPLACE_TABLE = {
'&amp;' => '\\&',
'&gt;' => '$>$',
'&lt;' => '$<$',
'&nbsp;' => '~',
'&quot;' => '"',
}
def initialize(file)
if file.kind_of?(File) then
@f = file
else
@f = File.new(file)
end
@buf = nil
@bpos = 0
end
def read_until(endsym)
complete = FALSE
tag = []
begin
while @bpos < @buf.size
c = @buf[@bpos]
if c == endsym then
tag.push(c.chr)
complete = TRUE
@bpos += 1
break
end
if c == 10 || c == 13 then
tag.push(' ')
else
tag.push(c.chr)
end
@bpos += 1
end
unless complete
@buf = @f.gets
@bpos = 0
break if @f.eof?
end
end until complete
return tag.join('')
end
def get
while TRUE
if @buf.nil? then
@buf = Kconv.toeuc(@f.gets)
if @f.eof? then
return nil
end
@bpos = 0
end
if @buf[@bpos] == TAG_START then
return Tag.new(read_until(TAG_END))
elsif @buf[@bpos] == AMP_START then
return replace_amp(read_until(AMP_END))
else
i = @bpos
while i < @buf.size && @buf[i] != TAG_START && @buf[i] != AMP_START
i += 1
end
r = @buf[@bpos,i-@bpos]
if i == @buf.size then
@buf = nil
else
@bpos = i
end
redo if r =~ /^\s+$/
return r
end
end
end
public :eof?
def eof?
@f.eof?
end
def replace_amp(s)
if AMP_REPLACE_TABLE.key?(s) then
return AMP_REPLACE_TABLE[s]
else
return s
end
end
end
def print_header
print '
\documentstyle[epsf]{jarticle}
\def\hr{\par\hbox to \textwidth{\hrulefill}}
\def\pre{\begin{quote}\def\baselinestretch{0.8}\tt\obeylines}
\def\endpre{\end{quote}}
\makeatletter
\@ifundefined{gt}{\let\gt=\dg}{}
\makeatother
'
end
class Environ_stack
def initialize(*envs)
@stack = envs
end
def action(tag)
if tag =~ /^!/ then # comment
return ["",nil]
end
i = @stack.size-1
while i >= 0
a = @stack[i].action(tag)
unless a.nil? then
return a
end
i -= 1
end
return nil
end
def pop
@stack.pop
end
def push(env)
@stack.push(env)
end
def top
@stack[@stack.size-1]
end
def dup
@stack.push(top.clone)
end
end
class Environment
def initialize(interp)
@silent = FALSE
@in_table = FALSE
@interp = interp;
@align = nil;
end
def action(tag)
return @interp[tag]
end
def flush(tok)
if tok.kind_of?(String) then
tok = tok.gsub(/&/,"\\&");
tok = tok.gsub(/%/,"\\%");
tok = tok.gsub(/#/,"\\#");
tok = tok.gsub(/\$/,"\\$");
tok = tok.gsub(/_/,"\\verb+_+");
tok = tok.gsub(/\^/,"\\verb+^+");
tok = tok.gsub(/~/,"\\verb+~+");
end
if @in_table then
@table[@table_rows][@table_cols] += tok
elsif !@silent then
if !@align.nil? && tok =~ /\n$/ then
print tok.chop,"\\\\\n"
else
print tok
end
end
end
def set_interp(interp)
@interp = interp
end
# tag processing methods
# <TITLE>
def do_silent(tag)
@silent = TRUE
end
# </TITLE>
def undo_silent(tag)
@silent = FALSE
end
# <IMG>
def img_proc(tag)
src = tag.switch('src')
newfile = src.sub(/\.GIF/i,".eps")
gif2eps(src,newfile)
flush "\\epsfile{file=#{newfile}}\n"
end
# <TABLE>
def starttable(tag)
@table = []
@tablespan = []
@table_rows = -1
@table_cols_max = 0
@in_table = TRUE
unless tag.switch('border').nil? then
@table_border = TRUE
else
@table_border = FALSE
end
end
# <TR>
def start_row(tag)
@table_rows += 1
@table[@table_rows] = []
@tablespan[@table_rows] = []
@table_cols = -1
@colspan = 1
end
# <TD>
def start_col(tag)
@colspan = tag.switch('colspan')
if @colspan.nil? then
@colspan = 1
else
@colspan = @colspan.to_i
end
@tablespan[@table_rows][@table_cols+1] = @colspan
@table_cols += @colspan
if @table_cols > @table_cols_max then
@table_cols_max = @table_cols
end
end
# </TABLE>
def endtable(tag)
@in_table = FALSE
flush "\\begin{tabular}{*{"
flush @table_cols_max+1
if @table_border then
flush "}{|l}|}\n\\hline\n"
else
flush "}{l}}\n"
end
for i in 0..@table_rows
j = 0
while j <= @table_cols
span = @tablespan[i][j]
if span == 1 then
flush @table[i][j]
elsif @table_border then
form = "|l"
if j+span > @table_cols then
form = "|l|"
end
flush "\\multicolumn{"+span.to_s+"}{"+form+"}{"
flush @table[i][j+span-1]
flush "}"
else
flush "\\multicolumn{"+span.to_s+"}{l}{"
flush @table[i][j+span-1]
flush "}"
end
j += span
if j <= @table_cols then
flush "&"
end
end
flush "\\\\\n"
flush "\\hline\n" if @table_border
end
flush "\\end{tabular}\n"
end
# <CENTER>
def startcenter(tag)
if @in_table then
flush "\\hfil"
else
flush "\\begin{center}\n"
end
end
# </CENTER>
def endcenter(tag)
if @in_table then
flush "\\hfil"
else
flush "\\end{center}\n"
end
end
# <P>
def paragraph(tag)
align = tag.switch('align')
if align.nil? then
flush "\\par\n"
@endparagraph = ""
else
align = align.downcase
case align
when "left" then
flush "\\begin{flushleft}\n"
@endparagraph = "\\end{flushleft}\n"
when "center" then
flush "\\begin{center}\n"
@endparagraph = "\\end{center}\n"
when "right" then
flush "\\begin{flushright}\n"
@endparagraph = "\\end{flushright}\n"
end
end
@align = align
end
# </P>
def endparagraph(tag)
unless @align.nil? then
@align = nil
flush @endparagraph
end
end
end
enum_interp = {
'li' => ["\\item ",nil]
}
item_interp = {
'li' => ["\\item ",nil]
}
desc_interp = {
'dt' => ["\\item[",nil],
'dd' => ["]\n",nil]
}
table_interp = {
'tr' => [:start_row,nil],
'td' => [:start_col,nil],
'/tr' => ["",nil],
'/td' => ["",nil],
}
para_interp = {
'/p' => [:endparagraph ,"pop",TRUE],
}
main_interp = {
'body' => ["\\begin{document}\n",nil,FALSE],
'/body' => ["\\end{document}\n",nil,FALSE],
'head' => ["",nil,FALSE],
'/head' => ["",nil,FALSE],
'html' => ["",nil,FALSE],
'/html' => ["",nil,FALSE],
'title' => [:do_silent,nil,FALSE],
'/title' => [:undo_silent,nil,FALSE],
'!' => ["",nil,FALSE],
'h1' => ["\\section{",nil,TRUE],
'h2' => ["\\subsection{",nil,TRUE],
'h3' => ["\\subsubsection{",nil,TRUE],
'h4' => ["\\paragraph{",nil,TRUE],
'/h1' => ["}\n",nil,TRUE],
'/h2' => ["}\n",nil,TRUE],
'/h3' => ["}\n",nil,TRUE],
'/h4' => ["}\n",nil,TRUE],
'a' => ["",nil,TRUE],
'/a' => ["",nil,TRUE],
'center' => [:startcenter,nil,TRUE],
'/center' => [:endcenter,nil,TRUE],
'ol' => ["\\begin{enumerate}\n",enum_interp,TRUE],
'/ol' => ["\\end{enumerate}\n","pop",TRUE],
'ul' => ["\\begin{itemize}\n",item_interp,TRUE],
'/ul' => ["\\end{itemize}\n","pop",TRUE],
'dl' => ["\\begin{description}\n",desc_interp,TRUE],
'/dl' => ["\\end{description}\n","pop",TRUE],
'pre' => ["\\begin{pre}\n",nil,TRUE],
'/pre' => ["\\end{pre}\n",nil,TRUE],
'p' => [:paragraph ,para_interp,TRUE],
'br' => ["\\par ",nil,TRUE],
'img' => [:img_proc,nil,TRUE],
'hr' => ["\\hr ",nil,TRUE],
'b' => ["{\\bf\\gt ",nil,TRUE],
'/b' => ["}",nil,TRUE],
'strong' => ["{\\bf\\gt ",nil,TRUE],
'/strong' => ["}",nil,TRUE],
'dfn' => ["{\\bf\\gt ",nil,TRUE],
'/dfn' => ["}",nil,TRUE],
'i' => ["{\\it",nil,TRUE],
'/i' => ["}",nil,TRUE],
'address' => ["{\\it",nil,TRUE],
'/address'=> ["}",nil,TRUE],
'cite' => ["{\\it",nil,TRUE],
'/cite' => ["}",nil,TRUE],
'code' => ["{\\tt",nil,TRUE],
'/code' => ["}",nil,TRUE],
'kbd' => ["{\\tt",nil,TRUE],
'/kbd' => ["}",nil,TRUE],
'tt' => ["{\\tt",nil,TRUE],
'/tt' => ["}",nil,TRUE],
'samp' => ["{\\tt",nil,TRUE],
'/samp' => ["}",nil,TRUE],
'em' => ["{\\em",nil,TRUE],
'/em' => ["}",nil,TRUE],
'u' => ["$\\underline{\\mbox{",nil,TRUE],
'/u' => ["}}$",nil,TRUE],
'sub' => ["${}_\mbox{",nil,TRUE],
'/sub' => ["}$",nil,TRUE],
'sup' => ["${}^\mbox{",nil,TRUE],
'/sup' => ["}$",nil,TRUE],
'table' => [:starttable, table_interp,TRUE],
'/table' => [:endtable, "pop",TRUE],
'font' => ["",nil,TRUE],
'/font' => ["",nil,TRUE],
}
################################ MAIN ####################################
$in_document = FALSE
print_header
intp = Environ_stack.new(Environment.new(main_interp))
f = TokenStream.new(ARGV[0])
until f.eof?
tok = f.get
if tok.kind_of?(Tag) then
case tok.tagname
when "body"
$in_document = TRUE
when "/body"
$in_document = FALSE
end
act = intp.action(tok.tagname)
if act.nil? then
STDERR.print "tag ",tok.tagname," ignored\n"
else
if act[2] && !$in_document then
print "\\begin{document}\n"
$in_document = TRUE
end
# environment push
if act[1].kind_of?(Hash) &&
(tok.tagname != "p" || tok.switch('align') != nil) then
intp.dup
intp.top.set_interp(act[1])
end
if act[0].kind_of?(String) then
intp.top.flush act[0]
elsif act[0].kind_of?(Fixnum) then # interned symbol
intp.top.send(act[0],tok)
end
# environment pop
if act[1] == "pop" then
intp.pop
end
end
elsif !tok.nil? then
intp.top.flush tok
end
end
if $in_document then
print "\\end{document}\n"
end

12
Bonus/htmldump Executable file
View File

@@ -0,0 +1,12 @@
#!/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

266
Bonus/makeref Executable file
View File

@@ -0,0 +1,266 @@
#!/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
return t+">"
end
each do |a,v|
if v == true then
t += " #{a}"
else
t += " #{a}=\"#{v}\""
end
end
t+">"
end
end
class TokenStream
TAG_START = ?<
TAG_END = ?>
AMP_START = ?&
AMP_END = ?;
def initialize(file)
if file.kind_of?(IO) then
@f = file
else
@f = File.new(file)
end
@buf = nil
@bpos = 0
end
def read_until(endsym)
complete = FALSE
tag = []
begin
while @bpos < @buf.size
c = @buf[@bpos]
if c == endsym then
tag.push(c.chr)
complete = TRUE
@bpos += 1
break
end
if c == 10 || c == 13 then
tag.push(' ')
else
tag.push(c.chr)
end
@bpos += 1
end
unless complete
@buf = @f.gets
@bpos = 0
break if @f.eof?
end
end until complete
return tag.join('')
end
def get
while TRUE
if @buf.nil? then
@buf = @f.gets
if @f.eof? then
return nil
end
@buf = Kconv.toeuc(@buf)
@bpos = 0
end
if @buf[@bpos] == TAG_START then
return Tag.new(read_until(TAG_END))
elsif @buf[@bpos] == AMP_START then
return read_until(AMP_END)
else
i = @bpos
while i < @buf.size && @buf[i] != TAG_START && @buf[i] != AMP_START
i += 1
end
r = @buf[@bpos,i-@bpos]
if i == @buf.size then
@buf = nil
else
@bpos = i
end
redo if r =~ /^\s+$/
return r
end
end
end
public :eof?
def eof?
@f.eof?
end
end
################################ MAIN ####################################
refs = []
refnum = 0
body_finished = false
html_finished = false
currentURL = nil
immediate_ref = false
while ARGV[0] =~ /^-/
case ARGV.shift
when '-url'
currentURL = URL.new(ARGV.shift)
when '-u'
immediate_ref = true
end
end
if ARGV.size > 0 then
f = TokenStream.new(ARGV[0])
else
f = TokenStream.new(STDIN)
end
until f.eof?
tok = f.get
if tok.kind_of?(Tag) then
if tok.tagname == 'a' and !tok.switch('href').nil? then
refs[refnum] = tok.switch('href')
refnum += 1
elsif tok.tagname == '/a' then
if immediate_ref then
r = refs[refnum-1]
if !currentURL.nil? then
r = URL.new(r).complete(currentURL).to_s
end
print "[#{r}]"
else
print "[#{refnum}]"
end
elsif tok.tagname == '/body' then
body_finished = true
break
elsif tok.tagname == '/html' then
html_finished = true
break
end
print tok.to_s
elsif !tok.nil? then
print tok
end
end
if !immediate_ref and refs.size > 0 then
print "<hr><h2>References</h2>\n"
for i in 0..refs.size-1
if currentURL.nil? then
r = refs[i]
else
r = URL.new(refs[i])
r.complete(currentURL)
r = r.to_s
end
print "[#{i+1}] #{r}<br>\n"
end
end
print "</body>\n" unless body_finished
print "</html>\n" unless html_finished

183
Bonus/oldconfigure.sh Executable file
View File

@@ -0,0 +1,183 @@
#! /bin/sh
#
# oldconfig.sh: convert a config.param file and execute configure
#
# functions
opt_push () {
# OPT="${OPT} $1"
OPT="${OPT} \\
$1"
}
opt_enable_set () {
val=""
if test x"$1" = xy; then
val="--enable-$2"
elif test x"$1" = xn; then
val="--disable-$2"
fi
if test x"$val" != x; then
opt_push "$val"
fi
}
opt_with_set () {
val=""
if test x"$1" != x; then
val="--with-$2='$1'"
else
val="--without-$2"
fi
if test x"$val" != x; then
opt_push "$val"
fi
}
env_set () {
# no overwrite
if test x"$1" != x && eval "test -z \"\$$1\"" > /dev/null; then
echo "$1='$2'; export $1"
eval "$1='$2'; export $1"
fi
}
# main
topdir="`dirname $0`/.."
if test x"$1" = x-v; then
echo_only=yes
shift
fi
if test x"$1" = x; then
echo "USAGE: $0 [-v] <config.param file>"
echo " option: -v ... echo only"
exit 1
fi
if expr "$1" : '.*/' > /dev/null; then
conffile="$1"
else
conffile=./"$1"
fi
. "$conffile" # read config.param
OPT=""
libdir=`echo $libdir | sed 's@/w3m[^/]*/cgi-bin@@'`
libexecdir=`echo $auxbindir | sed 's@/w3m[^/]*@@'`
datadir=`echo $helpdir | sed 's@/w3m[^/]*@@'`
sysconfdir=`echo $sysconfdir | sed 's@/w3m[^/]*@@'`
opt_push "--bindir='$bindir'"
opt_push "--libexecdir='$libexecdir'"
opt_push "--datadir='$datadir'"
opt_push "--sysconfdir='$sysconfdir'"
opt_push "--libdir='$libdir'"
opt_push "--mandir='$mandir'"
#case "$dmodel" in
# 1) val=baby;;
# 2) val=little;;
# 3) val=mouse;;
# 4) val=cookie;;
# 5) val=monster;;
# *) echo "ERROR: Illegal model type (model=$dmodel)."
# exit 1;;
#esac
#opt_push "--enable-model=$val"
case "$lang" in
JA)
if test x$display_code != x; then
opt_push "--enable-japanese='$display_code'"
else
opt_push "--enable-japanese"
fi
opt_enable_set "$kanji_symbols" kanjisymbols
;;
*)
;;
esac
opt_enable_set "$use_color" color
opt_enable_set "$use_ansi_color" ansi-color
opt_enable_set "$use_bg_color" bgcolor
if test x"$use_migemo" = xy; then
if test x"$def_migemo_command" != x; then
opt_push "--with-migemo='$def_migemo_command'"
fi
elif test x"$use_migemo" = xn; then
opt_push "--without-migemo"
fi
opt_enable_set "$use_mouse" mouse
opt_enable_set "$use_menu" menu
opt_enable_set "$use_cookie" cookie
opt_enable_set "$use_dict" dict
opt_enable_set "$use_history" history
opt_enable_set "$use_digest_auth" digest-auth
opt_enable_set "$use_nntp" nntp
opt_enable_set "$use_gopher" gopher
if test x"$use_lynx_key" = xy; then
opt_push "--enable-keymap=lynx"
else
opt_push "--enable-keymap=w3m"
fi
opt_with_set "$ded" editor
opt_with_set "$dmail" mailer
opt_with_set "$dbrowser" browser
opt_enable_set "$use_help_cgi" help-cgi
opt_enable_set "$use_external_uri_loader" external-uri-loader
opt_enable_set "$use_w3mmailer" w3mmailer
opt_enable_set "$use_alarm" alarm
if test x"$use_image" = xy; then
val_x11=""
val_fb=""
if test x"$use_w3mimg_x11" = xy; then
val_x11="x11"
fi
if test x"$use_w3mimg_fb" = xy; then
if test x"$w3mimgdisplay_setuid" = xy; then
val_fb="fb+s"
else
val_fb="fb"
fi
fi
if test x"$val_x11" != x; then
if test x"$val_fb" != x; then
val="$val_x11,$val_fb"
else
val="$val_x11"
fi
elif test x"$val_fb" != x; then
val="$val_fb"
fi
if test x"$val" = x; then
opt_push "--enable-image"
else
opt_push "--enable-image='$val'"
fi
opt_enable_set "$use_xface" xface
elif test x"$use_image" = xn; then
opt_push "--disable-image"
fi
if test x"$dtermlib" != x; then
dtermlib=`echo "$dtermlib"|sed 's/^-l//'`
opt_with_set "$dtermlib" termlib
fi
if test x"$use_ssl" = xy; then
opt_push "--with-ssl"
opt_enable_set "$use_ssl_verify" sslverify
elif test x"$use_ssl" = xn; then
opt_push "--without-ssl"
fi
opt_enable_set "$use_ipv6" ipv6
env_set CC "$dcc"
env_set CFLAGS "$dcflags"
env_set LDFLAGS "$dldflags"
echo "( cd '$topdir' && sh configure ${OPT} )"
if test "${echo_only+set}" != set; then
echo "( cd '$topdir' && sh configure ${OPT} )" | sh
fi

88
Bonus/scanhist.rb Normal file
View File

@@ -0,0 +1,88 @@
#!/usr/local/bin/ruby
# scan history
def usage
STDERR.print "usage: scanhist -h HISTORY ML-archive1 ML-archive2 ...\n"
exit 1
end
def html_quote(s)
s.gsub!(/&/,"&amp;")
s.gsub!(/</,"&lt;")
s.gsub!(/>/,"&gt;")
s
end
if ARGV.size == 0 then
usage
end
histfile = nil
while ARGV[0] =~ /^-/
case ARGV.shift
when "-h"
histfile = ARGV.shift
else
usage
end
end
if histfile.nil? then
usage
end
patched = {}
histline = {}
f = open(histfile)
while f.gets
if /Subject: (\[w3m-dev.*\])/ then
patched[$1] = true
histline[$1] = $.
end
end
f.close
archive = {}
subject = nil
for fn in ARGV
f = open(fn)
while f.gets
if /^From / then
# beginning of a mail
subject = nil
elsif subject.nil? and /^Subject: / then
$_ =~ /Subject: (\[w3m-dev.*\])/
subject = $1
archive[subject] = [$_.chop.sub(/^Subject:\s*/,""),false,fn+"#"+($.).to_s]
elsif /^\+\+\+/ or /\*\*\*/ or /filename=.*(patch|diff).*/ or /^begin \d\d\d/
archive[subject][1] = true
end
end
f.close
end
print "<html><head><title>w3m patch configuration\n</title></head><body>\n"
print "<pre>\n"
for sub in archive.keys.sort
a = archive[sub]
if a[1] then
if patched[sub] then
print "[<a href=\"#{histfile}\##{histline[sub]}\">+</a>]"
else
print "[-]"
end
print "<a href=\"#{a[2]}\">"
print "<b>",html_quote(a[0]),"</b></a>\n"
else
if patched[sub] then
print "[<a href=\"#{histfile}\##{histline[sub]}\">o</a>]"
else
print " "
end
print "<a href=\"#{a[2]}\">"
print "<b>",html_quote(a[0]),"</b></a>\n"
end
end
print "</pre></body></html>\n"

462
Bonus/smb.cgi Executable file
View File

@@ -0,0 +1,462 @@
#!/usr/bin/perl
# Workgroup list: file:/$LIB/smb.cgi
# Server list: file:/$LIB/smb.cgi?workgroup
# Sahre list: file:/$LIB/smb.cgi?//server
# file:/$LIB/smb.cgi/server
# Directory: file:/$LIB/smb.cgi?//server/share
# file:/$LIB/smb.cgi?//server/share/dir...
# file:/$LIB/smb.cgi/server/share
# Get file: file:/$LIB/smb.cgi?//server/share/dir.../file
# file:/$LIB/smb.cgi/server/share/dir.../file
#
# ----- ~/.w3m/smb -----
# workgroup = <workgroup>
# [ username = <username> ]
# [ password = <password> ]
# [ password_file = <password_file> ]
# ----------------------
# --- <password_file> ---
# <password>
# -----------------------
# default:
# <username> = $USER
# <password> = $PASSWD (Don't use!)
# <password_file> = $PASSWD_FILE
$DEBUG = 1;
$MIME_TYPE = "~/.mime.types";
$AUTH_FILE = "~/.w3m/smb";
$MIME_TYPE =~ s@^~/@$ENV{"HOME"}/@;
$AUTH_FILE =~ s@^~/@$ENV{"HOME"}/@;
$WORKGROUP = "-";
$USER = $ENV{"USER"};
$PASSWD = $ENV{"PASSWD"};
$PASSWD_FILE = $ENV{"PASSWD_FILE"};
&load_auth_file($AUTH_FILE);
$NMBLOOKUP = "nmblookup";
$SMBCLIENT = "smbclient";
@NMBLOOKUP_OPT = ("-T");
@SMBCLIENT_OPT = ("-N");
$USE_OPT_A = defined($PASSWD) && (-f $AUTH_FILE) && &check_opt_a();
if ($USE_OPT_A) {
push(@SMBCLIENT_OPT, "-A", $AUTH_FILE);
} elsif (-f $PASSWD_FILE) {
$USE_PASSWD_FILE = 1;
} elsif (defined($PASSWD)) {
$USE_PASSWD_FD = 1;
$PASSWD_FD = 0;
}
if (defined($PASSWD)) {
$passwd = "*" x 8;
}
$DEBUG && print <<EOF;
DEBUG: NMBLOOKUP=$NMBLOOKUP @NMBLOOKUP_OPT
DEBUG: SMBCLIENT=$SMBCLIENT @SMBCLIENT_OPT
DEBUG: WORKGROUP=$WORKGROUP
DEBUG: USER=$USER
DEBUG: PASSWD=$passwd
DEBUG: PASSWD_FILE=$PASSWD_FILE
DEBUG: PASSWD_FD=$PASSWD_FD
EOF
$PAGER = "cat";
$FILE = "F000";
$CGI = "file://" . &file_encode($ENV{"SCRIPT_NAME"} || $0);
$QUERY = $ENV{"QUERY_STRING"};
$PATH_INFO = $ENV{"PATH_INFO"};
if ($PATH_INFO =~ m@^/@) {
$_ = $PATH_INFO;
if (! m@^//@) {
$_ = "/$_";
}
s@[\r\n\0\\"]@@g;
$DEBUG && print "DEBUG: PATH_INFO=\"$_\"\n";
$Q = "";
}
else {
$_ = &file_decode($QUERY);
$DEBUG && print "DEBUG: QUERY_STRING=\"$_\"\n";
$Q = "?";
}
if (s@^//([^/]+)@@) {
$server = $1;
# if (!$USE_OPT_A && !defined($PASSWD)) {
# &print_form("//$server$_");
# exit;
# }
if (s@^/([^/]+)@@) {
&file_list("//$server/$1", &cleanup($_));
} else {
&share_list($server);
}
} elsif (m@^[^/]@) {
&server_list($_);
} else {
&group_list();
}
sub file_list {
local($service, $file) = @_;
local(@files) = ();
local($dir, $qservice, $qfile);
local($_, $c);
$DEBUG && print "DEBUG: service=\"$service\" file=\"$file\"\n";
if ($file eq "/") {
goto get_list;
}
$_ = $file;
s@/@\\@g;
@cmd = ($SMBCLIENT, $service, @SMBCLIENT_OPT, "-c", "ls \"$_\"");
$F = &open_pipe(1, @cmd);
while (<$F>) {
$DEBUG && print "DEBUG: $_";
/^\s/ && last;
}
close($F);
if (s/\s+([A-Z]*) {1,8}\d+ (\w{3} ){2}[ \d]\d \d\d:\d\d:\d\d \d{4}\s*$//
&& $1 !~ /D/) {
&get_file($service, $file);
exit;
}
get_list:
$_ = "$file/*";
s@/+@\\@g;
@cmd = ($SMBCLIENT, $service, @SMBCLIENT_OPT, "-c", "ls \"$_\"");
$F = &open_pipe(1, @cmd);
while (<$F>) {
/^\s*$/ && last;
$DEBUG && print "DEBUG: $_";
/^cd\s+/ && last;
/^\S/ && next;
s/\r?\n//;
push(@files, $_);
}
close($F);
$qservice = &html_quote($service);
$service = &file_encode($service);
$qfile = &html_quote($file);
$file = &file_encode($file);
print "Content-Type: text/html\n\n";
print "<title>$qservice$qfile</title>\n";
print "<b>$qservice$qfile</b>\n";
print "<pre>\n";
for (sort @files) {
s/\s+([A-Z]*) {1,8}\d+ (\w{3} ){2}[ \d]\d \d\d:\d\d:\d\d \d{4}\s*$// || next;
$c = $&;
s/^ //;
$_ eq "." && next;
print "<a href=\"$CGI$Q$service"
. &cleanup("$file/" . &file_encode($_)) . "\">"
. &html_quote($_) . "</a>"
. &html_quote($c) . "\n";
}
print "</pre>\n";
}
sub get_file {
local($service, $file) = @_;
local($encoding, $type);
local($_, @cmd);
$_ = $file;
s@/@\\@g;
@cmd = ($SMBCLIENT, $service, @SMBCLIENT_OPT, "-E", "-c", "more \"$_\"");
$DEBUG && print "DEBUG: @cmd\n";
($encoding, $type) = &guess_type($file);
$file =~ s@^.*/@@;
$| = 1;
print "Content-Encoding: $encoding\n" if $encoding;
print "Content-Type: $type; name=\"$file\"\n\n";
$ENV{"PAGER"} = $PAGER if $PAGER;
&exec_cmd(1, @cmd);
}
sub share_list {
local($server) = @_;
local(@share);
local($qserver, $_, $d, @c);
@share = &get_list(1, $server, "Share");
$qserver = &html_quote($server);
$server = &file_encode($server);
print "Content-Type: text/html\n\n";
print "<title>Share list: $qserver</title>\n";
print "<table>\n";
print "<tr><td colspan=3><b>$qserver</b>";
for (sort @share) {
($_, $d, @c) = split(" ");
if ($d eq 'Disk') {
print "<tr><td>+ <a href=\"$CGI$Q//$server/"
. &file_encode($_) . "\">"
. &html_quote($_) . "</a>";
} else {
print "<tr><td>+ "
. &html_quote($_);
}
print "<td><td>"
. &html_quote($d) . "<td><td>"
. &html_quote("@c") . "\n";
}
print "</table>\n";
}
sub server_list {
local($group) = @_;
local($master, @server);
local($_, @c);
$master = &get_master($group);
@server = &get_list(0, $master, "Server");
$group = &html_quote($group);
print "Content-Type: text/html\n\n";
print "<title>Server list: $group</title>\n";
print "<table>\n";
print "<tr><td colspan=3><b>$group</b>\n";
for (sort @server) {
($_, @c) = split(" ");
print "<tr><td>+ <a href=\"$CGI$Q//"
. &file_encode($_) . "\">"
. &html_quote($_) . "</a><td><td>"
. &html_quote("@c") . "\n";
}
print "</table>\n";
}
sub group_list {
local($master, @group);
local($_, @c);
$master = &get_master($WORKGROUP || "-");
@group = &get_list(0, $master, "Workgroup");
print "Content-Type: text/html\n\n";
print "<title>Workgroup list</title>\n";
print "<table>\n";
for (sort @group) {
($_, @c) = split(" ");
print "<tr><td><a href=\"$CGI?"
. &file_encode($_) . "\">"
. &html_quote($_) . "</a><td><td>"
. &html_quote("@c") . "\n";
}
print "</table>\n";
}
sub check_opt_a {
local($_, $F, @cmd);
@cmd = ($SMBCLIENT, "-h");
$F = &open_pipe(0, @cmd);
while (<$F>) {
if (/^\s*-A\s/) {
$DEBUG && print "DEBUG: $_";
close($F);
return 1;
}
}
close($F);
return 0;
}
sub get_master {
local($group) = @_;
local($_, $F, @cmd);
@cmd = ($NMBLOOKUP, "-M", @NMBLOOKUP_OPT, $group);
$F = &open_pipe(0, @cmd);
$_ = <$F>;
$_ = <$F>;
close($F);
($_) = split(/[,\s]/);
s/\.*$//;
return $_;
}
sub get_list {
local($passwd, $server, $header) = @_;
local(@list) = ();
local($_, @cmd, $F);
@cmd = ($SMBCLIENT, @SMBCLIENT_OPT, "-L", $server);
$F = &open_pipe($passwd, @cmd);
while (<$F>) {
if (/^\s*$header/) {
$DEBUG && print "DEBUG: $_";
last;
}
}
while (<$F>) {
/^\s*$/ && last;
$DEBUG && print "DEBUG: $_";
/^\S/ && last;
/^\s*-/ && next;
push(@list, $_);
}
close($F);
return @list;
}
sub open_pipe {
local($passwd, @cmd) = @_;
local($F) = $FILE++;
$DEBUG && print "DEBUG: @cmd\n";
open($F, "-|") || &exec_cmd($passwd, @cmd);
return $F;
}
sub exec_cmd {
local($passwd, @cmd) = @_;
$ENV{"LC_ALL"} = "C";
$ENV{"USER"} = $USER;
if ($passwd && !$USE_OPT_A) {
if ($USE_PASSWD_FILE) {
$ENV{"PASSWD_FILE"} = $PASSWD_FILE;
} elsif ($USE_PASSWD_FD) {
$ENV{"PASSWD_FD"} = $PASSWD_FD;
if (open(W, "|-")) {
print W $PASSWD;
close(W);
exit;
}
}
}
open(STDERR, ">/dev/null");
exec @cmd;
exit 1;
}
sub print_form {
local($_) = @_;
local($q) = &html_quote($_);
$_ = &file_encode($_);
print <<EOF;
Content-Type: text/html
<h1>$q</h1>
<form action="$CGI$Q$_" method=POST>
<table>
<tr><td>Workgroup <td>User <td>Password
<tr><td><input type=text size=8 name=group value="$WORKGROUP">
<td><input type=text size=8 name=user value="$USER">
<td><input type=password size=8 name=passwd value="$PASSWD">
<td><input type=submit name=OK value=OK>
</table>
</form>
EOF
}
sub load_auth_file {
local($_) = @_;
if ($USER =~ s/%(.*)$//) {
$PASSWD = $1 unless $PASSWD;
}
open(F, $_) || return;
while (<F>) {
s/\s+$//;
if (s/^workgroup\s*=\s*//i) {
$WORKGROUP = $_;
} elsif (s/^user(name)?\s*=\s*//i) {
$USER = $_;
} elsif (s/^passw(or)?d\s*=\s*//i) {
$PASSWD = $_;
} elsif (s/^passw(or)?d_file\s*=\s*//i) {
$PASSWD_FILE = $_;
}
}
close(F);
}
sub load_mime_type {
local($_) = @_;
local(%mime) = ();
local($type, @suffix);
open(F, $_) || return ();
while(<F>) {
/^#/ && next;
chop;
(($type, @suffix) = split(" ")) >= 2 || next;
for (@suffix) {
$mime{$_} = $type;
}
}
close(F);
return %mime;
}
sub guess_type {
local($_) = @_;
local(%mime) = &load_mime_type($MIME_TYPE);
local($encoding) = undef;
if (s/\.gz$//i) {
$encoding = "gzip";
} elsif (s/\.Z$//i) {
$encoding = "compress";
} elsif (s/\.bz2?$//i) {
$encoding = "bzip2";
}
/\.(\w+)$/;
$_ = $1;
tr/A-Z/a-z/;
return ($encoding, $mime{$_} || "text/plain");
}
sub cleanup {
local($_) = @_;
$_ .= "/";
s@//+@/@g;
s@/\./@/@g;
while(m@/\.\./@) {
s@^/(\.\./)+@/@;
s@/[^/]+/\.\./@/@;
}
s@(.)/$@$1@;
return $_;
}
sub file_encode {
local($_) = @_;
s/[\000-\040\+:#?&%<>"\177-\377]/sprintf('%%%02X', unpack('C', $&))/eg;
return $_;
}
sub file_decode {
local($_) = @_;
s/\+/ /g;
s/%([\da-f][\da-f])/pack('C', hex($1))/egi;
s@[\r\n\0\\"]@@g;
return $_;
}
sub html_quote {
local($_) = @_;
local(%QUOTE) = (
'<', '&lt;',
'>', '&gt;',
'&', '&amp;',
'"', '&quot;',
);
s/[<>&"]/$QUOTE{$&}/g;
return $_;
}

21
Bonus/utf8.cgi Normal file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/perl
#
# [w3m-dev 03783]
# Install it in $LIB/utf8.cgi and configure keymap as
# keymap "x u" GOTO file:/$LIB/utf8.cgi
#
$conv = "lv -Iu -Oe";
# $conv = "iconv -f UTF-8 -t EUC-JP";
$type = $ENV{W3M_TYPE} || "text/plain";
$url = $ENV{W3M_URL};
$file = $ENV{W3M_SOURCEFILE};
-f $file || exit;
$| = 1;
print <<EOF;
Content-Type: $type; charset=EUC-JP
EOF
if ($type =~ /^text\/html/i && $url) {
print "<BASE HREF=\"$url\">\n";
}
exec split(" ", $conv), $file;

33
Bonus/wrap3m Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/sh
HOMEPAGE=http://ei5nazha.yz.yamagata-u.ac.jp/~aito/w3m/
OPT=""
URL=""
for i in $@
do
case $i in
-*)
OPT="$OPT $i"
;;
*)
URL="$URL $i"
;;
esac
done
if [ -z "$URL" ]; then
URL=$HOMEPAGE
fi
URLARG=""
for u in $URL
do
if [ `expr $u : '[a-z][a-z]*://'` -gt 0 ]; then
URLARG="$URLARG $u"
elif [ -f $u -o -d $u ]; then
URLARG="$URLARG $u"
else
URLARG="$URLARG http://$u"
fi
done
w3m $OPTS $URLARG