#!/usr/bin/perl
use strict;
my($app_svnid) = '$HeadURL$ $LastChangedRevision$';
#  Allow bare words, so &ade_err_error() calls look nicer.
no strict 'subs';
use lib substr `ade-config ade_include_prefix`,0,-1;

use ADE;
use Getopt::Long qw(:config no_ignore_case);

&ade_err_registerdefderrs({
    adeperlf_err_misc        => { fmt => "%s" },
    adeperlf_err_internal        => { fmt => "%s" },
});

my(@adeperlf_config_hasharray) = (
);

sub adeperlf
{
    my($errstack_ref) = @_;
    my($rc, $listpaths, $optval, $perlcode, $procopts_hashref);

    ##########################################################################
    #
    #  Process options
    #
    ##########################################################################

    $procopts_hashref = {
    };
    if (($rc=&ade_spc_procopts($errstack_ref, \&adeperlf_listpaths, \&adeperlf_usage, \&adeperlf_version, \@adeperlf_config_hasharray, $procopts_hashref)) != $ade_err_ok) {
        return($rc);
    }

    ##########################################################################
    #
    #  Process arguments
    #
    ##########################################################################

    (!$ARGV[0] || $ARGV[1]) && &ade_msg_usage($errstack_ref, \&adeperlf_usage, 1);
    $perlcode = $ARGV[0];

    &ade_err_debug($errstack_ref, 10, "main: \$perlcode=$perlcode");
    $rc = eval $perlcode;
    if (!defined($rc)) {
        chomp($@);
        &ade_err_error($errstack_ref, adeperlf_err_misc, "code failed to execute ($@)");
        return($ade_err_fail);
    } elsif ($rc != 0) {
        &ade_err_error($errstack_ref, adeperlf_err_misc, "code executed, but returned non-zero ($rc)");
        return($rc);
    }
    #  Ensure sensible return code
    return($ade_err_ok);
}

sub adeperlf_version
{
    my($errstack_ref, $version_ref) = @_;

    return(&ade_smf_extractversionfromsvnstring($errstack_ref, $app_svnid, $version_ref));
}

sub adeperlf_usage
{
    my($errstack_ref, $passno) = @_;

    if ($passno == 1) {
        print "<code>\n";
    } elsif ($passno == 2) {
    } else {
        &ade_err_error($errstack_ref, adeperlf_err_internal, "adeperlf_usage: $passno: bad pass number");
        return($ade_err_fail);
    }

    return($ade_err_ok);
}

sub adeperlf_listpaths
{
    my($errstack_ref, $pathlist_ref) = @_;
    my($rc);
    
    %{$pathlist_ref} = ();
    return($ade_err_ok);
}   

&ade_gep_main(\&adeperlf);
