1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#!/usr/bin/perl -w
###################################################
# package to parse IDL files and generate code for
# rpc functions in Samba
# Copyright tridge@samba.org 2000
# released under the GNU GPL
use strict;
my($PIDLBASE) = "$ENV{HOME}/pidl";
use lib "$ENV{HOME}/pidl";
use Getopt::Long;
use Data::Dumper;
use Parse::RecDescent;
use dump;
use header;
use parser;
use eparser;
use client;
use util;
my($opt_help) = 0;
my($opt_parse) = 0;
my($opt_dump) = 0;
my($opt_diff) = 0;
my($opt_header) = 0;
my($opt_parser) = 0;
my($opt_eparser) = 0;
my($opt_client);
my($opt_keep) = 0;
my($opt_output);
#####################################################################
# parse an IDL file returning a structure containing all the data
sub IdlParse($)
{
# this autoaction allows us to handle simple nodes without an action
# $::RD_TRACE = 1;
$::RD_AUTOACTION = q {
$#item==1 && ref($item[1]) eq "" ?
$item[1] :
"XX_" . $item[0] . "_XX[$#item]" };
my($filename) = shift;
my($grammer) = util::FileLoad("$PIDLBASE/idl.gram");
my($parser) = Parse::RecDescent->new($grammer);
my($saved_sep) = $/;
undef $/;
my($idl) = $parser->idl(`cpp $filename`);
$/ = $saved_sep;
util::CleanData($idl);
return $idl;
}
#########################################
# display help text
sub ShowHelp()
{
print "
perl IDL parser and code generator
Copyright (C) tridge\@samba.org
Usage: pidl.pl [options] <idlfile>
Options:
--help this help page
--output OUTNAME put output in OUTNAME.*
--parse parse a idl file to a .pidl file
--dump dump a pidl file back to idl
--header create a C header file
--parser create a C parser
--eparser create an ethereal parser
--client FILENAME create client calls in FILENAME
--diff run diff on the idl and dumped output
--keep keep the .pidl file
\n";
exit(0);
}
# main program
GetOptions (
'help|h|?' => \$opt_help,
'output=s' => \$opt_output,
'parse' => \$opt_parse,
'dump' => \$opt_dump,
'header' => \$opt_header,
'parser' => \$opt_parser,
'eparser' => \$opt_eparser,
'client=s' => \$opt_client,
'diff' => \$opt_diff,
'keep' => \$opt_keep
);
if ($opt_help) {
ShowHelp();
exit(0);
}
my($idl_file) = shift;
die "ERROR: You must specify an idl file to process" unless ($idl_file);
if (!defined($opt_output)) {
$opt_output = $idl_file;
}
my($pidl_file) = util::ChangeExtension($opt_output, "pidl");
if ($opt_parse) {
print "Generating $pidl_file from $idl_file\n";
my($idl) = IdlParse($idl_file);
util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
}
if ($opt_dump) {
my($idl) = util::LoadStructure($pidl_file);
print IdlDump::Dump($idl);
}
if ($opt_header) {
my($idl) = util::LoadStructure($pidl_file);
my($header) = util::ChangeExtension($opt_output, "h");
print "Generating $header\n";
util::FileSave($header, IdlHeader::Parse($idl));
}
if ($opt_parser) {
my($idl) = util::LoadStructure($pidl_file);
my($parser) = util::ChangeExtension($opt_output, "c");
print "Generating $parser\n";
util::FileSave($parser, IdlParser::Parse($idl));
}
if ($opt_eparser) {
my($idl) = util::LoadStructure($pidl_file);
my($parser) = util::ChangeExtension($opt_output, "c");
print "Generating $parser for ethereal\n";
util::FileSave($parser, IdlEParser::Parse($idl));
}
if ($opt_client) {
my($idl) = util::LoadStructure($pidl_file);
my($client) = util::ChangeExtension($opt_client, "c");
print "Generating $client client calls\n";
util::FileSave($client, IdlClient::Parse($idl));
}
if ($opt_diff) {
my($idl) = util::LoadStructure($pidl_file);
my($tempfile) = util::ChangeExtension($opt_output, "tmp");
util::FileSave($tempfile, IdlDump::Dump($idl));
system("diff -wu $idl_file $tempfile");
unlink($tempfile);
}
if (!$opt_keep) {
system("rm -f $pidl_file");
}
|