my $ln = shift(@{ $self->{line} });
print $ln, "\n";
next unless $ln =~ /^\#\s*((if)(?:n?def)?|elsif|else|endif)\b/;
- my $statement = $+;
- if ($statement eq 'if') {
- $XSS_work_idx = @{ $self->{XSStack} };
- push(@{ $self->{XSStack} }, {type => 'if'});
- }
- else {
- death ("Error: `$statement' with no matching `if'")
- if $self->{XSStack}->[-1]{type} ne 'if';
- if ($self->{XSStack}->[-1]{varname}) {
- push(@{ $self->{InitFileCode} }, "#endif\n");
- push(@{ $BootCode_ref }, "#endif");
- }
-
- my(@fns) = keys %{$self->{XSStack}->[-1]{functions}};
- if ($statement ne 'endif') {
- # Hide the functions defined in other #if branches, and reset.
- @{$self->{XSStack}->[-1]{other_functions}}{@fns} = (1) x @fns;
- @{$self->{XSStack}->[-1]}{qw(varname functions)} = ('', {});
- }
- else {
- my($tmp) = pop(@{ $self->{XSStack} });
- 0 while (--$XSS_work_idx
- && $self->{XSStack}->[$XSS_work_idx]{type} ne 'if');
- # Keep all new defined functions
- push(@fns, keys %{$tmp->{other_functions}});
- @{$self->{XSStack}->[$XSS_work_idx]{functions}}{@fns} = (1) x @fns;
- }
- }
+ ( $XSS_work_idx, $BootCode_ref ) =
+ print_preprocessor_statements( $self, $XSS_work_idx, $BootCode_ref );
}
next PARAGRAPH unless @{ $self->{line} };
exit 1;
}
+sub print_preprocessor_statements {
+ my ($self, $XSS_work_idx, $BootCode_ref) = @_;
+
+ my $statement = $+;
+ if ($statement eq 'if') {
+ $XSS_work_idx = @{ $self->{XSStack} };
+ push(@{ $self->{XSStack} }, {type => 'if'});
+ }
+ else {
+ death ("Error: `$statement' with no matching `if'")
+ if $self->{XSStack}->[-1]{type} ne 'if';
+ if ($self->{XSStack}->[-1]{varname}) {
+ push(@{ $self->{InitFileCode} }, "#endif\n");
+ push(@{ $BootCode_ref }, "#endif");
+ }
+
+ my(@fns) = keys %{$self->{XSStack}->[-1]{functions}};
+ if ($statement ne 'endif') {
+ # Hide the functions defined in other #if branches, and reset.
+ @{$self->{XSStack}->[-1]{other_functions}}{@fns} = (1) x @fns;
+ @{$self->{XSStack}->[-1]}{qw(varname functions)} = ('', {});
+ }
+ else {
+ my($tmp) = pop(@{ $self->{XSStack} });
+ 0 while (--$XSS_work_idx
+ && $self->{XSStack}->[$XSS_work_idx]{type} ne 'if');
+ # Keep all new defined functions
+ push(@fns, keys %{$tmp->{other_functions}});
+ @{$self->{XSStack}->[$XSS_work_idx]{functions}}{@fns} = (1) x @fns;
+ }
+ }
+ return ($XSS_work_idx, $BootCode_ref);
+}
+
1;