#!/usr/bin/perl
### Display all (or selected) files in directory. (+++ subdirs, too?)
### Also display TITLE/ABSTRACT info.
### head.txt and tail.txt are also displayed.
########################################################################
### Copyright (C) Tripodics.com
### Author: Bruce A. Martin
### File Name: display.pl
### Versions:
### 0.3 (Don't show .pl source code.)
### 0.2 bam:2004/08/03 Add PNG, also link for DIR.
### 0.1 bam:2004/02/22 Extract description from HTML
### 0.0 bam:2003/11/20
#########################################################################
use strict;
use CGI qw/:standard/;
print header; # html format is permitted to output.
my $NL = "\n";
my $Q = '"';
### Get parameters from html form.
#
my %in_para;
foreach (param()){
$in_para{$_} = join " ", param($_);
# Multiple-values (checkbox) joined with blanks.
}
#### Set prefix to path. ####
my $name = $ENV { 'COMPUTERNAME' } ;
my $path = "";
#### Set file names. ####
my $DIRNAME = $in_para{DIRNAME};
my $dirname = $path . "./";
if ($DIRNAME) { $dirname = $path . $DIRNAME . "/"; }
my $MAXLINES = $in_para{MAXLINES};
my $maxlines = $MAXLINES;
if ($maxlines < 1) { $maxlines = 10; }
my $head = $path . "head.html";
my $tail = $path . "tail.html";
### Main processing
#
&show( $head );
&showdir( $dirname );
print "
TAIL:
";
&show( $tail );
print "
";
my $s='';
$s .= '';
print $s;
exit;
######## The following subroutines are from the Tripodics Library. ########
#### Copyright 1996-2002 by Tripodics, All Rights Reserved. ####
#### Tripodics Computing Service, POBox 456 Middle Island, NY 11953 ####
#+++ (Nonexclusive usage granted to PhDsigns, Bay Shore, NY.) +++#
############################################################################
################################### show.pl
# Print contents of an HTML file.
#
sub show( $f )
{
my $f = $path . @_[0];
open(F,"$f") or return 0;
while(){
print;
}
close(F);
}
sub showdir( $d )
{
my $d = $path . @_[0];
my @allfiles;
opendir(D,$d) or return 0;
@allfiles = grep !/^\./, readdir D;
closedir D;
print "#### allfiles= @allfiles
";
print "\n";
my $f;
my $max=$maxlines;
my $next;
foreach $name ( @allfiles ) {
my $f = $path . $dirname . $name;
#-- my $fn= fileno $f ;
print '- ';
print '';
print "$f";
#--print "$f \n";
print '';
## Display file name and info ##
if ( -z $f ) { print "ZERO SIZE"; }
## Special cases for html, gif, etc.
if ( $f =~ /\.html*$/i ) {
print '';
&shownotags( $f, $max );
print '';
}
elsif ( $f =~ /\.pl*$/i ) {
#-- print '';
#-- &showtext( $f, $max );
#-- print '';
}
elsif ( $f =~ /\.png$/i ) {
print "png: ";
print '';
print '';
print '';
}
elsif ( $f =~ /\.gif$/i ) {
print "GIF: ";
print '';
print '';
print '';
}
elsif ( $f =~ /\.jp[e]*g$/i ) {
print "JPEG: ";
print '';
print '';
print '';
}
## Check file type; display if text.
elsif ( -T $f ) {
&showtext( $f, $max );
}
elsif ( -d $f ) {
print " ";
print " -- DIRECTORY";
print "\n";
my $dd = $path . $f;
my @ddfiles;
opendir(DD,$dd) or print ' [[[[ Cannot open DIR. ]]]]';
@ddfiles = grep !/^\./, readdir DD;
closedir DD;
print "
@ddfiles
";
#++ font.
}
elsif ( -l $f ) { print " -- SYMLINK"; }
else {
print "
[[[[ $f is not a text file ]]]]\n";
print "++++ $f
\n"; &showtext( $f, $max );
#-- print "
\n";
}
}
print "<\UL>\n";
}
sub showtext( $f, $max )
{
#-- my $f = $path . $dirname . @_[0];
my $f = @_[0];
my $maxlines = @_[1];
## Display text file contents ##
open(F,$f) or print "Cannot open $f";
print "";
while(){
s/\</g; # Suppress tags.
print "- $_";
if ($. >= $maxlines)
{
print ". . .";
last;
}
}
print "
\n";
close(F);
}
sub shownotags( $f, $max )
{
#-- my $f = $path . $dirname . @_[0];
my $f = @_[0];
my $maxlines = @_[1];
my $lines = $maxlines;
print $lines;
## Display without tags ##
open(F,$f) or print "Cannot open $f";
print "";
while(){
if ( / +++++
\n";
}
if ( /]*>*//g; # Suppress tags.
print "- TITLE: $_
\n";
}
s/<[^>]*>*//g; # Suppress tags.
next if ( /^\s*$/ );
print "$_";
$lines--;
if ($lines < 0 )
{
print ". . .";
last;
}
}
print "
\n";
close(F);
}
############################## End of bamlib.inc #############################