#!/usr/bin/perl

# acceptable forms:
#   ctunattach project      - attach to the personal flavor of the project

sub CTUnattachUsage {
   print STDERR "Usage: ctattach project(s)\n" ;
   &CTAttachWriteNullScript( $tmpname ) ;
   print $tmpname . "\n" ;
   exit;
}

$tool = $ENV{"DTOOL"} ;

require "$tool/built/include/ctattch.pl" ;
require "$tool/built/include/ctunattach.pl" ;
require "$tool/built/include/ctquery.pl" ;

$tmpname = "/tmp/script.$$" ;

if ( $#ARGV == -1 ) {
   &CTUnattachUsage ;
}

foreach $proj ( @ARGV ) {
   &CTUDebug( "project is '$proj'\n" ) ;

   $curflav = &CTQueryProj( $proj ) ;
   if ( $curflav ne "" ) {
      $envsep{"PATH"} = ":" ;
      $envsep{"LD_LIBRARY_PATH"} = ":" ;
      $envsep{"DYLD_LIBRARY_PATH"} = ":" ;
      $envsep{"PFPATH"} = ":" ;
      $envsep{"SSPATH"} = ":" ;
      $envsep{"STKPATH"} = ":" ;
      $envsep{"DC_PATH"} = ":" ;
      $spec = &CTUnattachCompute( $proj, $curflav ) ;
      if ( $spec eq "" ) {
	 &CTAttachWriteNullScript( $tmpname ) ;
	 print $tmpname . "\n" ;
      } else {
	 &CTUnattachWriteScript( $tmpname ) ;
	 print $tmpname . "\n" ;
      }
   } else {
      &CTAttachWriteNullScript( $tmpname ) ;
      print $tmpname . "\n" ;
   }
}
