From 1cd587d241b4511b17e01ac31dbe9a38003758eb Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Tue, 1 Aug 2000 00:51:14 +0000 Subject: [PATCH] utility to trim trailing whitespace --- util/spacewhack.pl | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 util/spacewhack.pl diff --git a/util/spacewhack.pl b/util/spacewhack.pl new file mode 100644 index 0000000000..801f89ce1f --- /dev/null +++ b/util/spacewhack.pl @@ -0,0 +1,84 @@ +#!/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 = )) { + 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. + $_ = ; + $/ = "\n"; # Back to line-at-a-time for . + + 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); +