1 # Make prototypes from .c files
2 # $Id: make-proto.pl,v 1.16 2002/09/19 19:29:42 joda Exp $
11 $private_func_re = "^_";
13 do Getopts('o:p:dqR:P:') || die "foo";
24 $private_func_re = $opt_R;
28 print $brace, " ", $_ if($debug);
32 if($if_0 && /^\#endif/) {
55 if(!/^static/ && !/^PRIVATE/){
56 if(/(.*)(__attribute__\s?\(.*\))/) {
66 while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
68 # remove parameter names
69 if($opt_P eq "remove") {
70 s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
71 s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
72 } elsif($opt_P eq "comment") {
73 s/([a-zA-Z0-9_]+)([,>])/\/\*$1\*\/$2/g;
74 s/\(\*([a-zA-Z0-9_]+)\)/(*\/\*$1\*\/)/g;
77 # add newlines before parameters
82 /([a-zA-Z0-9_]+)\s*\</;
91 # only add newline if more than one parameter
98 # insert newline before function name
99 s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
116 $line = $line . " " . $_;
129 open(OUT, ">$opt_o");
130 $block = &foo($opt_o);
132 $block = "__public_h__";
136 open(PRIV, ">$opt_p");
137 $private = &foo($opt_p);
139 $private = "__private_h__";
145 $public_h_header = "/* This is a generated file */
151 $public_h_header .= "#ifdef __STDC__
164 $public_h_header .= "#include <stdarg.h>
169 $private_h_header = "/* This is a generated file */
175 $private_h_header .= "#ifdef __STDC__
188 $private_h_header .= "#include <stdarg.h>
192 foreach(sort keys %funcs){
193 if(/^(main)$/) { next }
194 if(/$private_func_re/) {
195 $private_h .= $funcs{$_} . "\n\n";
196 if($funcs{$_} =~ /__attribute__/) {
197 $private_attribute_seen = 1;
200 $public_h .= $funcs{$_} . "\n\n";
201 if($funcs{$_} =~ /__attribute__/) {
202 $public_attribute_seen = 1;
207 if ($public_attribute_seen) {
208 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
209 #define __attribute__(x)
215 if ($private_attribute_seen) {
216 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
217 #define __attribute__(x)
224 if ($public_h ne "") {
225 $public_h = $public_h_header . $public_h . "#endif /* $block */\n";
227 if ($private_h ne "") {
228 $private_h = $private_h_header . $private_h . "#endif /* $private */\n";
235 print PRIV $private_h;