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 ($funcs{$_} =~ /\^/) {
257 $beginblock = "#ifdef __BLOCKS__\n";
258 $endblock = "#endif /* __BLOCKS__ */\n";
260 $beginblock = $endblock = "";
262 if(!defined($exported{$_}) && /$private_func_re/) {
263 $private_h .= $beginblock . $funcs{$_} . "\n" . $endblock . "\n";
264 if($funcs{$_} =~ /__attribute__/) {
265 $private_attribute_seen = 1;
268 if($flags{"function-blocking"}) {
270 if($exported{$_} =~ /proto/) {
271 $public_h .= "#if !defined(HAVE_$fupper) || defined(NEED_${fupper}_PROTO)\n";
273 $public_h .= "#ifndef HAVE_$fupper\n";
276 $public_h .= $beginblock . $funcs{$_} . "\n" . $endblock;
277 if($funcs{$_} =~ /__attribute__/) {
278 $public_attribute_seen = 1;
280 if($flags{"function-blocking"}) {
281 $public_h .= "#endif\n";
287 if($flags{"gnuc-attribute"}) {
288 if ($public_attribute_seen) {
289 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
290 #define __attribute__(x)
296 if ($private_attribute_seen) {
297 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
298 #define __attribute__(x)
305 $public_h_header .= "#ifdef __cplusplus
310 $public_h_trailer .= "#ifdef __cplusplus
318 $public_h_header .= "#ifndef $opt_E
319 #ifndef ${opt_E}_FUNCTION
321 #define ${opt_E}_FUNCTION __declspec(dllimport)
322 #define ${opt_E}_CALL __stdcall
323 #define ${opt_E}_VARIABLE __declspec(dllimport)
325 #define ${opt_E}_FUNCTION
326 #define ${opt_E}_CALL
327 #define ${opt_E}_VARIABLE
333 $private_h_header .= "#ifndef $opt_E
334 #ifndef ${opt_E}_FUNCTION
336 #define ${opt_E}_FUNCTION __declspec(dllimport)
337 #define ${opt_E}_CALL __stdcall
338 #define ${opt_E}_VARIABLE __declspec(dllimport)
340 #define ${opt_E}_FUNCTION
341 #define ${opt_E}_CALL
342 #define ${opt_E}_VARIABLE
350 if ($public_h ne "" && $flags{"header"}) {
351 $public_h = $public_h_header . $public_h .
352 $public_h_trailer . "#endif /* $block */\n";
354 if ($private_h ne "" && $flags{"header"}) {
355 $private_h = $private_h_header . $private_h .
356 $private_h_trailer . "#endif /* $private */\n";
363 print PRIV
$private_h;