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";
33 my($opt_template) = 0;
41 my $idl_parser = new idl;
43 #####################################################################
44 # parse an IDL file returning a structure containing all the data
48 my $idl = $idl_parser->parse_idl($filename);
49 util::CleanData($idl);
54 #########################################
59 perl IDL parser and code generator
60 Copyright (C) tridge\@samba.org
62 Usage: pidl.pl [options] <idlfile>
66 --output OUTNAME put output in OUTNAME.*
67 --parse parse a idl file to a .pidl file
68 --dump dump a pidl file back to idl
69 --header create a C header file
70 --parser create a C parser
71 --server create server boilerplate
72 --template print a template for a pipe
73 --eparser create an ethereal parser
74 --swig create swig wrapper file
75 --diff run diff on the idl and dumped output
76 --keep keep the .pidl file
83 'help|h|?' => \$opt_help,
84 'output=s' => \$opt_output,
85 'parse' => \$opt_parse,
87 'header' => \$opt_header,
88 'server' => \$opt_server,
89 'template' => \$opt_template,
90 'parser' => \$opt_parser,
91 'eparser' => \$opt_eparser,
104 my $idl_file = shift;
108 my $basename = basename($idl_file, ".idl");
110 if (!defined($opt_output)) {
113 $output = $opt_output . $basename;
116 my($pidl_file) = util::ChangeExtension($output, ".pidl");
118 print "Compiling $idl_file\n";
121 $pidl = IdlParse($idl_file);
122 defined @$pidl || die "Failed to parse $idl_file";
123 IdlValidator::Validate($pidl);
124 if ($opt_keep && !util::SaveStructure($pidl_file, $pidl)) {
125 die "Failed to save $pidl_file\n";
128 $pidl = util::LoadStructure($pidl_file);
129 defined $pidl || die "Failed to load $pidl_file - maybe you need --parse\n";
133 print IdlDump::Dump($pidl);
137 my($header) = util::ChangeExtension($output, ".h");
138 util::FileSave($header, IdlHeader::Parse($pidl));
142 my($server) = util::ChangeExtension($output, "_s.c");
144 foreach my $x (@{$pidl}) {
145 next if ($x->{TYPE} ne "INTERFACE");
147 if (util::has_property($x, "object")) {
148 $res .= IdlStub::ParseInterface($x);
150 $res .= IdlServer::ParseInterface($x);
153 util::FileSave($server, $res);
157 my($parser) = util::ChangeExtension($output, ".c");
158 IdlParser::Parse($pidl, $parser);
162 my($parser) = dirname($output) . "/packet-dcerpc-$basename.c";
163 IdlEParser::Parse($pidl, $parser);
164 $parser = dirname($output) . "/packet-dcerpc-proto-$basename.h";
165 IdlEParser::ParseHeader($pidl, $parser);
166 my($header) = dirname($output) . "/packet-dcerpc-proto.h";
167 open(OUT, ">>$header") || die "can't open $header";
168 print OUT "#include \"ndr_$basename.h\"\n";
169 print OUT "#include \"packet-dcerpc-proto-$basename.h\"\n";
174 my($filename) = $output;
175 $filename =~ s/\/ndr_/\//;
176 $filename = util::ChangeExtension($filename, ".i");
177 util::FileSave($filename, IdlSwig::Parse($pidl));
181 my($tempfile) = util::ChangeExtension($output, ".tmp");
182 util::FileSave($tempfile, IdlDump::Dump($pidl));
183 system("diff -wu $idl_file $tempfile");
188 print IdlTemplate::Parse($pidl);
193 foreach my $filename (@ARGV) {
194 process_file($filename);