//----------------------------------------------------------------// u32 MOAIDeserializer::IsLuaFile ( cc8* filename ) { ZLFILE* file = ( ZLFILE* )zl_fopen ( filename, "r" ); if ( !file ) return LOAD_ERROR; char magic [ 256 ]; char* str = zl_fgets ( magic, 6, file ); UNUSED ( str ); zl_fclose ( file ); if ( strcmp ( magic, this->GetFileMagic ()) != 0 ) return INVALID_FILE; return SUCCESS; }
//----------------------------------------------------------------// int work_zl_ungetc ( int argc, char **argv ) { char buffer [ 256 ]; // try it straight FILE* file = fopen ( "ungetc.txt", "r" ); memset ( buffer, 0, 256 ); fread ( buffer, 1, 5, file ); ungetc ( '0', file ); ungetc ( '1', file ); ungetc ( '2', file ); ungetc ( '3', file ); ungetc ( '4', file ); fread ( buffer, 1, 3, file ); fseek ( file, 0, SEEK_CUR ); fread ( buffer, 1, 3, file ); fclose ( file ); // try it virtual zl_init (); zl_mount_virtual ( "test", "ungetc.zip" ); zl_chdir ( "test" ); ZLFILE* zfile = zl_fopen ( "ungetc.txt", "r" ); memset ( buffer, 0, 256 ); zl_fread ( buffer, 1, 5, zfile ); zl_ungetc ( '0', zfile ); zl_ungetc ( '1', zfile ); zl_ungetc ( '2', zfile ); zl_ungetc ( '3', zfile ); zl_ungetc ( '4', zfile ); zl_fread ( buffer, 1, 3, zfile ); zl_fseek ( zfile, 0, SEEK_CUR ); zl_fread ( buffer, 1, 3, zfile ); zl_fclose ( zfile ); zl_cleanup (); return 0; }
//----------------------------------------------------------------// int work_zl_fscanf ( int argc, char **argv ) { int result; float f1, f2, f3; char s [ 256 ]; u32 i1, i2; cc8* scanString = "%f, %fabc%f,e-,%*s%d,%x"; f1 = -1.0f; f2 = -1.0f; f3 = -1.0f; *s = 0; i1 = 0; i2 = 0; // try it straight FILE* file = fopen ( "scan.txt", "r" ); result = fscanf ( file, scanString, &f1, &f2, &f3, &i1, &i2 ); fclose ( file ); // try it virtual zl_init (); f1 = -1.0f; f2 = -1.0f; f3 = -1.0f; *s = 0; i1 = 0; i2 = 0; ZLFILE* zfile = zl_fopen ( "scan.txt", "r" ); result = zl_fscanf ( zfile, scanString, &f1, &f2, &f3, &i1, &i2 ); zl_fclose ( zfile ); zl_cleanup (); return 0; }
//----------------------------------------------------------------// bool USFileStream::Open ( cc8* filename, u32 mode ) { this->Close (); if ( !filename ) return false; if ( !filename [ 0 ]) return false; zl_stat fileStat; bool exists = USFileSys::GetFileStat ( filename, fileStat ); bool affirmPath = false; cc8* modeStr = 0; switch ( mode ) { case APPEND: modeStr = "a+"; this->mCaps = CAN_WRITE | CAN_READ | CAN_SEEK; break; case READ: modeStr = "rb"; this->mCaps = CAN_READ | CAN_SEEK; break; case READ_WRITE: modeStr = "rb+"; this->mCaps = CAN_READ | CAN_WRITE | CAN_SEEK; break; case READ_WRITE_AFFIRM: if ( exists ) { modeStr = "rb+"; } else { affirmPath = true; modeStr = "wb+"; } this->mCaps = CAN_READ | CAN_WRITE | CAN_SEEK; break; case READ_WRITE_NEW: affirmPath = true; modeStr = "wb+"; this->mCaps = CAN_READ | CAN_WRITE | CAN_SEEK; break; case WRITE: modeStr = "rb+"; this->mCaps = CAN_WRITE | CAN_SEEK; break; } if ( affirmPath ) { if ( !USFileSys::AffirmPath ( USFileSys::TruncateFilename ( filename ))) { modeStr = 0; } } if ( modeStr ) { this->mFile = ( ZLFILE* )zl_fopen ( filename, modeStr ); if ( this->mFile ) { // Make sure to get the correct size std::string remappedFilename; if ( ZLFileSystem::Get ().CheckFileRemapping ( filename, remappedFilename ) ) { exists = USFileSys::GetFileStat ( remappedFilename.c_str (), fileStat ); } if ( exists ) { this->mLength = fileStat.mSize; } } } return this->mFile != NULL; }