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