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

 
Output of file : DBCOPY.C contained in archive : TC-DBF.ZIP
/*
** file: dbcopy.c
** purpose: program to copy structure and records to another file
** usage: dbcopy fromfile tofile
** notes: dos copy does this faster, but this program exercizes most
** of the dbf functions
** author: Mark Sadler
** revised: 6/19/87
*/


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

void db_error(int errornum,char *filename)
{
printf("\nError opening file: ");
switch (errornum)
{
case OUT_OF_MEM:
printf("Not enough memory.\n");
break;
case NO_FILE:
printf("Can not open file %s.\n",filename);
break;
case BAD_FORMAT:
printf("File %s is not a dBASE III file.\n",filename);
break;
}
}

void main(int argc,char *argv[])
{
struct DBF in,out;
int errornum,fld;
unsigned long rec;
char *buff;

if(argc < 2)
{
printf("Usage DBCOPY infile outfile\n");
exit(1);
}

/* open input file */
strcpy(in.filename,argv[1]);
if(!strchr(in.filename,'.')) /* default to .dbf file */
strcat(in.filename,".DBF");
if((errornum = d_open(&in))!=0) /* open file */
{
db_error(errornum,in.filename);
exit(1);
}

/* copy input file structure to outputfile */
strcpy(out.filename,argv[2]);
if(!strchr(out.filename,'.')) /* default to .dbf file */
strcat(out.filename,".DBF");
if((errornum = d_cpystr(&in,&out))!=0) /* open file */
{
db_error(errornum,out.filename);
exit(1);
}

for (rec=1L;rec <= in.records;rec++) /* records loop */
{
d_getrec(&in,rec);

/*
** note: this loop could be replaced by just copying the record with
** using memcopy to copy to the out file record. faster still
** by changing the out file structure record pointer to point
** to the record in the in file structure.
*/
if ((buff=(char *)malloc(MAX_RECORD))==NULL)
{
db_error(OUT_OF_MEM,"filename error");
exit(1);
}
for (fld=1;fld <= in.num_fields;fld++) /* fields loop */
{
d_getfld(&in,fld,buff);
d_putfld(&out,fld,buff);
} /* fields loop */

*out.record_ptr = *in.record_ptr; /* copy deleted file marker */
d_addrec(&out);
} /* records loop */
free(buff);
d_close(&in);
d_close(&out);
}



  3 Responses to “Category : C Source Code
Archive   : TC-DBF.ZIP
Filename : DBCOPY.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/