-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmkstandardsgmltable
More file actions
executable file
·195 lines (169 loc) · 5.51 KB
/
Copy pathmkstandardsgmltable
File metadata and controls
executable file
·195 lines (169 loc) · 5.51 KB
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
#!/usr/bin/perl
use Carp;
use Getopt::Long;
use DBI;
use HTML::Entities;
use Env qw(LSBUSER LSBDBPASSWD LSBDB LSBDBHOST);
sub usage()
{
print STDERR <<"EOM"
mkstandardsgmltable -a <archname> [-v <lsbversion> [-m <submodule>]] [-s <specids>] [-x <exclids>] [-t <spectype>]
Generate SGML table of referenced standards.
-a Architecture.
-v LSB Version.
The following options take a single name or a comma-separated list:
-m SubModule name(s). If specified, entries from the SModStd table will
be taken into account. If this option is set, LSB Version must
also be specified, too.
-s Spec identifier(s) (Standard.Sid) to be included in the table.
-x Spec identifier(s) (Standard.Sid) that should not be included in
the table, even if they would be selected in other ways.
-t Type of specification(s) (Standard.Stype) that should be taken into
account when generating. Default is "'Standard','Reference'".
EOM
; exit(1);
}
# make sure a string (including a list) is quoted properly for mysql
sub quote($)
{
my ($type) = @_;
return $type if ($type =~ /^'.*'$/);
my @tlist = split(/,/, $type);
foreach $t (@tlist) {
$t = "'$t'" if ($t !~ /^'.*'$/);
}
return join(',', @tlist);
}
# Uncomment to trace SQL statments
#$trace=1;
#
# 1) process the arguments
#
my $Stype="'Standard','Reference'";
GetOptions( "a=s" => \$archname,
"s=s" => \$specids,
"x=s" => \$exclids,
"m=s" => \$submodule,
"v=s" => \$lsbversion,
"t=s" => \$Stype,
);
if( !$archname && !$specids ) { usage(); }
if( $submodule && !$lsbversion ) {
die "When specifying submodule name, you should also specify target LSB version.";
}
#
# 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 architecture info
#
if( $archname ) {
$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'};
if( not $entry->{'Aname'} ) {
die "Unsupported architecture";
}
} else {
$Aid=0;
}
#
# 4) get submodule info
#
if( $submodule ) {
if( $submodule !~ /^'/ ) {
$submodule = "'$submodule'";
$submodule =~ s/\s//g; # drop spaces, if any
$submodule =~ s/,/','/g;
}
$select = "SELECT GROUP_CONCAT(SMid SEPARATOR ',') FROM SubModule WHERE ";
$select.= "SMname IN ($submodule)";
print STDERR $select,"\n" if $trace;
($SMid) = $dbh->selectrow_array($select) or die "Couldn't prepare $select query: ".DBI->errstr;
if( not $SMid ) {
die "Unknown submodule(s)";
}
} else {
$SMid=0;
}
# check Stype is quoted properly
$Stype = quote($Stype);
#
# 5) Get Standards. Include those standards that are listed in the $specids
# or which assigned to $submodule in the $lsbversion. Exclude entries
# listed in the $exclids.
#
$select = "SELECT DISTINCT Standard.* FROM Standard ";
if( $SMid ) {
$select.= "LEFT JOIN SModStd ON SMSsid=Sid ";
}
$select.= "WHERE Stype IN ($Stype) ";
if( $lsbversion ) {
$select.= "AND Sappearedin > '' AND Sappearedin <= '$lsbversion' ";
$select.= "AND (Swithdrawnin IS NULL OR Swithdrawnin > '$lsbversion') ";
}
$select.= "AND ( Sarch=$Aid OR Sarch=1 ) ";
if( $specids or $exclids or $SMid ) {
$select.= "AND (";
}
if( $exclids ) {
$select.= "Sname NOT IN ( $exclids ) ";
}
if( $specids ) {
$select.= " AND ( " if( $exclids );
$select.= "Sname IN ( $specids ) ";
}
if( $SMid ) {
if( $specids ) {
$select.= " OR (";
}
elsif( $exclids ) {
$select.= " AND (";
}
$select.= " SMSsmid IN ($SMid) ";
$select.= "AND SMSappearedin > '' AND SMSappearedin <= '$lsbversion' ";
$select.= "AND (SMSwithdrawnin IS NULL OR SMSwithdrawnin > '$lsbversion') ";
$select.= " ) " if( $specids or $exclids );
}
if( $specids or $exclids or $SMid ) {
$select.= ") ";
if( $specids and $exclids ) {
$select.= ") ";
}
}
$select.= "ORDER BY Sshort";
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;
printf("<!-- Start of generated text - do not edit! -->\n");
printf("<!-- generated from the LSB specification database by mkstandardsgmltable -->\n");
print "<thead>\n";
print "<row>";
print "<entry>Name</entry><entry>Title</entry><entry>URL</entry>";
print "</row>";
print "</thead>\n";
print "<tbody>\n";
for(1..$sth->rows) {
$entry=$sth->fetchrow_hashref;
print "<row>";
# Don't print the nickname. It may be confusing
#printf "<entry>%s</entry>",$entry->{'Sname'};
printf "<entry id=\"std.%s\" xreflabel=\"%s\">%s</entry>",$entry->{'Stag'},$entry->{'Sshort'},$entry->{'Sshort'};
printf "<entry>%s</entry>", $entry->{'Sfull'};
printf "<entry><ulink url=\"%s\">%s</ulink></entry>",
encode_entities($entry->{'Surl'},"%&"),
encode_entities($entry->{'Surl'});
#printf "<entry>%s</entry>",$entry->{'Sdescription'};
print "</row>\n";
}
$sth->finish;
$dbh->disconnect;
print "</tbody>\n";
printf("<!-- End of text generated from database -->\n");