-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkcmdlist
executable file
·108 lines (90 loc) · 3.39 KB
/
mkcmdlist
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
#!/usr/bin/perl
use Getopt::Long;
use DBI;
use Env qw(LSBUSER LSBDBPASSWD LSBDB LSBDBHOST);
sub usage()
{
print STDERR "mkcmdlist -v <lsbversion> [-m <submodule> ]\n Default submodule is LSB_Base\n";
die;
}
# Uncomment to trace SQL statments
#$trace=1;
#
# 1) process the arguments
#
# We can get submodule id from SubModule Table.
# Commands list will be generated as per submodules.
GetOptions("m=s" => \$submodule,
"v=s" => \$lsbversion);
if( !$lsbversion ) { usage(); }
#
# 2) Establish connection to the database
#
my $dbh = DBI->connect('DBI:mysql:database='.$LSBDB.';host='.$LSBDBHOST, $LSBUSER, $LSBDBPASSWD)
or die "Couldn't connect to database: ".DBI->errstr;
if( !$submodule ) {
$submodule='LSB_Base';
}
($submoduleid) = $dbh->selectrow_array("SELECT SMid FROM SubModule WHERE SMname='$submodule'");
die("Incorrect SubModule name") if not $submoduleid;
printf("<!-- Start of generated text - do not edit! -->\n");
printf("<!-- generated from the LSB specification database by mkcmdlist -->\n");
print "<sect1 id=cmdbehav>\n";
print "<title>Command Behavior</title>\n";
print "<para>\n";
print "This section contains descriptions for commands and utilities whose\n";
print "specified behavior in the LSB contradicts or extends the standards\n";
print "referenced. It also contains commands and utilities only required by\n";
print "the LSB and not specified by other standards.\n";
print "</para>\n";
#
# 3) get & print the library info
#
$select = "SELECT * FROM Command ";
$select.= "LEFT JOIN SModCmd ON SMCcid=Cid ";
$select.= "LEFT JOIN CmdStd ON CScid=Cid ";
$select.= "LEFT JOIN Standard ON Sid=CSsid ";
$select.= "WHERE SMCsmid=$submoduleid AND SMCappearedin <= '$lsbversion' AND SMCappearedin > '' ";
$select.= "AND (SMCwithdrawnin IS NULL OR SMCwithdrawnin > '$lsbversion') ";
$select.= "AND CSappearedin <= '$lsbversion' AND CSappearedin > '' ";
$select.= "AND (CSwithdrawnin IS NULL OR CSwithdrawnin > '$lsbversion') ";
$select.= "AND Cbuiltin != 'Yes' ";
$select.= "AND Sname='LSB' " ;
$select.= "ORDER BY Cname";
print STDERR $select,"\n" if $trace;
$cth = $dbh->prepare($select) or die "Couldn't prepare $select query: ".DBI->errstr;
$cth->execute or die "Couldn't execute $select query: ".DBI->errstr;
for(1..$cth->rows) {
$entry = $cth->fetchrow_hashref() or die "Fetchrow failed on $select query: ".DBI->errstr;
# If there is a "Cname.sgml" file, just use it
if( -e $entry->{'Cname'}.".sgml" ) {
print "m4_include(".$entry->{'Cname'}.".sgml)\n";
}
else {
# Otherwise we have different files for different LSB versions
# Let's select the proper one
$Cname = $entry->{'Cname'};
$prev_ver = "";
$found = 0;
open( F, "ls -1 ".$Cname."*sgml |" );
while(<F>) {
if( /$Cname\-(.+)\.sgml/ ) {
$ver = $1;
if( $ver > $lsbversion ) {
print "m4_include(".$Cname."-".$prev_ver.".sgml)\n";
$found = 1;
last;
}
$prev_ver = $ver;
}
}
close(F);
if( !$found ) {
print "m4_include(".$Cname."-".$prev_ver.".sgml)\n";
}
}
}
$cth->finish;
$dbh->disconnect;
print "</sect1>\n";
printf("<!-- End of text generated from database -->\n");