docs: update idmap cache time to be consistent with testparm
[Samba.git] / script / mks3param_ctx_table.pl
blob22efc88ca631f1bf713d7eb3b489a54dfb8082cd
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 file_load($)
52 my($filename) = @_;
53 local(*INPUTFILE);
54 open(INPUTFILE, $filename) or return undef;
55 my($saved_delim) = $/;
56 undef $/;
57 my($data) = <INPUTFILE>;
58 close(INPUTFILE);
59 $/ = $saved_delim;
60 return $data;
63 sub print_header($)
65 my ($file) = @_;
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");
68 $file->("{\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");
81 sub print_footer($)
83 my ($file) = @_;
84 $file->("};");
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) {
94 my $scope = $1;
95 my $type = $2;
96 my $name = $3;
98 $file->("\t.$name = lp_$name,\n");
102 sub process_file($$)
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";
114 my $comment = undef;
115 my $incomment = 0;
116 while (my $line = <FH>) {
117 if ($line =~ /^FN_/) {
118 handle_loadparm($file, $line);
120 next;
123 close(FH);
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";
139 close(PUBLIC);