###
### title.lc
###
### Extract titles from a set of files.
###
### The files are specified by running a program. This
### allows you to use a variety of ways to do things.
### Note that you don't want to use this from a CGI program
### with user derived input.
###
use strict;
use Cwd;
use vars qw(%Callable $TitleVersion);
$TitleVersion = 'title.lc v0.01 regan@ao.com';
###
### TitleLi
###
### Generate a set of list items (
) from the files
### which are HTML links to the specified file.
###
### Sample usage:
### #localcode title.lc
### TitleLi(ls Photos/*.html)
### TitleLi(find . -name "*.html" | sort)
###
sub TitleLi
{
my($args) = @_;
my($data, $file, @files, $retval);
@files = `$args`;
$retval = "";
for $file (@files)
{
chomp $file;
if (!open(FILE, "<$file"))
{
print STDERR "Cannot open $file: $!";
$retval .= "Cannot open $file: $!";
}
else
{
local($/);
undef $/;
$data = ;
close FILE;
if ($data =~ m#(.*)#si)
{
$data = $1;
$data =~ s/^[\r\n]+//;
$data =~ s/[\r\n]+$//;
$data =~ s/[\r\n]/ /g;
}
else
{
$data = $file;
}
$retval .= qq|$data\n|;
}
}
return $retval;
}
###
### PresetVars
###
### Preset some variables.
###
sub PresetVars
{
my($dir);
$dir = cwd();
$dir =~ s#.*/##;
$dir =~ s/\W/ /g;
$Symbols{'_DIRECTORY-NAME_'} = $dir;
}
###
### Library initialization
###
$Callable{'TitleLi'} = 1;
PresetVars();
return 1;