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
12 use Parse::RecDescent;
27 #####################################################################
28 # parse an IDL file returning a structure containing all the data
31 # this autoaction allows us to handle simple nodes without an action
33 $::RD_AUTOACTION = q {
34 $#item==1 && ref($item[1]) eq "" ?
36 "XX_" . $item[0] . "_XX[$#item]" };
37 my($filename) = shift;
38 my($grammer) = util::FileLoad("idl.gram");
39 my($parser) = Parse::RecDescent->new($grammer);
42 my($idl) = $parser->idl(`cpp $filename`);
44 util::CleanData($idl);
49 #########################################
54 perl IDL parser and code generator
55 Copyright tridge\@samba.org
57 Usage: pidl.pl [options] <idlfile>
61 --parse parse a idl file to a .pidl file
62 --dump dump a pidl file back to idl
63 --header create a C header file
64 --parser create a C parser
65 --eparser create an ethereal parser
66 --diff run diff on the idl and dumped output
73 'help|h|?' => \$opt_help,
74 'parse' => \$opt_parse,
76 'header' => \$opt_header,
77 'parser' => \$opt_parser,
78 'eparser' => \$opt_eparser,
87 my($idl_file) = shift;
88 die "ERROR: You must specify an idl file to process" unless ($idl_file);
90 my($pidl_file) = util::ChangeExtension($idl_file, "pidl");
93 print "Generating $pidl_file\n";
94 my($idl) = IdlParse($idl_file);
95 util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
99 my($idl) = util::LoadStructure($pidl_file);
100 print IdlDump::Dump($idl);
104 my($idl) = util::LoadStructure($pidl_file);
105 my($header) = util::ChangeExtension($idl_file, "h");
106 print "Generating $header\n";
107 util::FileSave($header, IdlHeader::Dump($idl));
111 my($idl) = util::LoadStructure($pidl_file);
112 my($parser) = util::ChangeExtension($idl_file, "c");
113 print "Generating $parser\n";
114 util::FileSave($parser, IdlParser::Parse($idl));
118 my($idl) = util::LoadStructure($pidl_file);
119 my($parser) = util::ChangeExtension($idl_file, "c");
120 print "Generating $parser for ethereal\n";
121 util::FileSave($parser, IdlEParser::Parse($idl));
125 my($idl) = util::LoadStructure($pidl_file);
126 my($tempfile) = util::ChangeExtension($idl_file, "tmp");
127 util::FileSave($tempfile, IdlDump::Dump($idl));
128 system("diff -wu $idl_file $tempfile");