#!/h/COE/Comp/PERL5/bin/perl -T -I/h/COE/lib -w

#-
 # Copyright (C) 2002, Federal Linux Systems
 # License: GNU Lesser General Public License, v2.1
#- 

use strict;
use Coe;
use Sys::Hostname;

my $PRGM="COE_get_current_profiles";
my $VERSION="1.1.4.1";

if (@ARGV > 1) {
	&useage;
   	exit 202;
} 

sub useage {
   	print "Useage: COE_get_current_profiles [options]\n";
}

my $arg1;
my $display;
my $home;
my $hostname;
my $lastprofiles;
my $COEDAT;
my $flagprof="false";

while (@ARGV > 0) {
	$arg1=cleanString(shift,1);
	if ("$arg1" eq "-h") {
		useage;
   		exit 0;
	} elsif ("$arg1" eq "-H") {
		coeMan("COE_COMP/UserMgmt/docs/man/$PRGM");
   		exit 0;
	} elsif ("$arg1" eq "-V") {
		print "VERSION: $VERSION\n";
   		exit 0;
	} 
}

# define path/file info
$home=$ENV{'HOME'};

#$_=$ENV{'HOSTNAME'};
#$hostname=cleanString($_,2);
$hostname=hostname();

$_=$ENV{'DISPLAY'};
s/^.*://;
s/\..*$//;
$display=$_;
if ("$display" eq "" ) {
	$display="0";
}

#- place the LastProfiles file into the users home directory, unless DII COE
$lastprofiles = coeFileConv("$home/LastProfiles_".$hostname."_".$display, 3);

#- if strict DII COE is needed, use the following
#$lastprofiles = coeFileConv("$home/../LastProfiles_".$hostname."_".$display, 3);

# overwrite existing files with the new profile data
if (-e $lastprofiles) {
	$COEDAT=readFile("$lastprofiles");
	while (<$COEDAT>) {print $_; $flagprof="true";}
	close $COEDAT;
}

if ("$flagprof" eq "true") {
	exit 0;
} else {
	exit 204;
}