Category : C++ Source Code
Archive   : WLIB0393.ZIP
Filename : WBTRIEVE.C

 
Output of file : WBTRIEVE.C contained in archive : WLIB0393.ZIP
#include
#include
#include

extern "C"
{
#include "turcbtrv.c"
}

#pragma hdrstop

// copyright (c) 1993 Paul Wheaton

BtrieveFile::BtrieveFile(const char* FileName,int Mode)
{
int BufLen=1;
int Status=BTRV(0,PosBlock,"",&BufLen,(char*)FileName,Mode);
if (Status!=0) FatalError("BT open "+Str(Status));
}

static struct AlternateCollatingSequence
{
char Signature;
char Name[8];
char Seq[256];
} ACS;

CreateBtrieveFile::CreateBtrieveFile(const char* FileName, int RecSize,
int PageSize)
{
Name=FileName;
F.RecLen=RecSize;
F.PageSize=PageSize;
F.PreAllocation=0;
Closed=False;
IncludeACS=False;
}

void CreateBtrieveFile::Done()
{
if (!Closed)
{
Closed=True;
F.Unused=0;
F.Reserved=0;
F.NumIndexes=int(K.Size());
/* the following chunk of code was used for debugging
puts("\n\nCreating "+String(Name));
puts("\n rec len = "+Str(F.RecLen));
puts("page size = "+Str(F.PageSize));
puts(" indexes = "+Str(F.NumIndexes));
String S=" flags = ";
int I;
For(I,16) S+=Str(F.Flags[I])+' ';
puts(S);
puts(" prealloc = "+Str(F.PreAllocation));
For(I,F.NumIndexes)
{
Delay(1500);
puts("\nIndex "+Str(I));
puts(" pos = "+Str(K[I].Pos));
puts(" len = "+Str(K[I].Len));
String S=" flags = ";
int J;
For(J,16) S+=Str(K[I].Flags[J])+' ';
puts(S);
puts("extended type = "+Str(K[I].ExtendedType));
puts(" null val = "+Str(K[I].NullValue));
}
*/
int BufSize1=16*(F.NumIndexes+1);
int BufSize=BufSize1;
if (IncludeACS) BufSize+=sizeof(ACS);
char* Buf=new char[BufSize];
memcpy(Buf,&F,16);
memcpy(&Buf[16],&K[0],F.NumIndexes*16);
if (IncludeACS) memcpy(&Buf[BufSize1],&ACS,sizeof(ACS));
char PosBlock[128];
int Status=BTRV(14,PosBlock,Buf,&BufSize,(char*)Name,0);
if (Status!=0) FatalError("BT create "+Str(Status));
delete(Buf);
}
}

void CreateBtrieveFile::SetFreeSpaceThreshold(int Percent)
{
if ((Percent==10)||(Percent==20)||(Percent==30))
{
if (Percent>=20)
{
F.Flags[7]=On;
Percent-=20;
}
if (Percent==10) F.Flags[6]=On;
}
}

void CreateBtrieveFile::PreAllocatePages(int Pages)
{
if (Pages>0)
{
F.PreAllocation=Pages;
F.Flags[2]=On;
}
}

void CreateBtrieveFile::DefineKey(int Pos, int Len, BtrieveKeyType BKT,
Bool Duplicates, Bool Modifiable, int KeyNum)
{
KeySpec KS;
KS.Pos=Pos+1; // btrieve calls "1" the first byte
KS.Len=Len;
KS.NotUsed=0;
KS.NullValue=0;
KS.Reserved=0;
KS.Flags[0]=Duplicates;
KS.Flags[1]=Modifiable;
KS.Flags[8]=True; // type is extended
KS.ExtendedType=char((BKT==BKInt)?1:11);
if (BKT==BKString)
{
ACS.Signature='\xac';
strcpy(ACS.Name,"lower ");
int I;
For(I,256) ACS.Seq[I]=I;
for(I='A';I<='Z';I++) ACS.Seq[I]=I+32;
KS.Flags[5]=True;
IncludeACS=True;
}
K[KeyNum]=KS;
}



  3 Responses to “Category : C++ Source Code
Archive   : WLIB0393.ZIP
Filename : WBTRIEVE.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/