2 # Generate loadparm interfaces tables for Samba3/Samba4 integration
4 # based on mkproto.pl Written by Jelmer Vernooij
5 # based on the original mkproto.sh by Andrew Tridgell
9 # don't use warnings module as it is not portable enough
16 #####################################################################
17 # read a file into a string
20 my $public_define = undef;
23 my $public_data = \
$_public;
35 print "Usage: mks3param.pl [options] [c files]\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";
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; },
54 open(INPUTFILE
, $filename) or return undef;
55 my($saved_delim) = $/;
57 my($data) = <INPUTFILE
>;
66 $file->("/* This file was automatically generated by mks3param_ctx.pl. DO NOT EDIT */\n\n");
67 $file->("static const struct loadparm_s3_helpers s3_fns =\n");
69 $file->("\t.get_parametric = lp_parm_const_string_service,\n");
70 $file->("\t.get_parm_struct = lp_get_parameter,\n");
71 $file->("\t.get_parm_ptr = lp_parm_ptr,\n");
72 $file->("\t.get_service = lp_service_for_s4_ctx,\n");
73 $file->("\t.get_servicebynum = lp_servicebynum_for_s4_ctx,\n");
74 $file->("\t.get_default_loadparm_service = lp_default_loadparm_service,\n");
75 $file->("\t.get_numservices = lp_numservices,\n");
76 $file->("\t.load = lp_load_for_s4_ctx,\n");
77 $file->("\t.set_cmdline = lp_set_cmdline,\n");
78 $file->("\t.dump = lp_dump,\n");
87 sub handle_loadparm
($$)
89 my ($file,$line) = @_;
91 # STRING isn't handled here, as we still don't know what to do with the substituted vars */
92 # LOCAL also isn't handled here
93 if ($line =~ /^FN_(GLOBAL)_(CONST_STRING|BOOL|bool|CHAR|INTEGER|LIST)\((\w+),.*\)/o) {
98 $file->("\t.$name = lp_$name,\n");
104 my ($file, $filename) = @_;
106 $filename =~ s/\.o$/\.c/g;
108 if ($filename =~ /^\//) {
109 open(FH
, "<$filename") or die("Failed to open $filename");
110 } elsif (!open(FH
, "< $builddir/$filename")) {
111 open(FH
, "< $srcdir/$filename") || die "Failed to open $filename";
116 while (my $line = <FH
>) {
117 if ($line =~ /^FN_/) {
118 handle_loadparm
($file, $line);
127 print_header
(\
&public
);
129 process_file
(\
&public
, $_) foreach (@ARGV);
130 print_footer
(\
&public
);
132 if (not defined($file)) {
133 print STDOUT
$$public_data;
136 mkpath
(dirname
($file), 0, 0755);
137 open(PUBLIC
, ">$file") or die("Can't open `$file': $!");
138 print PUBLIC
"$$public_data";