3 # ************************************************************
4 # Description : Preprocesses the supplied file.
5 # Author : Chad Elliott
6 # Create Date : 2/10/2002
7 # ************************************************************
9 # ************************************************************
11 # ************************************************************
17 # ************************************************************
19 # ************************************************************
22 my($class, $macros, $ipaths, $exclude) = @_;
23 return bless {'macros' => $macros,
25 'exclude' => $exclude,
34 my($self, $file, $noinline, $noincs) = @_;
35 my $fh = new FileHandle
();
37 ## Open the file, but if we can't we'll just silently ignore it.
38 if (open($fh, $file)) {
41 my $files = $self->{'files'};
42 my $dir = dirname
($file);
44 ## We only need to keep track of recursion inside this block
45 my $recurse = ++$self->{'recurse'};
49 ## As an optimization, use a very simple regular expression on the
50 ## outside that all of the inner regular expressions have in
51 ## common. That way we go down the path of if elsif only if it is
52 ## even possible due to the outside regular expression.
53 ## index() is faster than a regular expression, so use index first.
54 next if (index($_, '#') == -1 || not /^\s*#/);
56 ## Remove same line c comments (no need to worry about c++
57 ## comments due to the regular expressions) inside this if statement.
58 ## This saves about 5% off of processing the ace directory
59 ## and we only need to strip comments if we are actually
60 ## going to look at the string.
61 $_ =~ s/\/\*.*\*\///o;
63 if (/^\s*#\s*endif/) {
65 if (defined $zero[0] && $ifcount == $zero[$#zero]) {
69 elsif (/^\s*#\s*if\s+0/) {
70 push(@zero, $ifcount);
73 elsif (/^\s*#\s*if/) {
76 elsif (!defined $zero[0] &&
77 /^\s*#\s*include\s+[<"]([^">]+)[">]/o) {
78 ## Locate the include file
80 if (exists $self->{'ifound'}->{$1}) {
81 $inc = $self->{'ifound'}->{$1};
84 foreach my $dirp (@
{$self->{'ipaths'}}) {
92 ## If the file we're currently looking at contains a
93 ## directory name then, we need to look for include
94 ## files in that directory.
99 $self->{'ifound'}->{$1} = $inc;
102 ## If we've found the include file, then process it too.
103 next if (not defined $inc);
107 ($recurse == 1 || $inc !~ /\.i(nl)?$/o)) {
108 push(@
{$$files{$file}}, $inc);
109 if (!defined $$files{$inc}) {
110 ## Process this file, but do not return the include files
111 if (!defined $self->{'exclude'}->{substr($inc, rindex($inc, '/') + 1)}) {
112 $self->process($inc, $noinline, 1);
120 ## We only need to keep track of recursion inside this block
121 --$self->{'recurse'};
124 ## This has to be outside the if (open(...
125 ## If the last file to be processed isn't accessable then
126 ## we still need to return the array reference of includes.
131 foreach my $processed (@files) {
132 foreach my $inc (@
{$self->{'files'}->{$processed}}) {
133 if (!defined $ifiles{$inc}) {