C-Scan
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
}
$decl =~ /\G\s*/g or pos $decl = $pos;
$pos = pos $decl;
if (pos $decl != length $decl) {
pos $decl = $pos;
die "Expecting parenth after identifier in `$decl'\nafter `",
substr($decl, 0, $pos), "'"
unless $decl =~ /\G\(/g;
my $argstring = substr($decl, pos($decl) - length $decl);
matchingbrace($argstring) or die "Cannot find matching parenth in `$decl'";
$argstring = substr($argstring, 0, pos($argstring) - 1);
$argstring =~ s/ ^ ( \s* void )? \s* $ //x;
$args = [];
my @args;
if ($argstring ne '') {
my $top = top_level $argstring;
my $p = 0;
my $arg;
while ($top =~ /,/g) {
$arg = substr($argstring, $p, pos($top) - 1 - $p);
$arg =~ s/^\s+|\s+$//gs;
push @args, $arg;
$p = pos $top;
}
$arg = substr $argstring, $p;
$arg =~ s/^\s+|\s+$//gs;
push @args, $arg;
}
my $i = 0;
for (@args) {
push @$args, do_declaration2($_, $typedefs, $keywords, $i++);
}
}
[$type, $ident, $args, $decl, $repeater];
}
############################################################
package C::Preprocessed;
use Symbol;
use File::Basename;
use Config;
sub new {
die "usage: C::Preprocessed->new(filename[, defines[, includes[, cpp]]])"
if @_ < 2 or @_ > 5;
my ($class, $filename, $Defines, $Includes, $Cpp)
= (shift, shift, shift, shift, shift);
$Cpp ||= \%Config::Config;
my $filedir = dirname $filename || '.';
$Includes ||= [$filedir, '/usr/local/include', '.'];
my $addincludes = "";
$addincludes = "-I" . join(" -I", @$Includes)
if defined $Includes and @$Includes;
my($sym) = gensym;
my $cmd = "echo '\#include \"$filename\"' | $Cpp->{cppstdin} $Defines $addincludes $Cpp->{cppflags} $Cpp->{cppminus} |";
#my $cmd = "$Cpp->{cppstdin} $Defines $addincludes $Cpp->{cppflags} $Cpp->{cppminus} < $filename |";
#my $cmd = "echo '\#include <$filename>' | $Cpp->{cppstdin} $Defines $addincludes $Cpp->{cppflags} $Cpp->{cppminus} |";
(open($sym, $cmd) or die "Cannot open pipe from `$cmd': $!")
and bless $sym => $class;
}
sub text {
my $class = shift;
my $filter = shift;
if (defined $filter) {
return text_only_from($class, $filter, @_);
}
my $stream = $class->new(@_);
my $oh = select $stream;
$/ = undef;
select $oh;
<$stream>;
}
sub text_only_from {
my $class = shift;
my $from = shift || die "Expecting argument in `text_only_from'";
my $stream = $class->new(@_);
my $on = $from eq $_[0];
my $eqregexp = $on ? '\"\"|' : '';
my @out;
while (<$stream>) {
#print;
$on = /$eqregexp[\"\/]\Q$from\"/ if /^\#/;
push @out, $_ if $on;
}
join '', @out;
}
sub DESTROY {
close($_[0])
or die "Cannot close pipe from `$Config::Config{cppstdin}': err $?, $!\n";
}
# Autoload methods go after __END__, and are processed by the autosplit program.
# Return to the principal package.
package C::Scan;
1;
__END__
=head1 NAME
C::Scan - scan C language files for easily recognized constructs.
=head1 SYNOPSIS
$c = new C::Scan 'filename' => $filename, 'filename_filter' => $filter,
'add_cppflags' => $addflags;
$c->set('includeDirs' => [$Config::Config{shrpdir}]);
my $fdec = $c->get('parsed_fdecls');
=head1 DESCRIPTION
B<This description is I<VERY> incomplete.>
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.451 second using v1.00-cache-2.02-grep-82fe00e-cpan-f5108d614456 )