-
Notifications
You must be signed in to change notification settings - Fork 1
/
mksecttypestable
executable file
·102 lines (86 loc) · 2.66 KB
/
mksecttypestable
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
#!/usr/bin/perl
use Getopt::Long;
use DBI;
use Env qw(LSBUSER LSBDBPASSWD LSBDB LSBDBHOST);
sub usage()
{
print STDERR "mksecttypestable -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(); }
# lsbversion support added for consistency, not used yet
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";
}
$select = "SELECT * ";
$select.= "FROM SectionTypes,Standard ";
$select.= "WHERE STstandard=Sid and Sname=".$dbh->quote($stdname);
$select.= " AND STarch=$Aid";
$select.= " ORDER BY SectionTypes.STname ";
#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;
printf("<!-- Start of generated text - do not edit! -->\n");
printf("<!-- generated from the LSB specification database by mksecttypestable -->\n");
#
# Tables need IDs so we can XREF them ...
#
local $tbl_id;
$tbl_id = "tbl.$stdname";
printf "<TABLE ID=%s>\n", $tbl_id;
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>Value</ENTRY>";
print "<ENTRY ALIGN=center>Description</ENTRY>";
print "</ROW>\n";
print "</THEAD>\n";
print "<TBODY>\n";
for(1..$sth->rows) {
print "<ROW>";
$entry=$sth->fetchrow_hashref;
$stname = $entry->{'STname'};
$stname =~s/\_//g;
printf "<ENTRY ID=\"Secttype.%s\" XREFLABEL=\"%s\">%s</ENTRY>",
$stname, $entry->{'STname'}, $entry->{'STname'};
printf "<ENTRY>0x%x</ENTRY>",$entry->{'STvalue'};
printf "<ENTRY>%s</ENTRY>",$entry->{'STdescription'};
print "</ROW>\n";
}
$sth->finish;
$dbh->disconnect;
print "</TBODY>\n";
print "</TGROUP>\n";
print "</TABLE>\n";
printf("<!-- End of text generated from database -->\n");