#!/yer/perl/here ############################################################################### # # opml2ft v0.2 # Copyright (c) 2000 Aaron Straup Cope # # 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. ############################################################################### use strict; use XML::Parser; my $infile; my $outfile; my $title; my $body; my $outline; my $count = 1; my $last = 0; { &main; exit; } sub main { $infile = $ARGV[0]; $outfile = $ARGV[1]; die "'$infile' does not exist.\n" if (! -e $infile); open TREE, ">$outfile" || die "Failed to open '$outfile' for writing.\n"; &convert; close TREE; return 1; } sub convert { my $xml = new XML::Parser; $xml->setHandlers( Start => \&start, End => \&end , Char => \&char); $xml->parsefile($infile); return 1; } sub start { my $parser = shift; my $el = shift; my $attrs = { @_ }; $title = ($el =~ /^(title)$/); $body ||= ($el =~ /^(body)$/); return unless $body; if (! $outline->{'text'}) { $outline = $attrs; return 1; } my $spc; map { $spc .= " "; } (0..$last); print "$spc$outline->{'text'}\n"; map { $outline->{$_} =~ s/'/\\'/gm; $outline->{$_} =~ s/"/'/gm; } keys %$outline; my $aux = join("","aux",($count || "1")); my $p_aux = (! $last) ? "foldersTree" : join("","aux",$last); if ($last < $count) { print TREE $spc,"$aux = insFld($p_aux, gFld(\"$outline->{'text'}\", \"$outline->{'url'}\"))\n"; } else { print TREE $spc,"insDoc($p_aux, gLnk($count,\"$outline->{'text'}\", \"$outline->{'url'}\"))\n"; } $outline = $attrs; $last = $count; $count++; return 1; } sub end { my $parser = shift; my $el = shift; return unless $body; $count--; return 1; } sub char { my $parser = shift; my $el = shift; if ($title) { print TREE "foldersTree = gFld(\"$el\",\"\")\n"; undef $title; } return 1; }