################################################################################ # File: check_ws.pl # # <> # # Purpose: Report on the whitespace contents of the given file(s). # # Created: 2nd January 2001 # Updated: 3rd January 2001 # Author: Synesis Software (Pty) Ltd (C) 2000. All rights reserved. # (www.synesis-group.com/software). # # Status: Public-domain # # Copyright: Synesis Software (Pty) Ltd provides the source code contained in # this file/document free-of-charge according to the following # conditions: # # (i) No warranty, expressed or implied, is given as to the # correctness or efficiency of the code. # (ii) No part of this code may be modified or copied, by whatever # means without including a copy of this notice in its entirety # (this means the all content between the <> and <<:END>> # tokens inclusive, including, and not limited to, purpose, date # of creation, date of last update, authorship, address, copyright # and status). # (iii) This code, in whole or part, remains the property of # Synesis Software (Pty) Ltd, whether incorporated as-is, or in # modified form. # # <<:END>> # # ############################################################################## #_SYNSOFT_VER_PL_CHECK_WS_MAJOR 1 #_SYNSOFT_VER_PL_CHECK_WS_MINOR 0 #_SYNSOFT_VER_PL_CHECK_WS_REVISION 2 #_SYNSOFT_VER_PL_CHECK_WS_EDIT 3 use integer; sub trim_line { $_ = @_[0]; s/[\r\n]+$//; # strip cr-lf from end of line s/^\s*(.*?)\s*$/$1/; # trim spaces return $_; } if(scalar(@ARGV) > 0) { } else { print "Enter the path (no wildcards):"; $_ = ; (@ARGV) = ($_); } $length = 15; my $spaces = 0; my $tabs = 0; $_ = trim_line($_); foreach (@ARGV) { if(length($_) > $length) { $length = length($_); } } foreach $file (@ARGV) { if(!$file) { print qq(Invalid file specified " . $file . "\n); } elsif(! -T $file) { printf "Whitespace: %-*s is not a text file\n", $length, $file; } # elsif(! -W $file) # { # printf "Whitespace: %-*s cannot be modified\n", $length, $file; # } else { my $file_spaces = 0; my $file_tabs = 0; open(HEADER, $file); while(
) { s/[\r\n]+$//; # strip cr-lf from end of line $file_spaces += tr/ / /; $file_tabs += tr/\t/\t/; } $spaces += $file_spaces; $tabs += $file_tabs; printf "Whitespace: %-*s has %-8d tabs and %-8d spaces\n", $length, $file, $file_tabs, $file_spaces; } } printf "\nWhitespace: %-*s %-8d tabs and %-8d spaces\n", $length, "All files have", $tabs, $spaces;