#!/usr/bin/perl -w
#=============================== fhd_list ===================================
# Filename:  	       fhd_list
# Description:         Generate a filename hash from a list of filenames.
# Original Author:     Dale M. Amon
# Revised by:          $Author: $ 
# Date:                $Date: $ 
# Version:             $Revision: $
# License:	       LGPL 2.1, Perl Artistic or BSD
#
#=============================================================================
use strict;
use Getopt::Long;
use Pod::Usage;
use Fault::DebugPrinter;
use Fault::Logger;
use Fault::Delegate::Stderr;
use FileHash::Name;

#=============================================================================
#                   Logging, debugging and signal handling
#=============================================================================
my %opts;
$::PROCESS_NAME = "fhd_list";
$::DEBUG        = 0;

sub done {
  {local $SIG{'TERM'} = 'IGNORE'; kill 'TERM' => -$$;}
  Fault::Logger->log ("Shutdown.","NOTE",'notice');
  exit 1;
}

                 Fault::DebugPrinter->new(0);
my $delegate1  = Fault::Delegate::Stderr->new;
my @delegates = ($delegate1);
                 Fault::Logger->new (@delegates);

$SIG{'INT'}  = \&done;
$SIG{'TERM'} = \&done;

#=============================================================================
#                    Switch and argument handling
#=============================================================================
my ($HELP,$MAN,$DUMP,$DIAGNOSTIC_PRINT_LEVEL) = (0, 0, "/dev/stdout", 0);

my $opts  = Getopt::Long::Parser->new;
$opts->getoptions (
        'd|debug'      => sub { $::DEBUG = 1 },
        'v|verbose=i'  => \$DIAGNOSTIC_PRINT_LEVEL,
	'dump=s'       => \$DUMP,
        'h|help'       => \$HELP,
        'man'          => \$MAN
);
pod2usage(1)                            if $HELP;
pod2usage(-exitval => 0, -verbose => 2) if $MAN;
Fault::DebugPrinter->level ($DIAGNOSTIC_PRINT_LEVEL);

#-----------------------------------------------------------------------------

my $file       = ($#ARGV < 0 ) ? "/dev/stdin" :  $ARGV[0];
my $formatline = "path";
my $fnhash     = FileHash::Name->alloc;

$fnhash->initFromFile ($formatline,$file);
$fnhash->dump         ($DUMP);

exit 0;

#=============================================================================
#                          POD DOCUMENTATION                                
#=============================================================================
# You may extract and format the documention section with the 'perldoc' cmd.

=head1 NAME

 fhd_list

=head1 SYNOPSIS

 fhd_list {-h|--help|--man} \
	  {-d|--debug} \
	  {-v|--verbose=1} \
	  {--dump="~dump"} {/Archive/filenamelist}

=head1 Description

Generate a filename hash from a list of file names. That input may come 
from a file with pathnames one per line or from stdin.

If the --dump is not present, the filehash is dumped to stdout

=head1 Examples

 fhd_list --dump=mydump /home/amon/ListOfFilePathnames
 cat listofnames | fhd_list > mydump

=head1 Errors and Warnings

 Lots.

=head1 KNOWN BUGS

When using stdout, the log messages will be mixed with the output.

=head1 SEE ALSO

 None.

=head1 AUTHOR

Dale Amon <amon@vnl.com>

=cut

#=============================================================================
#                                CVS HISTORY
#=============================================================================
# $Log: $
# 20080716	Dale Amon <amon@vnl.com>
# 		Created.
1;
