lib/param: Merge struct loadparm_service into common
[samba.git] / source4 / script / mkproto.pl
index 6d76b9bc4f0e7638fdfc02ae610490e9ee494c30..348f150e6dadfb80ea6fb3de2a1492a058614c59 100755 (executable)
@@ -17,14 +17,15 @@ use File::Path;
 
 my $public_file = undef;
 my $private_file = undef;
+my $all_file = undef;
 my $public_define = undef;
 my $private_define = undef;
 my $_public = "";
 my $_private = "";
 my $public_data = \$_public;
 my $private_data = \$_private;
-my $builddir = undef;
-my $srcdir = undef;
+my $builddir = ".";
+my $srcdir = ".";
 
 sub public($)
 {
@@ -55,6 +56,7 @@ sub usage()
 
 GetOptions(
        'public=s' => sub { my ($f,$v) = @_; $public_file = $v; },
+       'all=s' => sub { my ($f,$v) = @_; $public_file = $v; $private_file = $v; },
        'private=s' => sub { my ($f,$v) = @_; $private_file = $v; },
        'define=s' => sub { 
                my ($f,$v) = @_; 
@@ -93,9 +95,9 @@ if ((defined($private_file) and defined($public_file) and ($private_file eq $pub
 
 sub file_load($)
 {
-    my($filename) = shift;
+    my($filename) = @_;
     local(*INPUTFILE);
-    open(INPUTFILE, $filename) || return undef;
+    open(INPUTFILE, $filename) or return undef;
     my($saved_delim) = $/;
     undef $/;
     my($data) = <INPUTFILE>;
@@ -125,29 +127,40 @@ sub print_footer($$)
 sub handle_loadparm($$) 
 {
        my ($file,$line) = @_;
-
-       if ($line =~ /^_PUBLIC_ FN_(GLOBAL|LOCAL)_(CONST_STRING|STRING|BOOL|bool|CHAR|INTEGER|LIST)\((\w+),.*\)/o) {
-               my $scope = $1;
-               my $type = $2;
-               my $name = $3;
-
-               my %tmap = (
-                           "BOOL" => "bool ",
-                               "bool" => "bool ",
-                           "CONST_STRING" => "const char *",
-                           "STRING" => "const char *",
-                           "INTEGER" => "int ",
-                           "CHAR" => "char ",
-                           "LIST" => "const char **",
-                           );
-
-               my %smap = (
-                           "GLOBAL" => "struct loadparm_context *",
-                           "LOCAL" => "struct loadparm_service *"
-                           );
-
-               $file->("$tmap{$type}$name($smap{$scope});\n");
+       my $scope;
+       my $type;
+       my $name;
+       my $var;
+
+       if ($line =~ /^FN_(GLOBAL|LOCAL)_(CONST_STRING|STRING|BOOL|bool|CHAR|INTEGER|LIST)\((\w+),(.*)\)/o) {
+               $scope = $1;
+               $type = $2;
+               $name = $3;
+               $var = $4;
+       } elsif ($line =~ /^FN_(GLOBAL|LOCAL)_PARM_(CONST_STRING|STRING|BOOL|bool|CHAR|INTEGER|LIST)\((\w+),(.*)\)/o) {
+               $scope = $1;
+               $type = $2;
+               $name = $3;
+               $var = $4;
+       } else {
+               return;
        }
+
+       my %tmap = (
+               "BOOL" => "bool ",
+               "CONST_STRING" => "const char *",
+               "STRING" => "const char *",
+               "INTEGER" => "int ",
+               "CHAR" => "char ",
+               "LIST" => "const char **",
+       );
+
+       my %smap = (
+               "GLOBAL" => "struct loadparm_context *",
+               "LOCAL" => "struct loadparm_service *, struct loadparm_service *"
+               );
+
+       $file->("$tmap{$type}lpcfg_$name($smap{$scope});\n");
 }
 
 sub process_file($$$) 
@@ -156,7 +169,9 @@ sub process_file($$$)
 
        $filename =~ s/\.o$/\.c/g;
 
-       if (!open(FH, "< $builddir/$filename")) {
+       if ($filename =~ /^\//) {
+               open(FH, "<$filename") or die("Failed to open $filename");
+       } elsif (!open(FH, "< $builddir/$filename")) {
            open(FH, "< $srcdir/$filename") || die "Failed to open $filename";
        }
 
@@ -187,8 +202,9 @@ sub process_file($$$)
 
                next if ($line =~ /^\/|[;]/);
 
-               if ($line =~ /^_PUBLIC_ FN_/) {
+               if ($line =~ /^FN_/) {
                        handle_loadparm($public_file, $line);
+                       handle_loadparm($private_file, $line);
                        next;
                }
 
@@ -199,17 +215,16 @@ sub process_file($$$)
 
                next unless ( $is_public || $line =~ /
                              ^(_DEPRECATED_ |_NORETURN_ |_WARN_UNUSED_RESULT_ |_PURE_ )*(
-                                 void|BOOL|bool|int|struct|char|const|\w+_[tT]\s|uint|unsigned|long|NTSTATUS|
+                                 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|FN_|init_module|
-                             GtkWidget|GType|smb_ucs2_t|krb5_error_code)
+                             GtkWidget|GType|smb_ucs2_t|krb5_error_code|NET_API_STATUS)
                              /xo);
 
                next if ($line =~ /^int\s*main/);
 
                $target->("\n$comment") if (defined($comment)); $comment = undef;
 
-               $line =~ s/BOOL /bool /g;
                if ( $line =~ /\(.*\)\s*$/o ) {
                        chomp $line;
                        $target->("$line;\n");
@@ -219,7 +234,6 @@ sub process_file($$$)
                $target->($line);
 
                while ($line = <FH>) {
-                       $line =~ s/BOOL /bool /g;
                        if ($line =~ /\)\s*$/o) {
                                chomp $line;
                                $target->("$line;\n");
@@ -234,7 +248,7 @@ sub process_file($$$)
 
 
 print_header(\&public, $public_define);
-if ($public_file ne $private_file) {
+if (defined($private_file) and defined($public_file) and $public_file ne $private_file) {
        print_header(\&private, $private_define);
 
        private("/* this file contains prototypes for functions that " .
@@ -254,7 +268,7 @@ public("#ifndef _WARN_UNUSED_RESULT_\n#define _WARN_UNUSED_RESULT_\n#endif\n\n")
 
 process_file(\&public, \&private, $_) foreach (@ARGV);
 print_footer(\&public, $public_define);
-if ($public_file ne $private_file) {
+if (defined($private_file) and $public_file ne $private_file) {
        print_footer(\&private, $private_define);
 }
 
@@ -266,15 +280,12 @@ if (not defined($private_file) and defined($public_file)) {
        print STDOUT $$private_data;
 }
 
-my $old_public_data = file_load($public_file);
-my $old_private_data = file_load($private_file);
-
 mkpath(dirname($public_file), 0, 0755);
 open(PUBLIC, ">$public_file") or die("Can't open `$public_file': $!"); 
 print PUBLIC "$$public_data";
 close(PUBLIC);
 
-if ($public_file ne $private_file) {
+if (defined($private_file) and $public_file ne $private_file) {
        mkpath(dirname($private_file), 0, 0755);
        open(PRIVATE, ">$private_file") or die("Can't open `$private_file': $!"); 
        print PRIVATE "$$private_data";