File: checkbrack

package info (click to toggle)
hxtools 20221119-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,760 kB
  • sloc: ansic: 5,114; perl: 3,612; cpp: 2,727; sh: 1,622; makefile: 156
file content (45 lines) | stat: -rwxr-xr-x 1,044 bytes parent folder | download
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
#!/usr/bin/perl
# SPDX-License-Identifier: MIT

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";
}