#!/usr/bin/perl
######################################################################
# Converts Opera-Bookmarks to HTML
# Tested with Opera 5.x 6.x and 7.x
#
# The following construct defines a folder:
#    #FOLDER                     (Beginn of a folder)
#       .... Descriptions will be ignored
#       .... URLs and other Folders
#    <CR><LF>                    (blank line)
#    -<CR><LF>                   (only "-" in this line)
#                                (the two lines above indicate the
#                                (end of a folder)
#
# 04.01.2000 Christian Schlegel rana@rana.at
######################################################################

use strict;

our $VERSION="1.1";

my $OPERAPATH="Daten";

my $depth = 1;			# depth of Folder/Subfolders Root = 1
my $kind   = "";		# Flag if URL or FOLDER
my $name;			# Name of URL

				# Set the source- and destinationfile
my $sourcefile = "$OPERAPATH/Opera6.adr";
my $destfile  = "$OPERAPATH/links.html";

#my $header     = "<!DOCTYPE html PUBLIC \"-//w3c//dtd html 4.0 transitional//en\">";
#$header .= "\n<html>";
#$header .= "\n<head>";
#$header .= "\n   ";
#$header .= "\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">";
#$header .= "\n   ";
#$header .= "\n  <meta name=\"Author\" content=\"Christian Schlegel\">";
#$header .= "\n   ";
#$header .= "\n  <meta name=\"GENERATOR\" content=\"generated by a Perl-Script\">";
#$header .= "\n  <title>Meine Links/My links</title>";
#$header .= "\n</head>";
#$header .= "\n<body>";
#$header .= "\n<center>";
#$header .= "\n<h1>Meine Linkseite/My linkpage</h1>";
#$header .= "\n</center>";
my $header     = "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n";
$header .= "<!-- This is an automatically generated file.\nIt will be read and overwritten\nDo not Edit! -->\n";
$header .= "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html, charset=UTF-8\">\n";
$header .= "<TITLE>Bookmarks</TITLE>\n<H1>BOOKMARKS</H1>\n";
$header .= "";

open (SOURCEFILE, $sourcefile)  || die "Can't open $sourcefile\n";
open (DESTFILE, ">$destfile") || die "Can't create $destfile\n";

print (DESTFILE $header);

						# Check each line of the Opera-Bookmarks
while (<SOURCEFILE>) {
	if (/^#URL/) { $kind = "URL"; }		# Specify an URL
	if (/^#FOLDER/) {			# Specify a folder
		$depth++;			# increase the folderdepth
		$kind = "FOLDER";
		print (DESTFILE "<DL><p>\n");	
	}
	if (/^-/) { 
		$depth--; 
		print (DESTFILE "</DL></p>");
	}
	if (/^\tNAME=(.+)?\n/) {
		if ($kind eq "FOLDER") {
			print (DESTFILE "<DT><H$depth>$1</H$depth>\n");
		}
		$name = $1;
	}
	if (/^\tURL=(.+)?\n/) {
			print (DESTFILE "<DT><A HREF=\"$1\">$name</A>\n");
	}
#	if (/^\tDESCRIPTION=(.+)?\n/) {
#			print (DESTFILE "<DT><>");
#	}
}

close SOURCEFILE;
close DESTFILE;

=head1 NAME

op2html.pl

=head1 VERSION

1.1

=head1 SYNOPSIS

op2html.pl

=head1 DESCRIPTION

Converts bookmark-files of the webbrowser B<Opera> to a HTML-file. This file can be used to import Opera-Bookmarks
in Netscape-Browsers like B<Netscape> or B<Phoenix/Firebird>.

=head1 ARGUMENTS

none

=head1 EXAMPLE

op2html.pl

=head1 AUTHOR

Christian Schlegel
