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/) {
103 if($_ =~ /\)$/ or $_ =~ /DEPRECATED$/){
104 if(!/^static/ && !/^PRIVATE/){
106 if(m/(.*)(__attribute__\s?\(.*\))/) {
110 if(m/(.*)\s(\w+DEPRECATED)/) {
118 while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
119 s/\<\s*void\s*\>/<>/;
120 # remove parameter names
121 if($opt_P eq "remove") {
122 s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
124 s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
125 } elsif($opt_P eq "comment") {
126 s/([a-zA-Z0-9_]+)([,>])/\/\
*$1\
*\
/$2/g;
127 s/\(\*([a-zA-Z0-9_]+)\)/(*\/\
*$1\
*\
/)/g;
130 # add newlines before parameters
131 if($flags{"multiline-proto"}) {
138 # match function name
139 /([a-zA-Z0-9_]+)\s*\</;
148 # only add newline if more than one parameter
149 if($flags{"multiline-proto"} && /,/){
155 # insert newline before function name
156 if($flags{"multiline-proto"}) {
157 s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
175 $line = $line . " " . $_;
188 open(OUT
, ">$opt_o");
189 $block = &foo
($opt_o);
191 $block = "__public_h__";
195 open(PRIV
, ">$opt_p");
196 $private = &foo
($opt_p);
198 $private = "__private_h__";
204 $public_h_header .= "/* This is a generated file */
210 $public_h_header .= "#ifdef __STDC__
223 $public_h_header .= "#include <stdarg.h>
227 $public_h_trailer = "";
229 $private_h_header = "/* This is a generated file */
235 $private_h_header .= "#ifdef __STDC__
248 $private_h_header .= "#include <stdarg.h>
252 $private_h_trailer = "";
254 foreach(sort keys %funcs){
255 if(/^(main)$/) { next }
256 if(!defined($exported{$_}) && /$private_func_re/) {
257 $private_h .= $funcs{$_} . "\n\n";
258 if($funcs{$_} =~ /__attribute__/) {
259 $private_attribute_seen = 1;
262 if($flags{"function-blocking"}) {
264 if($exported{$_} =~ /proto/) {
265 $public_h .= "#if !defined(HAVE_$fupper) || defined(NEED_${fupper}_PROTO)\n";
267 $public_h .= "#ifndef HAVE_$fupper\n";
270 $public_h .= $funcs{$_} . "\n";
271 if($funcs{$_} =~ /__attribute__/) {
272 $public_attribute_seen = 1;
274 if($flags{"function-blocking"}) {
275 $public_h .= "#endif\n";
281 if($flags{"gnuc-attribute"}) {
282 if ($public_attribute_seen) {
283 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
284 #define __attribute__(x)
290 if ($private_attribute_seen) {
291 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
292 #define __attribute__(x)
299 $public_h_header .= "#ifdef __cplusplus
304 $public_h_trailer .= "#ifdef __cplusplus
312 $public_h_header .= "#ifndef $opt_E
314 #define ${opt_E}_FUNCTION __stdcall __declspec(dllimport)
315 #define ${opt_E}_VARIABLE __declspec(dllimport)
317 #define ${opt_E}_FUNCTION
318 #define ${opt_E}_VARIABLE
324 $private_h_header .= "#ifndef $opt_E
326 #define ${opt_E}_FUNCTION __stdcall __declspec(dllimport)
327 #define ${opt_E}_VARIABLE __declspec(dllimport)
329 #define ${opt_E}_FUNCTION
330 #define ${opt_E}_VARIABLE
337 if ($public_h ne "" && $flags{"header"}) {
338 $public_h = $public_h_header . $public_h .
339 $public_h_trailer . "#endif /* $block */\n";
341 if ($private_h ne "" && $flags{"header"}) {
342 $private_h = $private_h_header . $private_h .
343 $private_h_trailer . "#endif /* $private */\n";
350 print PRIV
$private_h;