void PmxMaterial::Read(std::istream *stream, PmxSetting *setting) { this->material_name.swap(ReadString(stream, setting->encoding)); this->material_english_name.swap(ReadString(stream, setting->encoding)); stream->read((char*) this->diffuse, sizeof(float) * 4); stream->read((char*) this->specular, sizeof(float) * 3); stream->read((char*) &this->specularlity, sizeof(float)); stream->read((char*) this->ambient, sizeof(float) * 3); stream->read((char*) &this->flag, sizeof(uint8_t)); stream->read((char*) this->edge_color, sizeof(float) * 4); stream->read((char*) &this->edge_size, sizeof(float)); this->diffuse_texture_index = ReadIndex(stream, setting->texture_index_size); this->sphere_texture_index = ReadIndex(stream, setting->texture_index_size); stream->read((char*) &this->sphere_op_mode, sizeof(uint8_t)); stream->read((char*) &this->common_toon_flag, sizeof(uint8_t)); if (this->common_toon_flag) { stream->read((char*) &this->toon_texture_index, sizeof(uint8_t)); } else { this->toon_texture_index = ReadIndex(stream, setting->texture_index_size); } this->memo.swap(ReadString(stream, setting->encoding)); stream->read((char*) &this->index_count, sizeof(int)); }
void PmxVertexSkinningSDEF::Read(std::istream *stream, PmxSetting *setting) { this->bone_index1 = ReadIndex(stream, setting->bone_index_size); this->bone_index2 = ReadIndex(stream, setting->bone_index_size); stream->read((char*) &this->bone_weight, sizeof(float)); stream->read((char*) this->sdef_c, sizeof(float) * 3); stream->read((char*) this->sdef_r0, sizeof(float) * 3); stream->read((char*) this->sdef_r1, sizeof(float) * 3); }
void PmxVertexSkinningQDEF::Read(std::istream *stream, PmxSetting *setting) { this->bone_index1 = ReadIndex(stream, setting->bone_index_size); this->bone_index2 = ReadIndex(stream, setting->bone_index_size); this->bone_index3 = ReadIndex(stream, setting->bone_index_size); this->bone_index4 = ReadIndex(stream, setting->bone_index_size); stream->read((char*) &this->bone_weight1, sizeof(float)); stream->read((char*) &this->bone_weight2, sizeof(float)); stream->read((char*) &this->bone_weight3, sizeof(float)); stream->read((char*) &this->bone_weight4, sizeof(float)); }
void PmxFrameElement::Read(std::istream *stream, PmxSetting *setting) { stream->read((char*) &this->element_target, sizeof(uint8_t)); if (this->element_target == 0x00) { this->index = ReadIndex(stream, setting->bone_index_size); } else { this->index = ReadIndex(stream, setting->morph_index_size); } }
void PmxJointParam::Read(std::istream *stream, PmxSetting *setting) { this->rigid_body1 = ReadIndex(stream, setting->rigidbody_index_size); this->rigid_body2 = ReadIndex(stream, setting->rigidbody_index_size); stream->read((char*) this->position, sizeof(float) * 3); stream->read((char*) this->orientaiton, sizeof(float) * 3); stream->read((char*) this->move_limitation_min, sizeof(float) * 3); stream->read((char*) this->move_limitation_max, sizeof(float) * 3); stream->read((char*) this->rotation_limitation_min, sizeof(float) * 3); stream->read((char*) this->rotation_limitation_max, sizeof(float) * 3); stream->read((char*) this->spring_move_coefficient, sizeof(float) * 3); stream->read((char*) this->spring_rotation_coefficient, sizeof(float) * 3); }
char* ReadTextBuffer( fstream &File, DWORD Offset ) { DWORD Pos; DWORD Top; WORD wtf; DWORD TextSize; DWORD OldOffset; OldOffset = File.tellg(); File.seekg( Offset, ios_base::beg ); File.read((char*)(&Pos), sizeof(Pos)); File.read((char*)(&Top), sizeof(Top)); File.read((char*)(&wtf), sizeof(wtf)); TextSize = ReadIndex( File ); //cout << endl << dec << "Pos: " << Pos << ", Top: " << Top << ", wtf: " << wtf << ", TextSize: " << TextSize; if( TextSize > 0 ) { char *buffer = new char [TextSize]; File.read( buffer, TextSize); File.seekg( OldOffset, ios_base::beg ); return buffer; } return "empty textbuffer?"; }
void PmxMorphImplusOffset::Read(std::istream *stream, PmxSetting *setting) { this->rigid_body_index = ReadIndex(stream, setting->rigidbody_index_size); stream->read((char*) &this->is_local, sizeof(uint8_t)); stream->read((char*)this->velocity, sizeof(float) * 3); stream->read((char*)this->angular_torque, sizeof(float) * 3); }
void SubsonicService::onGetIndexesFinished() { QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); Q_ASSERT(reply); reply->deleteLater(); QXmlStreamReader reader(reply); reader.readNextStartElement(); Q_ASSERT(reader.name() == "subsonic-response"); if (reader.attributes().value("status") != "ok") { // TODO: error handling return; } reader.readNextStartElement(); Q_ASSERT(reader.name() == "indexes"); root_->setRowCount(0); while (reader.readNextStartElement()) { if (reader.name() == "index") { ReadIndex(&reader, root_); } else if (reader.name() == "child" && reader.attributes().value("isVideo") == "false") { ReadTrack(&reader, root_); } else { reader.skipCurrentElement(); } } }
void PmxIkLink::Read(std::istream *stream, PmxSetting *setting) { this->link_target = ReadIndex(stream, setting->bone_index_size); stream->read((char*) &this->angle_lock, sizeof(uint8_t)); if (angle_lock == 1) { stream->read((char*) this->max_radian, sizeof(float) * 3); stream->read((char*) this->min_radian, sizeof(float) * 3); } }
void PmxBone::Read(std::istream *stream, PmxSetting *setting) { this->bone_name.swap(ReadString(stream, setting->encoding)); this->bone_english_name.swap(ReadString(stream, setting->encoding)); stream->read((char*) this->position, sizeof(float) * 3); this->parent_index = ReadIndex(stream, setting->bone_index_size); stream->read((char*) &this->level, sizeof(int)); stream->read((char*) &this->bone_flag, sizeof(uint16_t)); if (this->bone_flag & 0x0001) { this->target_index = ReadIndex(stream, setting->bone_index_size); } else { stream->read((char*)this->offset, sizeof(float) * 3); } if (this->bone_flag & (0x0100 | 0x0200)) { this->grant_parent_index = ReadIndex(stream, setting->bone_index_size); stream->read((char*) &this->grant_weight, sizeof(float)); } if (this->bone_flag & 0x0400) { stream->read((char*)this->lock_axis_orientation, sizeof(float) * 3); } if (this->bone_flag & 0x0800) { stream->read((char*)this->local_axis_x_orientation, sizeof(float) * 3); stream->read((char*)this->local_axis_y_orientation, sizeof(float) * 3); } if (this->bone_flag & 0x2000) { stream->read((char*)this->key, sizeof(int)); } if (this->bone_flag & 0x0020) { this->ik_target_bone_index = ReadIndex(stream, setting->bone_index_size); stream->read((char*) &ik_loop, sizeof(int)); stream->read((char*) &ik_loop_angle_limit, sizeof(float)); stream->read((char*) &ik_link_count, sizeof(int)); this->ik_links = std::make_unique<PmxIkLink []>(ik_link_count); for (int i = 0; i < ik_link_count; i++) { ik_links[i].Read(stream, setting); } } }
void PmxMorphMaterialOffset::Read(std::istream *stream, PmxSetting *setting) { this->material_index = ReadIndex(stream, setting->material_index_size); stream->read((char*) &this->offset_operation, sizeof(uint8_t)); stream->read((char*)this->diffuse, sizeof(float) * 4); stream->read((char*)this->specular, sizeof(float) * 3); stream->read((char*) &this->specularity, sizeof(float)); stream->read((char*)this->ambient, sizeof(float) * 3); stream->read((char*)this->edge_color, sizeof(float) * 4); stream->read((char*) &this->edge_size, sizeof(float)); stream->read((char*)this->texture_argb, sizeof(float) * 4); stream->read((char*)this->sphere_texture_argb, sizeof(float) * 4); stream->read((char*)this->toon_texture_argb, sizeof(float) * 4); }
void LibOpen (const char* Name, int MustExist, int NeedTemp) /* Open an existing library and a temporary copy. If MustExist is true, the * old library is expected to exist. If NeedTemp is true, a temporary library * is created. */ { /* Remember the name */ LibName = xstrdup (Name); /* Open the existing library for reading */ Lib = fopen (Name, "rb"); if (Lib == 0) { /* File does not exist */ if (MustExist) { Error ("Library `%s' does not exist", Name); } else { /* Announce the library's creation if ar65 is verbose. */ Print (stdout, 1, "%s: Library `%s' will be created.\n", ProgName, Name); } } else { /* We have an existing file: Read the header */ ReadHeader (); /* Now read the existing index */ ReadIndex (); } if (NeedTemp) { /* Create the temporary library name */ NewLibName = xmalloc (strlen (Name) + strlen (".temp") + 1); strcpy (NewLibName, Name); strcat (NewLibName, ".temp"); /* Create the temporary library */ NewLib = fopen (NewLibName, "w+b"); if (NewLib == 0) { Error ("Cannot create temporary library file: %s", strerror (errno)); } /* Write a dummy header to the temp file */ WriteHeader (); } }
ExportItem* ReadExportTable( fstream &File, DWORD &ExportOffset, DWORD &ExportCount ) { File.seekg( ExportOffset, ios_base::beg ); DWORD i; ExportItem *ExportList; ExportList = (ExportItem *) malloc(ExportCount * sizeof(ExportItem)); for(i=0; i<ExportCount; i++) { ExportList[i].Class = ReadIndex( File ); ExportList[i].Super = ReadIndex( File ); File.read((char*)(&ExportList[i].Package), sizeof(ExportList[i].Package)); ExportList[i].ObjectName = ReadIndex( File ); File.read((char*)(&ExportList[i].ObjectFlags), sizeof(ExportList[i].ObjectFlags)); ExportList[i].SerialSize = ReadIndex( File ); if( ExportList[i].SerialSize > 0 ) ExportList[i].SerialOffset = ReadIndex( File ); // cout <<endl<< ExportList[i].ObjectName; } return ExportList; }
void PmxRigidBody::Read(std::istream *stream, PmxSetting *setting) { this->girid_body_name = ReadString(stream, setting->encoding); this->girid_body_english_name = ReadString(stream, setting->encoding); this->target_bone = ReadIndex(stream, setting->bone_index_size); stream->read((char*) &this->group, sizeof(uint8_t)); stream->read((char*) &this->mask, sizeof(uint16_t)); stream->read((char*) &this->shape, sizeof(uint8_t)); stream->read((char*) this->size, sizeof(float) * 3); stream->read((char*) this->position, sizeof(float) * 3); stream->read((char*) this->orientation, sizeof(float) * 3); stream->read((char*) &this->mass, sizeof(float)); stream->read((char*) &this->move_attenuation, sizeof(float)); stream->read((char*) &this->rotation_attenuation, sizeof(float)); stream->read((char*) &this->repulsion, sizeof(float)); stream->read((char*) &this->friction, sizeof(float)); stream->read((char*) &this->physics_calc_type, sizeof(uint8_t)); }
void LibOpen (const char* Name, int MustExist, int NeedTemp) /* Open an existing library and a temporary copy. If MustExist is true, the * old library is expected to exist. If NeedTemp is true, a temporary library * is created. */ { /* Remember the name */ LibName = xstrdup (Name); /* Open the existing library for reading */ Lib = fopen (Name, "rb"); if (Lib == 0) { /* File does not exist */ if (MustExist) { Error ("Library `%s' does not exist", Name); } else { Warning ("Library `%s' not found - will be created", Name); } } else { /* We have an existing file: Read the header */ ReadHeader (); /* Now read the existing index */ ReadIndex (); } if (NeedTemp) { /* Create the temporary library */ NewLib = tmpfile (); if (NewLib == 0) { Error ("Cannot create temporary file: %s", strerror (errno)); } /* Write a dummy header to the temp file */ WriteHeader (); } }
nsresult nsOE5File::ImportMailbox( PRUint32 *pBytesDone, PRBool *pAbort, nsString& name, nsIFile *inFile, nsIFile *pDestination, PRUint32 *pCount) { nsresult rv; PRInt32 msgCount = 0; if (pCount) *pCount = 0; nsCOMPtr <nsIInputStream> inputStream; rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), inFile); if (NS_FAILED( rv)) return( rv); nsCOMPtr <nsIOutputStream> outputStream; rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), pDestination, -1, 0600); if (NS_FAILED( rv)) return( rv); PRUint32 * pIndex; PRUint32 indexSize; if (!ReadIndex( inputStream, &pIndex, &indexSize)) { IMPORT_LOG1( "No messages found in mailbox: %S\n", name.get()); return( NS_OK); } char * pBuffer = new char[kMailboxBufferSize]; if (!(*pAbort)) ConvertIndex( inputStream, pBuffer, pIndex, indexSize); PRUint32 block[4]; PRInt32 sepLen = (PRInt32) strlen( m_pFromLineSep); PRUint32 written; /* Each block is: marker - matches file offset block length text length in block pointer to next block. (0 if end) Each message is made up of a linked list of block data. So what we do for each message is: 1. Read the first block data. 2. Write out the From message separator if the message doesn't already start with one. 3. If the block of data doesn't end with CRLF then a line is broken into two blocks, so save the incomplete line for later process when we read the next block. Then write out the block excluding the partial line at the end of the block (if exists). 4. If there's next block of data then read next data block. Otherwise we're done. If we found a partial line in step #3 then find the rest of the line from the current block and write out this line separately. 5. Reset some of the control variables and repeat step #3. */ PRUint32 didBytes = 0; PRUint32 next, size; char *pStart, *pEnd, *partialLineStart; nsCAutoString partialLine, tempLine; rv = NS_OK; for (PRUint32 i = 0; (i < indexSize) && !(*pAbort); i++) { if (! pIndex[i]) continue; if (ReadBytes( inputStream, block, pIndex[i], 16) && (block[0] == pIndex[i]) && (block[2] < kMailboxBufferSize) && (ReadBytes( inputStream, pBuffer, kDontSeek, block[2]))) { // block[2] contains the chars in the buffer (ie, buf content size). // block[3] contains offset to the next block of data (0 means no more data). size = block[2]; pStart = pBuffer; pEnd = pStart + size; // write out the from separator. if (IsFromLine( pBuffer, size)) { char *pChar = pStart; while ((pChar < pEnd) && (*pChar != '\r') && (*(pChar+1) != '\n')) pChar++; if (pChar < pEnd) { // Get the "From " line so write it out. rv = outputStream->Write(pStart, pChar-pStart+2, &written); NS_ENSURE_SUCCESS(rv,rv); // Now buffer starts from the 2nd line. pStart = pChar + 2; } } else { // Write out the default from line since there is none in the msg. rv = outputStream->Write( m_pFromLineSep, sepLen, &written); // FIXME: Do I need to check the return value of written??? if (NS_FAILED( rv)) break; } char statusLine[50]; PRUint32 msgFlags = 0; // need to convert from OE flags to mozilla flags PR_snprintf(statusLine, sizeof(statusLine), X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF); rv = outputStream->Write(statusLine, strlen(statusLine), &written); NS_ENSURE_SUCCESS(rv,rv); PR_snprintf(statusLine, sizeof(statusLine), X_MOZILLA_STATUS2_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF0000); rv = outputStream->Write(statusLine, strlen(statusLine), &written); NS_ENSURE_SUCCESS(rv,rv); do { partialLine.Truncate(); partialLineStart = pEnd; // If the buffer doesn't end with CRLF then a line is broken into two blocks, // so save the incomplete line for later process when we read the next block. if ( (size > 1) && !(*(pEnd - 2) == '\r' && *(pEnd - 1) == '\n') ) { partialLineStart -= 2; while ((partialLineStart >= pStart) && (*partialLineStart != '\r') && (*(partialLineStart+1) != '\n')) partialLineStart--; if (partialLineStart != (pEnd - 2)) partialLineStart += 2; // skip over CRLF if we find them. partialLine.Assign(partialLineStart, pEnd - partialLineStart); } // Now process the block of data which ends with CRLF. rv = EscapeFromSpaceLine(outputStream, pStart, partialLineStart); if (NS_FAILED(rv)) break; didBytes += block[2]; next = block[3]; if (! next) { // OK, we're done so flush out the partial line if it's not empty. if (partialLine.Length()) rv = EscapeFromSpaceLine(outputStream, (char *)partialLine.get(), (partialLine.get()+partialLine.Length())); } else if (ReadBytes(inputStream, block, next, 16) && (block[0] == next) && (block[2] < kMailboxBufferSize) && (ReadBytes(inputStream, pBuffer, kDontSeek, block[2]))) { // See if we have a partial line from previous block. If so then build a complete // line (ie, take the remaining chars from this block) and process this line. Need // to adjust where data start and size in this case. size = block[2]; pStart = pBuffer; pEnd = pStart + size; if (partialLine.Length()) { while ((pStart < pEnd) && (*pStart != '\r') && (*(pStart+1) != '\n')) pStart++; if (pStart < pEnd) // if we found a CRLF .. pStart += 2; // .. then copy that too. tempLine.Assign(pBuffer, pStart - pBuffer); partialLine.Append(tempLine); rv = EscapeFromSpaceLine(outputStream, (char *)partialLine.get(), (partialLine.get()+partialLine.Length())); if (NS_FAILED(rv)) break; // Adjust where data start and size (since some of the data has been processed). size -= (pStart - pBuffer); } } else { IMPORT_LOG2( "Error reading message from %S at 0x%lx\n", name.get(), pIndex[i]); rv = outputStream->Write( "\x0D\x0A", 2, &written); next = 0; } } while (next); // Always end a msg with CRLF. This will make sure that OE msgs without body is // correctly recognized as msgs. Otherwise, we'll end up with the following in // the msg folder where the 2nd msg starts right after the headers of the 1st msg: // // From - Jan 1965 00:00:00 <<<--- 1st msg starts here // Subject: Test msg // . . . (more headers) // To: <*****@*****.**> // From - Jan 1965 00:00:00 <<<--- 2nd msg starts here // Subject: How are you // . . .(more headers) // // In this case, the 1st msg is not recognized as a msg (it's skipped) // when you open the folder. rv = outputStream->Write( "\x0D\x0A", 2, &written); if (NS_FAILED(rv)) break; msgCount++; if (pCount) *pCount = msgCount; if (pBytesDone) *pBytesDone = didBytes; } else { // Error reading message, should this be logged??? IMPORT_LOG2( "Error reading message from %S at 0x%lx\n", name.get(), pIndex[i]); *pAbort = PR_TRUE; } } delete [] pBuffer; if (NS_FAILED(rv)) *pAbort = PR_TRUE; return( rv); }
/*========================================================================= * FUNCTION: tVM_Execute * TYPE: public interface * OVERVIEW: execute a basic function * INTERFACE: * parameters: * returns: * the result of the basic function *=======================================================================*/ int tVM_Execute() { int running = 1; u8 bytecode; u8 type; u8 ac_flag; s32 integer; s32 stackindex,index; tVMValue value1,value2,value3; tVMValue retValue;// = (tVMValue*)mem_alloc(sizeof(tVMValue)); /* initialize the running Stack FP */ setFP(FirstFP); /* seek to the entry function */ setFI(0); /* initialize the code reader */ tVM_InitializeCodeReader(); /* execute the byte codes in loop */ while(running) { bytecode = ReadCode(); switch(bytecode) { case C_NOP: break; case C_CONST: { ReadVMValue(&value1); PushVMValue(&value1); break; } case C_LOAD: { ac_flag =ReadAccessFlag(); if(ac_flag == ACCESS_FLAG_GLOBAL) stackindex = ReadIndex(); else stackindex = ReadIndex() + getFP(); LoadVMValue(stackindex,&value1); PushVMValue(&value1); break; } case C_STORE: { ac_flag =ReadAccessFlag(); if(ac_flag == ACCESS_FLAG_GLOBAL) stackindex = ReadIndex(); else stackindex = ReadIndex() + getFP(); PopVMValue(&value1); /* pop the source value */ StoreVMValue(stackindex,&value1); break; } case C_HEAP_LOAD: { type = ReadDataType(); PopVMValue(&value2); /* Pop Addr */ PopVMValue(&value1); /* Pop Base */ tVMValue_HeapLoad(value1.value.ptr_val+value2.value.int_val,type,&value3); /* load the heap memory */ PushVMValue(&value3); /* push the loaded value */ break; } case C_HEAP_STORE: { ptr32 addr; type = ReadDataType(); PopVMValue(&value3); /* Pop Addr */ PopVMValue(&value2); /* Pop Base */ PopVMValue(&value1); /* Pop Value */ addr = (ptr32)(value2.value.ptr_val + value3.value.int_val); if(value1.type != type) { tVMValue_ConvertType(&value1,type); } tVMValue_HeapStore(addr,&value1); break; } case C_FORCE_LOAD: { ac_flag =ReadAccessFlag(); if(ac_flag == ACCESS_FLAG_GLOBAL) stackindex = ReadIndex(); else stackindex = ReadIndex() + getFP(); type = ReadDataType(); ForceLoadVMValue(stackindex,type,&value1); PushVMValue(&value1); break; } case C_ALLOC: { PopVMValue(&value1); value2.type = PtrType; value2.value.ptr_val = (ptr32)mem_alloc(value1.value.int_val); memset(value2.value.ptr_val,0,value1.value.int_val); PushVMValue(&value2); break; } case C_ALLOC_ARRAY: { s32 i; s32 dimension; s32* index_ranges; dimension = ReadInteger(); if(dimension < 1) break; index_ranges = (s32*)mem_alloc(sizeof(s32)*dimension); for(i=0;i<dimension;i++) { PopVMValue(&value1); index_ranges[dimension-i-1] = value1.value.int_val; } value1.type = PtrType; value1.value.ptr_val = tVMValue_HeapAllocMultiArray(dimension,index_ranges,0); PushVMValue(&value1); mem_free(index_ranges); break; } case C_FREE: { PopVMValue(&value1); if(value1.value.ptr_val != NULL) mem_free(value1.value.ptr_val); break; } case C_FREE_ARRAY: { break; } case C_PUSH: { value1.type = ReadDataType(); value1.value.int_val = 0; PushVMValue(&value1); break; } case C_POP: { s32 i; integer = ReadInteger(); for(i=0;i<integer;i++) { PopVMValue(&value1); tVMValue_FreeSelf(&value1); } break; } case C_POP_RESTOP: { s32 i; integer = ReadInteger(); PopVMValue(&value2); /* reserve top value */ for(i=0;i<integer;i++) { PopVMValue(&value1); tVMValue_FreeSelf(&value1); } PushVMValue(&value2); /* push back top value */ break; } case C_CONVERT: { u8 type = (u8)ReadDataType(); PopVMValue(&value1); tVMValue_ConvertType(&value1,type); PushVMValue(&value1); break; } case C_ADD: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Add(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_SUB: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Sub(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_MUL: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Mul(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_DIV: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Div(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_MOD: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_Mod(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_OPP: { PopVMValue(&value1); tVMValue_Opp(&value1,&value2); PushVMValue(&value2); tVMValue_FreeSelf(&value1); break; } case C_AND: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_AND(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_OR: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_OR(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_EQ: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_EQ(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_NOT_EQ: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_NOTEQ(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_LT: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_LT(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_LG: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_LG(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_LT_EQ: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_LTEQ(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_LG_EQ: { PopVMValue(&value2); PopVMValue(&value1); tVMValue_LGEQ(&value1,&value2,&value3); PushVMValue(&value3); tVMValue_FreeSelf(&value1); tVMValue_FreeSelf(&value2); break; } case C_FJP: { s32 size = ReadIndex(); PopVMValue(&value1); if(value1.value.int_val == 0) /* if it is false */ addIP(size); break; } case C_TJP: { s32 size = ReadIndex(); PopVMValue(&value1); if(value1.value.int_val != 0) /* if it is true */ addIP(size); break; } case C_JMP: { s32 size = ReadIndex(); addIP(size); break; } case C_CALL: { /* read function name */ integer = ReadIndex(); /* push the stack frame */ PushInteger(getIP()); PushInteger(getFI()); PushInteger(getFP()); /* goto the call function code */ tVM_ReleaseCodeReader(); setFI(integer); tVM_InitializeCodeReader(); /* set new FP,RP */ setFP(getSP()); break; } case C_INVOKE: { /* read function name */ index = ReadIndex(); /* execute the native function */ tNativeFunction_Invoke(index); break; } case C_RET: { u32 param_bytes = ReadIndex(); /* get the result of the function */ retValue.type = NullType; PopVMValue(&retValue); /* if this is the start function,then exit the loop */ if(getFP() == FirstFP) { running = 0; /* set flag to stop while */ break; } /* restore last stack frame and return to last function code */ tVM_ReleaseCodeReader(); PopInteger(integer); setFP(integer); PopInteger(integer); setFI(integer); tVM_InitializeCodeReader(); PopInteger(integer); setIP(integer); /* pop the old parameters */ PopBytes(param_bytes); /* push back result of last function */ PushVMValue(&retValue); break; } } } /* close the code reader */ tVM_ReleaseCodeReader(); return 1; }
void ProcessPairedEndReads(const string& command, const string& index_file, const string& reads_file_p1, const string& reads_file_p2, const string& output_file, const uint32_t& n_reads_to_process, const uint32_t& max_mismatches, const string& adaptor, const uint32_t& top_k, const int& frag_range, const bool& ambiguous, const bool& unmapped, const bool& SAM, const int& num_of_threads) { // LOAD THE INDEX HEAD INFO Genome genome; HashTable hash_table; uint32_t size_of_index; ReadIndexHeadInfo(index_file, genome, size_of_index); genome.sequence.resize(genome.length_of_genome); hash_table.counter.resize(power(4, F2SEEDKEYWIGTH) + 1); hash_table.index.resize(size_of_index); vector<vector<string> > index_names(2, vector<string>(2)); index_names[0][0] = index_file + "_CT00"; index_names[0][1] = index_file + "_CT01"; index_names[1][0] = index_file + "_GA10"; index_names[1][1] = index_file + "_GA11"; vector<vector<string> > read_names(2, vector<string>(n_reads_to_process)); vector<vector<string> > read_seqs(2, vector<string>(n_reads_to_process)); vector<vector<string> > read_scores(2, vector<string>(n_reads_to_process)); vector<int> ranked_results_size(2); vector<vector<CandidatePosition> > ranked_results(2, vector<CandidatePosition>(MAX_NUM_EXACT_MAPPED)); vector<vector<TopCandidates> > top_results(2, vector<TopCandidates>(n_reads_to_process)); FILE * fin[2]; fin[0] = fopen(reads_file_p1.c_str(), "r"); if (!fin[0]) { throw SMITHLABException("cannot open input file " + reads_file_p1); } fin[1] = fopen(reads_file_p2.c_str(), "r"); if (!fin[1]) { throw SMITHLABException("cannot open input file " + reads_file_p2); } string adaptors[2]; extract_adaptors(adaptor, adaptors[0], adaptors[1]); clock_t start_t = clock(); FILE * fout = fopen(output_file.c_str(), "w"); if (!fout) { throw SMITHLABException("cannot open input file " + output_file); } uint32_t num_of_reads[2]; StatPairedReads stat_paired_reads(ambiguous, unmapped, output_file, SAM); bool AG_WILDCARD = true; fprintf(stderr, "[MAPPING PAIRED-END READS FROM THE FOLLOWING TWO FILES]\n"); fprintf(stderr, " %s (AND)\n %s\n", reads_file_p1.c_str(), reads_file_p2.c_str()); fprintf(stderr, "[OUTPUT MAPPING RESULTS TO %s]\n", output_file.c_str()); if (SAM) { SAMHead(index_file, command, fout); } omp_set_dynamic(0); omp_set_num_threads(num_of_threads); for (uint32_t i = 0;; i += n_reads_to_process) { num_of_reads[0] = num_of_reads[1] = 0; for (uint32_t pi = 0; pi < 2; ++pi) { // paired end reads _1 and _2 AG_WILDCARD = pi == 1 ? true : false; LoadReadsFromFastqFile(fin[pi], i, n_reads_to_process, adaptors[pi], num_of_reads[pi], read_names[pi], read_seqs[pi], read_scores[pi]); if (num_of_reads[pi] == 0) break; //Initialize the paired results for (uint32_t j = 0; j < num_of_reads[pi]; ++j) { top_results[pi][j].Clear(); top_results[pi][j].SetSize(top_k); } for (uint32_t fi = 0; fi < 2; ++fi) { ReadIndex(index_names[pi][fi], genome, hash_table); char strand = fi == 0 ? '+' : '-'; #pragma omp parallel for for (uint32_t j = 0; j < num_of_reads[pi]; ++j) { PairEndMapping(read_seqs[pi][j], genome, hash_table, strand, AG_WILDCARD, max_mismatches, top_results[pi][j]); } } } if (num_of_reads[0] != num_of_reads[1]) { fprintf(stderr, "The number of reads in paired-end files should be the same.\n"); exit( EXIT_FAILURE); } if (num_of_reads[0] == 0) { break; } stat_paired_reads.total_read_pairs += num_of_reads[0]; /////////////////////////////////////////////////////////// // Merge Paired-end results for (uint32_t j = 0; j < num_of_reads[0]; ++j) { for (uint32_t pi = 0; pi < 2; ++pi) { ranked_results_size[pi] = 0; while (!top_results[pi][j].candidates.empty()) { ranked_results[pi][ranked_results_size[pi]++] = top_results[pi][j].Top(); top_results[pi][j].Pop(); } } MergePairedEndResults(genome, read_names[0][j], read_seqs[0][j], read_scores[0][j], read_seqs[1][j], read_scores[1][j], ranked_results, ranked_results_size, frag_range, max_mismatches, SAM, stat_paired_reads, fout); } if (num_of_reads[0] < n_reads_to_process) break; } fclose(fin[0]); fclose(fin[1]); fclose(fout); OutputPairedStatInfo(stat_paired_reads, output_file); fprintf(stderr, "[MAPPING TAKES %.0lf SECONDS]\n", (double(clock() - start_t) / CLOCKS_PER_SEC)); }
int main( int argc, char **argv ) { char *args; int i = 0; FILE *op; char filename[MAX_PATH]; if (argc >= 2) { for(int i=1; i<argc; i++) { args = argv[i]; switch ( args[1] ) { case 'd': sprintf(gBaseDir,args + 2); break; case 'l': sprintf(gLangDir,args + 2); sprintf(gBaseDir,"D:\\falcon4\\%s\\campaign\\save",gLangDir); break; default: break; } } } else { sprintf(gBaseDir,"D:\\falcon4\\campaign\\save"); sprintf(gLangDir,"output"); printf("Working directory: %s",gBaseDir); // scanf("%s",baseDir); } ReadIndex("strings"); LoadNames("Korea"); BuildExampleNames(); sprintf(filename,"%s\\%s.txt",gBaseDir,gLangDir); op = fopen(filename,"w"); while (FilesToRead[i][0]) { ClearTokenList(); fprintf(op,"\n==============================\n"); fprintf(op,"FILENAME: %s\n",FilesToRead[i]); fprintf(op,"==============================\n"); printf("\n==============================\n"); printf("FILENAME: %s\n",FilesToRead[i]); printf("==============================\n"); AnalyseFile(FilesToRead[i]); DoFile(FilesToRead[i],op); i++; } FreeIndex(); FreeNames(); fclose(op); printf("Done! - press <return> to exit\n"); getchar(); return 1; }
void PmxVertexSkinningBDEF1::Read(std::istream *stream, PmxSetting *setting) { this->bone_index = ReadIndex(stream, setting->bone_index_size); }
void PmxModel::Read(std::istream *stream) { // マジック char magic[4]; stream->read((char*) magic, sizeof(char) * 4); if (magic[0] != 0x50 || magic[1] != 0x4d || magic[2] != 0x58 || magic[3] != 0x20) { std::cerr << "invalid magic number." << std::endl; throw; } // バージョン stream->read((char*) &version, sizeof(float)); if (version != 2.0f && version != 2.1f) { std::cerr << "this is not ver2.0 or ver2.1 but " << version << "." << std::endl; throw; } // ファイル設定 this->setting.Read(stream); // モデル情報 this->model_name.swap(ReadString(stream, setting.encoding)); this->model_english_name.swap(ReadString(stream, setting.encoding)); this->model_comment.swap(ReadString(stream, setting.encoding)); this->model_english_commnet.swap(ReadString(stream, setting.encoding)); // 頂点 stream->read((char*) &vertex_count, sizeof(int)); this->vertices = std::make_unique<PmxVertex []>(vertex_count); for (int i = 0; i < vertex_count; i++) { vertices[i].Read(stream, &setting); } // 面 stream->read((char*) &index_count, sizeof(int)); this->indices = std::make_unique<int []>(index_count); for (int i = 0; i < index_count; i++) { this->indices[i] = ReadIndex(stream, setting.vertex_index_size); } // テクスチャ stream->read((char*) &texture_count, sizeof(int)); this->textures = std::make_unique<std::wstring []>(texture_count); for (int i = 0; i < texture_count; i++) { this->textures[i] = ReadString(stream, setting.encoding); } // マテリアル stream->read((char*) &material_count, sizeof(int)); this->materials = std::make_unique<PmxMaterial []>(material_count); for (int i = 0; i < material_count; i++) { this->materials[i].Read(stream, &setting); } // ボーン stream->read((char*) &this->bone_count, sizeof(int)); this->bones = std::make_unique<PmxBone []>(this->bone_count); for (int i = 0; i < this->bone_count; i++) { this->bones[i].Read(stream, &setting); } // モーフ stream->read((char*) &this->morph_count, sizeof(int)); this->morphs = std::make_unique<PmxMorph []>(this->morph_count); for (int i = 0; i < this->morph_count; i++) { this->morphs[i].Read(stream, &setting); } // 表示枠 stream->read((char*) &this->frame_count, sizeof(int)); this->frames = std::make_unique<PmxFrame []>(this->frame_count); for (int i = 0; i < this->frame_count; i++) { this->frames[i].Read(stream, &setting); } // 剛体 stream->read((char*) &this->rigid_body_count, sizeof(int)); this->rigid_bodies = std::make_unique<PmxRigidBody []>(this->rigid_body_count); for (int i = 0; i < this->rigid_body_count; i++) { this->rigid_bodies[i].Read(stream, &setting); } // ジョイント stream->read((char*) &this->joint_count, sizeof(int)); this->joints = std::make_unique<PmxJoint []>(this->joint_count); for (int i = 0; i < this->joint_count; i++) { this->joints[i].Read(stream, &setting); } //// ソフトボディ //if (this->version == 2.1f) //{ // stream->read((char*) &this->soft_body_count, sizeof(int)); // this->soft_bodies = std::make_unique<PmxSoftBody []>(this->soft_body_count); // for (int i = 0; i < this->soft_body_count; i++) // { // this->soft_bodies[i].Read(stream, &setting); // } //} }
void PmxAncherRigidBody::Read(std::istream *stream, PmxSetting *setting) { this->related_rigid_body = ReadIndex(stream, setting->rigidbody_index_size); this->related_vertex = ReadIndex(stream, setting->vertex_index_size); stream->read((char*) &this->is_near, sizeof(uint8_t)); }
// Create the manager VXIcacheResult SBcacheManager::Create(const SBcacheNString &cacheDir, VXIulong cacheMaxSizeBytes, VXIulong entryMaxSizeBytes, VXIulong entryExpTimeSec, VXIbool unlockEntries, VXIulong cacheLowWaterBytes) { VXIcacheResult rc = VXIcache_RESULT_SUCCESS; // Avoid double initialization if ( _cacheDir.length( ) > 0 ) { Error (112, NULL); rc = VXIcache_RESULT_FATAL_ERROR; } // Create the path sequence number if (( rc == VXIcache_RESULT_SUCCESS ) && ( _pathSeqNum.Create( ) != VXItrd_RESULT_SUCCESS )) { Error (109, L"%s%s", L"mutex", L"path seq num"); rc = VXIcache_RESULT_SYSTEM_ERROR; } // Create the entry table mutex if (( rc == VXIcache_RESULT_SUCCESS ) && ( _entryTableMutex.Create(L"SBcacheManager entry table mutex") != VXItrd_RESULT_SUCCESS )) { Error (109, L"%s%s", L"mutex", L"entry table mutex"); rc = VXIcache_RESULT_SYSTEM_ERROR; } // Create the mutex pool if (( rc == VXIcache_RESULT_SUCCESS ) && ( _refCntMutexPool.Create(L"SBcacheManager refCnt mutex pool", CACHE_REF_COUNT_MUTEX_POOL_SIZE) )) { Error (109, L"%s%s", L"mutex", L"entry table mutex"); rc = VXIcache_RESULT_SYSTEM_ERROR; } // Create the cache size if (( rc == VXIcache_RESULT_SUCCESS ) && ( _curSizeBytes.Create( ) != VXItrd_RESULT_SUCCESS )) { Error (109, L"%s%s", L"mutex", L"cache size mutex"); rc = VXIcache_RESULT_SYSTEM_ERROR; } // Create the cache directory if required if ( rc == VXIcache_RESULT_SUCCESS ) { SBcacheStatInfo statInfo; if ( SBcacheStat (cacheDir.c_str( ), &statInfo) ) { // Exists, make sure it is a file if ( ! SBcacheIsDir(statInfo) ) { Error (113, L"%s%S", L"cacheDirectory", cacheDir.c_str( )); rc = VXIcache_RESULT_FATAL_ERROR; } else { // Load the cache index file rc = ReadIndex (cacheDir); } } else if ( ! SBcacheMkdir (cacheDir.c_str( )) ) { Error (114, L"%s%S", L"cacheDirectory", cacheDir.c_str( )); rc = VXIcache_RESULT_FATAL_ERROR; } } // Update data members if ( rc == VXIcache_RESULT_SUCCESS ) { _cacheDir = cacheDir; _maxSizeBytes = cacheMaxSizeBytes; _entryMaxSizeBytes = entryMaxSizeBytes; _lowWaterBytes = cacheLowWaterBytes; } _entryReserve = 0; ReserveEntries(0); // Disable, for now. Diag (SBCACHE_MGR_TAGID, L"Create", L"rc = %d", rc); return rc; }
void PmxMorphFlipOffset::Read(std::istream *stream, PmxSetting *setting) { this->morph_index = ReadIndex(stream, setting->morph_index_size); stream->read((char*) &this->morph_value, sizeof(float)); }
void PmxMorphBoneOffset::Read(std::istream *stream, PmxSetting *setting) { this->bone_index = ReadIndex(stream, setting->bone_index_size); stream->read((char*)this->translation, sizeof(float) * 3); stream->read((char*)this->rotation, sizeof(float) * 4); }
void PmxMorphUVOffset::Read(std::istream *stream, PmxSetting *setting) { this->vertex_index = ReadIndex(stream, setting->vertex_index_size); stream->read((char*)this->uv_offset, sizeof(float) * 4); }