Commit b26d06b3 authored by Pavel Vaynerman's avatar Pavel Vaynerman

Merge branch 'master' of git.eter:/projects/uniset

parents 180c78b0 15d30799
......@@ -33,7 +33,7 @@
int seek=0;
int b_size=100000;
int bj_size=1300000;
void testTable1(void)
{
char *chr=new char[20];
......@@ -212,7 +212,7 @@ bool reOpen()
int i,k=0;
char *str = new char[30];
printf("the same after reopen:\n");
if(!j.open("big_file.test",30,33000,seek))
if(!j.open("big_file.test",bj_size,30,33000,seek))
{
printf("Reopen file error\n");
delete str;
......@@ -234,7 +234,7 @@ bool reOpen()
bool testJournal1(void)
{
CycleStorage j("big_file.test",30,32000,seek,true);
CycleStorage j("big_file.test",bj_size,30,32000,seek,true);
int i,k=0;
char *str = new char[30];
printf("journal test 1\n");
......@@ -344,7 +344,7 @@ bool testJournal1(void)
void testJournal2(void)
{
CycleStorage j("big_file.test",30,32000,seek);
CycleStorage j("big_file.test",bj_size,30,32000,seek);
int i,k;
char *str = new char[30];
printf("journal test 2 - checking number of iterations to find head/tail\n");
......@@ -356,7 +356,7 @@ void testJournal2(void)
sprintf(str,"%d",k);
j.addRow(str);
}
j.open("big_file.test",30,32000,seek);
j.open("big_file.test",bj_size,30,32000,seek);
printf("i=%d, iterations = %d\n", i, j.getIter());
}
printf("\n");
......@@ -372,7 +372,7 @@ struct JItem
bool testJournal3()
{
CycleStorage j("journal3.test",sizeof(JItem),10,0,true);
CycleStorage j("journal3.test",bj_size,sizeof(JItem),10,0,true);
if( !j.isOpen() )
{
printf("create journal3.test failed\n");
......
......@@ -150,7 +150,7 @@ class CycleStorage
/*! Open, create=true
*/
CycleStorage(const char* name, int inf_sz, int inf_count, int seek,bool create=false);
CycleStorage(const char* name, int byte_sz, int inf_sz, int inf_count, int seek,bool create=false);
~CycleStorage();
......@@ -163,8 +163,8 @@ class CycleStorage
-
, getByteSize()
*/
bool open(const char* name, int inf_sz, int inf_count, int seek);
bool create(const char* name, int inf_sz, int inf_count, int seek);
bool open(const char* name, int byte_sz, int inf_sz, int inf_count, int seek);
bool create(const char* name, int byte_sz, int inf_sz, int inf_count, int seek);
bool isOpen(){ return (file!=NULL); }
......
......@@ -35,13 +35,13 @@ CycleStorage::CycleStorage()
file=NULL;
}
CycleStorage::CycleStorage(const char* name, int inf_sz, int inf_count, int seek, bool cr):
CycleStorage::CycleStorage(const char* name, int byte_sz, int inf_sz, int inf_count, int seek, bool cr):
file(NULL)
{
if(!open(name,inf_sz, inf_count, seek))
if(!open(name, byte_sz, inf_sz, inf_count, seek))
{
if(cr)
create(name,inf_sz, inf_count, seek);
create(name, byte_sz, inf_sz, inf_count, seek);
}
}
......@@ -138,17 +138,17 @@ bool CycleStorage::findHead()
return true;
}
bool CycleStorage::open(const char* name, int inf_sz, int inf_count, int seek)
bool CycleStorage::open(const char* name, int byte_sz, int inf_sz, int inf_count, int seek)
{
/*! ,
*/
if(file!=NULL)
if( file!=NULL )
fclose(file);
file = fopen(name, "r+");
if(file==NULL) return false;
if( file==NULL ) return false;
if(fseek(file,seek,0)==-1)
if( fseek(file,seek,0)==-1 )
{
fclose(file);
file=NULL;
......@@ -157,10 +157,10 @@ bool CycleStorage::open(const char* name, int inf_sz, int inf_count, int seek)
/*! */
CycleStorageAttr csa;
fread(&csa,sizeof(csa),1,file);
fread(&csa, sizeof(csa), 1, file);
/*! */
if((csa.size!=inf_count)||(csa.inf_size!=inf_sz)||(csa.seekpos!=seek))
if( ( csa.size!=inf_count ) || ( csa.inf_size!=inf_sz ) || ( csa.seekpos!=seek ) )
{
fclose(file);
file=NULL;
......@@ -171,27 +171,19 @@ bool CycleStorage::open(const char* name, int inf_sz, int inf_count, int seek)
size=inf_count;
seekpos=seek+sizeof(CycleStorageAttr);
if(!findHead())
if( ( byte_sz<getByteSize() ) || !findHead() )
{
fclose(file);
file=NULL;
file = NULL;
return false;
}
return true;
}
bool CycleStorage::create(const char* name, int inf_sz, int inf_count, int seek)
bool CycleStorage::create(const char* name, int byte_sz, int inf_sz, int inf_count, int seek)
{
if(file!=NULL) fclose(file);
file = fopen(name, "r+");
/*! , */
if(file==NULL)
{
FILE*f=fopen(name,"w");
fclose(f);
file = fopen(name, "r+");
}
inf_size=inf_sz;
full_size=sizeof(CycleStorageElem)+inf_size;
......@@ -200,6 +192,22 @@ bool CycleStorage::create(const char* name, int inf_sz, int inf_count, int seek)
iter=0;
seekpos=seek;
if( byte_sz<getByteSize() )
{
if( file!= NULL )
fclose(file);
file = NULL;
return false;
}
/*! , */
if(file==NULL)
{
FILE*f=fopen(name,"w");
fclose(f);
file = fopen(name, "r+");
}
if(fseek(file,seekpos,0)==-1) return false;
CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment