-
Notifications
You must be signed in to change notification settings - Fork 1
/
mksectiontable
executable file
·125 lines (109 loc) · 3.56 KB
/
mksectiontable
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
#!/usr/bin/perl
use Getopt::Long;
use DBI;
use Env qw(LSBUSER LSBDBPASSWD LSBDB LSBDBHOST);
sub usage()
{
print STDERR "mksectiontable -a <archname> -s <stdname> -t <tabletitle> -v <lsbversion>\n";
die;
}
# Uncomment to trace SQL statments
#$trace=1;
#
# 1) process the arguments
#
GetOptions("a=s" => \$archname,
"s=s" => \$stdname,
"v=s" => \$lsbversion,
"t=s" => \$title);
if( !$archname ) { usage(); }
if( !$stdname ) { usage(); }
if( !$title ) { usage(); }
if( !$lsbversion ) { usage(); }
#
# 2) Establish connection to the database
#
$dbh = DBI->connect('DBI:mysql:database='.$LSBDB.';host='.$LSBDBHOST, $LSBUSER, $LSBDBPASSWD)
or die "Couldn't connect to database: ".DBI->errstr;
#
# 3) get & print the architecture info
#
$select = "SELECT * FROM Architecture WHERE ";
$select.= "Architecture.Aname=".$dbh->quote($archname);
print STDERR $select,"\n" if $trace;
$sth = $dbh->prepare($select) or die "Couldn't prepare $select query: ".DBI->errstr;
$sth->execute or die "Couldn't execute $select query: ".DBI->errstr;
$entry=$sth->fetchrow_hashref;
$sth->finish;
$Aid=$entry->{'Aid'};
$Aname=$entry->{'Aname'};
if( not $Aname ) {
die "Unsupported architecture";
}
#
# 4) Get the data
#
$select = "SELECT * ";
$select.= "FROM ElfSections ";
$select.= "LEFT JOIN ArchES ON AESesid=ESid ";
$select.= "INNER JOIN Standard on AESstd=Sid ";
$select.= "LEFT JOIN SectionTypes ON STid=AEStype ";
$select.= "WHERE Sname=".$dbh->quote($stdname);
$select.= " AND AESaid=$Aid";
$select.= " AND (AESappearedin <= '$lsbversion' and AESappearedin<>'') ";
$select.= " AND (AESwithdrawnin IS NULL OR AESwithdrawnin > '$lsbversion')";
$select.= " ORDER BY ElfSections.ESname ";
$sth = $dbh->prepare($select) or die "Couldn't prepare $select query: ".DBI->errstr;
$sth->execute or die "Couldn't execute $select query: ".DBI->errstr;
printf("<!-- Start of generated text - do not edit! -->\n");
printf("<!-- generated from the LSB specification database by mksectiontable -->\n");
if($sth->rows) {
print "<TABLE>\n";
print "<TITLE>$title</TITLE>\n";
print "<TGROUP COLS=3>\n";
print "<THEAD>\n";
print "<ROW>\n";
print "<ENTRY ALIGN=center>Name</ENTRY>";
print "<ENTRY ALIGN=center>Type</ENTRY>";
print "<ENTRY ALIGN=center>Attributes</ENTRY>";
print "</ROW>\n";
print "</THEAD>\n";
print "<TBODY>\n";
for(1..$sth->rows) {
print "<ROW>";
$entry=$sth->fetchrow_hashref;
printf "<ENTRY>%s</ENTRY>",$entry->{'ESname'};
printf "<ENTRY>%s</ENTRY>",$entry->{'STname'};
printf "<ENTRY>%s</ENTRY>",$entry->{'AESattributes'};
print "</ROW>\n";
}
print "</TBODY>\n";
print "</TGROUP>\n";
print "</TABLE>\n";
}
$sth->finish;
$select = "SELECT * ";
$select.= "FROM Standard,ElfSections ";
$select.= "LEFT JOIN ArchES ON AESesid=ESid ";
$select.= "WHERE AESstd=Sid and Sname=".$dbh->quote($stdname);
$select.= " AND AESaid=$Aid";
$select.= " AND (AESappearedin <= '$lsbversion' and AESappearedin<>'') ";
$select.= " AND (AESwithdrawnin IS NULL OR AESwithdrawnin > '$lsbversion')";
$select.= " ORDER BY ElfSections.ESname ";
#print $select,"\n";
$sth = $dbh->prepare($select) or die "Couldn't prepare $select query: ".DBI->errstr;
$sth->execute or die "Couldn't execute $select query: ".DBI->errstr;
if($sth->rows) {
print "<VARIABLELIST>\n";
for(1..$sth->rows) {
print "<VARLISTENTRY>";
$entry=$sth->fetchrow_hashref;
printf "<TERM>%s</TERM>",$entry->{'ESname'};
printf "<LISTITEM><PARA>%s</PARA></LISTITEM>",$entry->{'AESdescription'};
print "</VARLISTENTRY>\n";
}
print "</VARIABLELIST>\n";
}
$sth->finish;
$dbh->disconnect;
printf("<!-- End of text generated from database -->\n");