// dbase.c - gaining access to dbf-files
// Written by Stefan Pfeiffer, DL1ELY, 950726
// Last modification: 950726
// (C) 1995 by Stefan Pfeiffer, DL1ELY@DB0PKE.#NRW.DEU.EU

#include "dbase.h"
#include <stdio.h>

void main(int argc, char **argv)
{
   struct db_rec_def def[20];
   struct db_header header;
   FILE *f;
   unsigned read;
   unsigned char field_cnt;
   unsigned char i;

   if(argc < 2)
   {
      printf("\nAufruf: DBASE <Dateiname>\n");
      return;
   };

   if((f = fopen(argv[1],"rb")) == NULL)
   {
      printf("\nFile %s nicht gefunden!\n",argv[1]);
      return;
   };

   read = fread(&header,1,sizeof(struct db_header),f);
   if(read != sizeof(struct db_header))
   {
      printf("\nFile %s ist kein DBF-File!\n",argv[1]);
      fclose(f);
      return;
   };

   printf("\nVersionsbyte: %02X\n",header.version);
   printf("Datum: %02d.%02d.%02d\n",header.last_access[2],header.last_access[1],header.last_access[0]);
   printf("Anzahl Records: %ld\n",header.rec_count);
   printf("Headerl„nge: %d\n",header.header_len);
   printf("Record-L„nge: %d\n",header.rec_len);

   field_cnt = 0;
   do
   {
      fread(&def[field_cnt],1,sizeof(struct db_rec_def),f);
      field_cnt++;
   } while(def[field_cnt-1].name[0] != FIELD_TERMINATOR);
   field_cnt--;

   printf("\nFelder pro Record: %d\n\n",field_cnt);

   for(i=0;i<field_cnt;i++)
      printf("%11s  %c  %d  %d\n",def[i].name,def[i].type,def[i].len,def[i].decimals);

   fseek(f,header.header_len,SEEK_SET);

   fclose(f);
   return;
};

