File: checkbrack

package info (click to toggle)
hxtools 20201116-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,696 kB
  • sloc: ansic: 5,074; perl: 3,589; cpp: 2,152; sh: 1,610; asm: 173; makefile: 153
file content (52 lines) | stat: -rwxr-xr-x 1,245 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
#
#	recursive_lower
#	written by Jan Engelhardt, 1999-2007
#
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the WTF Public License version 2 or
#	(at your option) any later version.
#

use Getopt::Long;
use strict;
my $perl_mode;

&Getopt::Long::Configure(qw(bundling));
&GetOptions("p" => \$perl_mode);

foreach my $file (@ARGV) {
	if (!-f $file) {
		next;
	}
	print "Displaying $file...\n";
	print "  # () [] {}\n";
	open(IN, "< $file") || warn "Error opening $file: $!\n";

	my($l, $p1, $p2, $p3, $num);
	while (defined(my $line = <IN>)) {
		++$num;
		chomp($line);
		my(@p11, @p12, @p21, @p22);
		if ($perl_mode) {
			@p11 = ($line =~ /((?<!\$)\()/g);
			@p12 = ($line =~ /((?<!\$)\))/g);
			@p21 = ($line =~ /((?<!\$)\[)/g);
			@p22 = ($line =~ /((?<!\$)\])/g);
		} else {
			@p11 = ($line =~ /(\()/g);
			@p12 = ($line =~ /(\))/g);
			@p21 = ($line =~ /(\[)/g);
			@p22 = ($line =~ /(\])/g);
		}
		my @p31 = ($line =~ /(\{)/g);
		my @p32 = ($line =~ /(\})/g);
		$p1 += scalar @p11; $p1 -= scalar @p12;
		$p2 += scalar @p21; $p2 -= scalar @p22;
		$p3 += scalar @p31; $p3 -= scalar @p32;
		printf "%3d %2d %2d %2d %s\n", $., $p1, $p2, $p3, $line;
	}

	close IN;
	print "\n";
}