1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00
samba-mirror/source/script/mkproto.pl

124 lines
2.2 KiB
Perl
Raw Normal View History

#!/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;
}
sub handle_loadparm {
my $line = shift;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ($line =~ /^FN_(GLOBAL|LOCAL)_(CONST_STRING|STRING|BOOL|CHAR|INTEGER|LIST)\((\w+),.*\)/o) {
0001-01-01 02:30:17 +02:30
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";
}
}
0001-01-01 02:30:17 +02:30
sub process_file($)
{
my $filename = shift;
my $line;
my $inheader;
my $gotstart;
0001-01-01 02:30:17 +02:30
open(FH, "< $filename") || die "Failed to open $filename";
0001-01-01 02:30:17 +02:30
$inheader = 0;
$gotstart = 0;
0001-01-01 02:30:17 +02:30
print "\n/* The following definitions come from $filename */\n\n";
0001-01-01 02:30:17 +02:30
while ($line = <FH>) {
# this ignores most lines
next if ($line =~ /^\s/);
$gotstart = 0;
if ($line =~ /^static|^extern/o ||
$line !~ /^[a-zA-Z]/o ||
$line =~ /[;]/o) {
next;
}
if ($line =~ /^FN_/) {
handle_loadparm($line);
}
0001-01-01 02:30:17 +02:30
next unless ($line =~ /\(/);
if ( $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) {
$gotstart = 1;
}
# goto next line if we don't have a start
next unless $gotstart;
if ( $line =~ /\(.*\)\s*$/o ) {
chomp $line;
print "$line;\n";
next;
}
0001-01-01 02:30:17 +02:30
print $line;
0001-01-01 02:30:17 +02:30
while ($line = <FH>) {
chomp $line;
if ($line =~ /\)\s*$/o) {
print "$line;\n";
0001-01-01 02:30:17 +02:30
last;
}
0001-01-01 02:30:17 +02:30
print "$line\n";
}
}
}
0001-01-01 02:30:17 +02:30
sub process_files {
foreach my $filename (@ARGV) {
process_file($filename);
}
}
print_header();
process_files();
print_footer();