#!/usr/bin/perl -w
#
# ff2ns
#
# Convert Firefox hotlist files into a format suitable for NetSurf.
# (c) Stephen Fryatt, 2006

# Open the input and output files.

open (INPUT, $ARGV[0]) || die "Can't open input file $ARGV[0]: $!\n";
open (OUTPUT, ">".$ARGV[1]) || die "Can't open output file $ARGV[1]: $!\n";

# Output the header of the NetSurf hotlist file.

print OUTPUT <<EOH;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>NetSurf hotlist</title>
</head>
<body>
EOH

# Read the lines in one at a time and process them.

while (defined ($line = <INPUT>))
{
  chomp($line);
 
  if ($line =~ /<dl>/i)
  {
    print OUTPUT "<ul>\n" 
  }
  
  if ($line =~ /<\/dl>/i)
  {
    print OUTPUT "<\/ul>\n"
  }
  
  if ($line =~ /<dt><h3.*?>(.+?)<\/h3>/i)
  {
    print OUTPUT "<h4>$1<\/h4>\n"
  }
  
  if ($line =~ /<dt><a href=(\"\S+\").*?>(.+?)<\/a>/i)
  {
    print OUTPUT "<li><a href=$1>$2<\/a><\/li>\n"
  }
}

# Output the footer of the NetSurf hotlist file.

print OUTPUT <<EOF;
</body>
</html>
EOF
