#!/bin/perl # # SYNOPSIS # @(#) Generates a hotlist file from a Netscape Bookmarks file. # # USAGE # b2h [-h] [-s] # # DESCRIPTION # A Netscape bookmarks file is split into HTML files, one per section. # Sections containing "private" in the name will be ignored. Created # files are named "hotlist.html" for the main file, "n.html" for section # files, where `n' is a number. # # By default, the file "$HOME/.netscape/bookmarks.html" will be used as # input, and the directory "$HOME/WWWHome/" will be the location of # output files. If option "-s" is given, input is read from STDIN and # output files are written to the current directory. # # OPTIONS # -s ... read from STDIN, write to the current directory. # # FILES # $HOME/.netscape/bookmarks.html ... default input file # $HOME/WWWHome/ ... default location of output files # hotlist.html ... main file # hotlist.head ... beginning of hotlist file # hotlist.tail ... end of hotlist file # # EXIT CODES $ERR_ARGS=1; # Error on arguments. $ERR_BFILE=2; # Bookmarks file not readable. $ERR_OFILE=3; # Output file not writeable. # # REVISION HISTORY # 95-11-20 Neubacher : Created this file. # 96-01-08 Neubacher : Switched to ".netscape/bookmarks.html". # # Set $opt_x variable according to options # require "getopts.pl"; if( ! &Getopts('hs') ) { print "\n"; do usage(); exit $ERR_ARGS; } # # Process -h option # if( $opt_h ) { do usage(); do help(); exit 0; } # # Process other options # $outdir = $ENV{"HOME"} . "/WWWHome/"; $infile="INFILE"; if ($opt_s) { $outdir="./"; $infile="STDIN"; } else { if (!open($infile, "<" . $ENV{"HOME"} . "/.netscape/bookmarks.html")) { print STDERR "Could not open file '" . $ENV{"HOME"} . "/.netscape/bookmarks.html" . "'!\n"; exit $ERR_BFILE; } } # # Process bookmarks file. # if (system("cp " . $outdir . "hotlist.head " . $outdir . "hotlist.html")) { print STDERR "Could not copy '%s' to '%s'!\n", $outdir . "hotlist.head", $outdir . "hotlist.html"; exit $ERR_OFILE; } if (!open(HOTOUT, ">>" . $outdir . "hotlist.html")) { print STDERR "Could not open file '%s'!\n", $outdir . "hotlist.html"; exit $ERR_OFILE; } $section=0; $nesting = 0; while (<$infile>) { if ($nesting > 0) { print SUBOUT if (!$ignore); if (/
/) { $nesting++; } if (/<\/DL>/) { $nesting--; if ($nesting == 1) { &subfooter(); close SUBOUT if (!$ignore); $nesting = 0; } } } else { if (/
/ || /
/ || /

]*>//; s:

::; if (/[pP]rivate/) { $ignore = 1; } else { $ignore = 0; $section++; $file = sprintf("%02d.html", $section); $title = $_; printf HOTOUT "
%s\n", $file, $title; if (!open(SUBOUT, ">" . $outdir . $file)) { print STDERR "Could not open '%s'!\n", $outdir . $file; exit $ERR_OFILE; } &subheader(); next; } } if (/<\/DL>/) { print HOTOUT; last; } } } close HOTOUT; if (system("cat " . $outdir . "hotlist.tail >>" . $outdir . "hotlist.html")) { print STDERR "Could not append '%s' to '%s'!\n", $outdir . "hotlist.tail", $outdir . "hotlist.html"; exit $ERR_OFILE; } exit 0; # # Header & Footer. # sub subheader { print SUBOUT < Andy's Hotlist: $title

$title

ENDOFHEADER } sub subfooter { print SUBOUT <

aneubach\@geocities.com
ENDOFFOOTER } # # Usage & Help functions. # sub usage { open(thisscript, $0); while( ) { last if /^\# USAGE/; } s/^#//; print; while( ) { last if /^\# DESCRIPTION/; s/thisfile/$SCRIPT/; s/^#//; print; }; close thisscript; } sub help { open(thisscript, $0); while( ) { last if /^\# DESCRIPTION/; } s/^#//; print; while( ) { last if /^\# REVISION HISTORY/; s/^#//; print; }; close thisscript; } # EMACS: # # Local Variables: # mode: Perl # End: