################################################################################ # File: width_check.pl # # <> # # Purpose: Report on lines exceeding a certain width. # # Created: 20th October 2000 # 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_HDR_VER_CHECK_MAJOR 1 #_SYNSOFT_VER_PL_HDR_VER_CHECK_MINOR 2 #_SYNSOFT_VER_PL_HDR_VER_CHECK_REVISION 2 #_SYNSOFT_VER_PL_HDR_VER_CHECK_EDIT 9 sub trim_line { $_ = @_[0]; s/[\r\n]+$//; # strip cr-lf from end of line s/^\s*(.*?)\s*$/$1/; # trim spaces return $_; } $argc = scalar(@ARGV); if($argc > 0) { $article = trim_line($ARGV[0]); } if($argc > 1) { $max_width = $ARGV[1]; } if($argc > 2) { $verbose = 1; } if(!$max_width) { $max_width = 80; } if(!$article) { print "USAGE: width_check.pl [] [v]\n\n\twidth = maximum number of characters per line\n\n"; print "Enter the path:"; $_ = ; $article = trim_line($_); } if(!$article) { print qq(Invalid file specified " . $article . "\n); } else { open(HEADER, $article); @lines =
; $line_num = 0; $errors = 0; $max_exceeding_line_width = 0; # Determine the ext and name foreach $line (@lines) { $line =~ s/[\r\n]+$//; #strip cr-lf from end of line ++$line_num; $line_len = length($line); if($line_len > $max_width) { print "Line $line_num exceeds $max_width characters (is $line_len characters)\n $line\n"; ++$errors; if($line_len > $max_exceeding_line_width) { $max_exceeding_line_width = $line_len; } } } if( $errors || $verbose) { print "$article has $errors line(s) exceeding $max_width characters width\n"; if($errors) { print "Maximum exceeding width is $max_exceeding_line_width characters\n"; } } }