diff options
author | Cash Costello <cash.costello@gmail.com> | 2011-12-11 06:38:23 -0500 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2011-12-11 06:38:23 -0500 |
commit | d9bf22a0e29c2a70049443a0ae8521a2c0492c8b (patch) | |
tree | c7599a9169d5def7df56c480ad6d67f312443d6f /models/openid-php-openid-782224d/admin/longlines.pl | |
download | elgg-d9bf22a0e29c2a70049443a0ae8521a2c0492c8b.tar.gz elgg-d9bf22a0e29c2a70049443a0ae8521a2c0492c8b.tar.bz2 |
initial commit for git repository
Diffstat (limited to 'models/openid-php-openid-782224d/admin/longlines.pl')
-rw-r--r-- | models/openid-php-openid-782224d/admin/longlines.pl | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/models/openid-php-openid-782224d/admin/longlines.pl b/models/openid-php-openid-782224d/admin/longlines.pl new file mode 100644 index 000000000..6ce65e87a --- /dev/null +++ b/models/openid-php-openid-782224d/admin/longlines.pl @@ -0,0 +1,46 @@ +#!/usr/bin/env perl -w + +use strict; + +my $filename = $ARGV[0]; + +if (!$filename) { + print "Usage: longlines.pl <filename> [length]\n"; + exit(1); +} + +# Set a default maximum line length. +my $max_length = $ARGV[1] || 80; + +my @lines = (); +my $line_num = 0; + +open(HANDLE, "<", $filename) or die "Cannot open $filename\n"; + +# Read the file and track the lines with length > $max_length. +while (<HANDLE>) { + $line_num++; + # Subtract one because the newline doesn't count toward the + # length. + if (length($_) - 1 > $max_length) { + push @lines, $line_num; + } +} + +# If more than five long lines were found, truncate to five and +# indicate that others were present, too. +if (@lines > 5) { + @lines = @lines[0..4]; + push @lines, "and others"; +} + +# If any long lines were found, notify and exit(1); otherwise, +# exit(0). +if (@lines) { + print $filename." (line".((@lines > 1) ? "s" : "")." ". + join(", ", @lines)." exceed".((@lines == 1) ? "s" : ""). + " length $max_length)\n"; + exit(1); +} else { + exit(0); +} |