#!/usr/bin/perl -w
# vim: set sw=4 ts=4 si et:
# Written by: Guido Socher
#
use strict;
use vars qw($opt_h $opt_r);
use Getopt::Std;
sub help();
#
getopts("r:h")||exit 1;
help() if ($opt_h);
help() unless ($opt_r);
my @content;
for my $file (@ARGV){
    @content=();
    if ( -w "$file" ){
        print "- $file\n";
        open(FF,"$file")||die;
        while(<FF>){
            if (m/$opt_r/io){
                print "REMOVE:$file: $_";
            }else{
                push(@content,$_);
            }
        }
        close FF;
        open(FF,">$file")||die;
        for (@content){
            print FF;
        }
        close FF;
    }else{
        print "ERROR: can not write $file\n";
    }
}
#
sub help(){
print "cleantalkback -- remove all talkback lines which
match a given pattern (not case sensitive).

USAGE: cleantalkback -r regexp files

The lines are totally removed from the talkbacks\n";
exit 0;
}
__END__

