3 # hotexplode -- a program for "exploding" a xmosaic hotlist or Netscape
4 # bookmark file into a hierarchial multi-page structure.
8 # v1.0: 1-3-1996: initial version
14 # header: some arbitrary HTML text which is appended below the title and
15 # above the hotlist data
20 This hotlist was generated with
21 <a href="http://www.zikzak.net/~acb/hacks/hotexplode.html">hotexplode</a>
24 <b>WARNING:</b> The inclusion of a link to a page on
25 this hotlist is not an indication of the maintainer's
26 approval of or agreement with its content.
30 Please <b>DO NOT</b> bookmark this page. Bookmark the
31 <a href="http://phd.pp.ru/Bookmarks/">main page</A> instead.
32 Any other page in the hierarchy can disappear at any time.
40 # which directory shall contain the hotlist?
45 # end of customisable portion
51 $outdir = $opt_o if $opt_o;
54 # seek forward to the title
56 if (/<TITLE>([^\<\>]*)<\/TITLE>/) {
62 $title = $opt_t if $opt_t;
64 # seek forward to the start of the list
68 if(/<UL>/) { warn "Detected xmosaic hotlist format\n" if $opt_v;
69 &parse_mosaic_hotlist($outdir, $title); last; }
70 if(/<DL>/) { warn "Detected Netscape bookmark format\n" if $opt_v;
71 &parse_netscape_bookmarks($outdir, $title); last; }
74 # parse an xmosaic hotlist
75 # exit when we meet a </UL>
76 # arguments: pathname of directory in which output is to be placed,
79 sub parse_mosaic_hotlist {
80 # we write the file at the very end, because (I think) filehandles do
81 # not have local scope, and this is recursive
82 local($prefix, $title) = @_;
83 local($result) = "<HTML><HEAD><TITLE>$title </TITLE></HEAD>\
84 <BODY>\n<CENTER><H1>$title </H1></CENTER>\n $header \n<hr>\n<ul>";
86 warn "Creating $prefix...\n" if $opt_v;
88 # create the directory, if needed
89 mkdir($prefix, 0755) unless -d $prefix;
94 if(/<LI> *<A HREF=\"([^\"]*)\"[^\>]*>([^\<]*)<\/A>/) {
98 local($url,$name) = ($1, $2);
99 $result = $result."<li><a href=\"$url\">$name </a>\n";
104 # we've got a live one here...
106 local($subtitle)=local($filename)=$1;
107 $filename =~ tr/0-9A-Za-z//cd;
108 $filename =~ tr/A-Z/a-z/;
109 <>; # eat the "<UL>" line.
110 $result .= "<li><b><a href=\"${filename}/index.html\">${subtitle}</a></b>\n";
111 &parse_mosaic_hotlist("${prefix}/${filename}", "${title}:${subtitle}");
117 $result = $result . $footer . "</body></html>";
119 open(FILE, ">${prefix}/index.html");
124 # parse a Netscape bookmarks list
125 # exit when we meet a </DL>
126 # arguments: pathname of directory in which output is to be placed,
129 sub parse_netscape_bookmarks {
130 # we write the file at the very end, because (I think) filehandles do
131 # not have local scope, and this is recursive
132 local($prefix, $title) = @_;
133 local($result) = "<HTML><HEAD><TITLE>$title </TITLE></HEAD>\
134 <BODY>\n<CENTER><H1>$title </H1></CENTER>\n $header \n<hr>\n<dl>";
136 warn "Creating $prefix...\n" if $opt_v;
138 # create the directory, if needed
139 mkdir($prefix, 0755) unless -d $prefix;
143 if (/<DT><H3[^\>]*>([^\<]*)<\/H3>/) {
149 $filename =~ tr/0-9A-Za-z//cd;
150 $filename =~ tr/A-Z/a-z/;
151 # parse the description here
157 $result = $result . "<dt><b><a href=\"${filename}/index.html\">${subtitle}</a></b>\n";
158 unless("$desc" eq "") { $result = $result . $desc; }
159 &parse_netscape_bookmarks("${prefix}/${filename}",
160 "${title}:${subtitle}");
163 if (/<DT><A HREF=\"([^\"]*)\"[^\>]*>([^\<]*)<\/A>/) {
167 local($url, $name) = ($1, $2);
168 $result = $result."<dt><a href=\"$url\">$name </a>\n";
171 $result = $result . $_;
173 $result = $result . $footer . "</body></html>";
175 open(FILE, ">${prefix}/index.html");