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,
39 my ($self, $funcname, $code) = @_;
40 $self->{funcs
}->{$funcname} = $code;
50 $x++ while(substr($_, $x, 1) !~ /\s/);
51 my $word = substr($_, 0, $x);
52 my $extern = 1 if($word eq "extern");
53 if($word eq "static" || $word eq "inline") {
56 $wasstatic = 1 unless $extern;
59 if(/(.*?)([\w_]+)\s*\(([\w\s_,\*\[\]\.\(\)]*?)\)\s*\{/
60 || ($self->{isheader
} &&
61 /(.*?)([\w_]+)\s*\((.*?)\)\s*;/)
64 my $decl = $1 . $name . "(" . $3 . ");";
65 push @
{$self->{statics
}}, $decl if($wasstatic);
66 #print $name , "\n" if $wasstatic;
67 $self->addfunc($name, $_);
68 #print "function $name\n$_";
69 } elsif($self->{isheader
}) {
72 warn "ERROR: $_\n" if $self->{printerrors
};
82 my @chars = split //, $shit;
85 $self->{openbraces
}++;
87 $self->{openbraces
}--;
103 #printf "parse line: %s, is header: %d\n", $_, $self->{isheader};
104 #print "PL: length line: ". length($line) . "\n";
105 return unless defined $_;
107 if(/^\s*#\s*(\w+)/) {
109 if($kw eq "if" || $kw eq "ifdef" || $kw eq "elif" || $kw eq "else" || $kw eq "endif") {
110 push @
{$self->{macros
}}, strip_macro
($_);
113 # $self->{line} = "" if $self->{isheader};
116 if($_ =~ /extern \"C\"/) {
117 # $self->{line} = "";
120 #$self->{line} .= $_ . "\n" if(!$self->{openbraces} || $self->{line} ne "");
121 #printf "%d\n", $self->{openbraces};
122 $self->{line
} .= $_ . "\n" if(!$self->{openbraces
} || $self->{line
} ne "");
123 $self->scanbraces($_) unless $self->{line
} =~ /^\s*#define/;
125 #print "$_ , line is $self->{line}\n";
127 if($self->{line
} ne "" && !$self->{openbraces
}) {
128 #print "A $self->{line}\n";
129 if($self->{line
} =~ /^\s*#/) {
130 if($self->{line
} =~ /\\\s*$/) {
133 push @
{$self->{macros
}}, strip_macro
($self->{line
});
136 } elsif($self->{line
} =~ /([;\}]{1})\s*\n*$/) {
138 #print $self->{line};
139 if ($self->{line
} =~ /=/ || $self->{line
} =~ /^\s*static[\s\n]+/) {
141 $self->{line
} =~ s/^\s*static\s*//;
142 push @
{$self->{extern
}}, $self->{line
};
143 } elsif($self->{isheader
}) {
145 $self->{line
} =~ /^\s*typedef\s+/
146 || $self->{line
} =~ /^\s*union\s+/
147 || $self->{line
} =~ /^\s*struct\s+/
149 push @
{$self->{typedefs
}}, strip_macro
($self->{line
});
151 $self->handlesub($self->{line
});
154 push @
{$self->{typedefs
}}, $self->{line
};
159 $self->handlesub($self->{line
});
162 } #elsif($self->{isheader} && !$self->{openbraces} && $self->{line} eq "" &&
171 open($f, "<", $self->{cfile
});
177 # print "$openbraces, $incomment\n";
178 if (/^\s*#\s*include\s+[<\"]{1}[\w_\-\/\
.]+[>\"]{1}/) {
179 push @
{$self->{includes
}}, $_;
181 next if(/^\s*$/); #skip empty lines
182 next if(/^\s*\/\
//); #skip one line comments.
183 # normal source code line.
184 if (!$self->{incomment
} && /(.*?)\/\
*(.*?
)$/) {
185 $self->parseline($1);
187 $self->{incomment
} = 1 unless $rest =~ /\*\//;
188 } elsif($self->{incomment
}) {
190 $self->parseline($2);
191 $self->{incomment
} = 0;
194 $self->parseline($_);