#!/usr/bin/perl -w
# delfilefromprj -- another tricky tool for the KDevelop-Project (Prototyp)
# removes files from the project
# (c) 1998 Sandy Meier <smeier@rz.uni-potsdam.de>
# begin: 21 Jul 1998
# last changes: 25 Jul 1998
# licensed  under the GPL


#syntax addfile2prj projectfile filename
# projectfile -- complete filename with dir
# filename -- only the filename

#read the commandline

($projectfile,$filename) = @ARGV;

#read the projectfile and extract the information

open (IN_PRJ,$projectfile);
@projectf = <IN_PRJ>;
$lenght = @projectf;

#interate the projectfile
for ($i=0;$i < $lenght;$i++){
    if ($projectf[$i] =~ /\#AUTHOR/){
	$author = $projectf[$i +1];
	chomp($author);
    }
    if ($projectf[$i] =~ /\#EMAIL/){
	$email = $projectf[$i +1];
	chomp($email);
    }
    if ($projectf[$i] =~ /\#PROJECT_NAME/){
	$project_name = $projectf[$i +1];
	chomp($project_name);
    }
    if ($projectf[$i] =~ /\#PROJECT_DIR/){
	$project_dir = $projectf[$i +1];
	chomp($project_dir);
    }
    if ($projectf[$i] =~ /\#PROJECT_SUB_DIR/){
	$project_sub_dir = $projectf[$i +1];
	chomp($project_sub_dir);
    }
    
}


# modified the projectfile

open (IN,$projectfile);
@prj_file = <IN>;

open (OUT,">" . $projectfile);

foreach $i (@prj_file){
    if ($i =~ /$filename/){
	;                            # if found do nothing
    }
    else {
	print OUT $i
    }
}

# modified the Makefile.am in the subdir,only if .cpp

if (!($filename =~ /\".cpp\"/)){
    exit;
}
open (IN_MAKE,$project_sub_dir . "Makefile.am");
@make_file = <IN_MAKE>;
open (OUT_MAKE,">" . $project_sub_dir . "Makefile.am");

foreach $i (@make_file){
    $i =~ s/$filename//;
    print OUT_MAKE $i;
}


