# /yer/perl/here ############################################################################### # # opml2ft v0.1 # 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 $body; my $outline; my $count = 0; my $last = -1; { &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 ); $xml->parsefile($infile); return 1; } sub start { my $parser = shift; my $el = shift; my $attrs = { @_ }; $body ||= ($el =~ /^(body)$/); return unless $body; if (! $outline->{'text'}) { $outline = $attrs; return 1; } my $spc; map { $spc .= " "; } (0..$last); print "$spc$outline->{'text'}\n"; my $root = ($last < 0) ? 1 : 0; my $parent = $last - 1; if ($root) { print TREE "foldersTree = gFld(\"$outline->{'text'}\",\"\")\n"; } else { my $aux = join("","aux",$count); my $p_aux = ($parent < 0) ? "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; }