[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] MCF files, BBEdit extensions



I wrote a quick script that can convert Netscape bookmark files to MCF
files (see http://hotsauce.apple.com/ for more info on HotSauce, a.k.a.
ProjectX).

Anyway, I thought I would post it here primarily because it was my first
use of the Perl Filters BBEdit extension announced previously by Brad
Hanson ... and it works great!  I use BBEdit all the time, and those BBEdit
extensions make my life happy.  :)

One question: is there a way to direct the STDOUT of a Perl Filter script
to a new window without selecting STDERR?  I suppose I could just preface
each script with "select STDERR" ...


#!perl
#-----------------------------------------------------------------#
#  pudgemcf.pl
#  pudge
#  Change Netscape Bookmark file into MCF doc
#
#  Created:       Chris Nandor (pudge@pbox.com)        12-Dec-1996
#-----------------------------------------------------------------#
#  This is just a quick script I whipped up ... STDIN is the
#  bookmark file, STDOUT is the MCF file.
#
#  I don't know how well this conforms to all the standards and
#  specs for MCF files ... I just know it works so far.
#-----------------------------------------------------------------#
print "begin-headers:\nMCFVersion: 0.95\n";
while (<>) {
    if (/<TITLE>(.*?)</) {
        $title = $1;
        last;
    }
}
print qq'name: "$title"\nend-headers:\n\n';
#-----------------------------------------------------------------
while (<>) {
    if (/<DL>/) {$dl++}
    elsif (/<\/DL>/) {$dl--}
    elsif (/<DT>/) {&newDT}
}
#-----------------------------------------------------------------
print qq'\n;;;  created with pudgemcf.pl\n';
#-----------------------------------------------------------------
sub newDT {
    if (/<A HREF="(.*?)".*?>(.*?)</) {
        print qq'unit: "$1"\nname: "$2"\ngenls: "$lg{$dl}"\n\n';
    } elsif (/<H3.*?>(.*?)</) {
        $lgn = $1;
        $lgn =~ tr/ /_/;
        print qq'unit: "/$lgn.mco"\nname: "$lgn"\ngenls: "$lg{$dl}"\n\n';
        $lg{($dl+1)} = "/$lgn.mco";
    }
}
#-----------------------------------------------------------------
__END__



#================================================================
perl -e 'srand();if(rand>.5){$i=0;foreach(@ARGV){@$i=split(//);$z
[$i]=0;foreach(@$i){$s[$i][$z[$i]]=$_;$z[$i]++;}$i++;}foreach(@s)
{foreach(@$_) {print}print" ";$_++}}else{print(join(" ", @ARGV))}
print"\n"' McClellan Clan Motto: Think On

Chris Nandor                                      pudge@pobox.com
PGP Key 0xB76E72AD                              http://pudge.net/