-
Notifications
You must be signed in to change notification settings - Fork 1
/
mksynop
executable file
·239 lines (208 loc) · 6.12 KB
/
mksynop
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#! /usr/bin/perl -I../build_env
#
# mksynop
# - write out the XML/SGML synopsis for function/interface X
# from info in the db.
#
use DBI;
use Env qw(LSBUSER LSBDBPASSWD LSBDB LSBDBHOST);
use strict;
use Getopt::Long;
use specdb;
my $level = 0;
my $dbh;
my $lsbversion;
my $arch;
my $Aid;
#
#
sub indent($) {
# function abandoned
}
#
# return <tag>content<tag>
# suitably indented.
#
sub tag($$$) {
my ( $tagname, $content, $multiline ) = @_;
my $retstr = "";
$level += 2;
$retstr .= indent($level);
if ($multiline) {
$retstr .= sprintf( "<%s>\n", $tagname );
$level += 2;
$retstr .= indent($level);
$retstr .= sprintf( "%s\n", $content );
$level -= 2;
$retstr .= sprintf( "</%s>", $tagname );
}
else {
$retstr .= sprintf( "<%s>%s</%s>\n", $tagname, $content, $tagname );
}
$level -= 2;
return $retstr;
}
sub function($) {
my ($name) = @_;
return tag( "function", $name, 0 );
}
sub funcdef($$) {
my ( $type, $name ) = @_;
return tag( "funcdef",
sprintf( "%s\n%s%s", $type, indent( $level + 2 ), function($name) ),
0 );
}
sub paramdef($$) {
my ( $type, $name ) = @_;
return "<void>" if ( !defined($type) || $type eq "" || $type eq "void" );
return "<varargs>" if ( $type eq "..." );
return tag( "paramdef",
sprintf( "%s\n%s%s", $type, indent( $level + 2 ), parameter($name) ),
0 );
}
sub parameter($) {
my ($name) = @_;
tag( "parameter", $name, 0 );
}
sub refsynopsisdiv($) {
my ($content) = @_;
tag( "refsynopsisdiv", $content, 1 );
}
sub funcsynopsisinfo($) {
my ($hdr) = @_;
return tag( "funcsynopsisinfo", $hdr, 1 );
}
sub funcsynopsis($$$) {
my ( $hdrinfo, $funcdef, $args ) = @_;
my $argstr = "";
for my $arg (@$args) {
$level += 2;
$argstr .= paramdef( $arg->{'type'}, $arg->{name} );
$level -= 2;
}
tag( "funcsynopsis",
sprintf( "%s%s%s", $hdrinfo, funcprototype( $funcdef . $argstr ) ), 1 );
}
sub funcprototype($) {
my ($hdr) = @_;
return tag( "funcprototype", $hdr, 1 );
}
sub trim($) {
my ($str) = @_;
$str =~ s/^ *(.*)$/\1/;
$str =~ s/(.*) +$/\1/;
return $str;
}
sub usage() {
die "Usage: mksynop -v <lsbversion> -a <archname> [<interface_name> ...]\n";
}
GetOptions( "v=s" => \$lsbversion, "a=s" => \$arch );
if ( !$lsbversion ) { usage(); }
my @args;
die "Invalid database" if ( !defined($LSBDB) || $LSBDB eq "" );
$dbh = DBI->connect( 'DBI:mysql:database=' . $LSBDB . ';host=' . $LSBDBHOST,
$LSBUSER, $LSBDBPASSWD )
or die "Couldn't connect to database: " . DBI->errstr;
$specdb::dbh = $dbh;
specdb::prepareQueries();
if ( !$arch ) {
print STDERR
"Generating generic information. Note that synopsis can vary on different architectures.\n";
$Aid = 1;
}
else {
my $select = "SELECT Aid FROM Architecture WHERE Aname='$arch'";
my $th = $dbh->prepare($select)
or die "Couldn't prepare $select query: " . DBI->errstr;
$th->execute or die "Couldn't execute $select query: " . DBI->errstr;
my $entry = $th->fetchrow_hashref;
$th->finish;
if ( $entry->{'Aid'} ) {
$Aid = $entry->{'Aid'};
}
else {
die "Illegal architecture\n";
}
}
$specdb::ArchId = $Aid;
#
# we need four things from the db for the interface in $ARGV[0]
# - the name (well, we've got that anyway)
# - the header file with the prototype
# - the type (as a string)
# - an array of its parameters (in the right order!), [basically, we
# can only get their type at this time, so make up names for these]
#
for my $func (@ARGV) {
my $sql = "select * from Interface ";
$sql .= "left join ArchInt on Iid=AIint ";
$sql .= "left join Type on Tid=AIreturn ";
$sql .= "left join Header on Hid=Iheader ";
$sql .= "where ";
$sql .= "Iname='$func' and ";
$sql .= "Itype='Function' AND ";
$sql .= "(Isrcbin ='SrcOnly' ";
$sql .= "OR ( AIappearedin <= '$lsbversion' AND AIappearedin > '' ";
$sql .= "AND (AIwithdrawnin IS NULL OR AIwithdrawnin >'$lsbversion') ) ) ";
my $sth = $dbh->prepare($sql)
or die "Couldn't prepare $sql query: " . DBI->errstr;
$sth->execute or die "Couldn't execute $sql query: " . DBI->errstr;
if ( $sth->rows() > 0 ) {
my $entry = $sth->fetchrow_hashref;
$sth->finish;
$specdb::TMaid = $Aid;
my $nameonly = 0;
if( $entry->{'Ttype'} eq 'FuncPtr' ) {
$specdb::funcPtrName = $entry->{'Iname'};
$nameonly = 1;
}
my $type = specdb::displaytyperef($entry, $nameonly);
my $hdr = sprintf( "#include <%s>", $entry->{'Hname'} );
#
# and now the args ...
#
my $pos = 0;
my $Iid = $entry->{'Iid'};
$sql = "select * from Parameter,Type ";
$sql .= "left join ArchType on ATtid=Tid ";
$sql .= "where Pint=$Iid and Ptype=Tid AND ATaid IN (1,$Aid) ";
$sql .= "group by Ppos,ATtid order by Ppos";
# Note that arch specific basetype will not be handled here correctly
$sth = $dbh->prepare($sql)
or die "Couldn't prepare $sql query: " . DBI->errstr;
$sth->execute or die "Couldn't execute $sql query: " . DBI->errstr;
my $argno = 0;
if ( $sth->rows == 0 ) {
# a void ...
push(
@args,
{
'type' => undef,
'name' => "irrelevant",
}
);
}
while ( ( $entry = $sth->fetchrow_hashref ) ) {
my $argname = $entry->{'Pname'} ? $entry->{'Pname'} : sprintf( "arg%d", $argno++ );
my $argtype = specdb::displaytyperef($entry,0);
push(
@args,
{
'type' => $argtype,
'name' => $argname,
}
);
}
printf "%s\n",
refsynopsisdiv(
funcsynopsis(
funcsynopsisinfo($hdr), funcdef( $type, $func ), \@args
)
);
}
else {
printf "%s: no such interface\n", $func;
}
$sth->finish;
}
$dbh->disconnect;