void CSegment::Read (CFile& cf) { #if DBG if (Index () == nDbgSeg) nDbgSeg = nDbgSeg; #endif if (gameStates.app.bD2XLevel) { m_owner = cf.ReadByte (); m_group = cf.ReadByte (); } else { m_owner = -1; m_group = -1; } ubyte flags = bNewFileFormat ? cf.ReadByte () : 0x7f; if (gameData.segs.nLevelVersion == 5) { // d2 SHAREWARE level ReadType (cf, flags); ReadVerts (cf); ReadChildren (cf, flags); } else { ReadChildren (cf, flags); ReadVerts (cf); if (gameData.segs.nLevelVersion <= 1) { // descent 1 level ReadType (cf, flags); } } m_objects = -1; if (gameData.segs.nLevelVersion <= 5) // descent 1 thru d2 SHAREWARE level m_xAvgSegLight = fix (cf.ReadShort ()) << 4; // Read the walls as a 6 byte array flags = bNewFileFormat ? cf.ReadByte () : 0x3f; int i; for (i = 0; i < MAX_SIDES_PER_SEGMENT; i++) m_sides [i].ReadWallNum (cf, (flags & (1 << i)) != 0); ushort sideVerts [4]; for (i = 0; i < MAX_SIDES_PER_SEGMENT; i++) { ::GetCorners (Index (), i, sideVerts); m_sides [i].Read (cf, sideVerts, m_children [i] == -1); } }
bool CECTag::ReadFromSocket(CECSocket& socket) { ec_tagname_t tmp_tagName; if (!socket.ReadNumber(&tmp_tagName, sizeof(ec_tagname_t))) { return false; } m_tagName = tmp_tagName >> 1; bool hasChildren = (tmp_tagName & 0x01) != 0; if (!socket.ReadNumber(&m_dataType, sizeof(ec_tagtype_t))) { return false; } if (!socket.ReadNumber(&m_dataLen, sizeof(ec_taglen_t))) { return false; } if (hasChildren && !ReadChildren(socket)) { return false; } unsigned int tmp_len = m_dataLen; m_dataLen = 0; m_dataLen = tmp_len - GetTagLen(); if (m_dataLen > 0) { NewData(); if (!socket.ReadBuffer(m_tagData, m_dataLen)) { return false; } } else { m_tagData = NULL; } return true; }
/*---------------------------------------------------------------------- | AP4_ContainerAtom::AP4_ContainerAtom +---------------------------------------------------------------------*/ AP4_ContainerAtom::AP4_ContainerAtom(Type type, AP4_Size size, bool is_full, AP4_ByteStream& stream, AP4_AtomFactory& atom_factory) : AP4_Atom(type, size, is_full, stream) { ReadChildren(atom_factory, stream, size-GetHeaderSize()); }
PictSelection::PictSelection (Graphic* gs) : (gs) { valid = true; } // PictSelection knows it's the outermost PictSelection because it was // called with a FILE* pointer, so it must read a version number, skip // over its name, read its graphic state and children, and scale // itself back to screen coordinates when it's finished. PictSelection::PictSelection (FILE* stream, State* state) : (nil) { int fd = fileno(stream); istream from(fd); ReadVersion(from); ReadGridSpacing(from); if (versionnumber < 3) { Skip(from); } ReadPictGS(from, state); ReadChildren(from, state); ScaleToScreenCoords(); valid = from.good(); } // Copy returns a copy of the PictSelection. Graphic* PictSelection::Copy () { Selection* copy = new PictSelection(this); for (First(); !AtEnd(); Next()) { copy->Append(GetCurrent()->Copy()); } return copy; } // HasChildren returns true so Idraw can ungroup this Picture. boolean PictSelection::HasChildren () { return Picture::HasChildren(); } // Propagate must preserve the PictSelection's transformation matrix // if it has any. void PictSelection::Propagate () { Transformer* original = GetTransformer(); if (original != nil) { original->Reference(); Selection::Propagate(); SetTransformer(original); delete original; } else { Selection::Propagate(); } }
/*---------------------------------------------------------------------- | AP4_SampleEntry::Read +---------------------------------------------------------------------*/ void AP4_SampleEntry::Read(AP4_ByteStream& stream, AP4_AtomFactory& atom_factory) { // read the fields before the children atoms ReadFields(stream); // read children atoms (ex: esds and maybe others) // NOTE: not all sample entries have children atoms AP4_Size payload_size = (AP4_Size)(GetSize()-GetHeaderSize()); AP4_Size fields_size = GetFieldsSize(); if (payload_size > fields_size) { ReadChildren(atom_factory, stream, payload_size-fields_size); } }
int Struct3D_Master:: ReadData(void) /************************************/ { char line[1024], *text; wxString fullfilename; FILE * file; int LineNum = 0; if ( m_Shape3DName.IsEmpty() ) { return 1; } fullfilename = g_RealLibDirBuffer + LIB3D_PATH; fullfilename += m_Shape3DName; #if defined (__WINDOWS__) fullfilename.Replace(UNIX_STRING_DIR_SEP,WIN_STRING_DIR_SEP); #else #if defined (__UNIX__) fullfilename.Replace(WIN_STRING_DIR_SEP,UNIX_STRING_DIR_SEP); #endif #endif file = wxFopen( fullfilename, wxT("rt") ); if ( file == NULL ) { return -1; } while ( GetLine(file, line, &LineNum, 512) ) { text = strtok(line, " \t\n\r"); if ( stricmp (text, "DEF" ) == 0 ) { while ( GetLine(file, line, &LineNum, 512) ) { text = strtok(line, " \t\n\r"); if ( text == NULL ) continue; if ( * text == '}' ) break; if ( stricmp (text, "children") == 0 ) { ReadChildren(file, &LineNum); } } } } fclose (file); return 0; }
/*---------------------------------------------------------------------- | AP4_OdheAtom::AP4_OdheAtom +---------------------------------------------------------------------*/ AP4_OdheAtom::AP4_OdheAtom(AP4_UI32 size, AP4_UI08 version, AP4_UI32 flags, AP4_ByteStream& stream, AP4_AtomFactory& atom_factory) : AP4_ContainerAtom(AP4_ATOM_TYPE_ODHE, size, false, version, flags) { // read the content type AP4_UI08 content_type_length; stream.ReadUI08(content_type_length); char content_type[256]; stream.Read(content_type, content_type_length); m_ContentType.Assign(content_type, content_type_length); // read the children AP4_Size bytes_available = size-(AP4_FULL_ATOM_HEADER_SIZE+1+content_type_length); ReadChildren(atom_factory, stream, bytes_available); }
PictSelection::PictSelection (istream& from, State* state) : (nil) { ReadPictGS(from, state); ReadChildren(from, state); valid = from.good(); } // ReadChildren loops determining which kind of Selection follows and // creating it until it reads "end" which means all of the children // have been created. void PictSelection::ReadChildren (istream& from, State* state) { while (from.good()) { Skip(from); Selection* child = nil; from >> buf; if (strcmp(buf, "BSpl") == 0) { child = new BSplineSelection(from, state); } else if (strcmp(buf, "Circ") == 0) { child = new CircleSelection(from, state); } else if (strcmp(buf, "CBSpl") == 0) { child = new ClosedBSplineSelection(from, state); } else if (strcmp(buf, "Elli") == 0) { child = new EllipseSelection(from, state); } else if (strcmp(buf, "Line") == 0) { child = new LineSelection(from, state); } else if (strcmp(buf, "MLine") == 0) { child = new MultiLineSelection(from, state); } else if (strcmp(buf, "Pict") == 0) { child = new PictSelection(from, state); } else if (strcmp(buf, "Poly") == 0) { child = new PolygonSelection(from, state); } else if (strcmp(buf, "Rect") == 0) { child = new RectSelection(from, state); } else if (strcmp(buf, "Text") == 0) { child = new TextSelection(from, state); } else if (strcmp(buf, "eop") == 0) { break; } else { fprintf(stderr, "unknown Selection %s, skipping\n", buf); continue; } if (from.good()) { Append(child); } else { delete child; } } } // WritePicture writes the picture's data and Postscript code to print // it wrapped in Postscript comments that minimally conform to version // 1.0 of Adobe Systems's structuring conventions for Postscript. The // picture must remove itself from its parent if it has a parent to // prevent the parent's transformation from affecting the picture's // calculation of its bounding box. void PictSelection::WritePicture (ostream& to, boolean verbose) { Picture* parent = (Picture*) Parent(); if (parent != nil) { parent->SetCurrent(this); parent->Remove(this); } ScaleToPostscriptCoords(); if (verbose) { WriteComments(to); WritePrologue(to); WriteVersion(to); WriteGridSpacing(to); WriteDrawing(to); WriteTrailer(to); } else { WriteVersion(to); WriteGridSpacing(to); WriteDrawing(to); } ScaleToScreenCoords(); if (parent != nil) { parent->InsertBeforeCur(this); } }
/*---------------------------------------------------------------------- | AP4_MoovAtom::AP4_MoovAtom +---------------------------------------------------------------------*/ AP4_MoovAtom::AP4_MoovAtom(AP4_Size size, AP4_ByteStream& stream, AP4_AtomFactory& atom_factory) : AP4_ContainerAtom(AP4_ATOM_TYPE_MOOV, size, false, stream, atom_factory), m_TimeScale(0) { if(AP4_ContainerAtom* cmov = dynamic_cast<AP4_ContainerAtom*>(GetChild(AP4_ATOM_TYPE_CMOV))) { AP4_DcomAtom* dcom = dynamic_cast<AP4_DcomAtom*>(cmov->GetChild(AP4_ATOM_TYPE_DCOM)); AP4_CmvdAtom* cmvd = dynamic_cast<AP4_CmvdAtom*>(cmov->GetChild(AP4_ATOM_TYPE_CMVD)); if(dcom && dcom->GetCompressorSubType() == AP4_ATOM_TYPE('z','l','i','b') && cmvd) { const AP4_DataBuffer& data = cmvd->GetDataBuffer(); z_stream d_stream; d_stream.zalloc = (alloc_func)0; d_stream.zfree = (free_func)0; d_stream.opaque = (voidpf)0; int res; if(Z_OK == (res = inflateInit(&d_stream))) { d_stream.next_in = (Bytef*)data.GetData(); d_stream.avail_in = data.GetDataSize(); unsigned char* dst = NULL; int n = 0; do { dst = (unsigned char*)realloc(dst, ++n*1000); d_stream.next_out = &dst[(n-1)*1000]; d_stream.avail_out = 1000; if(Z_OK != (res = inflate(&d_stream, Z_NO_FLUSH)) && Z_STREAM_END != res) { free(dst); dst = NULL; break; } } while(0 == d_stream.avail_out && 0 != d_stream.avail_in && Z_STREAM_END != res); inflateEnd(&d_stream); if(dst) { AP4_ByteStream* s = new AP4_MemoryByteStream(dst, d_stream.total_out); ReadChildren(atom_factory, *s, d_stream.total_out); s->Release(); free(dst); } if(AP4_MoovAtom* moov = dynamic_cast<AP4_MoovAtom*>(GetChild(AP4_ATOM_TYPE_MOOV))) { AP4_List<AP4_Atom> Children; for(AP4_List<AP4_Atom>::Item* item = moov->GetChildren().FirstItem(); item; item = item->GetNext()) { Children.Add(item->GetData()); } for(AP4_List<AP4_Atom>::Item* item = Children.FirstItem(); item; item = item->GetNext()) { AP4_Atom* atom = item->GetData(); atom->Detach(); atom->SetParent(this); m_Children.Add(atom); } moov->Detach(); delete moov; } } } } // collect all trak atoms m_Children.Apply(AP4_TrakAtomCollector(&m_TrakAtoms)); }
// ReadLines //------------------------------------------------------------------------------ bool TextReader::ReadLines() { for ( ;; ) { // Skip Leading AStackString<> token; if ( !GetToken( token ) ) { return true; } // object? if ( token == "object" ) { if ( !ReadObject() ) { return false; } continue; } // struct? if ( token == "struct" ) { if ( !ReadStruct() ) { return false; } continue; } // ref? if ( token == "ref" ) { if ( !ReadRef() ) { return false; } continue; } // children? if ( token == "children" ) { if ( !ReadChildren() ) { return false; } continue; } // begin object properties? if ( token == "{" ) { continue; } // end object/struct properties? if ( token == "}" ) { m_DeserializationStack.Pop(); continue; } // assume property PropertyType pt; pt = GetPropertyTypeFromString( token ); if ( pt != PT_NONE ) { if ( !ReadProperty( pt ) ) { return false; } continue; } if ( token == "weakRef" ) { if ( !ReadWeakRef() ) { return false; } continue; } if ( token == "array<" ) { if ( !ReadArray() ) { return false; } continue; } if ( token == "arrayOfStruct<" ) { if ( !ReadArrayOfStruct() ) { return false; } continue; } Error( "Unkown token" ); return false; } }