2003-11-23 04:29:42 +03:00
#!/usr/bin/perl
use strict ;
use warnings ;
my $ header_name = '_PROTO_H_' ;
if ( $ ARGV [ 0 ] eq '-h' ) {
shift @ ARGV ;
$ header_name = shift @ ARGV ;
}
sub print_header {
print "#ifndef $header_name\n" ;
print "#define $header_name\n\n" ;
print "/* This file is automatically generated with \"make proto\". DO NOT EDIT */\n\n" ;
}
sub print_footer {
printf "\n#endif /* %s */\n" , $ header_name ;
}
2003-11-23 04:53:54 +03:00
sub handle_loadparm {
my $ line = shift ;
2003-11-23 05:00:40 +03:00
2003-11-23 05:33:46 +03:00
if ( $ line =~ /^FN_(GLOBAL|LOCAL)_(CONST_STRING|STRING|BOOL|CHAR|INTEGER|LIST)\((\w+),.*\)/o ) {
2003-11-23 05:11:55 +03:00
my $ scope = $ 1 ;
my $ type = $ 2 ;
my $ name = $ 3 ;
my % tmap = (
"BOOL" = > "BOOL " ,
"CONST_STRING" = > "const char *" ,
"STRING" = > "char *" ,
"INTEGER" = > "int " ,
"CHAR" = > "char " ,
"LIST" = > "const char **" ,
) ;
my % smap = (
"GLOBAL" = > "void" ,
"LOCAL" = > "int "
) ;
print "$tmap{$type}$name($smap{$scope});\n" ;
2003-11-23 04:53:54 +03:00
}
}
2003-11-23 05:33:46 +03:00
sub process_file ($)
{
my $ filename = shift ;
2003-11-23 04:29:42 +03:00
2003-11-23 05:33:46 +03:00
open ( FH , "< $filename" ) || die "Failed to open $filename" ;
2003-11-23 04:29:42 +03:00
2003-11-23 05:33:46 +03:00
print "\n/* The following definitions come from $filename */\n\n" ;
2003-11-23 04:29:42 +03:00
2003-11-23 05:44:23 +03:00
while ( my $ line = <FH> ) {
# these are ordered for maximum speed
2003-11-23 05:33:46 +03:00
next if ( $ line =~ /^\s/ ) ;
2003-11-23 05:44:23 +03:00
next unless ( $ line =~ /\(/ ) ;
next if ( $ line =~ /^\/|[;]/ ) ;
2003-11-23 05:33:46 +03:00
if ( $ line =~ /^FN_/ ) {
handle_loadparm ( $ line ) ;
}
2003-11-23 04:29:42 +03:00
2003-11-23 05:44:23 +03:00
next unless ( $ line =~ /
^ void | ^ BOOL | ^ int | ^ struct | ^ char | ^ const | ^ \ w + _ [ tT ] \ s | ^ uint | ^ unsigned | ^ long |
^ NTSTATUS | ^ ADS_STATUS | ^ enum \ s . * \ ( | ^ DATA_BLOB | ^ WERROR | ^ XFILE | ^ FILE | ^ DIR |
^ double | ^ TDB_CONTEXT | ^ TDB_DATA | ^ TALLOC_CTX | ^ NTTIME
/ xo ) ;
2003-11-23 05:33:46 +03:00
if ( $ line =~ /\(.*\)\s*$/o ) {
chomp $ line ;
print "$line;\n" ;
next ;
}
2003-11-23 04:29:42 +03:00
2003-11-23 05:33:46 +03:00
print $ line ;
2003-11-23 04:29:42 +03:00
2003-11-23 05:33:46 +03:00
while ( $ line = <FH> ) {
chomp $ line ;
if ( $ line =~ /\)\s*$/o ) {
2003-11-23 04:29:42 +03:00
print "$line;\n" ;
2003-11-23 05:33:46 +03:00
last ;
2003-11-23 04:29:42 +03:00
}
2003-11-23 05:33:46 +03:00
print "$line\n" ;
2003-11-23 04:29:42 +03:00
}
}
2003-11-23 05:44:23 +03:00
close ( FH ) ;
2003-11-23 04:29:42 +03:00
}
2003-11-23 05:33:46 +03:00
sub process_files {
foreach my $ filename ( @ ARGV ) {
process_file ( $ filename ) ;
}
}
2003-11-23 04:29:42 +03:00
print_header ( ) ;
process_files ( ) ;
print_footer ( ) ;