3 ###################################################
4 # package to parse IDL files and generate code for
5 # rpc functions in Samba
6 # Copyright tridge@samba.org 2000
7 # released under the GNU GPL
11 my($PIDLBASE) = "$ENV{HOME}/pidl";
12 use lib "$ENV{HOME}/pidl";
16 use Parse::RecDescent;
33 #####################################################################
34 # parse an IDL file returning a structure containing all the data
37 # this autoaction allows us to handle simple nodes without an action
39 $::RD_AUTOACTION = q {
40 $#item==1 && ref($item[1]) eq "" ?
42 "XX_" . $item[0] . "_XX[$#item]" };
43 my($filename) = shift;
44 my($grammer) = util::FileLoad("$PIDLBASE/idl.gram");
45 my($parser) = Parse::RecDescent->new($grammer);
49 my($idl) = $parser->idl(`cpp $filename`);
51 util::CleanData($idl);
56 #########################################
61 perl IDL parser and code generator
62 Copyright 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,
98 my($idl_file) = shift;
99 die "ERROR: You must specify an idl file to process" unless ($idl_file);
101 if (!defined($opt_output)) {
102 $opt_output = $idl_file;
105 my($pidl_file) = util::ChangeExtension($opt_output, "pidl");
108 print "Generating $pidl_file from $idl_file\n";
109 my($idl) = IdlParse($idl_file);
110 util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
114 my($idl) = util::LoadStructure($pidl_file);
115 print IdlDump::Dump($idl);
119 my($idl) = util::LoadStructure($pidl_file);
120 my($header) = util::ChangeExtension($opt_output, "h");
121 print "Generating $header\n";
122 util::FileSave($header, IdlHeader::Dump($idl));
126 my($idl) = util::LoadStructure($pidl_file);
127 my($parser) = util::ChangeExtension($opt_output, "c");
128 print "Generating $parser\n";
129 util::FileSave($parser, IdlParser::Parse($idl));
133 my($idl) = util::LoadStructure($pidl_file);
134 my($parser) = util::ChangeExtension($opt_output, "c");
135 print "Generating $parser for ethereal\n";
136 util::FileSave($parser, IdlEParser::Parse($idl));
140 my($idl) = util::LoadStructure($pidl_file);
141 my($tempfile) = util::ChangeExtension($opt_output, "tmp");
142 util::FileSave($tempfile, IdlDump::Dump($idl));
143 system("diff -wu $idl_file $tempfile");
148 system("rm -f $pidl_file");