#!/usr/bin/perl
# just point this at a dir tree that has some c code in it, e.g. foo.pl /usr/src/linux
# it will scan the *.[ch] files for a #if or #ifdef line, and then should print:
#
# not in dbgline state is WWWXXXabc1234
# in dbgline state is WWWXXXabc1234
#
# but it doesn't! It prints:
#
# not in dbgline state is WWWXXXabc1234
# in dbgline state is abc1234
#
# Ok, now it gets really weird. If the RE the line is matched against
# changes from /^\s*#\s*if/ to /^\s*#\s*i/ then it does print the right
# thing! How is this possible?!!
use strict;
use File::Find;
sub filter_source ($) {
my %state=();
$state{'abc'} = 1234;
open IN, "<@_[0]";
while (<IN>) {
# if you remove the 'f' from the end of this RE, then
# dgbline will see the WWW=>XXX added to %state
# otherwise, it somehow doesn't see it and thinks %state
# is only abc=>1234
if (/^\s*#\s*if/) { # try /^\s*#\s*i/
$state{'WWW'} = 'XXX';
print STDERR "not in dbgline state is ", %state, "\n";
dbgline('test');
}
}
close IN;
sub dbgline($) {
print STDERR "in dbgline state is ", %state, "\n";
}
}
sub parse_dir {
my $file = $File::Find::name;
filter_source($file) if ($file =~ /\.[ch]$/);
}
my $SRC = shift;
find(\&parse_dir, $SRC);