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";
32 my($opt_template) = 0;
40 my $idl_parser = new idl;
42 #####################################################################
43 # parse an IDL file returning a structure containing all the data
47 my $idl = $idl_parser->parse_idl($filename);
48 util::CleanData($idl);
53 #########################################
58 perl IDL parser and code generator
59 Copyright (C) tridge\@samba.org
61 Usage: pidl.pl [options] <idlfile>
65 --output OUTNAME put output in OUTNAME.*
66 --parse parse a idl file to a .pidl file
67 --dump dump a pidl file back to idl
68 --header create a C header file
69 --parser create a C parser
70 --server create server boilerplate
71 --template print a template for a pipe
72 --eparser create an ethereal parser
73 --diff run diff on the idl and dumped output
74 --keep keep the .pidl file
81 'help|h|?' => \$opt_help,
82 'output=s' => \$opt_output,
83 'parse' => \$opt_parse,
85 'header' => \$opt_header,
86 'server' => \$opt_server,
87 'template' => \$opt_template,
88 'parser' => \$opt_parser,
89 'eparser' => \$opt_eparser,
102 my $idl_file = shift;
106 my $basename = basename($idl_file, ".idl");
108 if (!defined($opt_output)) {
111 $output = $opt_output . $basename;
114 my($pidl_file) = util::ChangeExtension($output, ".pidl");
116 print "Compiling $idl_file\n";
119 $pidl = IdlParse($idl_file);
120 defined $pidl || die "Failed to parse $idl_file";
121 IdlValidator::Validate($pidl);
122 if ($opt_keep && !util::SaveStructure($pidl_file, $pidl)) {
123 die "Failed to save $pidl_file\n";
126 $pidl = util::LoadStructure($pidl_file);
127 defined $pidl || die "Failed to load $pidl_file - maybe you need --parse\n";
131 print IdlDump::Dump($pidl);
135 my($header) = util::ChangeExtension($output, ".h");
136 util::FileSave($header, IdlHeader::Parse($pidl));
140 my($server) = util::ChangeExtension($output, "_s.c");
141 util::FileSave($server, IdlServer::Parse($pidl));
145 my($parser) = util::ChangeExtension($output, ".c");
146 IdlParser::Parse($pidl, $parser);
150 my($parser) = dirname($output) . "/packet-dcerpc-$basename.c";
151 IdlEParser::Parse($pidl, $parser);
152 $parser = dirname($output) . "/packet-dcerpc-proto-$basename.h";
153 IdlEParser::ParseHeader($pidl, $parser);
154 my($header) = dirname($output) . "/packet-dcerpc-proto.h";
155 open(OUT, ">>$header") || die "can't open $header";
156 print OUT "#include \"ndr_$basename.h\"\n";
157 print OUT "#include \"packet-dcerpc-proto-$basename.h\"\n";
162 my($filename) = $output;
163 $filename =~ s/\/ndr_/\//;
164 $filename = util::ChangeExtension($filename, ".i");
165 util::FileSave($filename, IdlSwig::Parse($pidl));
169 my($tempfile) = util::ChangeExtension($output, ".tmp");
170 util::FileSave($tempfile, IdlDump::Dump($pidl));
171 system("diff -wu $idl_file $tempfile");
176 print IdlTemplate::Parse($pidl);
181 foreach my $filename (@ARGV) {
182 process_file($filename);