#!/usr/bin/perl

use CGI;
use Mysql;

use Env qw(LSBUSER LSBDBPASSWD LSBDB LSBDBHOST);

sub usage()
{
print STDERR "mkcmdlist\n";
die;
}

# Uncomment to trace SQL statments
#$trace=1;

#
# 2) Establish connection to the database
#

$Dbh = Mysql->connect($LSBDBHOST,$LSBDB,$LSBUSER, $LSBDBPASSWD) || die $Mysql::db_errstr;

#
# 3) Get the list of cmds
#

open(CMDS,">cmds.h");
print CMDS "/* Generated file */\n\n";
print CMDS "struct cmds {\n";
print CMDS "\tchar *cmdname;\n";
print CMDS "\tchar *cmdpath;\n";
print CMDS "} cmdlist[] = {\n";

$select = "SELECT DISTINCT Cid,Cname,Cpath FROM Command ";
$select.= "WHERE Cstatus='Included' ";
$select.= "ORDER BY Cname ";

#print $select;

$sth = $Dbh->query($select) || die $Dbh->errmsg();

for(1..$sth->numrows) {
	%entry=$sth->fetchhash;
	print CMDS "	{\"$entry{'Cname'}\", \"$entry{'Cpath'}\"},\n";
}

print CMDS "};\n";
close(CMDS);
