Пример #1
0
//----------------------------------------------------------------//
bool MOAIDataBuffer::Load ( cc8* filename ) {

	ZLFileStream in;
	if ( !in.OpenRead ( filename )) return false;

	this->mMutex.Lock ();

	u32 size = in.GetLength ();
	this->mBytes.Init ( size );
	in.ReadBytes ( this->mBytes , size );

	this->mMutex.Unlock ();

	return true;
}
Пример #2
0
//----------------------------------------------------------------//
int main ( int argc, char** argv ) {

	if ( argc < 3 ) return 0;
	
	cc8* infile = argv [ 1 ];
	cc8* outfile = argv [ 2 ];
	
	ZLFileStream file;
	file.OpenRead ( infile );
	
	size_t size = file.GetLength ();
	void* data = malloc ( size );
	file.ReadBytes ( data, size );
	
	_dumpAsCPPHeader ( outfile, data, size, 16 );
	
	free ( data );
	return 0;
}
Пример #3
0
//----------------------------------------------------------------//
void ZLCgt::Load ( cc8* filename ) {

	ZLFileStream stream;
	stream.OpenRead ( filename );

	this->mHeader = this->ReadUnicodeAsASCII ( stream );
	
	size_t length = stream.GetLength ();
	while ( stream.GetCursor () < length ) {
		
		char recordType = stream.Read < u8 >( 0 );
		UNUSED ( recordType );
		assert ( recordType == 'M' );
		
		u16 totalEntries = stream.Read < u16 >( 0 );
		
		u8 contentType = this->ReadByteEntry ( stream );
		switch ( contentType ) {
			
			// Parameters
			case 'P': {
				
				this->mName = this->ReadStringEntry ( stream );
				this->mVersion = this->ReadStringEntry ( stream );
				this->mAuthor = this->ReadStringEntry ( stream );
				this->mAbout = this->ReadStringEntry ( stream );
				this->mCaseSensitive = this->ReadBoolEntry ( stream );
				this->mLALRStartSymbol = this->ReadIntEntry ( stream );
				
				break;
			}
			
			// Table Counts
			case 'T': {
				
				this->mSymbolTable.Init ( this->ReadIntEntry ( stream ));
				this->mCharSetTable.Init ( this->ReadIntEntry ( stream ));
				this->mRuleTable.Init ( this->ReadIntEntry ( stream ));
				this->mDFAStateTable.Init ( this->ReadIntEntry ( stream ));
				this->mLALRStateTable.Init ( this->ReadIntEntry ( stream ));
				
				break;
			}
			
			// Initial States
			case 'I': {
				
				this->mDFAInitialStateID = this->ReadIntEntry ( stream );
				this->mLALRInitialStateID = this->ReadIntEntry ( stream );
				
				break;
			}
			
			// Symbol Table Entry
			case 'S': {
				
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mSymbolTable.Size ());
				ZLCgtSymbol& symbol = this->mSymbolTable [ index ];
				
				symbol.mID = index;
				symbol.mName = this->ReadStringEntry ( stream );
				symbol.mKind = this->ReadIntEntry ( stream );
				
				break;
			}
			
			// Character Set Table Entry
			case 'C': {
			
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mCharSetTable.Size ());
				
				this->mCharSetTable [ index ].mCharacters = this->ReadStringEntry ( stream );
				
				break;
			}
			
			// Rule Table Entry
			case 'R': {
			
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mRuleTable.Size ());
				ZLCgtRule& rule = this->mRuleTable [ index ];
				
				rule.mRuleResult = this->ReadIntEntry ( stream );
				this->ReadEmptyEntry ( stream );
				
				// 4 is the # of entries read so far...
				u32 ruleSize = totalEntries - 4;
				rule.mRuleSymbols.Init ( ruleSize );
				for ( u32 i = 0; i < ruleSize; ++i ) {
					rule.mRuleSymbols [ i ] = this->ReadIntEntry ( stream );
				}
				break;
			}
			
			// DFA State Entry
			case 'D': {
			
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mDFAStateTable.Size ());
				ZLDfaState& dfaState = this->mDFAStateTable [ index ];
				
				dfaState.mID = index;
				dfaState.mAcceptState = this->ReadBoolEntry ( stream );
				dfaState.mAcceptSymbolID = this->ReadIntEntry ( stream );
				this->ReadEmptyEntry ( stream );
				
				// 5 is the # of entries read so far...
				u32 totalEdges = totalEntries - 5;
				assert (( totalEdges % 3 ) == 0 ); // Make sure it's a sensible number...
				totalEdges = ( u32 )( totalEdges / 3 ); // '3' is the size of each edge...
				
				dfaState.mEdges.Init ( totalEdges );
				
				for ( u32 i = 0; i < totalEdges; ++i ) {
					dfaState.mEdges [ i ].mCharSetID = this->ReadIntEntry ( stream );
					dfaState.mEdges [ i ].mTargetStateID = this->ReadIntEntry ( stream );
					this->ReadEmptyEntry ( stream );
				}
				break;
			}
			
			// LALR State Entry
			case 'L': {
			
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mLALRStateTable.Size ());
				ZLLalrState& lalrState = this->mLALRStateTable [ index ];
				
				lalrState.mID = index;
				this->ReadEmptyEntry ( stream );
				
				// 3 is the # of entries read so far...
				u32 totalActions = totalEntries - 3;
				assert (( totalActions % 4 ) == 0 ); // Make sure it's a sensible number...
				totalActions = ( u32 )( totalActions / 4 ); // '4' is the size of each edge...
				
				lalrState.mActions.Init ( totalActions );
				
				for ( u32 i = 0; i < totalActions; ++i ) {
					ZLLalrAction& action = lalrState.mActions [ i ];
					action.mInputSymbolID = this->ReadIntEntry ( stream );
					action.mActionType = this->ReadIntEntry ( stream );
					action.mTarget = this->ReadIntEntry ( stream );
					this->ReadEmptyEntry ( stream );
				}
				break;
			}
			
			// Unknown
			default: assert ( false );
		}
	}
}