3 # $Id: SWInfo.pm,v 1.2 1999/08/18 17:10:07 mdw Exp $
5 # Read and output GNU Info files
10 #----- Licensing notice -----------------------------------------------------
12 # This file is part of sw-tools.
14 # sw-tools is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # sw-tools is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with sw-tools; if not, write to the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #----- Revision history -----------------------------------------------------
31 # Revision 1.2 1999/08/18 17:10:07 mdw
32 # Slight improvements to URL and email address parsing.
34 # Revision 1.1 1999/07/30 18:46:37 mdw
35 # New CGI script for browsing installed software and documentation.
38 #----- Package preamble -----------------------------------------------------
45 use SWCGI
qw(:DEFAULT
:layout
);
49 #----- Useful functions -----------------------------------------------------
51 # --- @subst(IREF, FILE, INFO)@ ---
53 # Given an Info reference and the name of the current Info file, returns an
54 # HTML anchor which represents the link.
57 my ($iref, $file, $i) = @_;
62 # --- Dig out the node and file being referred to ---
70 if ($iref =~ /^.+: *(.+)$/) { $iref = $1; }
71 if ($iref =~ /(?:\(([^\)]*)\))?(.*)$/) {
78 # --- Transform it into something that won't get mangled ---
80 $node =~ s/[+&=%]|[^ -~]/sprintf("%%%02x", ord($&))/eg;
83 ($dir = $i->{dir}) =~ s:$C{prefix}/info/?::;
84 $dir = "&dir=$dir" if $dir;
86 return "<a href=\"$ref?act=info&file=$file&node=$node$dir\">$oref</a>$tail";
89 #----- Actions --------------------------------------------------------------
92 my $file = $Q{file} || "dir";
93 my $node = $Q{node} || "Top";
94 my $dir = $Q{dir} || "";
97 # --- Read the node in ---
99 Info::setpath("$C{prefix}/info");
101 "$dir/$file" =~ m:\./: and
102 barf("bad filename `$dir/$file'");
103 my $i = (($dir && Info->new("$dir/$file")) ||
105 or barf("couldn't find info file
`$file'");
106 my $n = $i->node($node) or
107 barf("info file `$file' doesn't contain node
`$node'");
109 # --- Now translate the node into HTML, first line first ---
114 $n =~ s/\A( [^\n]* Next:\ *) ([^,\n]*) / $1 . subst($2, $file, $i) /eix;
115 $n =~ s/\A( [^\n]* Prev:\ *) ([^,\n]*) / $1 . subst($2, $file, $i) /eix;
116 $n =~ s/\A( [^\n]* Up:\ *) ([^,\n]*) / $1 . subst($2, $file, $i) /eix;
118 # --- Grind through picking up any notes ---
123 if ($n =~ /(\*Note\s*)([^:]*: *(?:\([^\)]*\))?[^.,;:]*)([.,;:])/i) {
124 $out .= $` . $1 . subst
($2, $file, $i) . $3;
131 # --- If there's a menu then process that
---
133 if ($n =~ /\n\* *Menu:/s) {
137 if ($n =~ /(\n\* *)([^:]*: *(?:\([^\)]*\))?[^.,;:]*)([.,;:])/) {
138 $out .= $` . $1 . subst
($2, $file, $i) . $3;
147 $out =~ s!\b(https?|ftp|file|news):[^]&)\s]*[^]&).,\s\'\"]!<a href="$&">$&</a>!g;
148 $out =~ s!(?:\bmailto:)?([^\s()&;:{}.,\`\"][^\s()&;:{}\`\"]*\@[^\s()&;:{}\'\"]*[^\s()&;:{}.,\'\"])!<a href="mailto:$1">$&</a>!g;
149 $out =~ s!([-_.\w]+)\((\d+\w*)\)!SWMan::subst("$1($2)", $1, $2)!eg;
151 header("Info: ($file)$node");
152 print("<pre>\n$out</pre>\n");
156 #----- Actions provided -----------------------------------------------------
158 $main::ACT{"info"} = \&info;
160 #----- That's all
, folks
----------------------------------------------------