#!/usr/bin/perl
########################################################################
#
#                  CTC++ System, ctc (1.1)
#                  CTC++ Perl frontend (Cygwin)
#
# RCSfile     : $RCSfile: ctc $
# Version     : $Revision: 1.1 $ $Date: 2017/06/20 12:30:30 $
# Last Edited : 5.10.2017
# Author      : $Author: roland $
#
#               Copyright (c) 2013-2017 Verifysoft Technology GmbH
##########################################################################
# Additional notice to users:
# Verifysoft Technology provides support for this ctc cygwin component of
# the CTC++ System in the same way as Verifysoft Technology provides support
# for the other components of the CTC++ System. Because this component is
# provided in a source file form, you are able to modify this file.
# However, if you do any such modifications, Verifysoft Technology may not
# be capable of providing you support, and Verifysoft Technology reserves
# the right not to support you with this component, if you have done your
# own modifications to this file.
#
# Verifysoft Technology would however be pleased to receive your bug
# corrections/reports and enhancement suggestions and will consider them
# in future versions of this tool.
#
##########################################################################



##########################################################################
# subroutines
##########################################################################
sub makeopts;
sub expand_opts;
sub escape_opt;
sub cygpath;

##########################################################################
# global "constants"
##########################################################################
$version            = "ctc cygwin v1.1";

##########################################################################
# execution starts here !
##########################################################################

$ctchome = Cygwin::win_to_posix_path($ENV{CTCHOME});

 ARG:
if ($^O eq "cygwin") {
    for ($i=0;$i<=$#ARGV;$i++) {
	if ($ARGV[$i] eq '-V' ||
	    $ARGV[$i] eq '-v' ||
	    $ARGV[$i] eq '-k' ||
	    $ARGV[$i] eq '-2comp' ||
	    $ARGV[$i] eq '-no-comp' ||
	    $ARGV[$i] eq '-h' ||
	    $ARGV[$i] eq '-no-templates' ||
	    $ARGV[$i] eq '-no-warnings') {
	} elsif (substr($ARGV[$i],0,1) eq '@') {
	    my $rsp = substr($ARGV[$i],1);
	    if (!-f $rsp) {
		$rsp=cygpath($rsp);
		if (-f $rsp) {
		    $ARGV[$i]='@'.$rsp;
		}
	    }
	} elsif($ARGV[$i] eq '-i' ||
	    $ARGV[$i] eq '-C' ) {
	    $i++;
	} elsif($ARGV[$i] eq '-c') {
	    $i++;
	    my $conf = $ARGV[$i];
	    $ARGV[$i] = cygpath($conf);
	} else {
	    $exe = $ARGV[$i];
	    if (!-f $exe) {
		$exe = cygpath($exe);
		if (-x $exe) {
		    $ARGV[$i]=$exe;
		    last ARG;
		}
	    }
	}
    }
}

exec($ctchome."/ctc.exe", @ARGV);

# We should never hit this
exit 1; 

1;
##########################################################################
# SUBROUTINES
##########################################################################

##########################################################################
# SUBROUTINE: cygpath
# PURPOSE   : Wrapper to "cygpath"
# ARGUMENT  : - $file 
# RETURNS   : $file with Windows conventions
##########################################################################
sub cygpath
{
    my ($file) = @_;

    return Cygwin::posix_to_win_path($file) if $^O eq "cygwin";
    # External 
    #    $tt = qx#cygpath -m $file#;
    #    $tt =~ s/\015?\012$//;

    return $file;
}


# EOF $RCSfile: ctc $




