Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[50c14b]: VEF.cpp Maximize Restore History

Download this file

VEF.cpp    110 lines (94 with data), 2.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
// VEF.cpp: implementation of the CVEF class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "chitem.h"
#include "VEF.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CVEF::CVEF()
{
comp1 = NULL;
comp2 = NULL;
comp1count = 0;
comp2count = 0;
}
CVEF::~CVEF()
{
KillComp1Headers();
KillComp2Headers();
}
int CVEF::WriteVEFToFile(int fhandle, int calculate)
{
int bc1, bc2;
bc1 = comp1count*sizeof(vef_component);
bc2 = comp2count*sizeof(vef_component);
memcpy(header.filetype,"VEF \0\0\0",8);
header.offset1 = sizeof(vef_header);
header.count1 = comp1count;
header.offset2 = header.offset1 + bc1;
header.count2 = comp2count;
if(write(fhandle,&header,sizeof(vef_header) )!=sizeof(vef_header) )
{
return -2;
}
if (calculate)
{
return header.offset2+bc2;
}
if (write(fhandle, comp1, bc1)!=bc1)
{
return -2;
}
if (write(fhandle, comp2, bc2)!=bc2)
{
return -2;
}
m_changed=false;
return 0;
}
int CVEF::ReadVEFFromFile(int fhandle, long maxlen)
{
int bc1, bc2;
m_changed=false;
if(maxlen==-1) maxlen=filelength(fhandle);
if(maxlen<sizeof(vef_header) )
{
return -2;
}
if(read(fhandle,&header,sizeof(vef_header) )!=sizeof(vef_header) )
{
return -2;
}
if(header.count1!=comp1count)
{
KillComp1Headers();
comp1 = new vef_component[header.count1];
if (!comp1) return -3;
comp1count = header.count1;
}
bc1 = comp1count*sizeof(vef_component);
if (read(fhandle,comp1,bc1)!=bc1)
{
return -2;
}
if(header.count2!=comp2count)
{
KillComp2Headers();
comp2 = new vef_component[header.count2];
if (!comp2) return -3;
comp2count = header.count2;
}
bc2 = comp2count*sizeof(vef_component);
if (read(fhandle,comp2,bc2)!=bc2)
{
return -2;
}
return 0;
}