prototype generation

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3240 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-08-28 23:09:16 +00:00
parent 11c8ba6bd8
commit f1ff3ebf9a

78
cf/make-proto.pl Normal file
View File

@@ -0,0 +1,78 @@
# Make prototypes from .c files
# $Id$
$brace = 0;
$line = "";
$debug = 0;
while(<>) {
print $brace, " ", $_ if($debug);
if(/^\#if 0/) {
$if_0 = 1;
}
if($if_0 && /^\#endif/) {
$if_0 = 0;
}
if($if_0) { next }
if(/^\s*\#/) {
next;
}
if(/^\s*$/) {
$line = "";
next;
}
if(/\{/){
if($line =~ /\)\s$/){
$_ = $line;
s/^\s*//;
s/\s$//;
s/\s+/ /g;
if(!/^static/){
# remove outer ()
s/\s*\(/@/;
s/\)$/@/;
# remove , within ()
while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
s/,\s*/,\n\t/g;
# fix removed ,
s/\$/,/g;
# match function name
/([a-zA-Z0-9_]+)\s*@/;
$f = $1;
# only add newline if more than one parameter
if(/,/){
s/@/ __P((\n\t/;
}else{
s/@/ __P((/;
}
s/@/))/;
$_ = $_ . ";";
# insert newline before function name
s/(.*)\s([a-zA-Z0-9_]+ __P)/$1\n$2/;
$funcs{$f} = $_;
}
}
$line = "";
$brace++;
}
if(/\}/){
$brace--;
}
if(/^\}/){
$brace = 0;
}
if($brace == 0) {
$line = $line . " " . $_;
}
};
print "/* This is a generated file */\n\n";
print "#ifndef __krb5_protos_h__\n";
print "#define __krb5_protos_h__\n\n";
foreach(sort keys %funcs){
if(/^(main)$/) { next }
print $funcs{$_}, "\n\n";
}
print "#endif /* __krb5_protos_h__ */\n";