1 # Make prototypes from .c files
2 # $Heimdal: make-proto.pl 14183 2004-09-03 08:50:57Z lha $
12 $private_func_re = "^_";
14 do Getopts
('x:m:o:p:dqE:R:P:') || die "foo";
25 $private_func_re = $opt_R;
28 'multiline-proto' => 1,
30 'function-blocking' => 0,
31 'gnuc-attribute' => 1,
35 foreach $i (split(/,/, $opt_m)) {
37 $flags{"multiline-proto"} = 0;
39 $flags{"function-blocking"} = 0;
40 $flags{"gnuc-attribute"} = 0;
43 if(substr($i, 0, 3) eq "no-") {
44 $flags{substr($i, 3)} = 0;
58 if(/^([a-zA-Z0-9_]+)\s?(.*)$/) {
68 print $brace, " ", $_ if($debug);
72 if($if_0 && /^\#endif/) {
95 if(!/^static/ && !/^PRIVATE/){
96 if(/(.*)(__attribute__\s?\(.*\))/) {
106 while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
107 s/\<\s*void\s*\>/<>/;
108 # remove parameter names
109 if($opt_P eq "remove") {
110 s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
112 s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
113 } elsif($opt_P eq "comment") {
114 s/([a-zA-Z0-9_]+)([,>])/\/\
*$1\
*\
/$2/g;
115 s/\(\*([a-zA-Z0-9_]+)\)/(*\/\
*$1\
*\
/)/g;
118 # add newlines before parameters
119 if($flags{"multiline-proto"}) {
126 # match function name
127 /([a-zA-Z0-9_]+)\s*\</;
136 # only add newline if more than one parameter
137 if($flags{"multiline-proto"} && /,/){
143 # insert newline before function name
144 if($flags{"multiline-proto"}) {
145 s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
163 $line = $line . " " . $_;
176 open(OUT
, ">$opt_o");
177 $block = &foo
($opt_o);
179 $block = "__public_h__";
183 open(PRIV
, ">$opt_p");
184 $private = &foo
($opt_p);
186 $private = "__private_h__";
192 $public_h_header .= "/* This is a generated file */
198 $public_h_header .= "#ifdef __STDC__
211 $public_h_header .= "#include <stdarg.h>
215 $public_h_trailer = "";
217 $private_h_header = "/* This is a generated file */
223 $private_h_header .= "#ifdef __STDC__
236 $private_h_header .= "#include <stdarg.h>
240 $private_h_trailer = "";
242 foreach(sort keys %funcs){
243 if(/^(main)$/) { next }
244 if(!defined($exported{$_}) && /$private_func_re/) {
245 $private_h .= $funcs{$_} . "\n\n";
246 if($funcs{$_} =~ /__attribute__/) {
247 $private_attribute_seen = 1;
250 if($flags{"function-blocking"}) {
252 if($exported{$_} =~ /proto/) {
253 $public_h .= "#if !defined(HAVE_$fupper) || defined(NEED_${fupper}_PROTO)\n";
255 $public_h .= "#ifndef HAVE_$fupper\n";
258 $public_h .= $funcs{$_} . "\n";
259 if($funcs{$_} =~ /__attribute__/) {
260 $public_attribute_seen = 1;
262 if($flags{"function-blocking"}) {
263 $public_h .= "#endif\n";
269 if($flags{"gnuc-attribute"}) {
270 if ($public_attribute_seen) {
271 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
272 #define __attribute__(x)
278 if ($private_attribute_seen) {
279 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
280 #define __attribute__(x)
287 $public_h_header .= "#ifdef __cplusplus
292 $public_h_trailer .= "#ifdef __cplusplus
300 $public_h_header .= "#ifndef $opt_E
302 #define $opt_E _stdcall
310 $private_h_header .= "#ifndef $opt_E
312 #define $opt_E _stdcall
321 if ($public_h ne "" && $flags{"header"}) {
322 $public_h = $public_h_header . $public_h .
323 $public_h_trailer . "#endif /* $block */\n";
325 if ($private_h ne "" && $flags{"header"}) {
326 $private_h = $private_h_header . $private_h .
327 $private_h_trailer . "#endif /* $private */\n";
334 print PRIV
$private_h;