#!/usr/bin/perl -w
use strict;
use File::stat;
use mdefs;

# Simple directory processing

# Argument: one directory.  Otherwise, the current directory.
# What would it take to process multiple directories?
my $whichdir=".";             # current directory
if (defined @ARGV) { $whichdir=shift(@ARGV); }

print "Information about " . $whichdir . "\n";

# Is it a directory?
if ( ! -d "$whichdir" ) {
    die "$whichdir is not a directory!  Exiting.";
}

# Open it:
opendir (DH, "$whichdir")   || die "Opendir of $whichdir failed: $!";

# Put interesting filenames into an array: 
my @nodots; # all files/dirs not starting with a dot
while (my $a = readdir(DH)) {
    if ( ($a ne "..") && ($a ne ".") ) { 
	unshift @nodots, "$whichdir/$a"; # Push onto array
    }
}
closedir(DH);

# Define output formats.  Note: this would be easier with a
# formatted printf statement!
format STDOUT_TOP =
Filename                Owner    Date          Size
----------------------  -------  ------------  ----            
.

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<  @<<<<<<  @<< @<, @<<<  @<<<
$_, $mdefs::uid, $mdefs::mname[$mdefs::mon], $mdefs::mday, $mdefs::year, $mdefs::sb->size
.

# Loop: for each file

for (@nodots) {
    $mdefs::sb = stat($_);

    ($mdefs::sec,$mdefs::min,$mdefs::hour,$mdefs::mday,$mdefs::mon,$mdefs::year,$mdefs::wday,$mdefs::yday,$mdefs::isdst) = localtime $mdefs::sb->mtime;
    $mdefs::year += 1900;
    $mdefs::uid=getpwuid($mdefs::sb->uid);
    write;
}
