#!/usr/bin/perl # Created from thin air by abb@acm.org on 6/16/99. # # A little Perl script to process my bookmarks into a loosely # structured file tree. My bookmarks were totally out of control, # impossible to navigate, out of date, and useless IMHO, yet they # continue to receive thousands of hits/month?? Anyway, this makes # it much easier to navigate, by splitting folder levels into # separate files. # # I looked around for a SIMPLE script to do this, but could find none. # My aim here was to whip up something minimal. I mean really minimal, # no frills at all. # I am NOT a Perl wizard, as you can see. I just try to get the job done. # I limited myself to 2 hours work and less than 100 lines of code. # I don't have time for documentation, but IMHO just about anyone # should be able to figure out 100 lines of code for themselves. # # I think this should work on anybody's Netscape bookmarks file. # If it doesn't work for you that's your problem. I don't care. # It works for me. I expect to receive not a single e-mail in reference # to this script. # Understood?!! Am I making myself clear?!! Don't answer that... # (I'm a little stressed by all the morons who try to use my other software.) # # Usage: ./bm2html.pl ~/.netscape/bookmarks.html # Side effect: The script will attempt to create an HTML file for each # folder level in your bookmarks. The deepest folder level in my # bookmarks is 5, so this script creates 5 files for me. # Just give it a try in an empty directory and you'll understand. # (I just went over my 2 hour limit.) @heading = () ; @target = () ; @bmhtml = () ; @filehandle = () ; @filename = () ; $curlev = 0 ; $linkcount = 0 ; $fileprefix = "bm" ; $filename[1] = "index.html" ; $header = qq( \$head

[Andy's Medical Imaging Page] [Andy's Info & Referral Page] [Perl Script to Create This]

) ; ($mday,$mon,$year) = (localtime(time))[3,4,5] ; $mon++ ; # range is 0-11 $year += 1900 ; $update = "$mon/$mday/$year" ; $footer = qq(

[Andy's Medical Imaging Page] [Andy's Info & Referral Page] [Perl Script to Create This]

Nobody is responsible for anything here. Use it in any way you wish. Or not.
I first put my bookmarks up on 6/14/1995. Last Updated $update.
) ; sub OutputHTML { my( $level) = @_ ; if( !defined($filehandle[$level]) ) { $filehandle[$level] = "FILE$level" ; open( $filehandle[$level], ">$filename[$level]" ) || die( "Error opening $filehandle[$level].\n" ) ; my $thishead = $header ; $thishead =~ s/\$head/Andy Barclay's Bookmarks, Level $level/ ; print {$filehandle[$level]} $thishead ; } print {$filehandle[$level]} $bmhtml[$level] ; } while( <> ) { # Filter extraneous tags/attr. that Netscape uses. s/(dl>)

$/\1/i ; s/(]*/\1/i ; s/(]*/\1/i ; my $line = $_ ; if( $line =~ m/([^<]*)/i ) { my $newlevel = $curlev+1 ; $heading[$newlevel] = $1 ; if( $1 =~ m/^\s*\*/ ) { # Start of a private part. $privlev = $newlevel ; } if( !defined($filename[$newlevel]) ) { $filename[$newlevel] = "$fileprefix$newlevel.html" ; } $target[$newlevel] = $linkcount ; $line = qq(

Subfolder: $heading[$newlevel] ) ; } if( $line =~ s/
/