3 ###################################################
4 # package to parse IDL files and generate code for
5 # rpc functions in Samba
6 # Copyright tridge@samba.org 2000-2003
7 # released under the GNU GPL
11 use FindBin qw($RealBin);
13 use lib "$RealBin/lib";
38 my($opt_template) = 0;
45 my($opt_dcom_proxy) = 0;
46 my($opt_com_header) = 0;
50 my $idl_parser = new idl;
52 #####################################################################
53 # parse an IDL file returning a structure containing all the data
57 my $idl = $idl_parser->parse_idl($filename);
58 util::CleanData($idl);
63 #########################################
68 perl IDL parser and code generator
69 Copyright (C) tridge\@samba.org
71 Usage: pidl.pl [options] <idlfile>
75 --output OUTNAME put output in OUTNAME.*
76 --parse parse a idl file to a .pidl file
77 --dump dump a pidl file back to idl
78 --header create a C header file
79 --parser create a C NDR parser
80 --client create a C client
81 --server create server boilerplate
82 --template print a template for a pipe
83 --eparser create an ethereal parser
84 --swig create swig wrapper file
85 --diff run diff on the idl and dumped output
86 --keep keep the .pidl file
87 --odl accept ODL input
88 --dcom-proxy create DCOM proxy (implies --odl)
89 --com-header create header for COM interfaces (implies --odl)
96 'help|h|?' => \$opt_help,
97 'output=s' => \$opt_output,
98 'parse' => \$opt_parse,
100 'header' => \$opt_header,
101 'server' => \$opt_server,
102 'template' => \$opt_template,
103 'parser' => \$opt_parser,
104 'client' => \$opt_client,
105 'eparser' => \$opt_eparser,
106 'diff' => \$opt_diff,
108 'keep' => \$opt_keep,
109 'swig' => \$opt_swig,
110 'dcom-proxy' => \$opt_dcom_proxy,
111 'com-header' => \$opt_com_header
121 my $idl_file = shift;
125 my $basename = basename($idl_file, ".idl");
127 if (!defined($opt_output)) {
130 $output = $opt_output . $basename;
133 my($pidl_file) = util::ChangeExtension($output, ".pidl");
135 print "Compiling $idl_file\n";
138 $pidl = IdlParse($idl_file);
139 defined @$pidl || die "Failed to parse $idl_file";
140 IdlValidator::Validate($pidl);
141 if ($opt_keep && !util::SaveStructure($pidl_file, $pidl)) {
142 die "Failed to save $pidl_file\n";
145 $pidl = util::LoadStructure($pidl_file);
146 defined $pidl || die "Failed to load $pidl_file - maybe you need --parse\n";
150 print IdlDump::Dump($pidl);
154 my($tempfile) = util::ChangeExtension($output, ".tmp");
155 util::FileSave($tempfile, IdlDump::Dump($pidl));
156 system("diff -wu $idl_file $tempfile");
160 if ($opt_header || $opt_parser || $opt_com_header || $opt_dcom_proxy) {
161 typelist::LoadIdl($pidl);
164 if ($opt_com_header) {
165 my $res = COMHeader::Parse($pidl);
167 my $h_filename = dirname($output) . "/com_$basename.h";
168 util::FileSave($h_filename,
169 "#include \"librpc/gen_ndr/ndr_orpc.h\"\n" .
170 "#include \"librpc/gen_ndr/ndr_$basename.h\"\n" .
176 if ($opt_dcom_proxy) {
177 my $res = DCOMProxy::Parse($pidl);
179 my ($client) = util::ChangeExtension($output, "_p.c");
180 util::FileSave($client,
181 "#include \"includes.h\"\n" .
182 "#include \"librpc/gen_ndr/com_$basename.h\"\n" .
183 "#include \"lib/dcom/common/orpc.h\"\n". $res);
189 $pidl = ODL::ODL2IDL($pidl);
193 my($header) = util::ChangeExtension($output, ".h");
194 util::FileSave($header, NdrHeader::Parse($pidl));
196 my($eparserhdr) = dirname($output) . "/packet-dcerpc-$basename.h";
197 IdlEParser::RewriteHeader($pidl, $header, $eparserhdr);
200 my($filename) = $output;
201 $filename =~ s/\/ndr_/\//;
202 $filename = util::ChangeExtension($filename, ".i");
203 IdlSwig::RewriteHeader($pidl, $header, $filename);
208 my ($client) = util::ChangeExtension($output, "_c.c");
210 my $h_filename = util::ChangeExtension($output, ".h");
212 $res .= "#include \"includes.h\"\n";
213 $res .= "#include \"$h_filename\"\n\n";
215 foreach my $x (@{$pidl}) {
216 $res .= IdlClient::ParseInterface($x);
219 util::FileSave($client, $res);
223 my $h_filename = util::ChangeExtension($output, ".h");
227 foreach my $x (@{$pidl}) {
228 next if ($x->{TYPE} ne "INTERFACE");
230 if (util::has_property($x, "object")) {
231 $dcom .= DCOMStub::ParseInterface($x);
233 $plain .= IdlServer::ParseInterface($x);
238 util::FileSave(util::ChangeExtension($output, "_s.c"), $plain);
243 #include \"includes.h\"
244 #include \"$h_filename\"
245 #include \"rpc_server/dcerpc_server.h\"
246 #include \"rpc_server/common/common.h\"
250 util::FileSave(util::ChangeExtension($output, "_d.c"), $dcom);
255 my($parser) = util::ChangeExtension($output, ".c");
256 util::FileSave($parser, NdrParser::Parse($pidl, $parser));
258 my($eparser) = dirname($output) . "/packet-dcerpc-$basename.c";
259 IdlEParser::RewriteC($pidl, $parser, $eparser);
264 print IdlTemplate::Parse($pidl);
269 foreach my $filename (@ARGV) {
270 process_file($filename);