Commit 1cd587d2 authored by David Lawrence's avatar David Lawrence
Browse files

utility to trim trailing whitespace

parent f4a7d048
#!/usr/local/bin/perl -w
#
# Copyright (C) 2000 Internet Software Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# $Id: spacewhack.pl,v 1.1 2000/08/01 00:51:14 tale Exp $
$0 =~ s%.*/%%;
$find = "find . -type f -print";
open(FILES, "$find | sort |")
or die "can't start \"$find\": $!";
$total = 0;
printf "Lines Trimmed:\n";
while (defined($file = <FILES>)) {
chomp $file;
# Cheap test for files to ignore.
next if $file =~ m%/\.#%; # CVS conflict files.
next if $file =~ m%/CVS/%; # CVS metafiles.
next if $file =~ m%\.[oa]$%; # Object and library files.
next if $file =~ m%/#[^/]+#$%; # Emacs autosave.
next if $file =~ m%~([0-9]+~)?$%; # Emacs version control.
# Generated by configure.
next if -f "$file.in";
# Known binaries.
next if $file =~ m%/(named|lwresd|rndc)$%;
next if $file =~ m%/(dig|host|nslookup|nsupdate)$%;
next if $file =~ m%/dnsssec-(sign(key|zone)|keygen|makekeyset)$%;
next if $file =~ m%/t_[^.]*$%;
# A little more expensive test for remaining files to ignore.
next if -B $file;
unless (open(FILEIN, "< $file")) {
warn "$0: open < $file: $!, skipping\n";
next;
}
undef $/; # Slurp whole file.
$_ = <FILEIN>;
$/ = "\n"; # Back to line-at-a-time for <FILES>.
close(FILEIN);
$count = s/[ \t]+$//mg;
next unless $count > 0;
unless (open(FILEOUT, "> $file")) {
warn "$0: open > $file: $!, skipping\n";
next;
}
print FILEOUT or die "$0: printing to $file: $!, exiting\n";
close FILEOUT or die "$0: closing $file: $!, exiting\n";
printf("%6d lines trimmed in $file\n", $count) if $count > 0;
$total += $count;
}
printf "%6d TOTAL\n", $total;
exit(0);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment