#!/usr/bin/perl

# $Id: //depot/cad/tools/1.0/icp4-1.1/bin/p4co_wrapper#2 $
#
# CSWITCH CORPORATION CONFIDENTIAL PROPRIETARY
# 
# This file contains information which is the
# proprietary property of Cswitch Corporation.
# This file is confidential and its contents may
# not be disclosed without the expressed written
# consent of Cswitch Corporation.


use strict;
use warnings;

use FindBin qw($Bin);
use lib "$Bin/../lib";

use Icp4;
use Getopt::Std;
use File::Basename;

our (%opt, $Program);

MAIN: {

    my ($Dflag, $nflag);
    my ($libvar, $libpath, $groupname, $viewname, $cell, $cellname);

    $Program = $FindBin::Script;

    getopts('hDnw:c:', \%opt);

    if ($opt{h} || !$opt{w} || !$opt{c}) {
	print "Usage: $Program [-h] [-n] -w workingdir -c cell\n";
	print "   -h: help usage\n";
	print "   -n: show operation only\n";
	print "   -w: working dir\n";
	print "   -c: cell\n";
	exit;
    }

    $Dflag = "-D" if ($opt{D});
    $nflag = "-n" if ($opt{n});

    # from icstudio:
    ($libvar, $groupname, $viewname, $cellname) = split('/', $opt{c});
    $libpath = Icp4::get_libpath($opt{w}, $libvar);
    if ($libpath ne "UNKNOWN") {
	print "INFO: $libvar, $libpath, $groupname, $viewname, $cellname\n" if ($opt{D});
	$cell = $libpath . "/" . $groupname . "/". $viewname . "/" . $cellname;
	system("p4co $Dflag $nflag $cell");
    } else {
	die "ERROR: path to $libvar unknown.";
    }

    exit 0;
}