9 $l-- while($l && substr($x, $l, 1) ne ".");
10 return substr($x, 0, $l) if($l);
15 print "expected syntax: " . basename
($0) . " myfile.c myoutputdirectory/\n";
19 my $file = $ARGV[0] or syntax
;
20 my $outdir = $ARGV[1] or syntax
;
21 die("error accessing outdir") if(!-d
$outdir && !mkdir($outdir));
22 my $internal_header = name_wo_ext
(basename
($file)) . "_internal.h";
35 my @chars = split //, $shit;
46 my ($funcname, $code) = @_;
48 open($fd, ">", "$outdir/$funcname.c");
49 print {$fd} '#include "' . $internal_header . "\"\n\n";
50 print {$fd} $code, "\n";
60 $x++ while(substr($_, $x, 1) !~ /\s/);
61 my $word = substr($_, 0, $x);
62 if($word eq "static" || $word eq "inline") {
68 if(/(.*?)([\w_]+)\s*\((.*?)\)\s*\{/) {
70 my $decl = $1 . $name . "(" . $3 . ");";
71 push @statics, $decl if($wasstatic);
72 #print $name , "\n" if $wasstatic;
74 #print "function $name\n$_";
85 #print "PL: length line: ". length($line) . "\n";
86 return unless defined $_;
88 if($line eq "" && /^\s*#/) {
89 push @typedefs_macros, $_;
92 $line .= $_ . "\n" if(!$openbraces || $line ne "");
95 if($line ne "" && !$openbraces) {
96 if($line =~ /([;\}]{1})\s*\n*$/) {
99 if ($line =~ /=/ || $line =~ /^\s*static[\s\n]+/) {
101 $line =~ s/^\s*static\s*//;
104 push @typedefs_macros, $line;
119 # print "$openbraces, $incomment\n";
120 if (/^\s*#\s*include\s+[<\"]{1}[\w_\-\/\
.]+[>\"]{1}/) {
123 next if(/^\s*$/); #skip empty lines
124 next if(/^\s*\/\
//); #skip one line comments.
125 # normal source code line.
126 if (!$incomment && /(.*?)\/\
*(.*?
)$/) {
129 $incomment = 1 unless $rest =~ /\*\//;
130 } elsif($incomment) {
144 open($extfd, ">", $outdir . "/" . name_wo_ext
(basename
($file)) . "_variables.c");
145 print {$extfd} "#include \"$internal_header\"\n\n";
148 my $destname = "$outdir" . "/" . $internal_header;
150 open($fd, '>', $destname);
153 print {$fd} $_, "\n";
156 for(@typedefs_macros) {
157 print {$fd} $_, "\n";
163 my ($k, $v) = split /=/, $_;
164 print {$fd} "extern $k;\n";
165 print {$extfd} $_, "\n";
169 print {$fd} $_, "\n";
172 print {$fd} "//RcB: DEP \"*.c\"\n\n";
174 close $extfd if(@extern);