--- gman-0.9.3.orig/gman.pl
+++ gman-0.9.3/gman.pl
@@ -1,18 +1,30 @@
-#!/usr/bin/perl
-use strict(all);
+#!/usr/bin/perl -w
+use strict;
-my $cgi_path = "/cgi-bin/gman/gman.pl";
-my $man2html = "man2html -M $cgi_path";
-my $path = `man -w @ARGV`;
-my $tmp_file = "/tmp/gman.$ARGV[1].$ARGV[0]";
+if (@ARGV != 2) {
+ print <<_EOF_;
+Content-type: text/html
+<html><head><title>gman.pl: invalid use</title></head>
+<body>
+<h1>gman.pl cannot be used without arguments.</h1>
+</body></html>
+_EOF_
+ die;
+}
-if (!&file_exist($path)) {
- my $name = lc($ARGV[1]);
- $path = `man -w $ARGV[0] $name`;
-# print "check point 0.9\n";
+my $section = $ARGV[0]; # should also have some sanity check
+my $name = $ARGV[1];
+my $man2html = "/usr/lib/cgi-bin/man/man2html";
+my $path = `man -w $section $name`; chomp $path; $path =~ s/\s*$//;
+
+unless (-s "$path") {
+ warn "not -s $path\n";
+ $name = lc $name;
+ $path = `man -w $section $name`; chomp $path; $path =~ s/\s*$//;
}
-if (!&file_exist($path)) {
+unless (-s "$path") {
+ warn "not -s $path\n";
print <<end_of_line;
Content-type: text/html
@@ -21,39 +33,34 @@
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
-The requested man page $ARGV[1]($ARGV[0]) was not found on this server.<P>
+The requested man page $name($section) was not found on this server.
</BODY></HTML>
end_of_line
die;
}
-my $page;
-if ($path =~ /gz$/) {
- my $file = `gzip -cd $path`;
- open (TEMPFILE,">$tmp_file");
- print TEMPFILE $file;
- close (TEMPFILE);
- $page = `$man2html $tmp_file`;
- `rm $tmp_file`;
-} else {
- $page = `$man2html $path`;
-}
-$page =~ s/This document was created by\s*<A HREF=\"(http:\/\/.*)\">man2html<\/A>,\s*using the manual pages.<BR>/This document was created by
-<A HREF=\"$1?1+man2html\">man2html<\/A> for <A HREF=\"$1?1+gman\">gman<\/A>,
-using the manual pages.<BR>/;
-print $page;
-#print `cat /home/wxk/src/gtk/gman.html`;
+unless (-e "$man2html") {
+ warn "$man2html missing\n";
+ print <<end_of_line;
+Content-type: text/html
+
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<HTML><HEAD>
+<TITLE>man2html missing</TITLE>
+</HEAD><BODY>
+<H1>man2html missing</H1>
-sub file_exist {
- open (FILE,$_[0]);
- my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
- $atime,$mtime,$ctime,$blksize,$blocks) = stat(FILE);
- close(FILE);
-
-# print "check point 0.5, size = $size, $_[0]\n";
- if ($size == 0 or $size eq null) {
- return 0;
- } else {
- return 1;
- }
+<p>You have to install <tt>man2html</tt> in order to use this mode in gman.
+
+</BODY></HTML>
+end_of_line
+ die;
}
+
+my $page = `$man2html $path`;
+
+# $page =~ s/^Content-type: text\/html\n\n// if (not run as cgi...);
+
+$page =~ s/(This document was created by\n<a HREF=\".*\">man2html<\/a>)(,\nusing the manual pages.<br>)/$1 for <a href=\"\/cgi-bin\/gman.pl?1+gman\">gman<\/a>$2/io;
+
+print $page;