summaryrefslogtreecommitdiffstats
path: root/long-lines.pl
blob: 35ef85a3c875693ce07eda677b23d79f76a9f487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl
use warnings;
use strict;
use File::Basename;
use Getopt::Std;
use Text::Tabs;
use Carp;

my %opt;
getopts("hm:t:s:", \%opt);

if (@ARGV == 0 || $opt{h}) {
	print "usage: ", basename($0), " [options] file(s)...\n\n";
	print "Options:\n";
	print "  -m NUMBER     maximum chars tolerated per line (default: 80)\n";
	print "  -t NUMBER     count \\t as NUMBER chars (default: 4)\n";
	print "  -s REGEX      skip lines that match this regular expression\n";
	print "  -h            this help\n";
	exit 0;
}

my $max = 80;
my $line = 0;
$Text::Tabs::tabstop = 4;

$max = $opt{m} if ($opt{m});
$Text::Tabs::tabstop = $opt{t} if ($opt{t});

for my $file (@ARGV) {
	open my $fh,"<", $file or do {carp "Failed to open $file: $!"; next;};

	$line = 0;
	while (<$fh>) {
		$line++;
		next if defined $opt{s} and m/$opt{s}/;
		$_ = expand $_;
		if (length > $max) {
			print "\"$file\" - line $line: ", length, " chars\n";
		}
	}
	close $fh;
}