#!/usr/bin/perl -w
#
# $Revision: 1.4 $ $Date: 2012-07-26 17:11:47-04 $
# $Source: /home/vogelke/bin/RCS/bclinks,v $
# $Host: sys7.com $
# $UUID: 571dfc68-2bfd-3d07-b964-2e9550f2bbcc $
#
# Stolen from Blosxom Plugin: breadcrumbs
#<bclinks: create breadcrumbs link to a given page.
#
# Expects full path to document being displayed,
# including document root.  Relative path will assume
# starting point at the document root.

use strict;
use Cwd;

# What divider should I use between path components?
# my $divider = " :: ";
my $divider = " -&gt;\n";

# Other variables.
my ($path, $p, @p);
my $docroot = $ENV{'DOCROOT'} || '/var/www/html';
my $altroot = $docroot;  # if $docroot is a symlink.

# Accept an argument, or use the current directory.
# Strip the document root if it's there.
$_ = shift || getcwd();
s!^$docroot/!! if m!^/!;
s!^$altroot/!! if m!^/!;

# Get started, then walk the path.
push @p, '<a href="/">Home</a>';
$path = $_;

foreach (split /\//, $path) {
    next unless length($_);
    $p .= "/$_";
    $p =~ s!//!/!;
    push @p, qq{<a href="$p/">$_</a>};
}

$_ = join $divider, @p;
print "$_\n";
exit(0);
