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";
34 #####################################################################
35 # parse an IDL file returning a structure containing all the data
38 # this autoaction allows us to handle simple nodes without an action
40 $::RD_AUTOACTION = q {
41 $#item==1 && ref($item[1]) eq "" ?
43 "XX_" . $item[0] . "_XX[$#item]" };
44 my($filename) = shift;
45 my($parser) = idl->new;
49 my($idl) = $parser->idl(`cpp $filename | grep -v '^#'`);
51 util::CleanData($idl);
56 #########################################
61 perl IDL parser and code generator
62 Copyright (C) tridge\@samba.org
64 Usage: pidl.pl [options] <idlfile>
68 --output OUTNAME put output in OUTNAME.*
69 --parse parse a idl file to a .pidl file
70 --dump dump a pidl file back to idl
71 --header create a C header file
72 --parser create a C parser
73 --eparser create an ethereal parser
74 --diff run diff on the idl and dumped output
75 --keep keep the .pidl file
82 'help|h|?' => \$opt_help,
83 'output=s' => \$opt_output,
84 'parse' => \$opt_parse,
86 'header' => \$opt_header,
87 'parser' => \$opt_parser,
88 'eparser' => \$opt_eparser,
100 my $idl_file = shift;
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");
114 print "Generating $pidl_file from $idl_file\n";
115 my($idl) = IdlParse($idl_file);
116 defined $idl || die "Failed to parse $idl_file";
117 util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
119 IdlValidator::Validate($idl);
123 my($idl) = util::LoadStructure($pidl_file);
124 print IdlDump::Dump($idl);
128 my($idl) = util::LoadStructure($pidl_file);
129 my($header) = util::ChangeExtension($output, "h");
130 print "Generating $header\n";
131 util::FileSave($header, IdlHeader::Parse($idl));
135 my($idl) = util::LoadStructure($pidl_file);
136 my($parser) = util::ChangeExtension($output, "c");
137 print "Generating $parser\n";
138 IdlParser::Parse($idl, $parser);
142 my($idl) = util::LoadStructure($pidl_file);
143 my($parser) = util::ChangeExtension($output, "c");
144 print "Generating $parser for ethereal\n";
145 util::FileSave($parser, IdlEParser::Parse($idl));
149 my($idl) = util::LoadStructure($pidl_file);
150 my($tempfile) = util::ChangeExtension($output, "tmp");
151 util::FileSave($tempfile, IdlDump::Dump($idl));
152 system("diff -wu $idl_file $tempfile");
157 system("rm -f $pidl_file");
162 foreach my $filename (@ARGV) {
163 process_file($filename);