optionally remove __P and parameter names

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10929 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2002-04-18 11:30:09 +00:00
parent 4de5f97133
commit 857e7bb929

View File

@@ -7,13 +7,18 @@ require 'getopts.pl';
$brace = 0; $brace = 0;
$line = ""; $line = "";
$debug = 0; $debug = 0;
$oproto = 1;
do Getopts('o:p:d') || die "foo"; do Getopts('o:p:dqP:') || die "foo";
if($opt_d) { if($opt_d) {
$debug = 1; $debug = 1;
} }
if($opt_q) {
$oproto = 0;
}
while(<>) { while(<>) {
print $brace, " ", $_ if($debug); print $brace, " ", $_ if($debug);
if(/^\#if 0/) { if(/^\#if 0/) {
@@ -50,28 +55,43 @@ while(<>) {
$attr = ""; $attr = "";
} }
# remove outer () # remove outer ()
s/\s*\(/@/; s/\s*\(/</;
s/\)\s?$/@/; s/\)\s?$/>/;
# remove , within () # remove , within ()
while(s/\(([^()]*),(.*)\)/($1\$$2)/g){} while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
s/\<\s*void\s*\>/<>/;
# remove parameter names
if($opt_P eq "remove") {
s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
} elsif($opt_P eq "comment") {
s/([a-zA-Z0-9_]+)([,>])/\/\*$1\*\/$2/g;
s/\(\*([a-zA-Z0-9_]+)\)/(*\/\*$1\*\/)/g;
}
s/\<\>/<void>/;
# add newlines before parameters
s/,\s*/,\n\t/g; s/,\s*/,\n\t/g;
# fix removed , # fix removed ,
s/\$/,/g; s/\$/,/g;
# match function name # match function name
/([a-zA-Z0-9_]+)\s*@/; /([a-zA-Z0-9_]+)\s*\</;
$f = $1; $f = $1;
# only add newline if more than one parameter if($oproto) {
$LP = "(("; # XXX workaround for indentation bug in emacs $LP = "__P((";
$RP = "))"; $RP = "))";
$P = "__P(("; } else {
if(/,/){ $LP = "(";
s/@/ __P$LP\n\t/; $RP = ")";
}else{
s/@/ __P$LP/;
} }
s/@/$RP/; # only add newline if more than one parameter
if(/,/){
s/\</ $LP\n\t/;
}else{
s/\</ $LP/;
}
s/\>/$RP/;
# insert newline before function name # insert newline before function name
s/(.*)\s([a-zA-Z0-9_]+ __P)/$1\n$2/; s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
if($attr ne "") { if($attr ne "") {
$_ .= "\n $attr"; $_ .= "\n $attr";
} }
@@ -121,7 +141,9 @@ $public_h_header = "/* This is a generated file */
#ifndef $block #ifndef $block
#define $block #define $block
#ifdef __STDC__ ";
if ($oproto) {
$public_h_header .= "#ifdef __STDC__
#include <stdarg.h> #include <stdarg.h>
#ifndef __P #ifndef __P
#define __P(x) x #define __P(x) x
@@ -133,12 +155,15 @@ $public_h_header = "/* This is a generated file */
#endif #endif
"; ";
}
$private_h_header = "/* This is a generated file */ $private_h_header = "/* This is a generated file */
#ifndef $private #ifndef $private
#define $private #define $private
#ifdef __STDC__ ";
if($oproto) {
$private_h_header .= "#ifdef __STDC__
#include <stdarg.h> #include <stdarg.h>
#ifndef __P #ifndef __P
#define __P(x) x #define __P(x) x
@@ -150,7 +175,7 @@ $private_h_header = "/* This is a generated file */
#endif #endif
"; ";
}
foreach(sort keys %funcs){ foreach(sort keys %funcs){
if(/^(main)$/) { next } if(/^(main)$/) { next }
if(/^_/) { if(/^_/) {