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; },
50 sub normalize_define
($$)
52 my ($define, $file) = @_;
54 if (not defined($define) and defined($file)) {
55 $define = "__" . uc($file) . "__";
56 $define =~ tr{./}{__};
58 } elsif (not defined($define)) {
59 $define = '_S3_PARAM_H_';
65 $public_define = normalize_define
($public_define, $file);
71 open(INPUTFILE
, $filename) or return undef;
72 my($saved_delim) = $/;
74 my($data) = <INPUTFILE
>;
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.pl. DO NOT EDIT */\n\n");
86 $file->("struct loadparm_s3_context\n");
88 $file->("\tconst char * (*get_parametric)(struct loadparm_service *, const char *type, const char *option);\n");
89 $file->("\tstruct parm_struct * (*get_parm_struct)(const char *param_name);\n");
90 $file->("\tvoid * (*get_parm_ptr)(struct loadparm_service *service, struct parm_struct *parm);\n");
91 $file->("\tstruct loadparm_service * (*get_service)(const char *service_name);\n");
92 $file->("\tstruct loadparm_service * (*get_default_loadparm_service)(void);\n");
93 $file->("\tstruct loadparm_service * (*get_servicebynum)(int snum);\n");
94 $file->("\tint (*get_numservices)(void);\n");
95 $file->("\tbool (*load)(const char *filename);\n");
96 $file->("\tbool (*set_cmdline)(const char *pszParmName, const char *pszParmValue);\n");
97 $file->("\tvoid (*dump)(FILE *f, bool show_defaults, int maxtoprint);\n");
102 my ($file, $header_name) = @_;
104 $file->("\n#endif /* $header_name */\n\n");
107 sub handle_loadparm
($$)
109 my ($file,$line) = @_;
111 if ($line =~ /^FN_(GLOBAL|LOCAL)_(CONST_STRING|STRING|BOOL|bool|CHAR|INTEGER|LIST)\((\w+),.*\)/o) {
118 "CONST_STRING" => "const char *",
119 "STRING" => "const char *",
122 "LIST" => "const char **",
125 $file->("\t$tmap{$type} (*$name)(void);\n");
131 my ($file, $filename) = @_;
133 $filename =~ s/\.o$/\.c/g;
135 if ($filename =~ /^\//) {
136 open(FH
, "<$filename") or die("Failed to open $filename");
137 } elsif (!open(FH
, "< $builddir/$filename")) {
138 open(FH
, "< $srcdir/$filename") || die "Failed to open $filename";
143 while (my $line = <FH
>) {
144 if ($line =~ /^\/\
*\
*/) {
151 if ($line =~ /\*\//) {
156 # these are ordered for maximum speed
157 next if ($line =~ /^\s/);
159 next unless ($line =~ /\(/);
161 next if ($line =~ /^\/|[;]/);
163 if ($line =~ /^FN_/) {
164 handle_loadparm
($file, $line);
173 print_header
(\
&public
, $public_define);
175 process_file
(\
&public
, $_) foreach (@ARGV);
176 print_footer
(\
&public
, $public_define);
178 if (not defined($file)) {
179 print STDOUT
$$public_data;
182 mkpath
(dirname
($file), 0, 0755);
183 open(PUBLIC
, ">$file") or die("Can't open `$file': $!");
184 print PUBLIC
"$$public_data";