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;
35 #####################################################################
36 # parse an IDL file returning a structure containing all the data
39 # this autoaction allows us to handle simple nodes without an action
41 $::RD_AUTOACTION = q {
42 $#item==1 && ref($item[1]) eq "" ?
44 "XX_" . $item[0] . "_XX[$#item]" };
45 my($filename) = shift;
46 my($grammer) = util::FileLoad("$PIDLBASE/idl.gram");
47 my($parser) = Parse::RecDescent->new($grammer);
51 my($idl) = $parser->idl(`cpp $filename`);
53 util::CleanData($idl);
58 #########################################
63 perl IDL parser and code generator
64 Copyright (C) tridge\@samba.org
66 Usage: pidl.pl [options] <idlfile>
70 --output OUTNAME put output in OUTNAME.*
71 --parse parse a idl file to a .pidl file
72 --dump dump a pidl file back to idl
73 --header create a C header file
74 --parser create a C parser
75 --eparser create an ethereal parser
76 --client FILENAME create client calls in FILENAME
77 --diff run diff on the idl and dumped output
78 --keep keep the .pidl file
85 'help|h|?' => \$opt_help,
86 'output=s' => \$opt_output,
87 'parse' => \$opt_parse,
89 'header' => \$opt_header,
90 'parser' => \$opt_parser,
91 'eparser' => \$opt_eparser,
92 'client=s' => \$opt_client,
102 my($idl_file) = shift;
103 die "ERROR: You must specify an idl file to process" unless ($idl_file);
105 if (!defined($opt_output)) {
106 $opt_output = $idl_file;
109 my($pidl_file) = util::ChangeExtension($opt_output, "pidl");
112 print "Generating $pidl_file from $idl_file\n";
113 my($idl) = IdlParse($idl_file);
114 util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
118 my($idl) = util::LoadStructure($pidl_file);
119 print IdlDump::Dump($idl);
123 my($idl) = util::LoadStructure($pidl_file);
124 my($header) = util::ChangeExtension($opt_output, "h");
125 print "Generating $header\n";
126 util::FileSave($header, IdlHeader::Parse($idl));
130 my($idl) = util::LoadStructure($pidl_file);
131 my($parser) = util::ChangeExtension($opt_output, "c");
132 print "Generating $parser\n";
133 util::FileSave($parser, IdlParser::Parse($idl));
137 my($idl) = util::LoadStructure($pidl_file);
138 my($parser) = util::ChangeExtension($opt_output, "c");
139 print "Generating $parser for ethereal\n";
140 util::FileSave($parser, IdlEParser::Parse($idl));
144 my($idl) = util::LoadStructure($pidl_file);
145 my($client) = util::ChangeExtension($opt_client, "c");
146 print "Generating $client client calls\n";
147 util::FileSave($client, IdlClient::Parse($idl));
151 my($idl) = util::LoadStructure($pidl_file);
152 my($tempfile) = util::ChangeExtension($opt_output, "tmp");
153 util::FileSave($tempfile, IdlDump::Dump($idl));
154 system("diff -wu $idl_file $tempfile");
159 system("rm -f $pidl_file");