#!/bin/sh
# the next line restarts using wish \
exec tclsh "$0" "$@"

source [ file join $env(TCLTOOLS_HOME) TclToolInits.tcl ]
TclToolInits UDF UDFDB UTILS

lappend auto_path [file join $env(UDFTOOL_HOME) dBTools]
package require dBTools

# THE DBF file to dump

set DBFname [lindex $argv 0]

# OPEN and read the DBF file

DBdbfOpen $DBFname dB

puts stdout "\n\nFILE    = $DBFname"
puts stdout "HEADERLEN = $dB(HLen)"
puts stdout "RECORDS = $dB(NumRecs)"
puts stdout "RECLEN = $dB(RecLen)\n"

puts -nonewline stdout "RecN"
puts -nonewline stdout "  V_INST  B_YR B_D  B_MSEC  E_YR E_D  E_MSEC "
puts stdout "    SIZE    P P ST ARC   DATE"
puts -nonewline stdout "----"
puts -nonewline stdout " -------- ---- --- -------- ---- --- --------"
puts stdout " ---------- - - -- --- --------"

for { set I 0 } { $I < $dB(NumRecs) } { incr I } {
   set Num "   $I"
   set Len [string length $Num]
   set Beg [expr $Len - 4]
   set Num [string range $Num $Beg end]
   puts -nonewline stdout "$Num"
   set ToRec [expr $dB(HLen) + $dB(RecLen) * $I ]
   seek $dB(fd) $ToRec start
   set dbfRec [read $dB(fd) $dB(RecLen)]
  
   binary scan $dbfRec a39a10aaa2a3a8 Fld Size P1 P2 St Arc Dt
   puts stdout " $Fld $Size $P1 $P2 $St $Arc $Dt"
}

close $dB(fd)
exit 0
