Name

checkbrack — check parenthesis and bracket count

Syntax

checkbrack [-p] file...

Description

Displays each line of the file(s), together with their open bracket count that is reached at the end of line. Particularly, it allows you to find missing closing brackets. This is especially helpful because the Perl interpreter for example has problems telling you where exactly something went wrong.

Options

-p
Enable Perl/PHP mode, that is, do not consider presence $(, $), $[ and $] of a bracket imbalance.

Example

$ checkbrack /usr/lib/hxtools/bin/checkbrack | less -S
#   () [] {}
13  0  0  1 foreach my $file (@ARGV) {
14  0  0  1     if (!-f $file) { next; }
15  0  0  1     print "Displaying $file...0;
16  0  0  2     if (!open(IN, "< $file")) {
17  0  0  2         print "Error opening $file: $!0;
18  0  0  2         next;
19  0  0  1     }
The numbers at the front are: line number, number of unclosed left parentheses, number of unclosed left square brackets and number of unclosed left square braces.
At the end of line 19, we would need to close one more brace to make it syntactically valid code.
The interesting thing of this, that if GCC, Perl or whatever outputs an error and you do not figure out what it means — that is often the case with missing braces — run checkbrack on the source file, skip to the end, and watch the brace counts.
Scroll up until the brace counts seem normal (i.e. 0 open braces) at outside any function.

See also

hxtools(7)

Recommended readings

Pages related to checkbrack you should read also: