diff options
author | bptato <nincsnevem662@gmail.com> | 2024-01-27 12:44:30 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-01-27 12:46:04 +0100 |
commit | f9c74eac1260cd02302a70adaa4806c297428163 (patch) | |
tree | 58b3d987ad28c78ea6d7c175fda98972d324e0f5 /adapter/protocol | |
parent | fb2f0b91ae59612495143982212f3def20d3bf68 (diff) | |
download | chawan-f9c74eac1260cd02302a70adaa4806c297428163.tar.gz |
man: fix man -k
Diffstat (limited to 'adapter/protocol')
-rwxr-xr-x | adapter/protocol/man | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/adapter/protocol/man b/adapter/protocol/man index 7008a95b..88042c9f 100755 --- a/adapter/protocol/man +++ b/adapter/protocol/man @@ -25,33 +25,49 @@ $ENV{'PAGER'} = 'cat'; if ($QUERY =~ /^man-k:/) { $QUERY =~ s/^man-k://; - $query{"keyword"} = &form_decode($QUERY); - if ($query{"keyword"} =~ s/(.*)\((\w+)\)$//) { - $query{"keyword"} = $1; - $query{"section"} = $2; + my $keyword = &form_decode($QUERY); + my $sectionopt = ""; + if ($keyword =~ s/(.*)\((\w+)\)$//) { + $keyword = $1; + $sectionopt = "-s $2 "; } + my $k = &html_quote($keyword); + print <<EOF; +Content-Type: text/html + +<html> +<head><title>man $sectionopt-k $k</title></head> +<body> +<h2>man $sectionopt-k <b>$k</b></h2> +<ul> +EOF + $keyword =~ s:([^-\w\200-\377.,])::g; + open(F, "$MAN $sectionopt -k $keyword 2> /dev/null |"); + while(<F>) { + chop; + $_ = &html_quote($_); + s/(\s+-.*)$//; + $title = $1; + s@(\w[\w.\-]*(\s*\,\s*\w[\w.\-]*)*)\s*(\([\dn]\w*\))@&keyword_ref($1, $3)@ge; + print "<li>$_$title\n"; + } + close(F); + print <<EOF; +</ul> +</body> +</html> +EOF + exit; } elsif ($QUERY =~ /^man-l:/) { $QUERY =~ s/^man-l://; - $query{"local"} = &form_decode($QUERY); -} else { - $QUERY =~ s/^man://; - $query{"man"} = &form_decode($QUERY); -} - -if ($query{"local"}) { - $file = $query{"local"}; - if (! ($file =~ /^\//)) { - $file = $query{"pwd"} . '/' . $file; - } + $file = &form_decode($QUERY); open(F, "GROFF_NO_SGR=1 MAN_KEEP_FORMATTING=1 $MAN $file 2> /dev/null |"); } else { - $man = $query{"man"}; + $QUERY =~ s/^man://; + my $man = &form_decode($QUERY); if ($man =~ s/\((\w+)\)$//) { $section = $1; $man_section = "$man($1)"; - } elsif ($query{"section"}) { - $section = $query{"section"}; - $man_section = "$man($section)"; } else { $section = ""; $man_section = "$man"; @@ -61,6 +77,7 @@ if ($query{"local"}) { $man =~ s:([^-\w\200-\377.,])::g; open(F, "GROFF_NO_SGR=1 MAN_KEEP_FORMATTING=1 $MAN $section $man 2> /dev/null |"); } + $ok = 0; undef $header; $blank = -1; @@ -152,7 +169,7 @@ if ($prev) { } close(F); if (! $ok) { - if ($query{'local'}) { + if ($file) { print "Cha-Control: ConnectionError 4 file $file not found"; } else { print "Cha-Control: ConnectionError 4 no manual entry for $man_section"; |