spacewhack.pl revision 5fa46bc91672ef5737aee6f99763161511566c24
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff#!/usr/local/bin/perl -w
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff#
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# Copyright (C) 2004, 2007, 2012 Internet Systems Consortium, Inc. ("ISC")
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# Copyright (C) 2000, 2001 Internet Software Consortium.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff#
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# Permission to use, copy, modify, and/or distribute this software for any
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# purpose with or without fee is hereby granted, provided that the above
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# copyright notice and this permission notice appear in all copies.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff#
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff# PERFORMANCE OF THIS SOFTWARE.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff# $Id$
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff$0 =~ s%.*/%%;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graffif (@ARGV != 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff warn "Usage: $0 < list-of-files\n";
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff warn "The util/copyrights file is normally used for list-of-files.\n";
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff exit(1);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff$total = 0;
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graffprintf "Lines Trimmed:\n";
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graffwhile (defined($line = <STDIN>)) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff ($file) = split(/\s+/, $line, 2);
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff # These are binary and must be ignored.
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff next if $file =~ m%/random.data|\.gif$%;
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff next if -B $file;
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff print "$file\n";
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff unless (open(FILEIN, "< $file")) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff warn "$0: open < $file: $!, skipping\n";
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley next;
e45d323a2a0f4ca08d4b139546e60a5fa7bd3f0cMichael Graff }
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graff
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff undef $/; # Slurp whole file.
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff $_ = <FILEIN>;
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff $/ = "\n"; # Back to line-at-a-time for <FILES>.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff close(FILEIN);
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff $count = s/[ \t]+$//mg;
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff
439c0011e642fb1d26011116144af698125262dbMichael Graff next unless $count > 0;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff unless (open(FILEOUT, "> $file")) {
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff warn "$0: open > $file: $!, skipping\n";
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff next;
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff }
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff print FILEOUT or die "$0: printing to $file: $!, exiting\n";
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff close FILEOUT or die "$0: closing $file: $!, exiting\n";
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff printf("%6d lines trimmed in $file\n", $count) if $count > 0;
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff $total += $count;
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff}
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffprintf "%6d TOTAL\n", $total;
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley
fe14eafefa91fada7cea0a55b09196c01477406cBob Halleyexit(0);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff