diff options
author | Tatsuya Kinoshita <tats@vega.ocn.ne.jp> | 2011-05-04 07:05:14 +0000 |
---|---|---|
committer | Tatsuya Kinoshita <tats@vega.ocn.ne.jp> | 2011-05-04 07:05:14 +0000 |
commit | 72f72d64a422d6628c4796f5c0bf2e508f134214 (patch) | |
tree | 0c9ea90cc53310832c977265521fb44db24a515e /scripts/w3mman/w3mman.in | |
parent | Adding upstream version 0.3 (diff) | |
download | w3m-upstream/0.5.1.tar.gz w3m-upstream/0.5.1.zip |
Adding upstream version 0.5.1upstream/0.5.1
Diffstat (limited to 'scripts/w3mman/w3mman.in')
-rw-r--r-- | scripts/w3mman/w3mman.in | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/w3mman/w3mman.in b/scripts/w3mman/w3mman.in new file mode 100644 index 0000000..6c6f65d --- /dev/null +++ b/scripts/w3mman/w3mman.in @@ -0,0 +1,41 @@ +#!@PERL@ + +@W3M = split(' ', $ENV{'W3MMAN_W3M'} || '@W3M@'); +$ENV{'W3MMAN_MAN'} ||= '@MAN@'; +$SCRIPT = 'file:///$LIB/w3mman2html.cgi'; + +sub usage { + ($_ = $0) =~ s@.*/@@; + print STDERR "$_ [-M <path>] [[<section>] <command>]\n"; + print STDERR "$_ [-M <path>] [-k <keyword>]\n"; + exit 1; +} + +$query = ""; +while (@ARGV) { + $_ = shift @ARGV; + if (/^-M$/) { + @ARGV || &usage(); + $ENV{'MANPATH'} = shift @ARGV; + } elsif (/^-k$/) { + @ARGV || &usage(); + $query = "?keyword=" . &form_encode(shift @ARGV); + } elsif (/^-/) { + &usage(); + } elsif (/^\d/ || $_ eq 'n') { + @ARGV || &usage(); + $query = "?quit=ok&man=" . &form_encode(shift @ARGV); + $query .= "§ion=" . &form_encode($_); + } else { + $query = "?quit=ok&man=" . &form_encode($_); + } +} + +exec @W3M, "$SCRIPT$query"; + +sub form_encode { + local($_) = @_; + s/[\000-\040\+:#?&%<>"\177-\377]/sprintf('%%%02X', unpack('C', $&))/eg; + return $_; +} + |