Category : C Source Code
Archive   : TC-DBF.ZIP
Filename : LISTDB.C

 
Output of file : LISTDB.C contained in archive : TC-DBF.ZIP
/* file: listdb.c
** purpose: program to list the records in a dbaseiii file
** usage: listdb filename
** notes: compile with "tcc listdb d_open d_getrec d_getfld d_close"
** author: Mark Sadler
** revised: 6/18/87
*/

#include
#include
#include
#include "dbf.h"


/* routine to format dbase date field - buff in is in form YYYYMMDD
buff out is in form MM/DD/YY
*/
void fdate(char *buff)
{
int day;
int mon;
int yr;
if (buff[0]==' ')
{
buff[0]='\0';
strcat(buff," / / ");
}
else
{
sscanf(buff,"%4d%02d%02d",&yr,&mon,&day);
sprintf(buff,"%02d/%02d/%d",mon,day,yr-1900);
}
}


main(int argc,char **argv)
{
int errornum;
long rec;
int fld;
struct DBF *d;
static char buff[255];

if(argc != 2)
{
printf("Usage LISTDB filename\n");
exit(1);
}

d = (struct DBF *)malloc(sizeof(struct DBF)); /* allocate space for DBF */

strcpy(d->filename,argv[1]);

if(!strchr(d->filename,'.')) /* default to .dbf file */
strcat(d->filename,".DBF");


if((errornum = d_open(d))!=0) /* open file */
{
printf("Error opening file: ");
switch (errornum)
{
case OUT_OF_MEM:
printf("Not enough memory.\n");
break;
case NO_FILE:
printf("Can not open file %s.\n",d->filename);
break;
case BAD_FORMAT:
printf("File %s is not a dBASE III file.\n",d->filename);
break;
}
free(d);
exit(1);
}

for(rec=1;rec<=d->records;rec++)
{
printf("\n%-5u",rec);

d_getrec(d,(long)rec);
for(fld=1;fld<=d->num_fields;fld++)
{
if(d_getfld(d,fld,buff) == 'D')
fdate(buff);
printf(" %s",buff);
}
}

d_close(d);
free(d);
}



  3 Responses to “Category : C Source Code
Archive   : TC-DBF.ZIP
Filename : LISTDB.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/