1 # Make prototypes from .c files
2 # $Id: make-proto.pl,v 1.15 2002/08/12 16:23:58 joda Exp $
3 # $DragonFly: src/crypto/heimdal/cf/Attic/make-proto.pl,v 1.2 2003/11/14 03:54:29 dillon Exp $
12 $private_func_re = "^_";
14 do Getopts('o:p:dqR:P:') || die "foo";
25 $private_func_re = $opt_R;
29 print $brace, " ", $_ if($debug);
33 if($if_0 && /^\#endif/) {
56 if(!/^static/ && !/^PRIVATE/){
57 if(/(.*)(__attribute__\s?\(.*\))/) {
67 while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
69 # remove parameter names
70 if($opt_P eq "remove") {
71 s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
72 s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
73 } elsif($opt_P eq "comment") {
74 s/([a-zA-Z0-9_]+)([,>])/\/\*$1\*\/$2/g;
75 s/\(\*([a-zA-Z0-9_]+)\)/(*\/\*$1\*\/)/g;
78 # add newlines before parameters
83 /([a-zA-Z0-9_]+)\s*\</;
92 # only add newline if more than one parameter
99 # insert newline before function name
100 s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
117 $line = $line . " " . $_;
130 open(OUT, ">$opt_o");
131 $block = &foo($opt_o);
133 $block = "__public_h__";
137 open(PRIV, ">$opt_p");
138 $private = &foo($opt_p);
140 $private = "__private_h__";
146 $public_h_header = "/* This is a generated file */
152 $public_h_header .= "#ifdef __STDC__
165 $public_h_header .= "#include <stdarg.h>
170 $private_h_header = "/* This is a generated file */
176 $private_h_header .= "#ifdef __STDC__
189 $private_h_header .= "#include <stdarg.h>
193 foreach(sort keys %funcs){
194 if(/^(main)$/) { next }
195 if(/$private_func_re/) {
196 $private_h .= $funcs{$_} . "\n\n";
197 if($funcs{$_} =~ /__attribute__/) {
198 $private_attribute_seen = 1;
201 $public_h .= $funcs{$_} . "\n\n";
202 if($funcs{$_} =~ /__attribute__/) {
203 $public_attribute_seen = 1;
208 if ($public_attribute_seen) {
209 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
210 #define __attribute__(x)
216 if ($private_attribute_seen) {
217 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
218 #define __attribute__(x)
225 if ($public_h ne "") {
226 $public_h = $public_h_header . $public_h . "#endif /* $block */\n";
228 if ($private_h ne "") {
229 $private_h = $private_h_header . $private_h . "#endif /* $private */\n";
236 print PRIV $private_h;