1 # Make prototypes from .c files
11 $private_func_re = "^_";
13 do Getopts
('x:m:o:p:dqE:R:P:') || die "foo";
24 $private_func_re = $opt_R;
27 'multiline-proto' => 1,
29 'function-blocking' => 0,
30 'gnuc-attribute' => 1,
34 foreach $i (split(/,/, $opt_m)) {
36 $flags{"multiline-proto"} = 0;
38 $flags{"function-blocking"} = 0;
39 $flags{"gnuc-attribute"} = 0;
42 if(substr($i, 0, 3) eq "no-") {
43 $flags{substr($i, 3)} = 0;
57 if(/^([a-zA-Z0-9_]+)\s?(.*)$/) {
67 print $brace, " ", $_ if($debug);
71 if($if_0 && /^\#endif/) {
94 if(!/^static/ && !/^PRIVATE/){
95 if(/(.*)(__attribute__\s?\(.*\))/) {
105 while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
106 s/\<\s*void\s*\>/<>/;
107 # remove parameter names
108 if($opt_P eq "remove") {
109 s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
111 s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
112 } elsif($opt_P eq "comment") {
113 s/([a-zA-Z0-9_]+)([,>])/\/\
*$1\
*\
/$2/g;
114 s/\(\*([a-zA-Z0-9_]+)\)/(*\/\
*$1\
*\
/)/g;
117 # add newlines before parameters
118 if($flags{"multiline-proto"}) {
125 # match function name
126 /([a-zA-Z0-9_]+)\s*\</;
135 # only add newline if more than one parameter
136 if($flags{"multiline-proto"} && /,/){
142 # insert newline before function name
143 if($flags{"multiline-proto"}) {
144 s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
162 $line = $line . " " . $_;
175 open(OUT
, ">$opt_o");
176 $block = &foo
($opt_o);
178 $block = "__public_h__";
182 open(PRIV
, ">$opt_p");
183 $private = &foo
($opt_p);
185 $private = "__private_h__";
191 $public_h_header .= "/* This is a generated file */
197 $public_h_header .= "#ifdef __STDC__
210 $public_h_header .= "#include <stdarg.h>
214 $public_h_trailer = "";
216 $private_h_header = "/* This is a generated file */
222 $private_h_header .= "#ifdef __STDC__
235 $private_h_header .= "#include <stdarg.h>
239 $private_h_trailer = "";
241 foreach(sort keys %funcs){
242 if(/^(main)$/) { next }
243 if(!defined($exported{$_}) && /$private_func_re/) {
244 $private_h .= $funcs{$_} . "\n\n";
245 if($funcs{$_} =~ /__attribute__/) {
246 $private_attribute_seen = 1;
249 if($flags{"function-blocking"}) {
251 if($exported{$_} =~ /proto/) {
252 $public_h .= "#if !defined(HAVE_$fupper) || defined(NEED_${fupper}_PROTO)\n";
254 $public_h .= "#ifndef HAVE_$fupper\n";
257 $public_h .= $funcs{$_} . "\n";
258 if($funcs{$_} =~ /__attribute__/) {
259 $public_attribute_seen = 1;
261 if($flags{"function-blocking"}) {
262 $public_h .= "#endif\n";
268 if($flags{"gnuc-attribute"}) {
269 if ($public_attribute_seen) {
270 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
271 #define __attribute__(x)
277 if ($private_attribute_seen) {
278 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
279 #define __attribute__(x)
286 $public_h_header .= "#ifdef __cplusplus
291 $public_h_trailer .= "#ifdef __cplusplus
299 $public_h_header .= "#ifndef $opt_E
301 #define $opt_E _stdcall
309 $private_h_header .= "#ifndef $opt_E
311 #define $opt_E _stdcall
320 if ($public_h ne "" && $flags{"header"}) {
321 $public_h = $public_h_header . $public_h .
322 $public_h_trailer . "#endif /* $block */\n";
324 if ($private_h ne "" && $flags{"header"}) {
325 $private_h = $private_h_header . $private_h .
326 $private_h_trailer . "#endif /* $private */\n";
333 print PRIV
$private_h;