1 # Make prototypes from .c files
13 my $private_func_re = "^_";
15 do Getopts
('x:m:o:p:dqE:R:P:') || die "foo";
26 $private_func_re = $opt_R;
29 'multiline-proto' => 1,
31 'function-blocking' => 0,
32 'gnuc-attribute' => 1,
36 foreach $i (split(/,/, $opt_m)) {
38 $flags{"multiline-proto"} = 0;
40 $flags{"function-blocking"} = 0;
41 $flags{"gnuc-attribute"} = 0;
44 if(substr($i, 0, 3) eq "no-") {
45 $flags{substr($i, 3)} = 0;
59 if(/^([a-zA-Z0-9_]+)\s?(.*)$/) {
69 print $brace, " ", $_ if($debug);
74 if ( s@
/\
*.*@@
) { $comment = 1;
75 } elsif ($comment && s@
.*\
*/@@
) { $comment = 0;
76 } elsif ($comment) { next; }
81 if($if_0 && /^\#endif/) {
104 if(!/^static/ && !/^PRIVATE/){
105 if(/(.*)(__attribute__\s?\(.*\))/) {
115 while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
116 s/\<\s*void\s*\>/<>/;
117 # remove parameter names
118 if($opt_P eq "remove") {
119 s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
121 s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
122 } elsif($opt_P eq "comment") {
123 s/([a-zA-Z0-9_]+)([,>])/\/\
*$1\
*\
/$2/g;
124 s/\(\*([a-zA-Z0-9_]+)\)/(*\/\
*$1\
*\
/)/g;
127 # add newlines before parameters
128 if($flags{"multiline-proto"}) {
135 # match function name
136 /([a-zA-Z0-9_]+)\s*\</;
145 # only add newline if more than one parameter
146 if($flags{"multiline-proto"} && /,/){
152 # insert newline before function name
153 if($flags{"multiline-proto"}) {
154 s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
172 $line = $line . " " . $_;
185 open(OUT
, ">$opt_o");
186 $block = &foo
($opt_o);
188 $block = "__public_h__";
192 open(PRIV
, ">$opt_p");
193 $private = &foo
($opt_p);
195 $private = "__private_h__";
201 $public_h_header .= "/* This is a generated file */
207 $public_h_header .= "#ifdef __STDC__
220 $public_h_header .= "#include <stdarg.h>
224 $public_h_trailer = "";
226 $private_h_header = "/* This is a generated file */
232 $private_h_header .= "#ifdef __STDC__
245 $private_h_header .= "#include <stdarg.h>
249 $private_h_trailer = "";
251 foreach(sort keys %funcs){
252 if(/^(main)$/) { next }
253 if(!defined($exported{$_}) && /$private_func_re/) {
254 $private_h .= $funcs{$_} . "\n\n";
255 if($funcs{$_} =~ /__attribute__/) {
256 $private_attribute_seen = 1;
259 if($flags{"function-blocking"}) {
261 if($exported{$_} =~ /proto/) {
262 $public_h .= "#if !defined(HAVE_$fupper) || defined(NEED_${fupper}_PROTO)\n";
264 $public_h .= "#ifndef HAVE_$fupper\n";
267 $public_h .= $funcs{$_} . "\n";
268 if($funcs{$_} =~ /__attribute__/) {
269 $public_attribute_seen = 1;
271 if($flags{"function-blocking"}) {
272 $public_h .= "#endif\n";
278 if($flags{"gnuc-attribute"}) {
279 if ($public_attribute_seen) {
280 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
281 #define __attribute__(x)
287 if ($private_attribute_seen) {
288 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
289 #define __attribute__(x)
296 $public_h_header .= "#ifdef __cplusplus
301 $public_h_trailer .= "#ifdef __cplusplus
309 $public_h_header .= "#ifndef $opt_E
311 #define $opt_E _stdcall
319 $private_h_header .= "#ifndef $opt_E
321 #define $opt_E _stdcall
330 if ($public_h ne "" && $flags{"header"}) {
331 $public_h = $public_h_header . $public_h .
332 $public_h_trailer . "#endif /* $block */\n";
334 if ($private_h ne "" && $flags{"header"}) {
335 $private_h = $private_h_header . $private_h .
336 $private_h_trailer . "#endif /* $private */\n";
343 print PRIV
$private_h;