9 $l-- while($l && substr($x, $l, 1) ne ".");
10 return substr($x, $l) if($l);
16 my ($pkg, @args) = @_;
17 die("need C file name as arg") if(scalar(@args) != 1);
18 my $isheader = file_ext
($args[0]) eq ".h";
21 isheader
=> $isheader,
31 typedefs_macros
=> [],
38 my ($self, $funcname, $code) = @_;
39 $self->{funcs
}->{$funcname} = $code;
49 $x++ while(substr($_, $x, 1) !~ /\s/);
50 my $word = substr($_, 0, $x);
51 my $extern = 1 if($word eq "extern");
52 if($word eq "static" || $word eq "inline") {
55 $wasstatic = 1 unless $extern;
58 if(/(.*?)([\w_]+)\s*\(([\w\s_,\*\[\]\.\(\)]*?)\)\s*\{/
59 || ($self->{isheader
} &&
60 /(.*?)([\w_]+)\s*\((.*?)\)\s*;/)
63 my $decl = $1 . $name . "(" . $3 . ");";
64 push @
{$self->{statics
}}, $decl if($wasstatic);
65 #print $name , "\n" if $wasstatic;
66 $self->addfunc($name, $_);
67 #print "function $name\n$_";
68 } elsif($self->{isheader
}) {
71 warn "ERROR: $_\n" if $self->{printerrors
};
81 my @chars = split //, $shit;
84 $self->{openbraces
}++;
86 $self->{openbraces
}--;
94 #printf "parse line: %s, is header: %d\n", $_, $self->{isheader};
95 #print "PL: length line: ". length($line) . "\n";
96 return unless defined $_;
100 if($kw eq "if" || $kw eq "ifdef" || $kw eq "elif" || $kw eq "else" || $kw eq "endif") {
101 push @
{$self->{typedefs_macros
}}, $_;
104 # $self->{line} = "" if $self->{isheader};
107 if($_ =~ /extern \"C\"/) {
108 # $self->{line} = "";
111 #$self->{line} .= $_ . "\n" if(!$self->{openbraces} || $self->{line} ne "");
112 #printf "%d\n", $self->{openbraces};
113 $self->{line
} .= $_ . "\n" if(!$self->{openbraces
} || $self->{line
} ne "");
114 $self->scanbraces($_) unless $self->{line
} =~ /^\s*#define/;
116 #print "$_ , line is $self->{line}\n";
118 if($self->{line
} ne "" && !$self->{openbraces
}) {
119 #print "A $self->{line}\n";
120 if($self->{line
} =~ /^\s*#/) {
121 if($self->{line
} =~ /\\\s*$/) {
124 push @
{$self->{typedefs_macros
}}, $self->{line
};
127 } elsif($self->{line
} =~ /([;\}]{1})\s*\n*$/) {
129 #print $self->{line};
130 if ($self->{line
} =~ /=/ || $self->{line
} =~ /^\s*static[\s\n]+/) {
132 $self->{line
} =~ s/^\s*static\s*//;
133 push @
{$self->{extern
}}, $self->{line
};
134 } elsif($self->{isheader
}) {
135 $self->handlesub($self->{line
});
137 push @
{$self->{typedefs_macros
}}, $self->{line
};
142 $self->handlesub($self->{line
});
145 } #elsif($self->{isheader} && !$self->{openbraces} && $self->{line} eq "" &&
154 open($f, "<", $self->{cfile
});
160 # print "$openbraces, $incomment\n";
161 if (/^\s*#\s*include\s+[<\"]{1}[\w_\-\/\
.]+[>\"]{1}/) {
162 push @
{$self->{includes
}}, $_;
164 next if(/^\s*$/); #skip empty lines
165 next if(/^\s*\/\
//); #skip one line comments.
166 # normal source code line.
167 if (!$self->{incomment
} && /(.*?)\/\
*(.*?
)$/) {
168 $self->parseline($1);
170 $self->{incomment
} = 1 unless $rest =~ /\*\//;
171 } elsif($self->{incomment
}) {
173 $self->parseline($2);
174 $self->{incomment
} = 0;
177 $self->parseline($_);