# -*-perl-*-
#
-# $Id: SWMan.pm,v 1.2 1999/08/18 17:10:07 mdw Exp $
+# $Id: SWMan.pm,v 1.5 2004/04/08 01:52:19 mdw Exp $
#
# Display and other fiddling of manual pages
#
# along with sw-tools; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#----- Revision history -----------------------------------------------------
-#
-# $Log: SWMan.pm,v $
-# Revision 1.2 1999/08/18 17:10:07 mdw
-# Slight improvements to URL and email address parsing.
-#
-# Revision 1.1 1999/07/30 18:46:37 mdw
-# New CGI script for browsing installed software and documentation.
-#
-
#----- Package preamble -----------------------------------------------------
package SWMan;
use SWCGI qw(:DEFAULT :layout);
@ISA = qw(Exporter);
-@EXPORT_OK = qw(subst check);
+@EXPORT_OK = qw(subst urlsubst check);
#----- Useful functions -----------------------------------------------------
sub subst($$$) {
my ($s, $n, $sec) = @_;
check($n, $sec) and
- return "<a href=\"$ref?act=man&man=$n&sec=$sec\">$s</a>";
- return "$s";
+ return sprintf("<a href=\"$ref?act=man&man=%s&sec=$sec\">$s</a>",
+ SWCGI::sanitize($n));
+ return $s;
+}
+
+# --- @urlsubst(URL, STRING)@ ---
+#
+# Substitutes in a URL reference. The important bit is that embedded `&'
+# characters are un-entitied from `&'. This doesn't seem to upset
+# Netscape or Lynx as much as I'd expect (or, in fact, at all), but it's
+# slightly untidy.
+
+sub urlsubst($$) {
+ my ($url, $name) = @_;
+ $url =~ s/\&\;/&/;
+ return "<a href=\"$url\">$name</a>";
}
# --- @sections()@ ---
# --- Translate the character if it's magical ---
$ch eq "&" and $ch = "&";
- $ch eq "<" and $ch = "<";
- $ch eq ">" and $ch = ">";
+ $ch eq "<" and $ch = "<<";
+ $ch eq ">" and $ch = ">>";
$l .= $ch;
}
$state and $l .= "</$state>";
# --- And email and hypertext references too ---
$l =~ s! ((?:\<[bi]\>)*) # Leading highlighting
- ((?:https?|ftp|file|news) # A protocol name
+ ( \b (?: http s? | ftp | file | news ) # A protocol name
: # The important and obvious bit
- [^]&)\s]+ # Most characters are allowed
- [^]&).,\s\'\"]) # Don't end on punctuation
+ [^]<>)\s<>\'\"]+ # Most characters are allowed
+ [^]<>).,\s<>\'\"]) # Don't end on punctuation
((?:\</[bi]\>)*) # Closing tags, optional
- !$1<a href="$2">$&</a>$3!gx;
+ !urlsubst($2, $&)!egx;
- $l =~ s! ((?:\<[bi]\>)*(?:\bmailto:)?)
- ( [^\s()&;:{}<>,.\`\"] [^\s()&;:{}<>\`\"]* \@
- [^\s()&;:{}<>\'\"]* [^\s()&;:{}<>.,\'\"])
+ $l =~ s! ( (?:\<[bi]\>)* (?:\bmailto:)? )
+ ( [^\s()<>;:{}&<>,.\`\'\"] [^\s()<>;:{}&<>\`\'\"]* \@
+ [^\s()<>;:{&}<>\'\"]* [^\s()<>;:{}&<>.,\'\"])
((?:\</[bi]\>)*)
- !$1<a href="mailto:$2">$&</a>$3!gx;
+ !<a href="mailto:$2">$&</a>!gx;
+
+ # --- Fix up the HTML ---
+
+ $l =~ s/\<\;\</</g;
+ $l =~ s/\>\>\;/>/g;
# --- Done! ---