1 # Make prototypes from .c files
13 my $private_func_re = "^_";
15 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 . " " . $_;
189 open(OUT
, ">$opt_o");
190 $block = &foo
($opt_o);
192 $block = "__public_h__";
196 open(PRIV
, ">$opt_p");
197 $private = &foo
($opt_p);
199 $private = "__private_h__";
205 $public_h_header .= "/* This is a generated file */
211 $public_h_header .= "#ifdef __STDC__
224 $public_h_header .= "#include <stdarg.h>
228 $public_h_trailer = "";
230 $private_h_header = "/* This is a generated file */
236 $private_h_header .= "#ifdef __STDC__
249 $private_h_header .= "#include <stdarg.h>
253 $private_h_trailer = "";
255 foreach(sort keys %funcs){
256 if(/^(main)$/) { next }
257 if ($funcs{$_} =~ /\^/) {
258 $beginblock = "#ifdef __BLOCKS__\n";
259 $endblock = "#endif /* __BLOCKS__ */\n";
261 $beginblock = $endblock = "";
263 if(!defined($exported{$_}) && /$private_func_re/) {
264 $private_h .= $beginblock . $funcs{$_} . "\n" . $endblock . "\n";
265 if($funcs{$_} =~ /__attribute__/) {
266 $private_attribute_seen = 1;
269 if($flags{"function-blocking"}) {
271 if($exported{$_} =~ /proto/) {
272 $public_h .= "#if !defined(HAVE_$fupper) || defined(NEED_${fupper}_PROTO)\n";
274 $public_h .= "#ifndef HAVE_$fupper\n";
277 $public_h .= $beginblock . $funcs{$_} . "\n" . $endblock;
278 if($funcs{$_} =~ /__attribute__/) {
279 $public_attribute_seen = 1;
281 if($flags{"function-blocking"}) {
282 $public_h .= "#endif\n";
288 if($flags{"gnuc-attribute"}) {
289 if ($public_attribute_seen) {
290 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
291 #define __attribute__(x)
297 if ($private_attribute_seen) {
298 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
299 #define __attribute__(x)
306 $public_h_header .= "#ifdef __cplusplus
311 $public_h_trailer .= "#ifdef __cplusplus
319 $public_h_header .= "#ifndef $opt_E
320 #ifndef ${opt_E}_FUNCTION
322 #define ${opt_E}_FUNCTION __declspec(dllimport)
323 #define ${opt_E}_CALL __stdcall
324 #define ${opt_E}_VARIABLE __declspec(dllimport)
326 #define ${opt_E}_FUNCTION
327 #define ${opt_E}_CALL
328 #define ${opt_E}_VARIABLE
334 $private_h_header .= "#ifndef $opt_E
335 #ifndef ${opt_E}_FUNCTION
337 #define ${opt_E}_FUNCTION __declspec(dllimport)
338 #define ${opt_E}_CALL __stdcall
339 #define ${opt_E}_VARIABLE __declspec(dllimport)
341 #define ${opt_E}_FUNCTION
342 #define ${opt_E}_CALL
343 #define ${opt_E}_VARIABLE
351 if ($public_h ne "" && $flags{"header"}) {
352 $public_h = $public_h_header . $public_h .
353 $public_h_trailer . "#endif /* $block */\n";
355 if ($private_h ne "" && $flags{"header"}) {
356 $private_h = $private_h_header . $private_h .
357 $private_h_trailer . "#endif /* $private */\n";
364 print PRIV
$private_h;