#!/usr/bin/perl
# $Id: ctools,v 1.9 2002/07/02 19:17:52 jeffb Exp $
use strict;
use Data::Dumper;

#$0 = "caddvsite";
$|;

#use lib "/usr/sausalito/perl";
use lib "/usr/shell-tools/perl";
#use lib "/home/cce-shell-tools/perl";
#use lib "/cvs/cce-shell-tools/perl";

require Shell;

# before anything check to see if we are reading to stdin
if(@ARGV) { &checkStdin }
elsif($0 =~ /clist/) { push @ARGV, "--list" } 
else { push @ARGV, "--quick" }

my $shell = Shell->new();
#warn "build: ", $shell->build, " prog: ", $shell->prog, "\n";

my $build = $shell->build;
my $prog = $shell->prog;

require "$build.pm";
my $conf = $build->new(%{ $shell->{obj} });

my $ret = $conf->$prog;
#warn "ret is: ", $ret, "\n";


exit 0;


sub checkStdin
{
	my (@stdin, $optValue, $len);

	my $optN = "--name";
	my $lastOpt = pop @ARGV;
	if($lastOpt eq '-') {
		warn "Reading from STDIN\n";
		while (my $line = <STDIN>) { 
			chomp $line;
			push @stdin, $line 
		}
		#$optValue = '"';
		foreach my $opt (@stdin) {
			if($opt =~ /^(\S+)\s(.*)/) {
				$optValue .= $1.",";
			} else { $optValue .= $opt."," }
		}
		#$optValue .= '"';
		push @ARGV, $optN, $optValue;
	} else { push @ARGV, $lastOpt }
}
