#! /usr/bin/perl

chdir();

# scarf the headers, and make them into an index.
open(MCOM, ".netscape-bookmarks.html") || open(MCOM, ".MCOM-bookmarks.html");
while(<MCOM>) {
	if (! /<H3/) { next; }
	chop;
	s,^.*>.*>(.*)<.*,$1,;
	push(@index, $_);
}

seek(MCOM, 0, 0);		# rewind
open(HOTLIST, ">html/hotlist.html");
while(<MCOM>) {
	if (/\>Table of Contents\</) {
	    print HOTLIST;
	    print HOTLIST "    <DL><p>\n";
	    foreach (sort(@index)) {
		print HOTLIST "        <DT><A HREF=\"#$_\">$_</A>\n";
	    }
	    print HOTLIST "    </DL><p>\n";
	    print HOTLIST "    <HR>\n";
	    next;
	}
	if (/<H3/) {
	    s,(^.*>.*>)(.*)(<.*),$1<A NAME="$2">$2</A>$3,;
	}
	chop;
	print HOTLIST;
	if (/ADD_DATE="([0-9]*)"/) {
	    if (time - $1 < 7*24*60*60) {
# From: David Filo <filo@konishiki.Stanford.EDU>
# To: nelson@crynwr.com (Russell Nelson)
# In-reply-to: nelson@crynwr.com's message of Sat, 14 Jan 95 13:37 EST
# Subject: may I?
# Reply-To: yahoo@akebono.stanford.edu
#
#> May I use your yahoo/icons/new.gif graphic?
#
#sure, you're free to use new.gif..
#
		print HOTLIST "<img alt=\"[NEW]\" src=\"new.gif\">";
	    }
	}
	print HOTLIST "\n";
}

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
printf HOTLIST "<HR>\nGenerated from my Netscape bookmark file on %d-%s-%d at %02d:%02d by a perl <a href=\"make-hotlist\">script</a>\n", $mday,
    ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")[$mon],
    $year, $hour, $min;

close(HOTLIST);
close(MCOM);
