remove gcc34
[dragonfly.git] / crypto / heimdal-0.6.3 / cf / make-proto.pl
blob769d96cc0278ee6a21ade293f4bdddfb17ca8065
1 # Make prototypes from .c files
2 # $Id: make-proto.pl,v 1.16 2002/09/19 19:29:42 joda Exp $
4 ##use Getopt::Std;
5 require 'getopts.pl';
7 $brace = 0;
8 $line = "";
9 $debug = 0;
10 $oproto = 1;
11 $private_func_re = "^_";
13 do Getopts('o:p:dqR:P:') || die "foo";
15 if($opt_d) {
16 $debug = 1;
19 if($opt_q) {
20 $oproto = 0;
23 if($opt_R) {
24 $private_func_re = $opt_R;
27 while(<>) {
28 print $brace, " ", $_ if($debug);
29 if(/^\#if 0/) {
30 $if_0 = 1;
32 if($if_0 && /^\#endif/) {
33 $if_0 = 0;
35 if($if_0) { next }
36 if(/^\s*\#/) {
37 next;
39 if(/^\s*$/) {
40 $line = "";
41 next;
43 if(/\{/){
44 if (!/\}/) {
45 $brace++;
47 $_ = $line;
48 while(s/\*\//\ca/){
49 s/\/\*(.|\n)*\ca//;
51 s/^\s*//;
52 s/\s*$//;
53 s/\s+/ /g;
54 if($_ =~ /\)$/){
55 if(!/^static/ && !/^PRIVATE/){
56 if(/(.*)(__attribute__\s?\(.*\))/) {
57 $attr = $2;
58 $_ = $1;
59 } else {
60 $attr = "";
62 # remove outer ()
63 s/\s*\(/</;
64 s/\)\s?$/>/;
65 # remove , within ()
66 while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
67 s/\<\s*void\s*\>/<>/;
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;
76 s/\<\>/<void>/;
77 # add newlines before parameters
78 s/,\s*/,\n\t/g;
79 # fix removed ,
80 s/\$/,/g;
81 # match function name
82 /([a-zA-Z0-9_]+)\s*\</;
83 $f = $1;
84 if($oproto) {
85 $LP = "__P((";
86 $RP = "))";
87 } else {
88 $LP = "(";
89 $RP = ")";
91 # only add newline if more than one parameter
92 if(/,/){
93 s/\</ $LP\n\t/;
94 }else{
95 s/\</ $LP/;
97 s/\>/$RP/;
98 # insert newline before function name
99 s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
100 if($attr ne "") {
101 $_ .= "\n $attr";
103 $_ = $_ . ";";
104 $funcs{$f} = $_;
107 $line = "";
109 if(/\}/){
110 $brace--;
112 if(/^\}/){
113 $brace = 0;
115 if($brace == 0) {
116 $line = $line . " " . $_;
120 sub foo {
121 local ($arg) = @_;
122 $_ = $arg;
123 s/.*\/([^\/]*)/$1/;
124 s/[^a-zA-Z0-9]/_/g;
125 "__" . $_ . "__";
128 if($opt_o) {
129 open(OUT, ">$opt_o");
130 $block = &foo($opt_o);
131 } else {
132 $block = "__public_h__";
135 if($opt_p) {
136 open(PRIV, ">$opt_p");
137 $private = &foo($opt_p);
138 } else {
139 $private = "__private_h__";
142 $public_h = "";
143 $private_h = "";
145 $public_h_header = "/* This is a generated file */
146 #ifndef $block
147 #define $block
150 if ($oproto) {
151 $public_h_header .= "#ifdef __STDC__
152 #include <stdarg.h>
153 #ifndef __P
154 #define __P(x) x
155 #endif
156 #else
157 #ifndef __P
158 #define __P(x) ()
159 #endif
160 #endif
163 } else {
164 $public_h_header .= "#include <stdarg.h>
169 $private_h_header = "/* This is a generated file */
170 #ifndef $private
171 #define $private
174 if($oproto) {
175 $private_h_header .= "#ifdef __STDC__
176 #include <stdarg.h>
177 #ifndef __P
178 #define __P(x) x
179 #endif
180 #else
181 #ifndef __P
182 #define __P(x) ()
183 #endif
184 #endif
187 } else {
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;
199 } else {
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)
210 #endif
215 if ($private_attribute_seen) {
216 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
217 #define __attribute__(x)
218 #endif
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";
231 if($opt_o) {
232 print OUT $public_h;
234 if($opt_p) {
235 print PRIV $private_h;
238 close OUT;
239 close PRIV;