#! perl -w
##
## Name: 
##
## p3_proe
##
## Purpose: 
##
## Invoke Pro/ENGINEER with CFX-Build as an export option.
##
## Synopsis:
#S
#S p3_proe
#S
## []  denotes an optional argument. 
## |   separates mutually exclusive arguments. 
## ... following an argument indicates that it may be repeated.
## <>  denotes that substitution of a suitable value is required. All other
##     arguments are keywords, some of which may have a short form.
##
## Arguments:
##
## -help
## -h
##      Print this message.
##
#------------------------------------------------------------------------------
#
# Modification History:-
#
# 19/05/98 ASM Original coding.
#
#------------------------------------------------------------------------------

# get the standard CFX-5 library directory
use FindBin;
use lib "$FindBin::Bin/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 append_to_execpath append_to_libpath);
use CFX5::PathManip qw(join_file);
use CFX5::Commands qw(do_cmd do_cmd_quiet handle_rv parse_rv);

use CFX5::Help qw(show_help);

CFX5::Config::read_config();

if (defined $ARGV[0]
    and ($ARGV[0] eq '-h' or $ARGV[0] eq '-help')) {
  show_help();
  exit(0);
}

#
# now the exciting bit: make sure we have exported the variables we
# need. The following is lifted from cfx5build.pl; p3_proe probably
# doesn't need all of them, but I don't know which it does need, so it
# can have them all anyway!
#
CFX5::Config::export_conf
  (qw(P3_HOME P3_USER_MESSAGES P3_HELP_DIRECTORY
      P3_ENABLE_NFS_DB_ACCESS P3_VERSION CFX_BUILD_DIR CFX_HELP_DIR

      CFX5OS CFX_BUILD_USE_PATRAN_LICENSE  CFX_RECORD_CALCULATE

      CFX5BROWSER CFX5EDITOR CFX5XTERM

      CFX5BINDIR CFX_DATA_DIR CFX_ICON_DIR CFX_EG_DIR CFX5EXECDIR
      CFX_NO_AUTO_HELP

      XENVIRONMENT

      AUTO_EXECUTE_DEFAULT_STATE MSCP_PROE_CMD P3_UG_ENTITY_FILTER
      ));

#
# make sure the required things are on the library and program paths
#
append_to_execpath(join_file($Config{P3_HOME}, "bin"));
append_to_libpath(join_file($Config{P3_HOME}, "lib"),
         	  join_file($Config{P3_HOME}, "interbase", "lib"));

#
# work around for bug on the DEC Alpha.
#
if ($Config{CFX5OS} eq "osf") {
  delete $ENV{P3_HELP_DIRECTORY};
}

my $rv;
if ($Config{windows_nt}) {
  $rv=handle_rv(do_cmd('cmd', '/c', join_file($Config{P3_HOME},'bin/p3_proe.cmd'),@ARGV));
} else {
  $rv=handle_rv(do_cmd(join_file($Config{P3_HOME},'bin','p3_proe'),@ARGV));
}

if (!defined $rv) {
  1;
} elsif ($rv) {
  _error("p3_proe returned exit status $rv");
}
exit (defined $rv ? $rv : 2);
