.
[glibc/history.git] / scripts / begin-end-check.pl
blob1616931bb0b67d6127f236a201a3ea67b2d2ed3e
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 # Check __BEGIN_NAMESPACE ... __END_NAMESPACE pairing in an include file.
8 my $code = 0;
9 for my $path (@ARGV) {
10 my $localcode = 0;
11 my @stack;
13 open my $in, '<', $path
14 or die "open $path failed: $!";
16 while (<$in>) {
17 if ( /^\s*__BEGIN_(.*)\b/ ) {
18 push @stack, $1;
20 elsif ( /^\s*__END_(.*)\b/ ) {
21 if (@stack) {
22 my $tag = pop @stack;
23 if ($1 ne $tag) {
24 print "$path:$.: BEGIN $tag paired with END $1\n";
25 $localcode = 1;
28 else {
29 print "$path:$.: END $1 does not match a begin\n";
30 $localcode = 1;
35 if (@stack) {
36 print "$path: Unmatched begin tags " . join (' ', @stack) ."\n";
37 $localcode = 1;
40 if ($localcode == 0) {
41 print "$path: OK\n";
42 } else {
43 $code = $localcode;
47 exit $code;