s3-torture: introduce test_cli_read()
[Samba/gebeck_regimport.git] / source4 / script / mks3param.pl
blob761cd6980f20add8b17bd2aa8aab7e39f30c6eaa
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_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.pl. DO NOT EDIT */\n\n");
86 $file->("struct loadparm_s3_context\n");
87 $file->("{\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 (*set_cmdline)(const char *pszParmName, const char *pszParmValue);\n");
98 sub print_footer($$)
100 my ($file, $header_name) = @_;
101 $file->("};");
102 $file->("\n#endif /* $header_name */\n\n");
105 sub handle_loadparm($$)
107 my ($file,$line) = @_;
109 if ($line =~ /^FN_(GLOBAL|LOCAL)_(CONST_STRING|STRING|BOOL|bool|CHAR|INTEGER|LIST)\((\w+),.*\)/o) {
110 my $scope = $1;
111 my $type = $2;
112 my $name = $3;
114 my %tmap = (
115 "BOOL" => "bool ",
116 "CONST_STRING" => "const char *",
117 "STRING" => "const char *",
118 "INTEGER" => "int ",
119 "CHAR" => "char ",
120 "LIST" => "const char **",
123 $file->("\t$tmap{$type} (*$name)(void);\n");
127 sub process_file($$)
129 my ($file, $filename) = @_;
131 $filename =~ s/\.o$/\.c/g;
133 if ($filename =~ /^\//) {
134 open(FH, "<$filename") or die("Failed to open $filename");
135 } elsif (!open(FH, "< $builddir/$filename")) {
136 open(FH, "< $srcdir/$filename") || die "Failed to open $filename";
139 my $comment = undef;
140 my $incomment = 0;
141 while (my $line = <FH>) {
142 if ($line =~ /^\/\*\*/) {
143 $comment = "";
144 $incomment = 1;
147 if ($incomment) {
148 $comment .= $line;
149 if ($line =~ /\*\//) {
150 $incomment = 0;
154 # these are ordered for maximum speed
155 next if ($line =~ /^\s/);
157 next unless ($line =~ /\(/);
159 next if ($line =~ /^\/|[;]/);
161 if ($line =~ /^FN_/) {
162 handle_loadparm($file, $line);
164 next;
167 close(FH);
171 print_header(\&public, $public_define);
173 process_file(\&public, $_) foreach (@ARGV);
174 print_footer(\&public, $public_define);
176 if (not defined($file)) {
177 print STDOUT $$public_data;
180 mkpath(dirname($file), 0, 0755);
181 open(PUBLIC, ">$file") or die("Can't open `$file': $!");
182 print PUBLIC "$$public_data";
183 close(PUBLIC);