975 lines
34 KiB
C++
975 lines
34 KiB
C++
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// FILE : Scr2Bin.cpp
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
#include "StdInc.h"
|
|
#include "Scr2Bin.h"
|
|
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : destructor
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
CScr2bin::~CScr2bin()
|
|
{
|
|
m_arSupportedFiles.DeleteAll();
|
|
m_arSections.DeleteAll();
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : adds section info
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CScr2bin::AddSection( CSectionTypeDesc*& pSection )
|
|
{
|
|
if(!pSection) return;
|
|
BOOL NA;
|
|
m_arSections.SAdd( pSection, NA, FALSE );
|
|
if(NA) delete pSection;
|
|
pSection = NULL;
|
|
}
|
|
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : sets the conversion rules from text script to binary
|
|
// PARAMS : the name of the rules file; optional pointer to an unsigned integer
|
|
// in which to return the number of the erroneus line
|
|
// RETURNS : 0(SC_ERR_NONE) if successful, the error code on failure
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
int CScr2bin::SetRules( char* szFile, unsigned* pLine /*=NULL*/ )
|
|
{
|
|
BOOL NotAdded;
|
|
int ErrorCode = SB_ERR_NONE;
|
|
if(pLine) *pLine = 0; // not yet inside the file
|
|
CTextParser P; // the file parser object
|
|
if(!P.AccessFile(szFile)) // try to acces the rules file
|
|
return SB_ERR_FILEOPEN; // file access failed
|
|
// P.SetType( "._-", CTP_TEXT);
|
|
P.SetType( "()", CTP_SEPARATOR);
|
|
P.SetType( ";", CTP_LINE_COMMENT);
|
|
P.SetType( "[", SB_ENUM );
|
|
P.SetType( "]", SB_END_ENUM );
|
|
P.SetType( "=", SB_ATTRIB );
|
|
P.SetType( ":", SB_KEYWORD );
|
|
CSectionTypeDesc* pCrtSection = NULL;
|
|
DWORD i = P.Advance();
|
|
while( !(i & CTP_EOF) && ErrorCode == SB_ERR_NONE )
|
|
if(i & SB_KEYWORD)
|
|
switch(((short*)P.Word())[0])
|
|
{
|
|
case 'ED': // default entry description
|
|
if(pCrtSection)
|
|
{
|
|
CEntryTypeDesc* pEn = new CEntryTypeDesc( "::DEFAULT::", pCrtSection->NumEntries() );
|
|
pEn->SetDef();
|
|
ErrorCode = pEn->SetProperties( P, i );
|
|
if( ErrorCode == SB_ERR_NONE ) pCrtSection->SetDefDesc( pEn );
|
|
else delete pEn;
|
|
}
|
|
else ErrorCode = SB_ERR_MISPLACED_KEYWORD;
|
|
break;
|
|
case 'ON': // do not sort the entries
|
|
if(pCrtSection)
|
|
pCrtSection->SetNoSort();
|
|
P.Advance(&i);
|
|
break;
|
|
case 'NE': // entries at file level
|
|
if(P.Advance(&i) & CTP_EOF) ErrorCode = SB_ERR_UNEXPECTED_EOF;
|
|
else
|
|
{
|
|
CSectionTypeDesc* pFileEntry = new CSectionTypeDesc (P.Word(), TAG_FILEENTRY );
|
|
CEntryTypeDesc* pEn = new CEntryTypeDesc( P.Word(), pFileEntry->NumEntries() );
|
|
ErrorCode = pEn->SetProperties( P, i );
|
|
if( ErrorCode == SB_ERR_VOID_ENTRY_DESCRIPTION) ErrorCode = SB_ERR_NONE;
|
|
if( ErrorCode == SB_ERR_NONE )
|
|
{
|
|
pFileEntry->AddEntryDescription( pEn );
|
|
AddSection( pFileEntry ); // the file entry ended - add it
|
|
}
|
|
else
|
|
{
|
|
delete pEn;
|
|
delete pFileEntry;
|
|
}
|
|
}
|
|
break;
|
|
case 'XE': // file extensions
|
|
while ( P.Advance(&i) == CTP_SEPARATOR )
|
|
{
|
|
CFileExtension* pExt = new CFileExtension(P.Word()); // create an extension descriptor
|
|
m_arSupportedFiles.SAdd( pExt, NotAdded, FALSE ); // add it to the list of available files
|
|
if( NotAdded ) delete pExt; // if allready present, igore it
|
|
}
|
|
break;
|
|
case 'ES': // section descriptions
|
|
AddSection( pCrtSection ); // the section ended - add it
|
|
if(P.Advance(&i) & CTP_EOF) ErrorCode = SB_ERR_UNEXPECTED_EOF;
|
|
else
|
|
{ // create a new section description
|
|
pCrtSection = new CSectionTypeDesc (P.Word());
|
|
ErrorCode = pCrtSection->SetProperties( P, i );
|
|
if( ErrorCode == SB_ERR_VOID_ENTRY_DESCRIPTION) ErrorCode = SB_ERR_NONE;
|
|
}
|
|
break;
|
|
case 'US': //subsections position
|
|
/* if (!pCrtSection) ErrorCode = SB_ERR_MISPLACED_KEYWORD;
|
|
else
|
|
{
|
|
CEntryTypeDesc* pSubSections = new CEntryTypeDesc( SB_STR_SUBSECT, pCrtSection->NumEntries() );
|
|
pSubSections->EnableEntryCount(); // the subsection number is automatically stored
|
|
pCrtSection->AddEntryDescription( pSubSections );
|
|
while(!( P.Advance(&i) & CTP_NEWLINE ) && !(i & CTP_EOF));
|
|
}*/
|
|
while(!( P.Advance(&i) & CTP_NEWLINE ) && !(i & CTP_EOF)); // ignore the keyword
|
|
break;
|
|
case 'AV': //value
|
|
if (!pCrtSection) ErrorCode = SB_ERR_MISPLACED_KEYWORD;
|
|
else
|
|
{
|
|
CEntryTypeDesc* pValues = new CEntryTypeDesc( SB_STR_VALUE, pCrtSection->NumEntries() );
|
|
ErrorCode = pValues->SetProperties( P, i );
|
|
if( ErrorCode == SB_ERR_NONE ) pCrtSection->AddEntryDescription( pValues );
|
|
else delete pValues;
|
|
}
|
|
break;
|
|
default: ErrorCode = SB_ERR_UNKNOWN_KEYWORD;
|
|
}
|
|
else if(!(i&CTP_NEWLINE) || !pCrtSection ) P.Advance(&i); // ignore irrelevant text
|
|
else
|
|
{
|
|
CEntryTypeDesc* pEn = new CEntryTypeDesc( P.Word(), pCrtSection->NumEntries() );
|
|
ErrorCode = pEn->SetProperties( P, i );
|
|
if( ErrorCode == SB_ERR_NONE )
|
|
pCrtSection->AddEntryDescription( pEn );
|
|
else
|
|
delete pEn;
|
|
}
|
|
if( ErrorCode == SB_ERR_NONE) AddSection( pCrtSection );
|
|
else delete pCrtSection;
|
|
if( !(i & CTP_EOF) && ErrorCode == SB_ERR_NONE ) ErrorCode = SB_ERR_UNKNOWN;
|
|
if( pLine ) *pLine = P.Line();
|
|
return ErrorCode;
|
|
}
|
|
|
|
|
|
BOOL CScr2bin::IsFileSupported( char* fName)
|
|
{
|
|
char Ext[_MAX_EXT], *ex = Ext+1;
|
|
Ext[1] = 0;
|
|
_splitpath( fName, NULL, NULL, NULL, Ext);
|
|
int idx = m_arSupportedFiles.Index((CFileExtension*)&ex);
|
|
return ( idx>=0 && (m_bFilterDisabled || m_arSupportedFiles[idx]->IsEnabled()));
|
|
}
|
|
|
|
BOOL CScr2bin::IsFileKnown( char* fName)
|
|
{
|
|
char Ext[_MAX_EXT], *ex = Ext+1;
|
|
Ext[1] = 0;
|
|
_splitpath( fName, NULL, NULL, NULL, Ext);
|
|
int idx = m_arSupportedFiles.Index((CFileExtension*)&ex);
|
|
return ( idx>=0 );
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : converts a certain script file
|
|
// PARAMS : the name of the script file; optional pointer to an unsigned integer
|
|
// in which to return the number of the erroneus line
|
|
// RETURNS : 0(SC_ERR_NONE) if successful, the error code on failure
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
int CScr2bin::Convert( char* inputFile, char* outputFile, unsigned* pLine /*= NULL*/, unsigned long* pPosition /*= NULL*/, unsigned long* pWritten/*= NULL*/)
|
|
{
|
|
int ErrorCode = SB_ERR_NONE;
|
|
|
|
char Ext[_MAX_EXT], *ex = Ext+1;
|
|
Ext[1] = 0;
|
|
_splitpath( inputFile, NULL, NULL, NULL, Ext);
|
|
if( m_arSupportedFiles.Index((CFileExtension*)&ex)<0 )
|
|
return SB_ERR_BAD_FILE_EXTENSION; // the extension is not supported, so we exit
|
|
|
|
CTextParser P; // the file parser object
|
|
if(!P.AccessFile(inputFile))
|
|
return SB_ERR_FILEOPEN; // unable to open the specifies script file
|
|
//P.SetType( "|*^.:_\\-", CTP_TEXT);
|
|
P.SetType( "()=,", CTP_SEPARATOR );
|
|
P.SetType( ";", CTP_LINE_COMMENT);
|
|
P.SetType( "[]", CTP_COMMENT);
|
|
P.SetType( "\"", CTP_WORD_WRAPPER);
|
|
P.SetType( "{", SB_BEGINSECTION);
|
|
P.SetType( "}", SB_ENDSECTION);
|
|
P.SetType( "$", SB_DIRECTIVE);
|
|
|
|
COutStream O; // the output stream
|
|
if((ErrorCode = O.Open(outputFile)) != SB_ERR_NONE)
|
|
return SB_ERR_OUTPUT_FILEOPEN;
|
|
|
|
CList<CConversionUnit> Data; // the data pool
|
|
|
|
CSTPArray<CCRef> Refs; // the references pool
|
|
Refs.SetGranularity(100); // increase default granularity to 100
|
|
|
|
//parse the script file
|
|
int CloseSectionCount = 0;
|
|
DWORD i = P.Advance();
|
|
while( !(i & CTP_EOF) && ErrorCode == SB_ERR_NONE)
|
|
if( i & SB_DIRECTIVE )
|
|
ErrorCode = ConvertDirective( Data, P, i);
|
|
else
|
|
ErrorCode = ConvertSection( Data, Refs, P, i, CloseSectionCount);
|
|
|
|
|
|
// save the binary file
|
|
if(ErrorCode == SB_ERR_NONE)
|
|
{
|
|
// process the sections level leap:
|
|
for(CSection* pCrtLev = (CSection*)Data.Start(), *pNext; pCrtLev; pCrtLev = pNext )
|
|
{
|
|
pNext = (CSection*)((CConversionUnit*)pCrtLev)->Next();
|
|
pCrtLev->m_Level = (pNext?pNext->m_Level: 0) - pCrtLev->m_Level;
|
|
}
|
|
|
|
O.Write("BINARY",6); // write the file label
|
|
|
|
//process and save the references
|
|
CTypedPtrArray<CRefChk*> RefTgs; // the reference tags pool
|
|
RefTgs.SetGranularity(20); // increase default granularity to 20
|
|
|
|
//*
|
|
SetTags( RefTgs, Refs ); // create the the reference tags table
|
|
WORD k=0, refCount = RefTgs.GetSize();
|
|
O.Write( &refCount, sizeof(WORD)); // write the the reference tags number
|
|
for( ;k<refCount; k++) RefTgs[k]->Write(O); // write the elements
|
|
/*/
|
|
WORD refCount = 0;
|
|
O.Write( &refCount, sizeof(WORD)); // the references are currently stored expanded
|
|
//*/
|
|
//save the binary information (sections and directives)
|
|
for(CConversionUnit* pCrt = Data.Start(); pCrt; pCrt = pCrt->Next() )
|
|
pCrt->Write(O);
|
|
//write the end of the file
|
|
O.Write("\0\0\0", 3);
|
|
|
|
RefTgs.DeleteAll(); // delete the reference tags
|
|
}
|
|
else
|
|
{
|
|
O.Close();
|
|
DeleteFile(outputFile); // delete the output file.
|
|
}
|
|
//return
|
|
Data.DeleteAll(); //cleanup
|
|
if( pLine ) *pLine = P.Line();
|
|
if( pPosition ) *pPosition = P.Position();
|
|
if( pWritten ) *pWritten = (ErrorCode == SB_ERR_NONE? O.Written() : 0);
|
|
return ErrorCode;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : computes the string tags
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CScr2bin::SetTags( CTypedPtrArray<CRefChk*> &RefTgs, CSTPArray<CCRef> &Refs )
|
|
{
|
|
int Sim, LSim, Start = 0, End = 0, i = 0, j = Refs.GetUpperBound();
|
|
while( i< j )
|
|
{
|
|
for(Start = i, Sim = LSim = 0xfffffff;; i++ )
|
|
{
|
|
End = i;
|
|
if( i == j ) break;
|
|
CCRef::GetSimCnt( LSim, Refs[i], Refs[i+1]);
|
|
if(LSim<3)
|
|
{
|
|
if(Sim == 0xfffffff) Sim = 0;
|
|
i++;
|
|
break;
|
|
}
|
|
if(LSim<Sim) Sim = LSim;
|
|
}
|
|
if(Sim>2)
|
|
{
|
|
CRefChk* pNewChk = Refs[Start]->GenerateChk(Sim);
|
|
pNewChk->SetTag(RefTgs.GetSize());
|
|
RefTgs.Add( pNewChk );
|
|
CSTPArray<CCRef> NewRefs;
|
|
NewRefs.SetGranularity(End-Start+1);
|
|
BOOL NA;
|
|
for( ;Start<=End; Start++ )
|
|
{
|
|
CCRef* pCrtRef = Refs[Start];
|
|
pCrtRef->AddChk( pNewChk );
|
|
NewRefs.SAdd( pCrtRef,NA );
|
|
}
|
|
SetTags( RefTgs, NewRefs );
|
|
}
|
|
}
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : converts a section
|
|
// PARAMS : the data pool; the parser, the parsercode
|
|
// RETURNS : 0(SC_ERR_NONE) if successful, the error code on failure
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
int CScr2bin::ConvertSection(CList<CConversionUnit> &Data, CSTPArray<CCRef> &Refs, CTextParser& P, DWORD& i, int & CloseSectionCount, unsigned char Level )
|
|
{
|
|
int ErrorCode = SB_ERR_NONE;
|
|
BOOL NA;
|
|
char* szName = P.AllocWord();
|
|
char* p = strchr (szName, ':');
|
|
if( p ) *p = 0;
|
|
int idx = m_arSections.Index((CSectionTypeDesc*)&szName);
|
|
delete[] szName;
|
|
if( idx<0 )
|
|
return SB_ERR_UNKNOWN_SECTION;
|
|
CSectionTypeDesc* PcrtDesc = m_arSections[idx];
|
|
CSection * pNewSection = new CSection( PcrtDesc, P.Word(), Level );
|
|
Data.Add(pNewSection);
|
|
//Refs.SAdd( pNewSection->GetRefName(),NA );
|
|
|
|
// construct the entry slots
|
|
BOOL bNotSorted = PcrtDesc->IsNotSorted();
|
|
if( bNotSorted )
|
|
{
|
|
//NO ENTRY GROUPING - script-like behaviour
|
|
pNewSection->m_arEntries.SetSize( 1 );
|
|
pNewSection->m_arEntries.SetAt(0,new CEntrySlot());
|
|
}
|
|
else
|
|
{
|
|
//NORMAL TREATMENT
|
|
int numtypes = PcrtDesc->NumEntries();
|
|
pNewSection->m_arEntries.SetSize( numtypes );
|
|
for(idx = 0; idx< numtypes; idx++ )
|
|
{
|
|
CEntryTypeDesc* pETD = PcrtDesc->EntryDesc(idx);
|
|
CEntrySlot* pEn = new CEntrySlot();
|
|
pEn->m_pDesc = pETD;
|
|
pNewSection->m_arEntries.SetAt(pETD->Index(),pEn);
|
|
if(!strcmp(pETD->Name(), SB_STR_VALUE))
|
|
{
|
|
//Values;
|
|
for(int k = 0, max = pETD->NumParam(); k<max; k++)
|
|
{
|
|
CConversionUnit* pConv = pETD->Param(k)->CreateConversionUnit();
|
|
if( pConv->Code() == 1 ) Refs.SAdd( (CCRef*)pConv, NA); // this is a reference, it must be coded
|
|
pEn->m_arEntries.Add(pConv);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(PcrtDesc->Tag() == TAG_FILEENTRY)
|
|
{
|
|
//file entry
|
|
CEntryTypeDesc* pEntryDesc = PcrtDesc->EntryDesc(P.Word());
|
|
if(!pEntryDesc)
|
|
ErrorCode = SB_ERR_UNKNOWN_ENTRY;
|
|
else
|
|
{
|
|
CEntry * pEntry = new CEntry();
|
|
ErrorCode = pEntry->SetParams( pEntryDesc, Refs, P, i );
|
|
if(ErrorCode == SB_ERR_NONE)
|
|
pNewSection->m_arEntries[pEntryDesc->Index()]->m_arEntries.Add(pEntry);
|
|
else
|
|
delete pEntry;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//normal section
|
|
//Get The parameters
|
|
ErrorCode = pNewSection->SetParams( PcrtDesc, Refs, P, i );
|
|
if( ErrorCode == SB_ERR_NONE )
|
|
{
|
|
// get the entries
|
|
while(!(i & (CTP_EOF|SB_ENDSECTION)) && ErrorCode == SB_ERR_NONE && CloseSectionCount<=0 )
|
|
if( i & SB_BEGINSECTION)
|
|
{ //subsections
|
|
// int idx = PcrtDesc->Place(SB_STR_SUBSECT);
|
|
// if( idx<0 ) ErrorCode = SB_ERR_SUBSECTIONS_NOT_SUPPORTED;
|
|
// else ErrorCode = ConvertSection( pNewSection->m_arEntries[idx]->m_arEntries, Refs, P, i, CloseSectionCount);
|
|
ErrorCode = ConvertSection( Data, Refs, P, i, CloseSectionCount, Level + 1);
|
|
}
|
|
else
|
|
{
|
|
//entries
|
|
CEntryTypeDesc* pEntryDesc = PcrtDesc->EntryDesc(P.Word());
|
|
if(!pEntryDesc)
|
|
ErrorCode = SB_ERR_UNKNOWN_ENTRY;
|
|
else
|
|
{
|
|
CEntry * pEntry = new CEntry();
|
|
ErrorCode = pEntry->SetParams( pEntryDesc, Refs, P, i, bNotSorted );
|
|
if(ErrorCode == SB_ERR_NONE)
|
|
pNewSection->m_arEntries[bNotSorted? 0:pEntryDesc->Index()]->m_arEntries.Add(pEntry);
|
|
else
|
|
delete pEntry;
|
|
}
|
|
}
|
|
if( i&SB_ENDSECTION )
|
|
{
|
|
CloseSectionCount = P.GetCodeCount(SB_ENDSECTION);
|
|
i &= ~SB_ENDSECTION ;
|
|
}
|
|
CloseSectionCount--;
|
|
}
|
|
}
|
|
// if( ErrorCode == SB_ERR_NONE )
|
|
// Data.Add(pNewSection);
|
|
// else
|
|
// delete pNewSection;
|
|
return ErrorCode;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : converts a directive entry
|
|
// PARAMS : the data pool; the parser, the parsercode
|
|
// RETURNS : 0(SC_ERR_NONE) if successful, the error code on failure
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
int CScr2bin::ConvertDirective( CList<CConversionUnit> &Data, CTextParser& P, DWORD& i, unsigned char Level )
|
|
{
|
|
i &= ~CTP_NEWLINE;
|
|
int ErrorCode = SB_ERR_NONE;
|
|
CDirective* pDir = NULL;
|
|
if(!strcmp(P.Word(), "SetCurrentFileLong"))
|
|
{
|
|
pDir = new CDirective( TAG_SetCurrentFileLong, Level );
|
|
if( P.Advance(&i) == CTP_SEPARATOR )
|
|
{
|
|
pDir->Add( new CCShort((short)atoi(P.Word())) );
|
|
if( P.Advance(&i) == CTP_SEPARATOR )
|
|
pDir->Add( new CCLong( atoi(P.Word())) );
|
|
else ErrorCode = SB_ERR_PARAMETER_MISSING;
|
|
}
|
|
else ErrorCode = SB_ERR_PARAMETER_MISSING;
|
|
}
|
|
else if(!strcmp(P.Word(), "SetCurrentFileDouble"))
|
|
{
|
|
pDir = new CDirective( TAG_SetCurrentFileDouble, Level );
|
|
if( P.Advance(&i) == CTP_SEPARATOR )
|
|
{
|
|
pDir->Add( new CCShort((short)atoi(P.Word())) );
|
|
if( P.Advance(&i) == CTP_SEPARATOR )
|
|
pDir->Add( new CCDouble( atof(P.Word())) );
|
|
else ErrorCode = SB_ERR_PARAMETER_MISSING;
|
|
}
|
|
else ErrorCode = SB_ERR_PARAMETER_MISSING;
|
|
}
|
|
else if(!strcmp(P.Word(), "Comments"))
|
|
{
|
|
do P.Advance(&i);
|
|
while(!(i & CTP_EOF) && !( i & SB_DIRECTIVE && !strcmp(P.Word(), "EndComments")));
|
|
}
|
|
else if(!strcmp(P.Word(), "ForceAnalyse")) pDir = new CDirective( TAG_ForceAnalyse, Level );
|
|
else if(!strcmp(P.Word(), "EndForceAnalyse")) pDir = new CDirective( TAG_EndForceAnalyse, Level );
|
|
else if(!strcmp(P.Word(), "NotSaveSection")) pDir = new CDirective( TAG_NotSaveSection, Level );
|
|
else if(!strcmp(P.Word(), "EndNotSaveSection")) pDir = new CDirective( TAG_EndNotSaveSection, Level );
|
|
else if(!strcmp(P.Word(), "BreakPoint")) pDir = new CDirective( TAG_BreakPoint, Level );
|
|
else if(!strcmp(P.Word(), "UpdateLog")) pDir = new CDirective( TAG_UpdateLog, Level );
|
|
else return SB_ERR_UNKNOWN_DIRECTIVE;
|
|
|
|
if(ErrorCode == SB_ERR_NONE) Data.Add( pDir );
|
|
else delete pDir;
|
|
while( !( i & (CTP_NEWLINE|CTP_EOF))) P.Advance(&i);
|
|
|
|
return ErrorCode;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : properties setting for the entry description
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
int CScr2bin::CEntryTypeDesc::SetProperties( CTextParser & P, DWORD& i )
|
|
{
|
|
BOOL Assigned = FALSE;
|
|
int ERRoR = SB_ERR_NONE;
|
|
P.Advance(&i);
|
|
while( !(i & CTP_EOF) && !(i & CTP_NEWLINE) && ERRoR == SB_ERR_NONE)
|
|
{
|
|
Assigned = TRUE;
|
|
if( i & SB_ENUM )
|
|
{
|
|
CEnumDesc* pNewEnum = new CEnumDesc();
|
|
while( !(i & SB_END_ENUM) && ERRoR == SB_ERR_NONE )
|
|
if(i & CTP_EOF) ERRoR = SB_ERR_UNEXPECTED_EOF;
|
|
else
|
|
{
|
|
char* szName = P.AllocWord();
|
|
if( P.Advance(&i) & SB_ATTRIB && !(i & SB_END_ENUM) )
|
|
{
|
|
pNewEnum->AddValue(szName, (char)atoi(P.Word()) );
|
|
P.Advance(&i);
|
|
}
|
|
else pNewEnum->AddValue(szName, ED_DEFAULT_INDEX );
|
|
delete[] szName;
|
|
}
|
|
i &= ~SB_END_ENUM;
|
|
if(ERRoR == SB_ERR_NONE) m_arParams.Add( pNewEnum );
|
|
else delete( pNewEnum );
|
|
}
|
|
else if(i & SB_ATTRIB)
|
|
{
|
|
int k = m_arParams.GetUpperBound();
|
|
if (k>=0)
|
|
{
|
|
m_arParams[k]->SetDefaultValue(P.Word());
|
|
P.Advance(&i);
|
|
}
|
|
else ERRoR = SB_ERR_ILLEGAL_ASSIGNEMENT;
|
|
}
|
|
else
|
|
{
|
|
const char *szParDesc = P.Word();
|
|
int k = 0, l = strlen(szParDesc);
|
|
m_arParams.SetGranularity(l);
|
|
for(; k<l; k++)
|
|
switch(szParDesc[k])
|
|
{
|
|
//parameters
|
|
case 'N': case 'n': m_arParams.Add( new CNULLDesc()); break; // NULL parameter
|
|
case 'C': case 'c': m_arParams.Add( new CCharDesc()); break; // signed/unsigned char
|
|
case 'W': case 'w': m_arParams.Add( new CShortDesc()); break; // signed/unsigned short
|
|
case 'L': case 'l': m_arParams.Add( new CLongDesc()); break; // signed/unsigned long
|
|
case 'F': case 'f': m_arParams.Add( new CFloatDesc()); break; // float
|
|
case 'D': case 'd': m_arParams.Add( new CDoubleDesc()); break; // double
|
|
case 'S': case 's': m_arParams.Add( new CStringDesc()); break; // string
|
|
case 'R': case 'r': m_arParams.Add( new CRefDesc()); break; // reference
|
|
|
|
//flags
|
|
case 'T': // tag assignement
|
|
if( k!=l-1 || P.Advance(&i) & CTP_EOF || ! ( i & SB_ATTRIB ))
|
|
k=l, ERRoR = SB_ERR_TAG_VALUE_MISSING;
|
|
else
|
|
EnableTag( (unsigned char) atoi(P.Word()));
|
|
break;
|
|
case 'Q': EnableEntryCount(); break; // entry count
|
|
case 'P': EnableParamCount(); break; // parameters count
|
|
default: ERRoR = SB_ERR_UNKNOWN_TYPE; k=l;
|
|
}
|
|
P.Advance(&i);
|
|
}
|
|
}
|
|
if( !Assigned && ERRoR == SB_ERR_NONE ) ERRoR = SB_ERR_VOID_ENTRY_DESCRIPTION;
|
|
return ERRoR;
|
|
}
|
|
|
|
|
|
//__________________________________________________________________________________________________
|
|
// Output stream
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : opens a new stream
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
int COutStream::Open( char* szName)
|
|
{
|
|
Close();
|
|
m_written = 0;
|
|
m_hFile = CreateFile( szName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS , FILE_ATTRIBUTE_NORMAL, NULL);
|
|
return ( m_hFile == INVALID_HANDLE_VALUE)? SB_ERR_FILEOPEN: SB_ERR_NONE;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : closes the current stream
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void COutStream::Close()
|
|
{
|
|
if(m_hFile != INVALID_HANDLE_VALUE)
|
|
{
|
|
Flush();
|
|
CloseHandle( m_hFile );
|
|
}
|
|
m_hFile = INVALID_HANDLE_VALUE;
|
|
m_spaceUsed = 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
//__________________________________________________________________________________________________
|
|
// Enum Parameter functions
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : adds an enum element
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CScr2bin::CEnumDesc::SetDefaultValue(char* szWord )
|
|
{
|
|
int i = m_arEnum.Index((CEnum*)&szWord);
|
|
if(i>=0) m_Default = m_arEnum[i]->Tag();
|
|
else m_Default = (char)atoi(szWord);
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : adds an enum element
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CScr2bin::CEnumDesc::AddValue(char* szName, char Value )
|
|
{
|
|
if(Value != ED_DEFAULT_INDEX) m_crtValue = Value;
|
|
CEnum* pEn = new CEnum( m_crtValue, szName);
|
|
BOOL NotAdded;
|
|
m_arEnum.SAdd( pEn, NotAdded, FALSE);
|
|
if(NotAdded) delete pEn;
|
|
else m_crtValue++;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : creates the corresponding conversion unit
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
CConversionUnit* CScr2bin::CEnumDesc::CreateConversionUnit( char* szWord )
|
|
{
|
|
char tag = m_Default;
|
|
if( szWord )
|
|
{
|
|
int i = m_arEnum.Index((CEnum*)&szWord);
|
|
if(i>=0) tag = m_arEnum[i]->Tag();
|
|
}
|
|
return new CCChar( tag );
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
// String conversion unit functions
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : constructor
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
CScr2bin::CCString::CCString( char* Value )
|
|
{
|
|
unsigned size = strlen(Value);
|
|
_ASSERT( size < 0xffff);
|
|
m_pString = new char[size + sizeof(unsigned short) +1];
|
|
((unsigned short*)m_pString)[0] = (unsigned short)size;
|
|
strcpy( m_pString + sizeof(unsigned short), Value );
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
// String parameter statics
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
char CScr2bin::CStringDesc::CSTRING_DEFAULT_PARAM[1] = {0};
|
|
|
|
//__________________________________________________________________________________________________
|
|
// Reference parameter statics
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
char CScr2bin::CRefDesc::CREF_DEFAULT_PARAM[1] = {0};
|
|
|
|
|
|
//__________________________________________________________________________________________________
|
|
// Reference tag holder methods
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : constructor
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
CRefChk::CRefChk( char* szStr, WORD size ): CListElement<CRefChk>()
|
|
{
|
|
m_Tag = 0xffff;
|
|
memcpy( m_szStr = new char[size+1], szStr, size);
|
|
m_szStr[size] = 0;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : tag stream output
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CRefChk::Write( COutStream& stream )
|
|
{
|
|
WORD len = strlen(m_szStr);
|
|
stream.Write( &len, sizeof(WORD));
|
|
stream.Write( m_szStr, len );
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : tag chain output
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CRefChk::WriteTags( COutStream& stream, WORD len )
|
|
{
|
|
if( Next() ) Next()->WriteTags( stream , 1 );
|
|
WORD Tag = m_Tag | 0x8000 | (len? 0: 0x4000);
|
|
stream.Write( &Tag, sizeof(WORD));
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
// Reference conversion unit methods
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
void CScr2bin::CCRef::GetSimCnt (int &Sim, CCRef* pFrst, CCRef* pScnd )
|
|
{
|
|
int i = strlen(pScnd->m_crtStr), j = strlen(pFrst->m_crtStr);
|
|
j = min(i, j);
|
|
j = min(j, Sim);
|
|
for(i = 0; i<j && pFrst->m_crtStr[i] == pScnd->m_crtStr[i] ; i++ );
|
|
Sim = i;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : size function
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
DWORD CScr2bin::CCRef::Size()
|
|
{
|
|
int len = strlen(m_crtStr);
|
|
DWORD size = 0;
|
|
for( CRefChk* pRefTag = m_pTags; pRefTag; pRefTag = pRefTag->Next() )
|
|
size += sizeof(WORD);
|
|
size += len + ((len || !size)? sizeof(WORD): 0);
|
|
return size;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : stream output
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CScr2bin::CCRef::Write( COutStream& stream )
|
|
{
|
|
WORD len = strlen(m_crtStr);
|
|
if(m_pTags) m_pTags-> WriteTags( stream, len);
|
|
if(len || !m_pTags)
|
|
{
|
|
len |= 0x4000;
|
|
stream.Write( &len, sizeof(WORD));
|
|
stream.Write( m_crtStr, len & ~0x4000);
|
|
}
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
// Directive
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
DWORD CScr2bin::CDirective::Size()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : output fn
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CScr2bin::CDirective::Write( COutStream& stream )
|
|
{
|
|
stream.Write( &m_ucTag, sizeof(char) );
|
|
WORD size = 0;
|
|
for(CConversionUnit* pCrt = Start(); pCrt; pCrt = pCrt->Next() )
|
|
size += (WORD)(pCrt->Size());
|
|
stream.Write( &size, sizeof(WORD) );
|
|
for(pCrt = Start(); pCrt; pCrt = pCrt->Next() )
|
|
pCrt->Write( stream );
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
// Section
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : constructor
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
CScr2bin::CSection::CSection( CSectionTypeDesc* pDesc, char* szName, unsigned char Level )
|
|
{
|
|
m_Level = Level;
|
|
m_pName = new CCString( szName );
|
|
// m_pName = new CCRef( szName );
|
|
m_pDesc = pDesc;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : constructor
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
CScr2bin::CSection::~CSection()
|
|
{
|
|
delete m_pName;
|
|
m_arEntries.DeleteAll();
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : size info
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
DWORD CScr2bin::CSection::Size()
|
|
{
|
|
DWORD size = 1 + 2 + CEntry::Size();
|
|
int i = 0, j = m_arEntries.GetSize();
|
|
for( ;i<j; i++)
|
|
size+= m_arEntries[i]->Size();
|
|
if(size >= 0xffff) size+=4;
|
|
size+= m_pName->Size();
|
|
size += 1; // level character
|
|
if(m_pDesc->IsNotSorted()) size++;
|
|
return size;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : output
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CScr2bin::CSection::Write( COutStream& stream )
|
|
{
|
|
char ucTag = TAG_SECTION;
|
|
stream.Write( &ucTag, sizeof(char)); // the section tag
|
|
m_pName->Write(stream); // the section name
|
|
WORD sizeW = 0xffff;
|
|
DWORD size = CEntry::Size();
|
|
int i = 0, j = m_arEntries.GetSize();
|
|
for( ;i<j; i++)
|
|
size += m_arEntries[i]->Size();
|
|
size += 1; // level character
|
|
//write the section size
|
|
if( size<0xffff )
|
|
{
|
|
sizeW = (WORD) size;
|
|
stream.Write( &sizeW, sizeof(WORD)); // the section size -> WORD based
|
|
}
|
|
else
|
|
{
|
|
stream.Write( &sizeW, sizeof(WORD)); // overflow flag
|
|
stream.Write( &size, sizeof(DWORD)); // the section size -> DWORD based
|
|
}
|
|
CEntry::Write(stream); //the section parameters
|
|
for( i = 0; i<j; i++)
|
|
m_arEntries[i]->Write(stream); // the entries
|
|
if(m_pDesc->IsNotSorted())
|
|
{
|
|
char a = -1;
|
|
stream.Write( &a, sizeof(char)); // the end value
|
|
}
|
|
stream.Write( &m_Level, sizeof(char)); // the level leap
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
// Entry Slot
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : size info
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
DWORD CScr2bin::CEntrySlot::Size()
|
|
{
|
|
DWORD size = 0, NumEntries = 0;
|
|
for(CConversionUnit* pCrt = m_arEntries.Start(); pCrt; pCrt = pCrt->Next() )
|
|
{
|
|
size += pCrt->Size();
|
|
NumEntries++;
|
|
}
|
|
if(m_pDesc)
|
|
{
|
|
if(m_pDesc->HasCount())
|
|
{
|
|
size+=2; // the count of entries is added
|
|
if(m_pDesc->IsTagged()) size++;
|
|
}
|
|
else if(m_pDesc->IsTagged()) size+= NumEntries;
|
|
}
|
|
return size;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : output
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CScr2bin::CEntrySlot::Write( COutStream& stream )
|
|
{
|
|
if(m_pDesc)
|
|
{
|
|
WORD num = (WORD)m_arEntries.GetSize();
|
|
unsigned char ucTag = m_pDesc->Tag();
|
|
|
|
if(m_pDesc->HasCount())
|
|
{
|
|
if(m_pDesc->IsTagged()) stream.Write( &ucTag, sizeof(char) );
|
|
stream.Write( &num, sizeof(WORD) );
|
|
}
|
|
else if(m_pDesc->IsTagged())
|
|
{
|
|
for(CConversionUnit* pCrt = m_arEntries.Start(); pCrt; pCrt = pCrt->Next() )
|
|
{
|
|
stream.Write( &ucTag, sizeof(char) );
|
|
pCrt->Write( stream );
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
for(CConversionUnit* pCrt = m_arEntries.Start(); pCrt; pCrt = pCrt->Next() )
|
|
pCrt->Write( stream );
|
|
}
|
|
|
|
|
|
//__________________________________________________________________________________________________
|
|
// Entry
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : size info
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
DWORD CScr2bin::CEntry::Size()
|
|
{
|
|
DWORD size = 0;
|
|
for(CConversionUnit* pCrt = m_arParams.Start(); pCrt; pCrt = pCrt->Next() )
|
|
size += pCrt->Size();
|
|
if(m_bPCount&1) size++;
|
|
if(m_bPCount&2) size++;
|
|
return size;
|
|
}
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : output
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
void CScr2bin::CEntry::Write( COutStream& stream )
|
|
{
|
|
CConversionUnit* pCrt = m_arParams.Start();
|
|
|
|
BYTE numP = (BYTE)m_arParams.GetSize();
|
|
if(m_bPCount&2)
|
|
{
|
|
pCrt->Write( stream );
|
|
pCrt = pCrt->Next();
|
|
numP--;
|
|
}
|
|
if( m_bPCount ) stream.Write( &numP, 1);
|
|
for(; pCrt; pCrt = pCrt->Next() )
|
|
pCrt->Write( stream );
|
|
}
|
|
|
|
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : Parameter assignement
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
int CScr2bin::CEntry::SetParams( CEntryTypeDesc* pEntryDesc, CSTPArray<CCRef> &Refs, CTextParser& P, DWORD& i, BOOL NoSort )
|
|
{
|
|
BOOL NA;
|
|
m_bPCount = (pEntryDesc->HasParamCount()? 1:0);
|
|
if(NoSort) // the default entry type
|
|
{
|
|
m_bPCount |=2;
|
|
m_arParams.Add( new CCChar(pEntryDesc->Tag()) );
|
|
}
|
|
if(pEntryDesc->IsDef()) // the default entry type
|
|
m_arParams.Add( new CCString(P.Word()) );
|
|
|
|
int numP = pEntryDesc->NumParam();
|
|
int idx = 0;
|
|
|
|
for(P.Advance(&i); !(i & (CTP_EOF|CTP_NEWLINE)) && idx<numP; idx++, P.Advance(&i))
|
|
m_arParams.Add( pEntryDesc->Param(idx)->CreateConversionUnit(P.Word()));
|
|
|
|
while (!(i & (CTP_EOF|CTP_NEWLINE))) P.Advance(&i);
|
|
|
|
if(!(m_bPCount&1)) // fixed param count
|
|
for( ;idx<numP; idx++ )
|
|
m_arParams.Add( pEntryDesc->Param(idx)->CreateConversionUnit());
|
|
|
|
//ref search
|
|
for(CConversionUnit* pCrt = m_arParams.Start(); pCrt; pCrt = pCrt->Next() )
|
|
if(pCrt->Code()) Refs.SAdd( (CCRef*)pCrt,NA );
|
|
return SB_ERR_NONE;
|
|
}
|