#! /usr/bin/perl
use strict;

sub rmdouble {
	my $file = shift;
	my @lines = `cat $file`;
	my @newlines;
	my $empty=1;
	for (my $i=0; $empty && $i<$#lines; $i++) {
		if ($i < 17 || $i%2 == 0) {
			push(@newlines, $lines[$i]);
		} else {
			if ($lines[$i] ne "\n") {
				$empty = 0;
				print "$file: error on line $i\n";
			}
		}
	}
	if ($empty) {
		open (FH, "> $file") or die;
		foreach (@newlines) {
			print FH;
		}
	}
}

foreach (`ls *.h *.cpp`) {
	chomp;
	rmdouble($_);
}
