Esempio n. 1
0
//----------------------------------------------------------------//
bool ZLFileSys::Copy ( cc8* path, cc8* newPath ) {

	zl_stat fileStat;

	if ( !ZLFileSys::GetFileStat ( path, fileStat )) return false;
	if ( !fileStat.mExists ) return false;

	if ( fileStat.mIsDir ) {
		
		bool result = true;
		
		STLString cwd = ZLFileSys::GetCurrentPath ();
		STLString toPath = ZLFileSys::GetAbsoluteDirPath ( newPath );
		
		ZLFileSys::AffirmPath ( toPath );
		
		ZLFileSys::SetCurrentPath ( path );
		
		ZLDIR* itr = zl_dir_open ();
		if ( itr ) {
			while ( zl_dir_read_entry ( itr )) {
				cc8* entry = zl_dir_entry_name ( itr );
				if ( strcmp ( entry, "." ) == 0 ) continue;
				if ( strcmp ( entry, ".." ) == 0 ) continue;
				
				STLString destEntry = toPath;
				destEntry.append ( entry );
				
				if ( !ZLFileSys::Copy ( entry, destEntry )) {
					result = false;
					break;
				}
			}
			zl_dir_close ( itr );
		}
		ZLFileSys::SetCurrentPath ( cwd );
		
		return result;
	}
	else {
		ZLFileStream infile;
		if ( infile.OpenRead ( path )) {
		
			ZLFileStream outfile;
			if ( outfile.OpenWrite ( newPath )) {
				outfile.WriteStream ( infile );
				return true;
			}
		}
	}
	
	return false;
}
Esempio n. 2
0
//----------------------------------------------------------------//
bool MOAIDataBuffer::Save ( cc8* filename ) {

	ZLFileStream out;

	if ( !out.OpenWrite ( filename )) return false;

	this->mMutex.Lock ();
	out.WriteBytes ( this->mBytes , this->mBytes.Size ());
	this->mMutex.Unlock ();

	return true;
}
Esempio n. 3
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;
}
Esempio n. 4
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;
}
Esempio n. 5
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 );
		}
	}
}
Esempio n. 6
0
//----------------------------------------------------------------//
void _write_png ( MOAIImage& image, cc8* filename ) {

	ZLFileStream out;
	out.OpenWrite ( filename );
	image.WritePNG ( out );
}