#!/usr/bin/perl
#
# URL
#
# a simple little tool so that I can print out url's from a directory
# that we're in.
#
# Tue Dec 3 16:19:34 EST 2002 v1.0
# Fri Jan 3 14:59:03 EST 2003 v1.1 (added UBB codes)
#
use Cwd;
$gHtDocs = "public_html";
$gUrlBase = "http://www.cis.rit.edu/~";
# -r straight listings of urls (raw)
# -a wrap in: XX
# -i wrap in:
# -m wrap in: '
# for UBB
# -u wrap in: [url]URL[/url]
# -y wrap in: [img]URL[/img]
sub PrintFormattedString
{
local $url = shift;
local $type = shift;
if( "-r" eq lc $type) {
printf "%s\n", $url;
} elsif( "-a" eq lc $type) {
printf "XX\n", $url;
} elsif( "-i" eq lc $type) {
printf "
\n", $url;
} elsif( "-u" eq lc $type) {
printf "[url]%s[/url]\n", $url;
} elsif( "-y" eq lc $type) {
printf "[img]%s[/img]\n", $url;
} elsif( "-m" eq lc $type) {
printf "'<%s>\n", $url;
}
}
# snag the current directory
@gCwdBits = split /\//, cwd();
# figure out where the "public_html" is in the path
$gHtDocsIndex = -1;
$x=0;
foreach $i (@gCwdBits)
{
if ($i eq $gHtDocs)
{
$gHtDocsIndex = $x;
}
$x++;
}
#if there is none, bail.
if ($gHtDocsIndex == -1)
{
printf stderr "Error: Not in your web heirarchy!\n";
exit( -1 );
}
# now start to build up the url; first the base url for this directory
$gUserName = $gCwdBits[$gHtDocsIndex-1];
$gUrlString = $gUrlBase . $gUserName;
for( $y = $gHtDocsIndex+1 ; length( $gCwdBits[ $y ] ) ; $y++ )
{
$gUrlString .= "/";
$gUrlString .= $gCwdBits[ $y ];
}
$gUrlString .= "/";
# and now check the command line parameters...
# url .
# url blah
# url
#these can also be:
# url [option] .
# url [option] blah
# url [option]
# where option is:
# -r straight listings of urls (raw)
# -a wrap in: XX
# -i wrap in:
# -m wrap in: '
$gCmdLineOption = "-r";
$gCmdLineParameter = "";
if ("-" eq substr $ARGV[0], 0, 1)
{
$gCmdLineOption = $ARGV[0];
$gCmdLineParameter = $ARGV[1];
} else {
$gCmdLineParameter = $ARGV[0];
}
if ($gCmdLineParameter eq ".")
{
PrintFormattedString( $gUrlString, $gCmdLineOption );
} elsif (length( $gCmdLineParameter ) > 0) {
PrintFormattedString( $gUrlString . $gCmdLineParameter, $gCmdLineOption );
} else {
opendir ID, ".";
foreach $gDirName (readdir ID)
{
next if( $gDirName eq "." );
next if( $gDirName eq ".." );
PrintFormattedString( $gUrlString . $gDirName, $gCmdLineOption );
}
closedir ID;
}