#!/usr/bin/perl -w
#
# moz2dil.pl
#
# A trivial but usefull script to generate a Dillo (bm_srv12) bookmarks
# file from a Mozilla bookmarks file.
#
# Example Usage:
# moz2dil.pl ~/.mozilla/default/bookmarks.html > ~/.dillo/bm.txt
#
# Copyright (C) 2003
# All rights reserved
# Kyle Amon
# amonk@gnutec.com
# http://www.gnutec.com/~amonk/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

require 5.004;
use strict;

my (
     @sections, @links,
     $section, $link,
     $scount, $lcount
);

if (! $ARGV[0]) {
  print "Example: moz2dil.pl ~/.mozilla/default/bookmarks.html > ~/.dillo/bm.txt\n";
  exit;
}

$scount = 0;
$lcount = 0;
open (MOZBM, "< $ARGV[0]") || die "cannot open: $!";
while (<MOZBM>) {
  if (/.*<A HREF="(.[^"]*)".*>(.[^<]*)<\/A>/) {
    push @links, 's'.$lcount.' '.$1.' '.$2;
  } elsif (/.*<H3.*>(.[^<]*)<\/H3>/) {
    push @sections, ':s'.$scount.': '.$1;
    $scount++;
    if ($scount > 1) {
      $lcount++;
    }
  }
}

close MOZBM;

foreach $section (@sections) {
  print $section."\n";
}

foreach $link (@links) {
  print $link."\n";
}

exit;
