#!/usr/bin/env perl

use strict;
use Cwd;
use File::Basename;
use Getopt::Long;
use FindBin qw($Bin);
use English;
use IO::File;

(my $ProgName = $0) =~ s!(.*)/!!;      # name of this script

my $caseroot = "$ENV{'CASEROOT'}";
if ( defined($ENV{'CASEROOT'})) {
    # do nothing
} else {
    die "$ProgName - ERROR: env variable CASEROOT is not defined \n";
}	

my @dirs = ("$caseroot/Tools");
unshift @INC, @dirs;
require SetupTools;

my %opts = ( user_nl_file => undef);
GetOptions( "user_nl_file=s" => \$opts{'user_nl_file'}) or die "need to specify user_nl_file as input";
my $user_nl_file = $opts{'user_nl_file'};

my  $fh = new IO::File;
$fh->open("<$user_nl_file") or die "** can't open file: $user_nl_file\n";

while (my $line = <$fh>) {
    if ($line =~ /^[\&\/\!]/ ) {
	# do nothing
	next;
    }elsif ($line =~ /\$([\w\_]+)/){
	my $var = $1;
	my $xmlhash;
	SetupTools::getxmlvars($caseroot,$xmlhash);
	$line = SetupTools::expand_env_var($line,$xmlhash);
    }
    print "$line";
}
$fh->close()
