stuff to generate headerfile for roken

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@12920 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2003-09-25 13:26:56 +00:00
parent 740e4a08a6
commit d841047ce6

View File

@@ -10,7 +10,7 @@ $debug = 0;
$oproto = 1; $oproto = 1;
$private_func_re = "^_"; $private_func_re = "^_";
do Getopts('o:p:dqR:P:') || die "foo"; do Getopts('x:m:o:p:dqR:P:') || die "foo";
if($opt_d) { if($opt_d) {
$debug = 1; $debug = 1;
@@ -24,6 +24,21 @@ if($opt_R) {
$private_func_re = $opt_R; $private_func_re = $opt_R;
} }
if($opt_x) {
open(EXP, $opt_x);
while(<EXP>) {
chomp;
s/\#.*//g;
s/\s+/ /g;
if(/^([a-zA-Z0-9_]+)\s?(.*)$/) {
$exported{$1} = $2;
} else {
print $_, "\n";
}
}
close EXP;
}
while(<>) { while(<>) {
print $brace, " ", $_ if($debug); print $brace, " ", $_ if($debug);
if(/^\#if 0/) { if(/^\#if 0/) {
@@ -68,6 +83,7 @@ while(<>) {
# remove parameter names # remove parameter names
if($opt_P eq "remove") { if($opt_P eq "remove") {
s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g; s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
s/\s+\*/*/g;
s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g; s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
} elsif($opt_P eq "comment") { } elsif($opt_P eq "comment") {
s/([a-zA-Z0-9_]+)([,>])/\/\*$1\*\/$2/g; s/([a-zA-Z0-9_]+)([,>])/\/\*$1\*\/$2/g;
@@ -75,7 +91,11 @@ while(<>) {
} }
s/\<\>/<void>/; s/\<\>/<void>/;
# add newlines before parameters # add newlines before parameters
s/,\s*/,\n\t/g; if($opt_m eq "roken") {
s/,\s*/, /g;
} else {
s/,\s*/,\n\t/g;
}
# fix removed , # fix removed ,
s/\$/,/g; s/\$/,/g;
# match function name # match function name
@@ -89,14 +109,16 @@ while(<>) {
$RP = ")"; $RP = ")";
} }
# only add newline if more than one parameter # only add newline if more than one parameter
if(/,/){ if($opt_m ne "roken" && /,/){
s/\</ $LP\n\t/; s/\</ $LP\n\t/;
}else{ }else{
s/\</ $LP/; s/\</ $LP/;
} }
s/\>/$RP/; s/\>/$RP/;
# insert newline before function name # insert newline before function name
s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/; if($opt_m ne "roken") {
s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
}
if($attr ne "") { if($attr ne "") {
$_ .= "\n $attr"; $_ .= "\n $attr";
} }
@@ -142,13 +164,14 @@ if($opt_p) {
$public_h = ""; $public_h = "";
$private_h = ""; $private_h = "";
$public_h_header = "/* This is a generated file */ if($opt_m ne "roken") {
$public_h_header = "/* This is a generated file */
#ifndef $block #ifndef $block
#define $block #define $block
"; ";
if ($oproto) { if ($oproto) {
$public_h_header .= "#ifdef __STDC__ $public_h_header .= "#ifdef __STDC__
#include <stdarg.h> #include <stdarg.h>
#ifndef __P #ifndef __P
#define __P(x) x #define __P(x) x
@@ -160,19 +183,18 @@ $public_h_header .= "#ifdef __STDC__
#endif #endif
"; ";
} else { } else {
$public_h_header .= "#include <stdarg.h> $public_h_header .= "#include <stdarg.h>
"; ";
} }
$private_h_header = "/* This is a generated file */
$private_h_header = "/* This is a generated file */
#ifndef $private #ifndef $private
#define $private #define $private
"; ";
if($oproto) { if($oproto) {
$private_h_header .= "#ifdef __STDC__ $private_h_header .= "#ifdef __STDC__
#include <stdarg.h> #include <stdarg.h>
#ifndef __P #ifndef __P
#define __P(x) x #define __P(x) x
@@ -184,48 +206,63 @@ $private_h_header .= "#ifdef __STDC__
#endif #endif
"; ";
} else { } else {
$private_h_header .= "#include <stdarg.h> $private_h_header .= "#include <stdarg.h>
"; ";
}
} }
foreach(sort keys %funcs){ foreach(sort keys %funcs){
if(/^(main)$/) { next } if(/^(main)$/) { next }
if(/$private_func_re/) { if(!defined($exported{$_}) && /$private_func_re/) {
$private_h .= $funcs{$_} . "\n\n"; $private_h .= $funcs{$_} . "\n\n";
if($funcs{$_} =~ /__attribute__/) { if($funcs{$_} =~ /__attribute__/) {
$private_attribute_seen = 1; $private_attribute_seen = 1;
} }
} else { } else {
$public_h .= $funcs{$_} . "\n\n"; if($opt_m eq "roken") {
$fupper = uc $_;
if($exported{$_} =~ /proto/) {
$public_h .= "#if !defined(HAVE_$fupper) || defined(NEED_${fupper}_PROTO)\n";
} else {
$public_h .= "#ifndef HAVE_$fupper\n";
}
}
$public_h .= $funcs{$_} . "\n";
if($funcs{$_} =~ /__attribute__/) { if($funcs{$_} =~ /__attribute__/) {
$public_attribute_seen = 1; $public_attribute_seen = 1;
} }
if($opt_m eq "roken") {
$public_h .= "#endif\n";
}
$public_h .= "\n";
} }
} }
if ($public_attribute_seen) { if($opt_m ne "roken") {
$public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__) if ($public_attribute_seen) {
$public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
#define __attribute__(x) #define __attribute__(x)
#endif #endif
"; ";
} }
if ($private_attribute_seen) { if ($private_attribute_seen) {
$private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__) $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
#define __attribute__(x) #define __attribute__(x)
#endif #endif
"; ";
} }
if ($public_h ne "") { if ($public_h ne "") {
$public_h = $public_h_header . $public_h . "#endif /* $block */\n"; $public_h = $public_h_header . $public_h . "#endif /* $block */\n";
} }
if ($private_h ne "") { if ($private_h ne "") {
$private_h = $private_h_header . $private_h . "#endif /* $private */\n"; $private_h = $private_h_header . $private_h . "#endif /* $private */\n";
}
} }
if($opt_o) { if($opt_o) {