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 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 --client FILENAME create client calls in FILENAME
75 --diff run diff on the idl and dumped output
76 --keep keep the .pidl file
83 'help|h|?' => \$opt_help,
84 'output=s' => \$opt_output,
85 'parse' => \$opt_parse,
87 'header' => \$opt_header,
88 'parser' => \$opt_parser,
89 'eparser' => \$opt_eparser,
90 'client=s' => \$opt_client,
100 my($idl_file) = shift;
101 die "ERROR: You must specify an idl file to process" unless ($idl_file);
103 if (!defined($opt_output)) {
104 $opt_output = $idl_file;
107 my($pidl_file) = util::ChangeExtension($opt_output, "pidl");
110 print "Generating $pidl_file from $idl_file\n";
111 my($idl) = IdlParse($idl_file);
112 defined $idl || die "Failed to parse $idl_file";
113 util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
117 my($idl) = util::LoadStructure($pidl_file);
118 print IdlDump::Dump($idl);
122 my($idl) = util::LoadStructure($pidl_file);
123 my($header) = util::ChangeExtension($opt_output, "h");
124 print "Generating $header\n";
125 util::FileSave($header, IdlHeader::Parse($idl));
129 my($idl) = util::LoadStructure($pidl_file);
130 my($parser) = util::ChangeExtension($opt_output, "c");
131 print "Generating $parser\n";
132 IdlParser::Parse($idl, $parser);
136 my($idl) = util::LoadStructure($pidl_file);
137 my($parser) = util::ChangeExtension($opt_output, "c");
138 print "Generating $parser for ethereal\n";
139 util::FileSave($parser, IdlEParser::Parse($idl));
143 my($idl) = util::LoadStructure($pidl_file);
144 my($client) = util::ChangeExtension($opt_client, "c");
145 print "Generating $client client calls\n";
146 util::FileSave($client, IdlClient::Parse($idl));
150 my($idl) = util::LoadStructure($pidl_file);
151 my($tempfile) = util::ChangeExtension($opt_output, "tmp");
152 util::FileSave($tempfile, IdlDump::Dump($idl));
153 system("diff -wu $idl_file $tempfile");
158 system("rm -f $pidl_file");