MAJOR=5
MINOR=1
DEVNAME=console
  6   'ˆl–ß=¿J
j"T% íÆŸ¸ ©‹Fÿ�þ_x±¬ÙctO€OŒMùÕ„eð´ïÔÄÑ ?÷     '#!/usr/bin/perl -w
#========================================================================
#
# ttree
#
# DESCRIPTION
#   Script for processing all directory trees containing templates.
#   Template files are processed and the output directed to the 
#   relvant file in an output tree.  The timestamps of the source and
#   destination files can then be examined for future invocations 
#   to process only those files that have changed.  In other words,
#   it's a lot like 'make' for templates.
#
# AUTHOR
#   Andy Wardley   <abw@wardley.org>
#
# COPYRIGHT
#   Copyright (C) 1996-2013 Andy Wardley.  All Rights Reserved.
#   Copyright (C) 1998-2003 Canon Research Centre Europe Ltd.
#
#   This module is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
#========================================================================

use strict;
use Template;
use AppConfig qw( :expand );
use File::Copy;
use File::Path;
use File::Spec;
use File::Basename;
use Text::ParseWords qw(quotewords);

my $NAME     = "ttree";
my $VERSION  = 2.90;
my $HOME     = $ENV{ HOME } || '';
my $RCFILE   = $ENV{"\U${NAME}rc"} || "$HOME/.${NAME}rc";
my $TTMODULE = 'Template';

#------------------------------------------------------------------------
# configuration options
#------------------------------------------------------------------------

# offer create a sample config file if it doesn't exist, unless a '-f'
# has been specified on the command line
unless (-f $RCFILE or grep(/^(-f|-h|--help)$/, @ARGV) ) {
    print("Do you want me to create a sample '.ttreerc' file for you?\n",
      "(file: $RCFILE)   [y/n]: ");
    my $y = <STDIN>;
    if ($y =~ /^y(es)?/i) {
        write_config($RCFILE);
        exit(0);
    }
}

# read configuration file and command line arguments - I need to remember 
# to fix varlist() and varhash() in AppConfig to make this nicer...
my $config   = read_config($RCFILE);
my $dryrun   = $config->nothing;
my $verbose  = $config->verbose || $dryrun;
my $colour   = $config->colour;
my $summary  = $config->summary;
my $recurse  = $config->recurse;
my $preserve = $config->preserve;
my $all      = $config->all;
my $libdir   = $config->lib;
my $ignore   = $config->ignore;
my $copy     = $config->copy;
my $link     = $config->link;
my $accept   = $config->accept;
my $absolute = $config->absolute;
my $relative = $config->relative;
my $suffix   = $config->suffix;
my $binmode  = $config->binmode;
my $depends  = $config->depend;
my $depsfile = $config->depend_file;
my ($n_proc, $n_unmod, $n_skip, $n_copy, $n_link, $n_mkdir) = (0) x 6;

my $srcdir   = $config->src
    || die "Source directory not set (-s)\n";
my $destdir  = $config->dest
    || die "Destination directory not set (-d)\n";
die "Source and destination directories may not be the same:\n  $srcdir\n"
    if $srcdir eq $destdir;

# unshift any perl5lib directories onto front of INC
unshift(@INC, @{ $config->perl5lib });

# get all template_* options from the config and fold keys to UPPER CASE
my %ttopts   = $config->varlist('^template_', 1);
my $ttmodule = delete($ttopts{ module });
my $ucttopts = {
    map { my $v = $ttopts{ $_ }; defined $v ? (uc $_, $v) : () }
    keys %ttopts,
};

# get all template variable definitions
my $replace = $config->get('define');

# now create complete parameter hash for creating template processor
my $ttopts   = {
    %$ucttopts,
    RELATIVE     => $relative,
    ABSOLUTE     => $absolute,
    INCLUDE_PATH => [ $srcdir, @$libdir ],
    OUTPUT_PATH  => $destdir,
};

# load custom template module 
if ($ttmodule) {
    my $ttpkg = $ttmodule;
    $ttpkg =~ s[::][/]g;
    $ttpkg .= '.pm';
    require $ttpkg;
}
else {
    $ttmodule = $TTMODULE;
}


#------------------------------------------------------------------------
# inter-file dependencies
#------------------------------------------------------------------------

if ($depsfile or $depends) {
    $depends = dependencies($depsfile, $depends);
} 
e