#!/usr/local/bin/perl
#
# From: "T. Alexander Popiel" <popiel@rintintin.Colorado.EDU>
#
# Script to convert chimera 1.65 bookmarks to 2.0 bookmarks.html

$line = <>;
$line eq "chimera_bookmarkv2\n" || die "Bad bookmark format\n";

while ($line = <>) {
    if ($line =~ /^group (.*)$/o) {
        $group = $1;
        if ($in_group) {
            print "</ul>\n";
        }
        print "\n<h3>$group</h3>\n<ul>\n";
        $in_group = 1;
    } elsif ($line =~ /^mark ([^ ]*) (.*)$/o) {
        $url = $1;
        $name = $2;
        print "<li><a href=\"$url\">$name</a>\n";
    } else {
        warn "Unparsable line in input, line $.\n";
    }
}

if ($in_group) {
    print "</ul>\n\n";
}
