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";
31 my($opt_template) = 0;
38 my $idl_parser = new idl;
40 #####################################################################
41 # parse an IDL file returning a structure containing all the data
45 my $idl = $idl_parser->parse_idl($filename);
46 util::CleanData($idl);
51 #########################################
56 perl IDL parser and code generator
57 Copyright (C) tridge\@samba.org
59 Usage: pidl.pl [options] <idlfile>
63 --output OUTNAME put output in OUTNAME.*
64 --parse parse a idl file to a .pidl file
65 --dump dump a pidl file back to idl
66 --header create a C header file
67 --parser create a C parser
68 --server create server boilterplate
69 --template print a template for a pipe
70 --eparser create an ethereal parser
71 --diff run diff on the idl and dumped output
72 --keep keep the .pidl file
79 'help|h|?' => \$opt_help,
80 'output=s' => \$opt_output,
81 'parse' => \$opt_parse,
83 'header' => \$opt_header,
84 'server' => \$opt_server,
85 'template' => \$opt_template,
86 'parser' => \$opt_parser,
87 'eparser' => \$opt_eparser,
103 my $basename = basename($idl_file, ".idl");
105 if (!defined($opt_output)) {
108 $output = $opt_output . $basename;
111 my($pidl_file) = util::ChangeExtension($output, ".pidl");
113 print "Compiling $idl_file\n";
116 $pidl = IdlParse($idl_file);
117 defined $pidl || die "Failed to parse $idl_file";
118 IdlValidator::Validate($pidl);
119 if ($opt_keep && !util::SaveStructure($pidl_file, $pidl)) {
120 die "Failed to save $pidl_file\n";
123 $pidl = util::LoadStructure($pidl_file);
124 defined $pidl || die "Failed to load $pidl_file - maybe you need --parse\n";
128 print IdlDump::Dump($pidl);
132 my($header) = util::ChangeExtension($output, ".h");
133 util::FileSave($header, IdlHeader::Parse($pidl));
137 my($server) = util::ChangeExtension($output, "_s.c");
138 util::FileSave($server, IdlServer::Parse($pidl));
142 my($parser) = util::ChangeExtension($output, ".c");
143 IdlParser::Parse($pidl, $parser);
147 my($parser) = util::ChangeExtension($output, "_ethereal.c");
148 util::FileSave($parser, IdlEParser::Parse($pidl));
152 my($tempfile) = util::ChangeExtension($output, ".tmp");
153 util::FileSave($tempfile, IdlDump::Dump($pidl));
154 system("diff -wu $idl_file $tempfile");
159 print IdlTemplate::Parse($pidl);
164 foreach my $filename (@ARGV) {
165 process_file($filename);