#! /usr/bin/perl -w
#
#  This script lists all parameter files required by the process list. By
#  default, only the files that do not match a file name in the current
#  directory are listed. All requested files may be listed by specifying
#  --all in the command line.
#
#  The command syntax is:
#
#     procsetup [--file:<file-base>] [--all] [--debug]
#
#
#  Input files:
#     The procesetup input files consist of lines comprised of one or more
#     fields separated by blanks or tabs. Fields containing white-space 
#     characters should be enclosed in braces ("{}"). The configuration line 
#     may be continued over multiple text lines by ending a non-terminal 
#     line with a backslash (\). Comments start with a hash-mark (#) and 
#     continue to the end of the line.
#
#--- Define Phase subroutines
#
$prefix="/usr";
$exec_prefix="${prefix}";
#
#--- Do initialization
#
$|=1;  #autoflush

$Node = `uname -n`;
chomp $Node;

$Debug = (grep(/--debug/, @ARGV))[0];
if (defined($Debug)) {
    $Debug = 1;
}else {
    $Debug = 0;
}

$All = (grep(/--all/, @ARGV))[0];
if (defined($All)) {
    $All = 1;
}else {
    $All = 0;
}

$FileBase = (grep(/--file:/, @ARGV))[0];
if (defined($FileBase)) {
    $FileBase =~ s/--file://;
} else {
    $FileBase = "$ENV{DMTHOME}/$ENV{DMTVERSION}/etc/procmgt";
}

@ProcList = ();
$nProcs = 0;
$req_mflops=0;

require "${exec_prefix}/bin/procmgt_proclist.pl";

GetProcs();

#---------------------------------------  Print parameter files for each process
for (my $i=0; $i<@ProcList; $i+=proc_ncol()) {
    next if ( $ProcList[$i+5] eq "");
    my @list = split(/[, ]/, $ProcList[$i+5]);
    if ($All) {
        print "$ProcList[$i]: ", join(' ', @list), "\n";
    } else {
	my @need = ();
	for (my $j=0; $j<@list; $j+=1) {
	    if ( ! -f $list[$j]) {
	        push(@need, $list[$j]);
	    }
	}
	my $needlist = join(' ', @need);
	next if ( $needlist eq "");
	print "$ProcList[$i]: $needlist\n";
    }
}
