It checks for unmatched pairs of braces, skipping the backslashed forms. At the end, if all three numbers aren't zero, then there are unmatched brace(s) somewhere in the document. That's it! It's small, effective, and it does its work!#!/usr/bin/perl if ( $#ARGV==-1 ) { die "Not enough arguments"; } open IN, "<".$ARGV[0] or die "Cannot open `$ARGV[0]'"; $brc[0]=$brc[1]=$brc[2]=0; while (<IN>) { while (( s/\\\(// || (s/\(// && ($brc[0]++, print "(")) ) || ( s/\\\)// || (s/\)// && ($brc[0]--, print ")")) ) || ( s/\\\{// || (s/\{// && ($brc[1]++, print "{")) ) || ( s/\\\}// || (s/\}// && ($brc[1]--, print "}")) ) || ( s/\\\[// || (s/\[// && ($brc[2]++, print "[")) ) || ( s/\\\]// || (s/\]// && ($brc[2]--, print "]")) )) { ; } } print "\n(): $brc[0], {}: $brc[1], []: $brc[2]\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (La)TeX brace counter (athomason)
by athomason (Curate) on Jul 18, 2000 at 13:37 UTC | |
by Strahinja (Initiate) on Jul 24, 2000 at 21:41 UTC |