#!/usr/bin/perl # #//===----------------------------------------------------------------------===// #// #// The LLVM Compiler Infrastructure #// #// This file is dual licensed under the MIT and the University of Illinois Open #// Source Licenses. See LICENSE.txt for details. #// #//===----------------------------------------------------------------------===// # use strict; use warnings; use File::Glob ":glob"; use FindBin; use lib "$FindBin::Bin/lib"; use tools; our $VERSION = "0.02"; sub wipe($$$) { my ( $input, $output, $wipe ) = @_; my $bulk = read_file( $input, -binary => 1 ); $bulk =~ s{($wipe)}{ " " x length( $1 ) }ge; write_file( $output, \$bulk, -binary => 1 ); return undef; }; # sub wipe my @wipe; my $target = "."; get_options( "wipe-literal=s" => sub { my $arg = $_[ 1 ]; push( @wipe, qr{@{ [ quotemeta( $arg ) ] }} ); }, "wipe-regexp=s" => sub { my $arg = $_[ 1 ]; push( @wipe, qr{$arg} ); }, "target-directory=s" => \$target, ); # Convert strings to regular expression. my $wipe = qr{@{ [ join( "|", @wipe ) ] }}; my %jobs; # Collect files to process. # jobs: output -> input. foreach my $arg ( @ARGV ) { my @inputs = ( $^O eq "MSWin32" ? bsd_glob( $arg ) : ( $arg ) ); foreach my $input ( @inputs ) { my $file = get_file( $input ); my $output = cat_file( $target, $file ); if ( exists( $jobs{ $output } ) ) { runtime_error( "\"$jobs{ $output }\" and \"$input\" input files tend to be written " . "to the same output file \"$output\"" ); }; # if $jobs{ $output } = $input; }; # foreach }; # foreach $file # Process files. %jobs = reverse( %jobs ); # jobs: input -> output. foreach my $input ( sort( keys( %jobs ) ) ) { my $output = $jobs{ $input }; info( "\"$input\" -> \"$output\"" ); wipe( $input, $output, $wipe ); }; # foreach $input exit( 0 ); __END__ # # Embedded documentation. # =pod =head1 NAME B -- Wipe string in text or binary files. =head1 SYNOPSIS B I