#include "stdio.h"
#define ERROR 0 /* error constant */
#define EOF 13 /* dBASE II EOF marker */
/************************************************************************/
/* This program is designed to list the structure of any dBASE II file.*/
/* If you would like more information on how to access dBASE II files */
/* & dBASE II indexes send $35.00 to: */
/* */
/* ANDERSON COMPUTER-WARE */
/* P. O. BOX 8116 */
/* SPRINGFIELD, MO 65801 */
/* */
/* Written by: Kelly C. Anderson, June 1984 */
/************************************************************************/
main (argc, argv)
int argc;
char **argv;
{
FILE *fd, *fopen();
int pos, high, low, records, month, day, year, lhigh, llow, length;
int counter, width, decimal, j;
int c;
char fd1 [10];
char fd2 [14];
char name[], desc [10];
char type[], field [1];
/* Get the file name from the keyboard */
if (argc != 2)
{
printf ("This program will display any dBASE II file structure.\n\n");
printf ("Enter the dBASE file name now without its extension: ");
scanf ("%s", fd1);
} else
strcpy (fd1, argv[1]);
/* Add to the file name the ".DBF" extension. */
strncpy (fd2,fd1,10);
strcat (fd2,".DBF");
/* Capitalize the inputted file name. */
cap (fd2);
/* Check to make sure the file exists. */
if ((fd = fopen (fd2,"r")) == ERROR)
printf ("\n\nNo such file %s!!! Program aborting.", fd2);
else{
/* Check to make sure the file is a dBASE II file. */
c = getc (fd);
if (c != 2)
{
printf ("\n\n%s is not a dBase II file!!! Program aborting.", fd2);
}else{
printf ("\nSTRUCTURE FOR FILE: %s", fd2);
/* Find out how many records are in the file */
c = getc (fd);
low = c;
c = getc (fd);
high = c;
records = low + high * 256;
printf ("\nNUMBER OF RECORDS: %d", records);
/* Get the date the last changes were made */
c = getc (fd);
month = c;
c = getc (fd);
day = c;
c = getc (fd);
year = c;
printf ("\nDATE OF LAST UPDATE: %d/%d/%d", month, day, year);
/* Get the record length of each record */
c = getc (fd);
llow = c;
c = getc (fd);
lhigh = c;
length = llow + lhigh * 256;
printf ("\nRECORD LENGTH: %d bytes", length);
printf ("\nFLD NAME TYPE WIDTH DEC\n");
/* Begin listing the structure onto the console */
counter = 1;
while ((c = getc (fd)) != EOF)
{
name[0] = c;
/* Get the field description */
for (j=1; j<10; j++)
{
c = getc (fd);
name[j] = c;
}
strncpy (desc, name, 10);
/* Get the type of field */
c = getc (fd);
c = getc (fd);
type[0] = c;
strncpy (field, type, 1);
/* Get the length of the field */
c = getc (fd);
width = c;
/* Get the decimal length of the field if the field is numeric */
c = getc (fd);
c = getc (fd);
c = getc (fd);
decimal = c;
/* Display information onto screen */
printf ("%3d %-10s %1s %3d %3d\n", counter, desc, field,
width, decimal);
counter++;
}
}
}
/* Display logo & close the files */
printf ("\n--Anderson Computer-Ware--\n");
exit ();
}
/* This section will capitalize the variable passed to it */
cap (nstr)
char *nstr;
{
int i;
nstr [0] = toupper (nstr [0]);
for (i = 0; i < 13; i++)
nstr [i+1] = toupper (nstr [i+1]);
}
{
int i;
nstr [0] = toupper (nstr [0]);
for (i = 0; i < 13; i++)