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 | grep -v '^#'`);
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 defined $idl || die "Failed to parse $idl_file";
115 util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
119 my($idl) = util::LoadStructure($pidl_file);
120 print IdlDump::Dump($idl);
124 my($idl) = util::LoadStructure($pidl_file);
125 my($header) = util::ChangeExtension($opt_output, "h");
126 print "Generating $header\n";
127 util::FileSave($header, IdlHeader::Parse($idl));
131 my($idl) = util::LoadStructure($pidl_file);
132 my($parser) = util::ChangeExtension($opt_output, "c");
133 print "Generating $parser\n";
134 util::FileSave($parser, IdlParser::Parse($idl));
138 my($idl) = util::LoadStructure($pidl_file);
139 my($parser) = util::ChangeExtension($opt_output, "c");
140 print "Generating $parser for ethereal\n";
141 util::FileSave($parser, IdlEParser::Parse($idl));
145 my($idl) = util::LoadStructure($pidl_file);
146 my($client) = util::ChangeExtension($opt_client, "c");
147 print "Generating $client client calls\n";
148 util::FileSave($client, IdlClient::Parse($idl));
152 my($idl) = util::LoadStructure($pidl_file);
153 my($tempfile) = util::ChangeExtension($opt_output, "tmp");
154 util::FileSave($tempfile, IdlDump::Dump($idl));
155 system("diff -wu $idl_file $tempfile");
160 system("rm -f $pidl_file");