param: Rename variable used for lp_ldap_suffix szLdapSuffix
[Samba.git] / script / mks3param_proto.pl
blob446e343ec51b0f562f5a045bb73e1812597c07b8
1 #!/usr/bin/perl
2 # Generate loadparm interfaces tables for Samba3/Samba4 integration
3 # by Andrew Bartlett
4 # based on mkproto.pl Written by Jelmer Vernooij
5 # based on the original mkproto.sh by Andrew Tridgell
7 use strict;
9 # don't use warnings module as it is not portable enough
10 # use warnings;
12 use Getopt::Long;
13 use File::Basename;
14 use File::Path;
16 #####################################################################
17 # read a file into a string
19 my $file = undef;
20 my $public_define = undef;
21 my $_public = "";
22 my $_private = "";
23 my $public_data = \$_public;
24 my $builddir = ".";
25 my $srcdir = ".";
27 sub public($)
29 my ($d) = @_;
30 $$public_data .= $d;
33 sub usage()
35 print "Usage: mks3param.pl [options] [c files]\n";
36 print "OPTIONS:\n";
37 print " --srcdir=path Read files relative to this directory\n";
38 print " --builddir=path Write file relative to this directory\n";
39 print " --help Print this help message\n\n";
40 exit 0;
43 GetOptions(
44 'file=s' => sub { my ($f,$v) = @_; $file = $v; },
45 'srcdir=s' => sub { my ($f,$v) = @_; $srcdir = $v; },
46 'builddir=s' => sub { my ($f,$v) = @_; $builddir = $v; },
47 'help' => \&usage
48 ) or exit(1);
50 sub normalize_define($$)
52 my ($define, $file) = @_;
54 if (not defined($define) and defined($file)) {
55 $define = "__" . uc($file) . "__";
56 $define =~ tr{./}{__};
57 $define =~ tr{\-}{_};
58 } elsif (not defined($define)) {
59 $define = '_S3_PARAM_PROTO_H_';
62 return $define;
65 $public_define = normalize_define($public_define, $file);
67 sub file_load($)
69 my($filename) = @_;
70 local(*INPUTFILE);
71 open(INPUTFILE, $filename) or return undef;
72 my($saved_delim) = $/;
73 undef $/;
74 my($data) = <INPUTFILE>;
75 close(INPUTFILE);
76 $/ = $saved_delim;
77 return $data;
80 sub print_header($$)
82 my ($file, $header_name) = @_;
83 $file->("#ifndef $header_name\n");
84 $file->("#define $header_name\n\n");
85 $file->("/* This file was automatically generated by mks3param_proto.pl. DO NOT EDIT */\n\n");
88 sub print_footer($$)
90 my ($file, $header_name) = @_;
91 $file->("\n#endif /* $header_name */\n\n");
94 sub handle_loadparm($$)
96 my ($file,$line) = @_;
98 my $scope;
99 my $type;
100 my $name;
101 my $var;
102 my $param;
104 if ($line =~ /^FN_(GLOBAL|LOCAL)_(CONST_STRING|STRING|BOOL|bool|CHAR|INTEGER|LIST)\((\w+),(.*)\)/o) {
105 $scope = $1;
106 $type = $2;
107 $name = $3;
108 $var = $4;
109 $param = "int";
110 } elsif ($line =~ /^FN_(GLOBAL|LOCAL)_PARM_(CONST_STRING|STRING|BOOL|bool|CHAR|INTEGER|LIST)\((\w+),(.*)\)/o) {
111 $scope = $1;
112 $type = $2;
113 $name = $3;
114 $var = $4;
115 $param = "const struct share_params *p";
116 } else {
117 return;
120 my %tmap = (
121 "BOOL" => "bool ",
122 "CONST_STRING" => "const char *",
123 "STRING" => "char *",
124 "INTEGER" => "int ",
125 "CHAR" => "char ",
126 "LIST" => "const char **",
129 my %smap = (
130 "GLOBAL" => "void",
131 "LOCAL" => "$param"
134 if (($type eq "STRING") and ($scope eq "GLOBAL")) {
135 $file->("$tmap{$type}lp_$name(TALLOC_CTX *ctx);\n");
136 } elsif (($type eq "STRING") and ($scope eq "LOCAL")) {
137 $file->("$tmap{$type}lp_$name(TALLOC_CTX *ctx, $smap{$scope});\n");
138 } else {
139 $file->("$tmap{$type}lp_$name($smap{$scope});\n");
143 sub process_file($$)
145 my ($file, $filename) = @_;
147 $filename =~ s/\.o$/\.c/g;
149 if ($filename =~ /^\//) {
150 open(FH, "<$filename") or die("Failed to open $filename");
151 } elsif (!open(FH, "< $builddir/$filename")) {
152 open(FH, "< $srcdir/$filename") || die "Failed to open $filename";
155 my $comment = undef;
156 my $incomment = 0;
157 while (my $line = <FH>) {
158 if ($line =~ /^\/\*\*/) {
159 $comment = "";
160 $incomment = 1;
163 if ($incomment) {
164 $comment .= $line;
165 if ($line =~ /\*\//) {
166 $incomment = 0;
170 # these are ordered for maximum speed
171 next if ($line =~ /^\s/);
173 next unless ($line =~ /\(/);
175 next if ($line =~ /^\/|[;]/);
177 if ($line =~ /^FN_/) {
178 handle_loadparm($file, $line);
180 next;
183 close(FH);
187 print_header(\&public, $public_define);
189 process_file(\&public, $_) foreach (@ARGV);
190 print_footer(\&public, $public_define);
192 if (not defined($file)) {
193 print STDOUT $$public_data;
196 mkpath(dirname($file), 0, 0755);
197 open(PUBLIC, ">$file") or die("Can't open `$file': $!");
198 print PUBLIC "$$public_data";
199 close(PUBLIC);