#! perl -w

# get the standard CFX-5 library directory
BEGIN {
  if ($0 =~ m!^([a-z]:)?[\\/]!i) {
    # it's an absolute path, use it as-is
    (my $nd=$0) =~ s!(perllib[\\/])?[^\\/]*$!!i;
    unshift @INC, "$nd/perllib";
  } else {
    # wrap this in an eval, and if it fails, pray ... for example,
    # this can fail on Windows if we're running off a share.
    eval {
      require FindBin;
      FindBin->import();
      unshift @INC, "$FindBin::Bin/perllib";
      my $dummy=$FindBin::Bin; # kill used only once warning
    };
    warn $@ if $@;
  }
  if (defined $ENV{CFX_LOCAL_PERLLIB}) {
     unshift @INC, $ENV{CFX_LOCAL_PERLLIB};
  }

}

use CFX5::Init;
CFX5::Init::init();

use vars qw($CVSVersion);
sub BEGIN {
  $CVSVersion='@(#) $Id$\n';
}

use strict;

use CFX5::Output qw(:all);
use CFX5::Config qw(%Config export_conf);
use CFX5::PathManip qw(join_file);
use CFX5::Commands qw(do_cmd handle_rv do_cmd_quiet);

#
# read the configuration
#
CFX5::Config::read_config();

# no command-line parsing, we delegate all that to gtmconvert

export_conf(qw(CFX5EXECDIR CFX5BINDIR CFX_DATA_DIR));

use CFX5::Config::def CFX5_GTMCONVERT_EXEC => sub { join_file($Config{CFX5EXECDIR}, 'gtmconvert.exe') };

my $rv=handle_rv(do_cmd($Config{CFX5_GTMCONVERT_EXEC}, @ARGV));

_warn("The CFX-5 GTM Conversion Tool exited with return code $rv")
  if ($rv);

exit(defined $rv ? $rv : 2);
