// Utility for telephone dbf-database convertation in
// Pocket PhonesDatabase format (for PocketPC)
// Written by ppcsoft.narod.ru (c) 2001-2002.
// Starting date 28.10.2001
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#define DBFRECORDSTART 0x1c9
#define DBFRECORDSIZE 123
#define DBFFIELDS 5
#define DBNAMELEN 25
void GetField(char *field, unsigned char fieldsize)
{
signed char i=fieldsize;
while ((i>=0) &&(field[i]==0x20)) i--;
field[i+1]=0;
}
main(int arvc, char ** argv)
{
unsigned char sRecSize;
int sPhone;
char *sPhonep=(char *)&sPhone;
char sDBName[DBNAMELEN];
char sOwner[50];
char sStreet[50];
char sHome[7];
char sDoor[7];
char *sData[4]={sOwner,sStreet,sHome,sDoor};
char oRec[DBFRECORDSIZE];
char pRec[DBFRECORDSIZE];
char *pRecp;
FILE *filein, *fileout;
int readRecs;
long numRecs;
unsigned char oFileds[DBFFIELDS]={8,50,50,7,7};
int i, addr;
printf(
"Utility for telephone dbf-database convertation in\r\n"
"Pocket PhonesDatabase format (for PocketPC)\r\n"
"Written by ppcsoft.narod.ru (c) 2001-2002.\r\n"
"Starting date 28.10.2001-05.05.2002\r\n\n");
if (arvc<4)
{
printf("Usage: convert database.in database.out dbname\r\n");
return -1;
}
if( (filein = fopen( argv[1], "rb" )) == NULL )
{
printf( "Can't find - '%s'\n", argv[1] );
return -2;
}
if( (fileout = fopen( argv[2], "w+b" )) == NULL )
{
printf( "Can't create - '%s'\n", argv[2] );
return -3;
}
// Move to start position
fseek(filein, DBFRECORDSTART,SEEK_SET);
// First 4 bytes in db - records count
fwrite( &numRecs, sizeof(numRecs), 1, fileout);
strset(sDBName,0);
// Copy dbname
strcpy(sDBName,argv[3]);
// Write DB Name
fwrite( &sDBName, sizeof(sDBName), 1, fileout);
// Start read file
numRecs=0;
do {
readRecs=fread( oRec, DBFRECORDSIZE, 1, filein );
if (readRecs==1)
{
numRecs++;
if(numRecs % 1000 ==0)
{
printf ("\r#%i ", numRecs);
}
GetField(oRec, oFileds[0]-1);
sPhone=atoi(oRec);
// Count record size
sRecSize=4;
// Get data
addr=0;
pRecp=pRec;
memset(pRecp,0,DBFRECORDSIZE);
pRecp+=sRecSize;
for(i=0;i<DBFFIELDS-1;i++)
{
addr+=oFileds[i];
GetField(oRec+addr, oFileds[i+1]-1);
OemToAnsi(oRec+addr,sData[i]);
AnsiUpper(sData[i]);
strcpy(pRecp, sData[i]);
sRecSize+=strlen(sData[i])+1;
pRecp+=strlen(sData[i]);
*pRecp=0;
pRecp++;
}
pRec[0]=sRecSize;
pRec[1]=*sPhonep;
pRec[2]=*(sPhonep+1);
pRec[3]=*(sPhonep+2);
fwrite( pRec, sRecSize, 1, fileout);
fflush(fileout);
}
} while (readRecs==1);
// add final bytes #FFFF
pRec[0]=0xFF;
pRec[1]=0xFF;
fwrite( pRec, 2, 1, fileout);
// Move to start position
fseek(fileout, 0,SEEK_SET);
// First 4 bytes in db - records count
fwrite( &numRecs, sizeof(numRecs), 1, fileout);
fflush(fileout);
fclose( filein );
fclose( fileout );
printf("\r\n\nAll done.");
return 0;
}
|