From f1ff3ebf9aae4ac2582b4fe8fa2561ff3d1f31f6 Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Thu, 28 Aug 1997 23:09:16 +0000 Subject: [PATCH] prototype generation git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3240 ec53bebd-3082-4978-b11e-865c3cabbd6b --- cf/make-proto.pl | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 cf/make-proto.pl diff --git a/cf/make-proto.pl b/cf/make-proto.pl new file mode 100644 index 000000000..686955717 --- /dev/null +++ b/cf/make-proto.pl @@ -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";