1 # Make prototypes from .c files
12 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/) {
104 if(!/^static/ && !/^PRIVATE/){
106 if(m/(.*)(__attribute__\s?\(.*\))/) {
110 if(m/(.*)\s(\w+DEPRECATED_FUNCTION)\s?(\(.*\))(.*)/) {
111 $depfunction{$2} = 1;
115 if(m/(.*)\s(\w+DEPRECATED)(.*)/) {
123 while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
124 s/\<\s*void\s*\>/<>/;
125 # remove parameter names
126 if($opt_P eq "remove") {
127 s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
129 s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
130 } elsif($opt_P eq "comment") {
131 s/([a-zA-Z0-9_]+)([,>])/\/\
*$1\
*\
/$2/g;
132 s/\(\*([a-zA-Z0-9_]+)\)/(*\/\
*$1\
*\
/)/g;
135 # add newlines before parameters
136 if($flags{"multiline-proto"}) {
143 # match function name
144 /([a-zA-Z0-9_]+)\s*\</;
153 # only add newline if more than one parameter
154 if($flags{"multiline-proto"} && /,/){
160 # insert newline before function name
161 if($flags{"multiline-proto"}) {
162 s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
180 $line = $line . " " . $_;
194 open(OUT
, ">$opt_o");
195 $block = &foo
($opt_o);
197 $block = "__public_h__";
201 open(PRIV
, ">$opt_p");
202 $private = &foo
($opt_p);
204 $private = "__private_h__";
210 $public_h_header .= "/* This is a generated file */
216 $public_h_header .= "#ifdef __STDC__
229 $public_h_header .= "#include <stdarg.h>
233 $public_h_trailer = "";
235 $private_h_header = "/* This is a generated file */
241 $private_h_header .= "#ifdef __STDC__
254 $private_h_header .= "#include <stdarg.h>
258 $private_h_trailer = "";
260 foreach(sort keys %funcs){
261 if(/^(main)$/) { next }
262 if ($funcs{$_} =~ /\^/) {
263 $beginblock = "#ifdef __BLOCKS__\n";
264 $endblock = "#endif /* __BLOCKS__ */\n";
266 $beginblock = $endblock = "";
268 if(!defined($exported{$_}) && /$private_func_re/) {
269 $private_h .= $beginblock . $funcs{$_} . "\n" . $endblock . "\n";
270 if($funcs{$_} =~ /__attribute__/) {
271 $private_attribute_seen = 1;
274 if($flags{"function-blocking"}) {
276 if($exported{$_} =~ /proto/) {
277 $public_h .= "#if !defined(HAVE_$fupper) || defined(NEED_${fupper}_PROTO)\n";
279 $public_h .= "#ifndef HAVE_$fupper\n";
282 $public_h .= $beginblock . $funcs{$_} . "\n" . $endblock;
283 if($funcs{$_} =~ /__attribute__/) {
284 $public_attribute_seen = 1;
286 if($flags{"function-blocking"}) {
287 $public_h .= "#endif\n";
293 if($flags{"gnuc-attribute"}) {
294 if ($public_attribute_seen) {
295 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
296 #define __attribute__(x)
302 if ($private_attribute_seen) {
303 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
304 #define __attribute__(x)
313 foreach (keys %depfunction) {
314 $depstr .= "#ifndef $_
315 #if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1 )))
316 #define $_(X) __attribute__((__deprecated__))
324 $public_h_trailer .= "#undef $_
327 $private_h_trailer .= "#undef $_
333 $public_h_header .= $depstr;
334 $private_h_header .= $depstr;
338 $public_h_header .= "#ifdef __cplusplus
343 $public_h_trailer = "#ifdef __cplusplus
347 " . $public_h_trailer;
351 $public_h_header .= "#ifndef $opt_E
352 #ifndef ${opt_E}_FUNCTION
354 #define ${opt_E}_FUNCTION __declspec(dllimport)
355 #define ${opt_E}_CALL __stdcall
356 #define ${opt_E}_VARIABLE __declspec(dllimport)
358 #define ${opt_E}_FUNCTION
359 #define ${opt_E}_CALL
360 #define ${opt_E}_VARIABLE
366 $private_h_header .= "#ifndef $opt_E
367 #ifndef ${opt_E}_FUNCTION
369 #define ${opt_E}_FUNCTION __declspec(dllimport)
370 #define ${opt_E}_CALL __stdcall
371 #define ${opt_E}_VARIABLE __declspec(dllimport)
373 #define ${opt_E}_FUNCTION
374 #define ${opt_E}_CALL
375 #define ${opt_E}_VARIABLE
383 $public_h_trailer .= $undepstr;
384 $private_h_trailer .= $undepstr;
386 if ($public_h ne "" && $flags{"header"}) {
387 $public_h = $public_h_header . $public_h .
388 $public_h_trailer . "#endif /* $block */\n";
390 if ($private_h ne "" && $flags{"header"}) {
391 $private_h = $private_h_header . $private_h .
392 $private_h_trailer . "#endif /* $private */\n";
399 print PRIV
$private_h;