#!/usr/bin/perl
#***************************************************************************
#                          dbf2tex  -  convert dbf files to TeX tables
#                             -------------------
#    begin                : 17-06-2000
#    copyright            : (C) 2000 by Steffen Macke
#    email                : sdteffen@yahoo.com
# ***************************************************************************/

#***************************************************************************
# *                                                                         *
# *   This program is free software; you can redistribute it and/or modify  *
# *   it under the terms of the GNU General Public License as published by  *
# *   the Free Software Foundation; either version 2 of the License, or     *
# *   (at your option) any later version.                                   *
# *                                                                         *
# ***************************************************************************/

use XBase;

# check arguments

if((@ARGN != 1)or(@ARGV == "--help")){
	printf("usage: dbf2tex file\n");
	exit
}

#open dbf file

my $table = new XBase @ARGV or die XBase->errstr;

my @names = $table->field_names;

    
#tex header
printf "\\documentclass{article}\n";
printf "\\begin{document}\n";
printf "\\begin{tabular}{|";
for (my $i = 0; $i < @names; $i++) {
	printf "r|";
}
printf "}\n";
printf "\\hline\n";

#table header
printf "$names[0]";
for (my $i = 1; $i < @names; $i++) {
	printf "\&\n$names[$i]";
}

printf "\\\\\n\\hline\n";

#table records
$table->dump_records("fs" => "\&\n", "rs" => "\\\\\n\\hline\n");

#tex tail
printf "\\end{tabular}\n";
printf "\\end{document}\n";
