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);
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($parser) = idl->new;
48 my($idl) = $parser->idl(`cpp $filename | grep -v '^#'`);
50 util::CleanData($idl);
55 #########################################
60 perl IDL parser and code generator
61 Copyright (C) tridge\@samba.org
63 Usage: pidl.pl [options] <idlfile>
67 --output OUTNAME put output in OUTNAME.*
68 --parse parse a idl file to a .pidl file
69 --dump dump a pidl file back to idl
70 --header create a C header file
71 --parser create a C parser
72 --eparser create an ethereal parser
73 --client FILENAME create client calls in FILENAME
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,
89 'client=s' => \$opt_client,
99 my($idl_file) = shift;
100 die "ERROR: You must specify an idl file to process" unless ($idl_file);
102 if (!defined($opt_output)) {
103 $opt_output = $idl_file;
106 my($pidl_file) = util::ChangeExtension($opt_output, "pidl");
109 print "Generating $pidl_file from $idl_file\n";
110 my($idl) = IdlParse($idl_file);
111 defined $idl || die "Failed to parse $idl_file";
112 util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
116 my($idl) = util::LoadStructure($pidl_file);
117 print IdlDump::Dump($idl);
121 my($idl) = util::LoadStructure($pidl_file);
122 my($header) = util::ChangeExtension($opt_output, "h");
123 print "Generating $header\n";
124 util::FileSave($header, IdlHeader::Parse($idl));
128 my($idl) = util::LoadStructure($pidl_file);
129 my($parser) = util::ChangeExtension($opt_output, "c");
130 print "Generating $parser\n";
131 IdlParser::Parse($idl, $parser);
135 my($idl) = util::LoadStructure($pidl_file);
136 my($parser) = util::ChangeExtension($opt_output, "c");
137 print "Generating $parser for ethereal\n";
138 util::FileSave($parser, IdlEParser::Parse($idl));
142 my($idl) = util::LoadStructure($pidl_file);
143 my($client) = util::ChangeExtension($opt_client, "c");
144 print "Generating $client client calls\n";
145 util::FileSave($client, IdlClient::Parse($idl));
149 my($idl) = util::LoadStructure($pidl_file);
150 my($tempfile) = util::ChangeExtension($opt_output, "tmp");
151 util::FileSave($tempfile, IdlDump::Dump($idl));
152 system("diff -wu $idl_file $tempfile");
157 system("rm -f $pidl_file");