#!/usr/local/bin/perl -w

#
# db_to_html_table
# Copyright (C) 2002 by John Heidemann <johnh@isi.edu>
# $Id: db_to_html_table,v 1.2 2002/10/25 21:46:49 johnh Exp $
#
# This program is distributed under terms of the GNU general
# public license, version 2.  See the file COPYING
# in $dblibdir for details.
#
sub usage {
    print <<END;
usage: $0 

Covert an existing dbtable to an HTML table.
Does NOT do any of the HTML stuff around the table.

Related programs:
    dbcolneaten, dbrecolize

END
    exit 1;
}

BEGIN {
    $dblibdir = "/usr/local/lib/jdb";
    push(@INC, $dblibdir);
}
require "$dblibdir/dblib.pl";
use DbGetopt;

my($debug) = 0;
my(@orig_argv) = @ARGV;
my($prog) = &progname;
my($dbopts) = new DbGetopt("d?", \@ARGV);
my($ch);
while ($dbopts->getopt) {
    $ch = $dbopts->opt;
    if ($ch eq 'd') {
	$debug++;
    } else {
	&usage;
    };
};
#&usage if ($#ARGV < 0);
my($new_fs_code) = @ARGV;


&readprocess_header;

@f = ();   # suppress warning
print "<table>\n";

print "<tr>";
foreach (@colnames) {
    print "<th>$_</th> ";
};
print "</tr>\n";

while (<STDIN>) {
    &delayed_pass_comments && next;
    &split_cols;
    print "<tr>";
    foreach (@f) {
	$_ = dblib_text2html($_);
	print "<td>$_</td> ";
    };
    print "</tr>\n";
};
print "</table>\n";

# print "#  | $prog ", join(" ", @orig_argv), "\n";
exit 0;

# warning suppression
@colnames = ();
