#include <stdio.h>
#include "dbftable.h"

static char HELP[] = "\n"
  "dbfpack  <input filespecs>  <output filespecs>\n"
  "\n"
  "removes all deleted records from the input file and writes the\n"
  "rest to the output file.\n";

int main(int argc, char **argv)
{
  if (argc < 3)
  {
    fputs(HELP, stderr);
    return 1;
  }

  dbf_table source, output;
  if (!source.open(argv[1], DBF_READ))
  {
    fprintf(stderr, "Can't open source file %s\n", argv[1]);
    return 1;
  }
  if (!output.open(argv[2], DBF_WRITE))
  {
    fprintf(stderr, "Can't open output file %s\n", argv[2]);
    return 1;
  }
  output.copy_fields(source);
  long i;
  for (i = 0; i < source.number_of_records; i++)
  {
    source.record_number = i;
    if (!source.deleted)
    {
      output << source;
      output.append();
    }
  }
  source.close();
  output.close();

}

