I am trying to convert a binary file to a pdb file . The binary file 
contains 1230 records but when the created database is uploaded on the 
device the rec count is only 95
Can anyone help me out
I just downloaded the code from some site


#include "stdafx.h"

void fopen_error (char* file_name);
void exit ();
# include <stdio.h>

//PUT RECORD SIZE HERE

#define REC_SIZE        42

#define invert32(x) (((x & 0x000000ff)<<24) | ((x & 0x0000ff00)<<8) | ((x & 
0x00ff0000)>>8) | ((x & 0xff000000) >> 24))
#define invert16(x) (((x & 0x00ff)<<8) | ((x & 0xff)>>8))

// Global variables
int     g_hSource       = -1;
int     g_hOutput       = -1;

int g_iLen;

// struct def
#pragma pack (push)
#pragma pack (1)

typedef struct
{
        char                    name [32];
        unsigned short  attributes;
        unsigned short  version;
        int                             creationDate;
        int                             modificationDate;
        int                             lastBackupDate;
        int                             modificationNumber;
        int                             appInfoID;
        int                             sortInfoID;
        int                             type;
        int                             creator;
        int                             unqueIDSeed;
} PDBHeader;

typedef struct
{
        int                             nextRecordistID;
        unsigned short  numRecords;
} RecordListType;

typedef struct
{
        int                             localChunkID;
        char                    attributes;
        char                    uid [3];
} FieldDescrType;
#pragma pack (pop)

int main(int argc, char* argv[])
{
        int             iResult, i;
        int             rec_num;
        time_t  ct;
        void*   buf;

        PDBHeader               header;
        RecordListType  rl;
        FieldDescrType  fd;

        if (argc < 4)
        {
                cout<<"Syntax: file2pdb[.exe] source_file pdb_file db_name"<<endl;
                return -1;
        }

        if ((g_hSource = _open (argv [1], O_RDONLY | O_BINARY)) == -1)
        {
                fopen_error (argv [1]);
                exit ();
                return -1;
        }

        // ���� �������� ���� ����������, ������� ���
        if ((iResult = _open (argv [2], O_RDONLY)) != -1)
        {
                close (iResult);
                remove (argv [2]);
        }

        g_iLen = _filelength (g_hSource);
        printf("%d",g_iLen);
        rec_num = (g_iLen / REC_SIZE) + 1;//change
        printf("\n%d",rec_num);
        time (&ct);
        ct += 2082844800;

        strcpy (header.name, argv [3]);
        header.attributes                       = 0x1000;
        header.version                          = 0;
        header.creationDate                     = invert32(ct);
        header.modificationDate         = invert32(ct);
        header.lastBackupDate           = invert32(ct);
        header.modificationNumber       = 0;
        header.appInfoID                        = NULL;
        header.sortInfoID                       = NULL;
        header.type                                     = invert32('pl00');
        header.creator                          = invert32('pl01');
        header.unqueIDSeed                      = 0;

        rl.nextRecordistID      = NULL;
        rl.numRecords           = invert16(rec_num);

        if ((g_hOutput = _open (argv [2], _O_WRONLY | _O_CREAT | _O_BINARY, 
_S_IWRITE)) == -1)
        {
                fopen_error (argv [2]);
                exit ();
                return -1;
        }
    printf("\n%d",rl.numRecords);
        _write (g_hOutput, (void*) &header, sizeof (header));
        _write (g_hOutput, (void*) &rl, sizeof (rl));

        for (i = 0; i < rec_num; i++)
        {
                iResult = sizeof (header) + sizeof (rl) + (rec_num * sizeof (fd)) + (i 
* 
REC_SIZE);
                fd.localChunkID = invert32(iResult);
                fd.attributes = 0;
                fd.uid [2] = i;
                _write (g_hOutput, (void*) &fd, sizeof (fd));
        }

        buf = new (char [g_iLen]);

        _read (g_hSource, buf, g_iLen);
        _write (g_hOutput, buf, g_iLen);

        delete (buf);

        exit ();

        return 0;
}

void fopen_error (char* file_name)
{
        switch (errno)
        {
                case ENOENT:
                        cout<<"**Fatal** Command line: Can't locate file: 
"<<file_name<<endl;
                        break;

                case EMFILE:
                        cout<<"**Fatal** Command line: Too many open files: 
"<<file_name<<endl;
                        break;

                case EACCES:
                        cout<<"**Fatal** Command line: Can't open file: 
"<<file_name<<endl;
                        break;
        }
}

void exit ()
{
        if (g_hSource != -1) close (g_hSource);
        if (g_hOutput != -1) close (g_hOutput);
}

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to