LinkLayerParser::State LinkLayerParser::ParseOneStep() { switch (state) { case(State::FindSync) : return ParseSync(); case(State::ReadHeader) : return ParseHeader(); case(State::ReadBody) : return ParseBody(); default: return state; } }
bool QDataProtocol::ParsePackageData( QByteArray& byPackageData, QString& strInfo ) { byBuffer.setBuffer( &byPackageData ); QByteArray byData; bool bRet = byBuffer.open( QIODevice::ReadOnly ); if( !bRet ) { goto ERROR_PROCESS; } bRet = byBuffer.reset( ); if( !bRet ) { goto ERROR_PROCESS; } byData = byBuffer.read( byDataToken.length( ) ); if ( byData.isEmpty( ) ) { bRet = false; goto ERROR_PROCESS; } bRet = ParseCommonHeader( byBuffer, byData ); if( !bRet ) { goto ERROR_PROCESS; } bRet = ParseAuxHeader( byBuffer, byData ); if( !bRet ) { goto ERROR_PROCESS; } bRet = ParseBody( byBuffer, byData ); ERROR_PROCESS: if( !bRet ) { strInfo = byBuffer.errorString( ); } byBuffer.close( ); return bRet; }
// ----------------------------------------------------------------------------- // CUpnpHttpChunkParser::Parse // Decoding the chunked-encoded buffer // ----------------------------------------------------------------------------- // TInt CUpnpHttpChunkParser::Parse(TDes8& aBuffer, TInt& aPos) { TBool interrupt = EFalse; while(!interrupt) { switch(iContext) { case EUnknown: iContext = EHeader; break; case EHeader: interrupt = ParseHeader(aBuffer,aPos); break; case ELastChunk: interrupt = ParseLastChunk(aBuffer,aPos); break; case EBody: interrupt = ParseBody(aBuffer,aPos); break; case EEndChunkBody: iContext = EHeader; break; case EExtension: interrupt = ParseExtension(aBuffer,aPos); break; case ETrailer: interrupt = ParseTrailer(aBuffer,aPos); break; case EError: return iError; case EFinish: return KErrNone; default: return KErrUnknown; } } return KErrNone; }
/* ================ idDeclAF::Parse ================ */ bool idDeclAF::Parse( const char *text, const int textLength ) { int i, j; idLexer src; idToken token; src.LoadMemory( text, textLength, GetFileName(), GetLineNum() ); src.SetFlags( DECL_LEXER_FLAGS ); src.SkipUntilString( "{" ); while( src.ReadToken( &token ) ) { if ( !token.Icmp( "settings" ) ) { if ( !ParseSettings( src ) ) { return false; } } else if ( !token.Icmp( "body" ) ) { if ( !ParseBody( src ) ) { return false; } } else if ( !token.Icmp( "fixed" ) ) { if ( !ParseFixed( src ) ) { return false; } } else if ( !token.Icmp( "ballAndSocketJoint" ) ) { if ( !ParseBallAndSocketJoint( src ) ) { return false; } } else if ( !token.Icmp( "universalJoint" ) ) { if ( !ParseUniversalJoint( src ) ) { return false; } } else if ( !token.Icmp( "hinge" ) ) { if ( !ParseHinge( src ) ) { return false; } } else if ( !token.Icmp( "slider" ) ) { if ( !ParseSlider( src ) ) { return false; } } else if ( !token.Icmp( "spring" ) ) { if ( !ParseSpring( src ) ) { return false; } } else if ( token == "}" ) { break; } else { src.Error( "unknown keyword %s", token.c_str() ); return false; } } for ( i = 0; i < bodies.Num(); i++ ) { // check for multiple bodies with the same name for ( j = i+1; j < bodies.Num(); j++ ) { if ( bodies[i]->name == bodies[j]->name ) { src.Error( "two bodies with the same name \"%s\"", bodies[i]->name.c_str() ); } } } for ( i = 0; i < constraints.Num(); i++ ) { // check for multiple constraints with the same name for ( j = i+1; j < constraints.Num(); j++ ) { if ( constraints[i]->name == constraints[j]->name ) { src.Error( "two constraints with the same name \"%s\"", constraints[i]->name.c_str() ); } } // check if there are two valid bodies set if ( constraints[i]->body1 == "" ) { src.Error( "no valid body1 specified for constraint '%s'", constraints[i]->name.c_str() ); } if ( constraints[i]->body2 == "" ) { src.Error( "no valid body2 specified for constraint '%s'", constraints[i]->name.c_str() ); } } // make sure the body which modifies the origin comes first for ( i = 0; i < bodies.Num(); i++ ) { if ( bodies[i]->jointName == "origin" ) { if ( i != 0 ) { idDeclAF_Body *b = bodies[0]; bodies[0] = bodies[i]; bodies[i] = b; } break; } } return true; }
void CIffIlbm::OnChunk(CIffChunk *pChunk, CMemoryMappedFile &pFile) { // "raw" data of the chunk, // locate by offset uint8_t *pChunkData = CIffContainer::GetViewByOffset(pChunk->m_iOffset, pFile); // suitable handling for chunk data.. if (pChunk->m_iChunkID == MakeTag("BMHD")) { // BMHD bitmap header chunk: // should be first in file (according to spec) // and needed by later processing of data ParseBitmapHeader(pChunkData, pChunk); } else if (pChunk->m_iChunkID == MakeTag("CMAP")) { // CMAP color map chunk m_lCmapCount = (pChunk->m_iChunkSize/sizeof(ColorRegister)); m_pCmap = new ColorRegister[m_lCmapCount]; // bytes only, copy as-is: no need for byteswap ::memcpy(m_pCmap, pChunkData, m_lCmapCount*sizeof(ColorRegister)); } else if (pChunk->m_iChunkID == MakeTag("GRAB")) { // GRAB "hotspot" position (optional) // (e.g. brush center) Point2D *pPt = (Point2D*)pChunkData; m_Pt2d.x = Swap2(pPt->x); m_Pt2d.y = Swap2(pPt->y); } else if (pChunk->m_iChunkID == MakeTag("DEST")) { // DEST (optional) DestMerge *pDst = (DestMerge*)pChunkData; m_DestMerge.depth = pDst->depth; m_DestMerge.pad1 = pDst->pad1; // padding, not necessary m_DestMerge.planePick = Swap2(pDst->planePick); m_DestMerge.planeOnOff = Swap2(pDst->planeOnOff); m_DestMerge.planeMask = Swap2(pDst->planeMask); } else if (pChunk->m_iChunkID == MakeTag("CRNG")) { // CRNG (optional), "nonstandard" // used by e.g. EA Deluxe Paint CRange *pRange = (CRange*)pChunkData; m_Range.pad1 = Swap2(pRange->pad1); // padding, not necessary m_Range.rate = Swap2(pRange->rate); m_Range.active = Swap2(pRange->active); m_Range.low = pRange->low; m_Range.high = pRange->high; } else if (pChunk->m_iChunkID == MakeTag("CCRT")) { // CCRT (optional) // (Color Cycling Range and Timing) CycleInfo *pCcrt = (CycleInfo*)pChunkData; m_CycleInfo.direction = Swap2(pCcrt->direction); m_CycleInfo.start = pCcrt->start; m_CycleInfo.end = pCcrt->end; m_CycleInfo.seconds = Swap4(pCcrt->seconds); m_CycleInfo.microseconds = Swap4(pCcrt->microseconds); m_CycleInfo.pad = Swap2(pCcrt->pad); // padding, not necessary } else if (pChunk->m_iChunkID == MakeTag("SPRT")) { // SPRT (optional), // when image intended as a sprite: // "Z"-plane order of sprite (0 foremost) m_SpriteOrder = Swap2((*(SpritePrecedence*)pChunkData)); } else if (pChunk->m_iChunkID == MakeTag("CAMG")) { // CAMG (optional), // Amiga "viewport mode" // e.g. "dual playfield", "hold and modify" m_lViewPortMode = Swap4((*((LONG*)pChunkData))); } else if (pChunk->m_iChunkID == MakeTag("BODY")) { // BODY raster body chunk // content is concatenation of scan lines ParseBody(pChunkData, pChunk); } }