Beispiel #1
0
void TcxReader::readLap(CTrack *track)
{
    Q_ASSERT(isStartElement() && name() == "Lap");

    int lap = 1;
    while (!atEnd())
    {
        readNext();

        if (isEndElement())
            break;

        if (isStartElement())
        {
            if (name() == "Track")
            {
                readTrack(track, lap);
            }
            else
                readUnknownElement();
        }
    }

}
Beispiel #2
0
bool ConfigReader::createConfig()
{
    bool inProcessingMode = false;
    while(!atEnd())
    {
        TokenType token = readNext();
        // First, check if processing is possible
        if(token == StartElement && name() == "olvisConfig")
        {
            inProcessingMode = true;
            continue;
        }
        if(!inProcessingMode)
            continue;

        switch(token)
        {
        case StartElement:
            if(name() == "makroFilter")
                createMakroFilter();
            else if(name() == "processor")
                createProcessor();
            else if(name() == "buffer")
                createBuffer();
            else if(name() == "join")
                createJoin();
            else if(name() == "filter")
            {
                createFilter();
                // Filter could not be created, cancel loading
                if(mCurrentFilter == -1){
                    return false;
                }
            }
            else if(name() == "port")
                setPort();
            else if(name() == "makroInput")
                addMakroInput();
            else if(name() == "makroOutput")
                addMakroOutput();
            else if(name() == "processorOutput")
                addProcessorOutput();
            else if(name() == "source")
                setSource();
            else if(name() == "connection")
                connectProcessors();
            else if(name() == "inputConnection")
                connectProcessorInput();
            mCurrentData = "";
            break;
        case Characters:
            mCurrentData += text();
            break;
        case EndElement:
            if(name() == "processor")
                mCurrentProcessor = 0;
            else if(name() == "filter")
                mCurrentFilter = 0;
            else if(name() == "port")
                mCurrentPort = "";
            else if(name() == "value")
                setValue();
            else if(name() == "olvisConfig")
                inProcessingMode = false;
            break;
        default:
            break;
        }
    }

    // Default: Return true, as config was loaded
    return true;
}
Beispiel #3
0
bool XMLimport::importPackage( QIODevice * device, QString packName, int moduleFlag)
{
    mPackageName = packName;
    setDevice( device );

    gotTrigger = false;
    gotTimer = false;
    gotAlias = false;
    gotKey = false;
    gotAction = false;
    gotScript = false;
    module = moduleFlag;
    /*if (moduleFlag)
        module=1;*/
    qDebug()<<"module flag:"<<module<<" importing: "<<mPackageName;


    if( ! packName.isEmpty() )
    {
        mpKey = new TKey( 0, mpHost );
        if (module){
            mpKey->mModuleMasterFolder=true;
            mpKey->mModuleMember=true;
        }
        mpKey->setPackageName( mPackageName );
        mpKey->setIsActive( true );
        mpKey->setName( mPackageName );
        mpKey->setIsFolder( true );

        mpTrigger = new TTrigger( 0, mpHost );
        if (module){
            mpTrigger->mModuleMasterFolder=true;
            mpTrigger->mModuleMember=true;
        }
        mpTrigger->setPackageName( mPackageName );
        mpTrigger->setIsActive( true );
        mpTrigger->setName( mPackageName );
        mpTrigger->setIsFolder( true );

        mpTimer = new TTimer( 0, mpHost );
        if (module){
            mpTimer->mModuleMasterFolder=true;
            mpTimer->mModuleMember=true;
        }
        mpTimer->setPackageName( mPackageName );
        mpTimer->setIsActive( true );
        mpTimer->setName( mPackageName );
        mpTimer->setIsFolder( true );

        mpAlias = new TAlias( 0, mpHost );
        if (module){
            mpAlias->mModuleMasterFolder=true;
            mpAlias->mModuleMember=true;
        }
        mpAlias->setPackageName( mPackageName );
        mpAlias->setIsActive( true );
        mpAlias->setName( mPackageName );
        mpAlias->setIsFolder( true );
        mpAction = new TAction( 0, mpHost );
        if (module){
            mpAction->mModuleMasterFolder=true;
            mpAction->mModuleMember=true;
        }
        mpAction->setPackageName( mPackageName );
        mpAction->setIsActive( true );
        mpAction->setName( mPackageName );
        mpAction->setIsFolder( true );
        mpScript = new TScript( 0, mpHost );
        if (module){
            mpScript->mModuleMasterFolder=true;
            mpScript->mModuleMember=true;
        }
        mpScript->setPackageName( mPackageName );
        mpScript->setIsActive( true );
        mpScript->setName( mPackageName );
        mpScript->setIsFolder( true );
        mpHost->getTriggerUnit()->registerTrigger( mpTrigger );
        mpHost->getTimerUnit()->registerTimer( mpTimer );
        mpHost->getAliasUnit()->registerAlias( mpAlias );
        mpHost->getActionUnit()->registerAction( mpAction );
        mpHost->getKeyUnit()->registerKey( mpKey );
        mpHost->getScriptUnit()->registerScript( mpScript );
    }
    while( ! atEnd() )
    {
        readNext();

        if( isStartElement() )
        {
            if( name() == "MudletPackage" )// && attributes().value("version") == "1.0")
            {
                readPackage();
            }
            else if( name() == "map" )
            {
                maxAreas = 0;
                maxRooms = 0;
                areaMap.clear();
                readMap();
                mpHost->mpMap->init(mpHost);
            }
            else
            {
                qDebug()<<"ERROR:name="<<name().toString()<<"text:"<<text().toString();
            }
        }
    }
    if( ! packName.isEmpty())
    {
       if( ! gotTrigger )
            mpHost->getTriggerUnit()->unregisterTrigger( mpTrigger );
       if( ! gotTimer )
            mpHost->getTimerUnit()->unregisterTimer( mpTimer );
       if( ! gotAlias )
            mpHost->getAliasUnit()->unregisterAlias( mpAlias );
       if( ! gotAction )
            mpHost->getActionUnit()->unregisterAction( mpAction );
       if( ! gotKey )
            mpHost->getKeyUnit()->unregisterKey( mpKey );
       if( ! gotScript )
            mpHost->getScriptUnit()->unregisterScript( mpScript );
    }
    return ! error();
}
Beispiel #4
0
void XMLimport::readKeyGroup( TKey * pParent )
{
    TKey * pT;
    if( pParent )
    {
        pT = new TKey( pParent, mpHost );
    }
    else
    {
        pT = new TKey( 0, mpHost );
    }
    mpHost->getKeyUnit()->registerKey( pT );
    pT->setIsActive( ( attributes().value("isActive") == "yes" ) );
    pT->mIsFolder = ( attributes().value("isFolder") == "yes" );
    if (module)
        pT->mModuleMember = true;

    while( ! atEnd() )
    {
        readNext();
        if( isEndElement() ) break;

        if( isStartElement() )
        {
            if( name() == "name" )
            {
                pT->mName = readElementText();
                continue;
            }
            else if( name() == "packageName")
            {
                pT->mPackageName = readElementText();
                continue;
            }
            else if( name() == "script")
            {
                QString script = readElementText();
                pT->setScript( script );
                continue;
            }
            else if( name() == "command")
            {
                pT->mCommand = readElementText();
                continue;
            }
            else if( name() == "keyCode" )
            {
                pT->mKeyCode = readElementText().toInt();
                continue;
            }
            else if( name() == "keyModifier" )
            {
                pT->mKeyModifier = readElementText().toInt();
                continue;
            }

            else if( name() == "KeyGroup" )
            {
                readKeyGroup( pT );
            }
            else if( name() == "Key" )
            {
                readKeyGroup( pT );
            }
            else
            {
                readUnknownKeyElement();
            }
        }
    }
}
Beispiel #5
0
void XMLimport::readActionGroup( TAction * pParent )
{
    TAction * pT;
    if( pParent )
    {
        pT = new TAction( pParent, mpHost );
    }
    else
    {
        pT = new TAction( 0, mpHost );
    }
    mpHost->getActionUnit()->registerAction( pT );
    pT->setIsActive( ( attributes().value("isActive") == "yes" ) );
    pT->mIsFolder = ( attributes().value("isFolder") == "yes" );
    pT->mIsPushDownButton = ( attributes().value("isPushButton") == "yes" );
    pT->mButtonFlat = ( attributes().value("isFlatButton") == "yes" );
    pT->mUseCustomLayout = ( attributes().value("useCustomLayout") == "yes" );
    if (module)
        pT->mModuleMember = true;

    while( ! atEnd() )
    {
        readNext();
        if( isEndElement() ) break;

        if( isStartElement() )
        {
            if( name() == "name" )
            {
                pT->mName = readElementText();
                continue;
            }
            else if( name() == "packageName")
            {
                pT->mPackageName = readElementText();
                continue;
            }
            else if( name() == "script")
            {
                QString script = readElementText();
                pT->setScript( script );
                continue;
            }
            else if( name() == "css")
            {
                pT->css = readElementText();
                continue;
            }
            else if( name() == "commandButtonUp")
            {
                pT->mCommandButtonUp = readElementText();
                continue;
            }
            else if( name() == "commandButtonDown")
            {
                pT->mCommandButtonDown = readElementText();
                continue;
            }
            else if( name() == "icon")
            {
                pT->mIcon = readElementText();
                continue;
            }
            else if( name() == "orientation")
            {
                pT->mOrientation = readElementText().toInt();
                continue;
            }
            else if( name() == "location")
            {
                pT->mLocation = readElementText().toInt();
                continue;
            }

            else if( name() == "buttonRotation")
            {
                pT->mButtonRotation = readElementText().toInt();
                continue;
            }
            else if( name() == "sizeX")
            {
                pT->mSizeX = readElementText().toInt();
                continue;
            }
            else if( name() == "sizeY")
            {
                pT->mSizeY = readElementText().toInt();
                continue;
            }
            else if( name() == "mButtonState")
            {
                pT->mButtonState = readElementText().toInt();
                continue;
            }
            else if( name() == "buttonColor")
            {
                pT->mButtonColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "buttonColumn")
            {
                pT->mButtonColumns = readElementText().toInt();
                continue;
            }

            else if( name() == "posX")
            {
                pT->mPosX = readElementText().toInt();
                continue;
            }
            else if( name() == "posY")
            {
                pT->mPosY = readElementText().toInt();
                continue;
            }

            else if( name() == "ActionGroup" )
            {
                readActionGroup( pT );
            }
            else if( name() == "Action" )
            {
                readActionGroup( pT );
            }
            else
            {
                readUnknownActionElement();
            }
        }
    }


}
Beispiel #6
0
void XMLimport::readTimerGroup( TTimer * pParent )
{
    TTimer * pT;
    if( pParent )
    {
        pT = new TTimer( pParent, mpHost );
    }
    else
    {
        pT = new TTimer( 0, mpHost );
    }
    pT->registerTimer();
    pT->setShouldBeActive( ( attributes().value("isActive") == "yes" ) );
    pT->mIsFolder = ( attributes().value("isFolder") == "yes" );
    pT->mIsTempTimer = ( attributes().value("isTempTimer") == "yes" );
    if (module)
        pT->mModuleMember = true;

    while( ! atEnd() )
    {
        readNext();
        if( isEndElement() ) break;

        if( isStartElement() )
        {
            if( name() == "name" )
            {
                pT->setName( readElementText() );
                continue;
            }
            else if( name() == "packageName")
            {
                pT->mPackageName = readElementText();
                continue;
            }
            else if( name() == "script")
            {
                QString script = readElementText();
                pT->setScript( script );
                continue;
            }
            else if( name() == "command")
            {
                pT->mCommand = readElementText();
                continue;
            }
            else if( name() == "time")
            {
                QString timeString = readElementText();
                QTime time = QTime::fromString( timeString, "hh:mm:ss.zzz" );
                pT->setTime( time );
                continue;
            }
            else if( name() == "TimerGroup" )
            {
                readTimerGroup( pT );
            }
            else if( name() == "Timer" )
            {
                readTimerGroup( pT );
            }
            else
            {
                readUnknownTimerElement();
            }
        }
    }

    if( ( ! pT->isOffsetTimer() ) && ( pT->shouldBeActive() ) )
        pT->enableTimer( pT->getID() );
    else
        pT->disableTimer( pT->getID() );

}
Beispiel #7
0
 WTF::Unicode::Direction direction() const { return atEnd() ? WTF::Unicode::OtherNeutral : WTF::Unicode::direction(current()); }
Beispiel #8
0
void YTFeedReader::readEntry() {
    Video* video = new Video();

    while (!atEnd()) {
        readNext();

        /*
        qDebug() << name();
        QXmlStreamAttribute attribute;
        foreach (attribute, attributes())
            qDebug() << attribute.name() << ":" << attribute.value();
        */

        if (isEndElement() && name() == QLatin1String("entry")) break;
        if (isStartElement()) {

            if (name() == QLatin1String("link")
                    && attributes().value("rel").toString() == QLatin1String("alternate")
                    && attributes().value("type").toString() == QLatin1String("text/html")
                    ) {
                QString webpage = attributes().value("href").toString();
                webpage.remove("&feature=youtube_gdata");
                video->setWebpage(webpage);
            } else if (name() == QLatin1String("author")) {
                while(readNextStartElement())
                    if (name() == QLatin1String("name")) {
                        QString author = readElementText();
                        video->setChannelTitle(author);
                    } else if (name() == QLatin1String("userId")) {
                        QString userId = readElementText();
                        video->setChannelId(userId);
                    } else skipCurrentElement();
            } else if (name() == QLatin1String("published")) {
                video->setPublished(QDateTime::fromString(readElementText(), Qt::ISODate));
            } else if (namespaceUri() == QLatin1String("http://gdata.youtube.com/schemas/2007")
                       && name() == QLatin1String("statistics")) {
                QString viewCount = attributes().value("viewCount").toString();
                video->setViewCount(viewCount.toInt());
            }
            else if (namespaceUri() == QLatin1String("http://search.yahoo.com/mrss/")
                     && name() == QLatin1String("group")) {

                // read media group
                while (!atEnd()) {
                    readNext();
                    if (isEndElement() && name() == QLatin1String("group")) break;
                    if (isStartElement()) {
                        if (name() == QLatin1String("thumbnail")) {
                            // qDebug() << "Thumb: " << attributes().value("url").toString();
                            QStringRef name = attributes().value("yt:name");
                            if (name == QLatin1String("mqdefault"))
                                video->setThumbnailUrl(
                                            attributes().value("url").toString());
                            else if (name == QLatin1String("hqdefault"))
                                video->setMediumThumbnailUrl(
                                            attributes().value("url").toString());
                        }
                        else if (name() == QLatin1String("title")) {
                            QString title = readElementText();
                            // qDebug() << "Title: " << title;
                            video->setTitle(title);
                        }
                        else if (name() == QLatin1String("description")) {
                            QString desc = readElementText();
                            // qDebug() << "Description: " << desc;
                            video->setDescription(desc);
                        }
                        else if (name() == QLatin1String("duration")) {
                            QString duration = attributes().value("seconds").toString();
                            // qDebug() << "Duration: " << duration;
                            video->setDuration(duration.toInt());
                        }
                        else if (name() == QLatin1String("license")) {
                            QString license = readElementText();
                            // qDebug() << "License: " << license;
                            if (license == QLatin1String("cc"))
                                video->setLicense(Video::LicenseCC);
                        }
                    }
                }
            }
        }
    }

    videos.append(video);

}
Beispiel #9
0
int main(int argc, char const ** argv)
{
    if (argc != 7)
    {
        std::cerr << "USAGE: " << argv[0] << " IN.bam IN.bam.bai REF BEGIN END COUNT\n";
        return 1;
    }

    // Open BGZF Stream for reading.
    seqan::Stream<seqan::Bgzf> inStream;
    if (!open(inStream, argv[1], "r"))
    {
        std::cerr << "ERROR: Could not open " << argv[1] << " for reading.\n";
        return 1;
    }

    // Read BAI index.
    seqan::BamIndex<seqan::Bai> baiIndex;
    if (read(baiIndex, argv[2]) != 0)
    {
        std::cerr << "ERROR: Could not read BAI index file " << argv[2] << "\n";
        return 1;
    }

    // Setup name store, cache, and BAM I/O context.
    typedef seqan::StringSet<seqan::CharString> TNameStore;
    typedef seqan::NameStoreCache<TNameStore>   TNameStoreCache;
    typedef seqan::BamIOContext<TNameStore>     TBamIOContext;
    TNameStore      nameStore;
    TNameStoreCache nameStoreCache(nameStore);
    TBamIOContext   context(nameStore, nameStoreCache);

    // Read header.
    seqan::BamHeader header;
    if (readRecord(header, context, inStream, seqan::Bam()) != 0)
    {
        std::cerr << "ERROR: Could not read header from BAM file " << argv[1] << "\n";
        return 1;
    }

    // Translate from reference name to rId.
    int rId = 0;
    if (!getIdByName(nameStore, argv[3], rId, nameStoreCache))
    {
        std::cerr << "ERROR: Reference sequence named " << argv[3] << " not known.\n";
        return 1;
    }

    // Translate BEGIN and END arguments to number, 1-based to 0-based.
    int beginPos = 0, endPos = 0;
    if (!seqan::lexicalCast2(beginPos, argv[4]) || beginPos <= 0)
    {
        std::cerr << "ERROR: Begin position " << argv[4] << " is invalid.\n";
        return 1;
    }
    beginPos -= 1;  // 1-based to 0-based.
    if (!seqan::lexicalCast2(endPos, argv[5]) || endPos <= 0)
    {
        std::cerr << "ERROR: End position " << argv[5] << " is invalid.\n";
        return 1;
    }
    endPos -= 1;  // 1-based to 0-based.

    // Translate number of elements to print to number.
    int num = 0;
    if (!seqan::lexicalCast2(num, argv[6]))
    {
        std::cerr << "ERROR: Count " << argv[6] << " is invalid.\n";
        return 1;
    }

    // Jump the BGZF stream to this position.
    bool hasAlignments = false;
    if (!jumpToRegion(inStream, hasAlignments, context, rId, beginPos, endPos, baiIndex))
    {
        std::cerr << "ERROR: Could not jump to " << argv[3] << ":" << argv[4] << "\n";
        return 1;
    }
    if (!hasAlignments)
        return 0;  // No alignments here.

    // Seek linearly to the selected position.
    seqan::BamAlignmentRecord record;
    int numPrinted = 0;
    while (!atEnd(inStream) && numPrinted < num)
    {
        if (readRecord(record, context, inStream, seqan::Bam()) != 0)
        {
            std::cerr << "ERROR: Could not read record from BAM file.\n";
            return 1;
        }

        // If we are on the next reference or at the end already then we stop.
        if (record.rId == -1 || record.rId > rId || record.pos >= endPos)
            break;
        // If we are left of the selected position then we skip this record.
        if (record.pos < beginPos)
            continue;

        // Otherwise, we print it to the user.
        numPrinted += 1;
        if (write2(std::cout, record, context, seqan::Sam()) != 0)
        {
            std::cerr << "ERROR: Could not write record to stdout.\n";
            return 1;
        }
    }

    return 0;
}
Beispiel #10
0
void SglExprLex::scanLetters()
{
  while ( !atEnd() && isLetter() )
    ++index;
  end = index;
}
Beispiel #11
0
  bool Parser::Impl::parseStringList() {
    // string-list := "[" string *("," string) "]" / string
    //  ;; if there is only a single string, the brackets are optional
    //
    // However, since strings are already handled separately from
    // string lists in parseArgument(), our ABNF is modified to:
    // string-list := "[" string *("," string) "]"

    if ( !obtainToken() || atEnd() )
      return false;

    if ( token() != Lexer::Special || tokenValue() != "[" )
      return false;

    if ( scriptBuilder() )
      scriptBuilder()->stringListArgumentStart();
    consumeToken();

    // generic while/switch construct for comma-separated lists. See
    // parseTestList() for another one. Any fix here is like to apply there, too.
    bool lastWasComma = true;
    while ( !atEnd() ) {
      if ( !obtainToken() )
        return false;

      switch ( token() ) {
      case Lexer::None:
        break;
      case Lexer::Special:
        assert( tokenValue().length() == 1 );
        switch ( tokenValue()[0].toLatin1() ) {
        case ']':
          consumeToken();
          if ( lastWasComma ) {
            makeError( Error::ConsecutiveCommasInStringList );
            return false;
          }
          if ( scriptBuilder() )
            scriptBuilder()->stringListArgumentEnd();
          return true;
        case ',':
          consumeToken();
          if ( lastWasComma ) {
            makeError( Error::ConsecutiveCommasInStringList );
            return false;
          }
          lastWasComma = true;
          break;
        default:
          makeError( Error::NonStringInStringList );
          return false;
        }
        break;

      case Lexer::QuotedString:
      case Lexer::MultiLineString:
        if ( !lastWasComma ) {
          makeError( Error::MissingCommaInStringList );
          return false;
        }
        lastWasComma = false;
        if ( scriptBuilder() )
          scriptBuilder()->stringListEntry( tokenValue(), token() == Lexer::MultiLineString, QString() );
        consumeToken();
        break;

      default:
        makeError( Error::NonStringInStringList );
        return false;
      }
    }

    makeError( Error::PrematureEndOfStringList );
    return false;
  }
Beispiel #12
0
 bool Parser::Impl::parseTestList() {
   // test-list := "(" test *("," test) ")"
   
   if ( !obtainToken() || atEnd() )
     return false;
   
   if ( token() != Lexer::Special || tokenValue() != "(" )
     return false;
   if ( scriptBuilder() )
     scriptBuilder()->testListStart();
   consumeToken();
   
   // generic while/switch construct for comma-separated lists. See
   // parseStringList() for another one. Any fix here is like to apply there, too.
   bool lastWasComma = true;
   while ( !atEnd() ) {
     if ( !obtainToken() )
       return false;
     
     switch ( token() ) {
     case Lexer::None:
       break;
     case Lexer::Special:
       assert( tokenValue().length() == 1 );
       assert( tokenValue()[0].toLatin1() );
       switch ( tokenValue()[0].toLatin1() ) {
       case ')':
         consumeToken();
         if ( lastWasComma ) {
           makeError( Error::ConsecutiveCommasInTestList );
           return false;
         }
         if ( scriptBuilder() )
           scriptBuilder()->testListEnd();
         return true;
       case ',':
         consumeToken();
         if( lastWasComma ) {
           makeError( Error::ConsecutiveCommasInTestList );
           return false;
         }
         lastWasComma = true;
         break;
       default:
         makeError( Error::NonStringInStringList );
         return false;
       }
       break;
       
     case Lexer::Identifier:
       if ( !lastWasComma ) {
         makeError( Error::MissingCommaInTestList );
         return false;
       } else {
         lastWasComma = false;
         if ( !parseTest() ) {
           assert( error() );
           return false;
         }
       }
       break;
       
     default:
       makeUnexpectedTokenError( Error::NonTestInTestList );
       return false;
     }
   }
   
   makeError( Error::PrematureEndOfTestList );
   return false;
 }
Beispiel #13
0
  bool Parser::Impl::parseCommand() {
    // command   := identifier arguments ( ";" / block )
    // arguments := *argument [ test / test-list ]
    // block     := "{" *command "}"
    // our ABNF:
    // block     := "{" [ command-list ] "}"

    if ( atEnd() )
      return false;

    //
    // identifier
    //

    if ( !obtainToken() || token() != Lexer::Identifier )
      return false;

    if ( scriptBuilder() )
      scriptBuilder()->commandStart( tokenValue() );
    consumeToken();

    //
    // *argument
    //

    if ( !obtainToken() )
      return false;

    if ( atEnd() ) {
      makeError( Error::MissingSemicolonOrBlock );
      return false;
    }

    if ( isArgumentToken() && !parseArgumentList() ) {
      assert( error() );
      return false;
    }

    //
    // test / test-list
    //

    if ( !obtainToken() )
      return false;

    if ( atEnd() ) {
      makeError( Error::MissingSemicolonOrBlock );
      return false;
    }

    if ( token() == Lexer::Special && tokenValue() == "(" ) { // test-list
      if ( !parseTestList() ) {
        assert( error() );
        return false;
      }
    } else if ( token() == Lexer::Identifier ) { // should be test:
      if ( !parseTest() ) {
        assert( error() );
        return false;
      }
    }

    //
    // ";" / block
    //

    if ( !obtainToken() )
      return false;

    if ( atEnd() ) {
      makeError( Error::MissingSemicolonOrBlock );
      return false;
    }

    if ( token() != Lexer::Special ) {
      makeUnexpectedTokenError( Error::ExpectedBlockOrSemicolon );
      return false;
    }

    if ( tokenValue() == ";" )
      consumeToken();
    else if ( tokenValue() == "{" ) { // block
      if ( !parseBlock() )
        return false; // it's an error since we saw '{'
    } else {
      makeError( Error::MissingSemicolonOrBlock );
      return false;
    }

    if ( scriptBuilder() )
      scriptBuilder()->commandEnd();
    return true;
  }
void YouTubeStreamReader::readEntry() {
    Video* video = new Video();
    // qDebug(" *** ENTRY ***");

    while (!atEnd()) {
        readNext();

        /*
        qDebug() << name();
        QXmlStreamAttribute attribute;
        foreach (attribute, attributes())
            qDebug() << attribute.name() << ":" << attribute.value();
        */

        if (isEndElement() && name() == "entry") break;
        if (isStartElement()) {

            if (name() == "link"
                && attributes().value("rel").toString() == "alternate"
                && attributes().value("type").toString() == "text/html"
                ) {
                QString webpage = attributes().value("href").toString();
                webpage.remove("&feature=youtube_gdata");
                // qDebug() << "Webpage: " << webpage;
                video->setWebpage(QUrl(webpage));

            } else if (name() == "author") {
                readNext();
                if (name() == "name") {
                    QString author = readElementText();
                    // qDebug() << "Author: " << author;
                    video->setAuthor(author);
                }
            } else if (name() == "published") {
                video->setPublished(QDateTime::fromString(readElementText(), Qt::ISODate));
            } else if (namespaceUri() == "http://gdata.youtube.com/schemas/2007" && name() == "statistics") {

                QString viewCount = attributes().value("viewCount").toString();
                // qDebug() << "viewCount: " << viewCount;
                video->setViewCount(viewCount.toInt());
            }
            else if (namespaceUri() == "http://search.yahoo.com/mrss/" && name() == "group") {

                // read media group
                while (!atEnd()) {
                    readNext();
                    if (isEndElement() && name() == "group") break;
                    if (isStartElement()) {
                        if (name() == "thumbnail") {
                            // qDebug() << "Thumb: " << attributes().value("url").toString();
                            // video->thumbnailUrls() << QUrl(attributes().value("url").toString());
                            video->addThumbnailUrl(QUrl(attributes().value("url").toString()));
                        }
                        else if (name() == "title") {
                            QString title = readElementText();
                            // qDebug() << "Title: " << title;
                            video->setTitle(title);
                        }
                        else if (name() == "description") {
                            QString desc = readElementText();
                            // qDebug() << "Description: " << desc;
                            video->setDescription(desc);
                        }
                        else if (name() == "duration") {
                            QString duration = attributes().value("seconds").toString();
                            // qDebug() << "Duration: " << duration;
                            video->setDuration(duration.toInt());
                        }
                    }
                }
            }
        }
    }

    videos.append(video);

}
Beispiel #15
0
int main(int argc, char const ** argv)
{
    double startTime = 0;
    
    // -----------------------------------------------------------------------
    // Parse command line.
    // -----------------------------------------------------------------------
    FxSamCoverageOptions options;
    seqan::ArgumentParser::ParseResult res = parseArgs(options, argc, argv);
    if (res != seqan::ArgumentParser::PARSE_OK)
        return res == seqan::ArgumentParser::PARSE_ERROR;  // 1 on errors, 0 otherwise

    // -----------------------------------------------------------------------
    // Show options.
    // -----------------------------------------------------------------------
    if (options.verbosity >= 1)
    {
        std::cerr << "____OPTIONS___________________________________________________________________\n"
                  << "\n"
                  << "VERBOSITY    " << options.verbosity << "\n"
                  << "GENOME       " << options.inGenomePath << "\n"
                  << "SAM          " << options.inSamPath << "\n"
                  << "OUT          " << options.outPath << "\n"
                  << "WINDOW SIZE  " << options.windowSize << "\n";
    }

    // -----------------------------------------------------------------------
    // Load Genome FAI Index
    // -----------------------------------------------------------------------

    std::cerr << "\n"
              << "___PREPRATION_____________________________________________________________________\n"
              << "\n"
              << "Indexing GENOME file  " << options.inGenomePath << " ...";
    seqan::FaiIndex faiIndex;
    if (build(faiIndex, toCString(options.inGenomePath)) != 0)
    {
        std::cerr << "Could not build FAI index.\n";
        return 1;
    }
    std::cerr << " OK\n";

    // Prepare bins.
    seqan::String<seqan::String<BinData> > bins;
    resize(bins, numSeqs(faiIndex));

    // -----------------------------------------------------------------------
    // Compute C+G content 
    // -----------------------------------------------------------------------

    std::cerr << "\n"
              << "___C+G CONTENT COMPUTATION________________________________________________________\n"
              << "\n";

    for (unsigned i = 0; i < numSeqs(faiIndex); ++i)
    {
        std::cerr << "[" << sequenceName(faiIndex, i) << "] ...";
        unsigned numBins = (sequenceLength(faiIndex, i) + options.windowSize - 1) / options.windowSize;
        resize(bins[i], numBins);
        seqan::Dna5String contigSeq;
        if (readSequence(contigSeq, faiIndex, i) != 0)
        {
            std::cerr << "\nERROR: Could not read sequence " << sequenceName(faiIndex, i) << " from file!\n";
            return 1;
        }

        for (unsigned bin = 0; bin < numBins; ++bin)
        {
            unsigned cgCounter = 0;
            unsigned binSize = 0;
            bins[i][bin].length = options.windowSize;
            if ((bin + 1) * options.windowSize > length(contigSeq))
                bins[i][bin].length = length(contigSeq) - bin * options.windowSize;
            for (unsigned pos = bin * options.windowSize; pos < length(contigSeq) && pos < (bin + 1) * options.windowSize; ++pos, ++binSize)
                cgCounter += (contigSeq[pos] == 'C' || contigSeq[pos] == 'G');
            bins[i][bin].cgContent = 1.0 * cgCounter / binSize;
        }
        std::cerr << "DONE\n";
    }

    // -----------------------------------------------------------------------
    // Compute Coverage
    // -----------------------------------------------------------------------

    std::cerr << "\n"
              << "___COVERAGE COMPUATATION________________________________________________________\n"
              << "\n"
              << "Computing Coverage...";

    seqan::BamStream bamStream(toCString(options.inSamPath));
    if (!isGood(bamStream))
    {
        std::cerr << "Could not open " << options.inSamPath << "!\n";
        return 1;
    }

    seqan::BamAlignmentRecord record;
    while (!atEnd(bamStream))
    {
        if (readRecord(record, bamStream) != 0)
        {
            std::cerr << "ERROR: Could not read record from BAM file!\n";
            return 1;
        }

        if (hasFlagUnmapped(record) || hasFlagSecondary(record) || record.rId == seqan::BamAlignmentRecord::INVALID_REFID)
            continue;  // Skip these records.

        int contigId = 0;
        seqan::CharString const & contigName = nameStore(bamStream.bamIOContext)[record.rId];
        if (!getIdByName(faiIndex, contigName, contigId))
        {
            std::cerr << "ERROR: Alignment to unknown contig " << contigId << "!\n";
            return 1;
        }
        unsigned binNo = record.pos / options.windowSize;
        bins[contigId][binNo].coverage += 1;
    }

    std::cerr << "DONE\n";

    // -----------------------------------------------------------------------
    // Write Output
    // -----------------------------------------------------------------------

    std::ostream * out = &std::cout;
    std::ofstream outFile;
    if (options.outPath != "-")
    {
        outFile.open(toCString(options.outPath), std::ios::binary | std::ios::out);
        if (!outFile.good())
        {
            std::cerr << "ERROR: Could not open output file " << options.outPath << "!\n";
            return 1;
        }
        out = &outFile;
    }

    (*out) << "#BIN\tREF_NAME\tREF_BIN\tBIN_BEGIN\tBIN_LENGTH\tCOVERAGE\tCG_CONTENT\n";
    for (unsigned i = 0, globalBin = 0; i < length(bins); ++i)
    {
        for (unsigned refBin = 0; refBin < length(bins[i]); ++refBin, ++globalBin)
        {
            (*out) << globalBin << '\t'
                   << sequenceName(faiIndex, i) << '\t'
                   << refBin << '\t'
                   << refBin * options.windowSize << '\t'
                   << bins[i][refBin].length << '\t'
                   << bins[i][refBin].coverage << '\t'
                   << bins[i][refBin].cgContent << '\n';
        }
    }

    if (options.verbosity >= 2)
        std::cerr << "Took " << (sysTime() - startTime) << " s\n";

    return 0;
}
Beispiel #16
0
void UploadDevice::giveBandwidthQuota(qint64 bwq) {
    if (!atEnd()) {
        _bandwidthQuota = bwq;
        QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); // tell QNAM that we have quota
    }
}
Beispiel #17
0
bool Parser::checkMacroDefinition()
{
	const Token& first = peekToken();
	if (first.type != TokenType::Identifier)
		return false;

	if (!first.stringValueStartsWith(L'.') || first.getStringValue() != L".macro")
		return false;

	eatToken();

	// nested macro definitions are not allowed
	if (initializingMacro)
	{
		printError(first,L"Nested macro definitions not allowed");
		while (!atEnd())
		{
			const Token& token = nextToken();
			if (token.type == TokenType::Identifier && token.getStringValue() == L".endmacro")
				break;
		}

		return true;
	}

	std::vector<Expression> parameters;
	if (parseExpressionList(parameters,1,-1) == false)
		return false;
	
	// load name
	std::wstring macroName;
	if (parameters[0].evaluateIdentifier(macroName) == false)
		return false;

	// duplicate check the macro
	ParserMacro &macro = macros[macroName];
	if (macro.name.length() != 0)
	{
		printError(first,L"Macro \"%s\" already defined",macro.name);
		return false;
	}

	// and register it
	macro.name = macroName;
	macro.counter = 0;

	// load parameters
	for (size_t i = 1; i < parameters.size(); i++)
	{
		std::wstring name;
		if (parameters[i].evaluateIdentifier(name) == false)
			return false;

		macro.parameters.push_back(name);
	}

	// load macro content

	TokenizerPosition start = getTokenizer()->getPosition();
	bool valid = false;
	while (atEnd() == false)
	{
		const Token& tok = nextToken();
		if (tok.type == TokenType::Identifier && tok.getStringValue() == L".endmacro")
		{
			valid = true;
			break;
		}
	}
	
	// no .endmacro, not valid
	if (valid == false)
		return true;

	// get content
	TokenizerPosition end = getTokenizer()->getPosition().previous();
	macro.content = getTokenizer()->getTokens(start,end);

	return true;
}
Beispiel #18
0
int main(int argc, char ** argv)
{
    double startTime = 0;

    // Parse command line.
    SakOptions options;
    seqan::ArgumentParser::ParseResult res = parseArgs(options, argc, argv);
    if (res != seqan::ArgumentParser::PARSE_OK)
        return res == seqan::ArgumentParser::PARSE_ERROR;  // 1 on errors, 0 otherwise

    // -----------------------------------------------------------------------
    // Show options.
    // -----------------------------------------------------------------------
    if (options.verbosity >= 2)
    {
        std::cerr << "____OPTIONS___________________________________________________________________\n"
                  << "\n"
                  << "VERBOSITY    " << options.verbosity << "\n"
                  << "IN           " << options.inFastxPath << "\n"
                  << "OUT          " << options.outPath << "\n"
                  << "INFIX BEGIN  " << options.seqInfixBegin << "\n"
                  << "INFIX END    " << options.seqInfixEnd << "\n"
                  << "MAX LEN      " << options.maxLength << "\n"
                  << "READ PATTERN " << options.readPattern << "\n"
                  << "REVCOMP      " << yesNo(options.reverseComplement) << "\n"
                  << "SEQUENCES\n";
        for (unsigned i = 0; i < length(options.seqIndices); ++i)
            std::cerr << "  SEQ  " << options.seqIndices[i] << "\n";
        for (unsigned i = 0; i < length(options.seqIndexRanges); ++i)
            std::cerr << "  SEQS " << options.seqIndexRanges[i].i1 << "-" << options.seqIndexRanges[i].i2 << "\n";
    }

    // -----------------------------------------------------------------------
    // Open Files.
    // -----------------------------------------------------------------------
    seqan::SeqFileIn inFile;
    seqan::SeqFileOut outFile;

    bool openRes = false;
    if (!empty(options.inFastxPath))
        openRes = open(inFile, toCString(options.inFastxPath));
    else
        openRes = open(inFile, std::cin);
    if (!openRes)
    {
        std::cerr << "ERROR: Problem opening input file.\n";
        return 1;
    }

    if (!empty(options.outPath))
        openRes = open(outFile, toCString(options.outPath));
    else
        openRes = open(outFile, std::cout, seqan::Fastq());
    if (!openRes)
    {
        std::cerr << "ERROR: Problem opening output file.\n";
        return 1;
    }

    // Compute index of last sequence to write if any.
    uint64_t endIdx = seqan::maxValue<uint64_t>();
    for (unsigned i = 0; i < length(options.seqIndices); ++i)
        if (endIdx == seqan::maxValue<uint64_t>() || endIdx > options.seqIndices[i] + 1)
            endIdx = options.seqIndices[i] + 1;
    for (unsigned i = 0; i < length(options.seqIndexRanges); ++i)
        if (endIdx == seqan::maxValue<uint64_t>() || endIdx > options.seqIndexRanges[i].i2)
            endIdx = options.seqIndexRanges[i].i2;
    if (options.verbosity >= 2)
        std::cerr << "Sequence end idx: " << endIdx << "\n";

    // -----------------------------------------------------------------------
    // Read and Write Filtered.
    // -----------------------------------------------------------------------
    startTime = seqan::sysTime();

    unsigned idx = 0;
    uint64_t charsWritten = 0;
    seqan::CharString id;
    seqan::CharString seq;
    seqan::CharString quals;
    while (!atEnd(inFile) && charsWritten < options.maxLength && idx < endIdx)
    {
        try
        {
            readRecord(id, seq, quals, inFile);
        }
        catch (seqan::ParseError const & e)
        {
            std::cerr << "ERROR: Problem reading file: " << e.what() << "\n";
            return 1;
        }

        // Check whether to write out sequence.
        bool writeOut = false;
        if (empty(options.seqIndices) && empty(options.seqIndexRanges))
            writeOut = true;
        // One of options.seqIndices.
        if (!writeOut)
        {
            for (unsigned i = 0; i < length(options.seqIndices); ++i)
            {
                if (options.seqIndices[i] == idx)
                {
                    writeOut = true;
                    break;
                }
            }
        }
        // One of options.seqIndexRanges.
        if (!writeOut)
        {
            for (unsigned i = 0; i < length(options.seqIndexRanges); ++i)
            {
                if (idx >= options.seqIndexRanges[i].i1 && idx < options.seqIndexRanges[i].i2)
                {
                    writeOut = true;
                    break;
                }
            }
        }
        // Name pattern matches.
        if (!writeOut && !empty(options.readPattern))
        {
            unsigned l = length(options.readPattern);
            if (l > length(id))
                l = length(id);
            if (prefix(id, l) == prefix(options.readPattern, l))
                writeOut = true;
        }

        // Write out if we want this.
        if (writeOut)
        {
            // Get begin and end index of infix to write out.
            uint64_t infixBegin = 0;
            if (options.seqInfixBegin != seqan::maxValue<uint64_t>())
                infixBegin = options.seqInfixBegin;
            if (infixBegin > length(seq))
                infixBegin = length(seq);
            uint64_t infixEnd = length(seq);
            if (options.seqInfixEnd < length(seq))
                infixEnd = options.seqInfixEnd;
            if (infixEnd < infixBegin)
                infixEnd = infixBegin;
            if (options.verbosity >= 3)
                std::cerr << "INFIX\tbegin:" << infixBegin << "\tend:" << infixEnd << "\n";

            if (options.reverseComplement)
            {
                seqan::Dna5String seqCopy = seq;
                reverseComplement(seqCopy);
                reverse(quals);
                infixEnd = length(seq) - infixEnd;
                infixBegin = length(seq) - infixBegin;
                std::swap(infixEnd, infixBegin);

                writeRecord(outFile, id, infix(seqCopy, infixBegin, infixEnd), infix(quals, infixBegin, infixEnd));
            }
            else
                writeRecord(outFile, id, infix(seq, infixBegin, infixEnd), infix(quals, infixBegin, infixEnd));
        }

        // Advance counter idx.
        idx += 1;
    }

    if (options.verbosity >= 2)
        std::cerr << "Took " << (seqan::sysTime() - startTime) << " s\n";

    return 0;
}
Beispiel #19
0
bool TSReader::read(Translator &translator)
{
    STRING(both);
    STRING(byte);
    STRING(comment);
    STRING(context);
    STRING(defaultcodec);
    STRING(encoding);
    STRING(extracomment);
    STRING(filename);
    STRING(id);
    STRING(language);
    STRING(line);
    STRING(location);
    STRING(message);
    STRING(name);
    STRING(numerus);
    STRING(numerusform);
    STRING(obsolete);
    STRING(oldcomment);
    STRING(oldsource);
    STRING(source);
    STRING(sourcelanguage);
    STRING(translation);
    STRING(translatorcomment);
    STRING(true);
    STRING(TS);
    STRING(type);
    STRING(unfinished);
    STRING(userdata);
    STRING(utf8);
    STRING(value);
    //STRING(version);
    STRING(yes);

    static const QString strextrans(QLatin1String("extra-"));
    static const QString strUtf8(QLatin1String("UTF-8"));

    while (!atEnd()) {
        readNext();
        if (isStartDocument()) {
            // <!DOCTYPE TS>
            //qDebug() << attributes();
        } else if (isEndDocument()) {
            // <!DOCTYPE TS>
            //qDebug() << attributes();
        } else if (isDTD()) {
            // <!DOCTYPE TS>
            //qDebug() << tokenString();
        } else if (elementStarts(strTS)) {
            // <TS>
            //qDebug() << "TS " << attributes();
            QHash<QString, int> currentLine;
            QString currentFile;

            QXmlStreamAttributes atts = attributes();
            //QString version = atts.value(strversion).toString();
            translator.setLanguageCode(atts.value(strlanguage).toString());
            translator.setSourceLanguageCode(atts.value(strsourcelanguage).toString());
            while (!atEnd()) {
                readNext();
                if (isEndElement()) {
                    // </TS> found, finish local loop
                    break;
                } else if (isWhiteSpace()) {
                    // ignore these, just whitespace
                } else if (elementStarts(strdefaultcodec)) {
                    // <defaultcodec>
                    const QString &codec = readElementText();
                    if (!codec.isEmpty())
                        translator.setCodecName(codec.toLatin1());
                    // </defaultcodec>
                } else if (isStartElement()
                        && name().toString().startsWith(strextrans)) {
                    // <extra-...>
                    QString tag = name().toString();
                    translator.setExtra(tag.mid(6), readContents());
                    // </extra-...>
                } else if (elementStarts(strcontext)) {
                    // <context>
                    QString context;
                    while (!atEnd()) {
                        readNext();
                        if (isEndElement()) {
                            // </context> found, finish local loop
                            break;
                        } else if (isWhiteSpace()) {
                            // ignore these, just whitespace
                        } else if (elementStarts(strname)) {
                            // <name>
                            context = readElementText();
                            // </name>
                        } else if (elementStarts(strmessage)) {
                            // <message>
                            TranslatorMessage::References refs;
                            QString currentMsgFile = currentFile;

                            TranslatorMessage msg;
                            msg.setId(attributes().value(strid).toString());
                            msg.setContext(context);
                            msg.setType(TranslatorMessage::Finished);
                            msg.setPlural(attributes().value(strnumerus) == stryes);
                            const QStringRef &utf8Attr = attributes().value(strutf8);
                            msg.setNonUtf8(utf8Attr == strboth);
                            msg.setUtf8(msg.isNonUtf8() || utf8Attr == strtrue
                                 ||  attributes().value(strencoding) == strUtf8);
                            while (!atEnd()) {
                                readNext();
                                if (isEndElement()) {
                                    // </message> found, finish local loop
                                    msg.setReferences(refs);
                                    translator.append(msg);
                                    break;
                                } else if (isWhiteSpace()) {
                                    // ignore these, just whitespace
                                } else if (elementStarts(strsource)) {
                                    // <source>...</source>
                                    msg.setSourceText(readContents());
                                } else if (elementStarts(stroldsource)) {
                                    // <oldsource>...</oldsource>
                                    msg.setOldSourceText(readContents());
                                } else if (elementStarts(stroldcomment)) {
                                    // <oldcomment>...</oldcomment>
                                    msg.setOldComment(readContents());
                                } else if (elementStarts(strextracomment)) {
                                    // <extracomment>...</extracomment>
                                    msg.setExtraComment(readContents());
                                } else if (elementStarts(strtranslatorcomment)) {
                                    // <translatorcomment>...</translatorcomment>
                                    msg.setTranslatorComment(readContents());
                                } else if (elementStarts(strlocation)) {
                                    // <location/>
                                    QXmlStreamAttributes atts = attributes();
                                    QString fileName = atts.value(strfilename).toString();
                                    if (fileName.isEmpty()) {
                                        fileName = currentMsgFile;
                                    } else {
                                        if (refs.isEmpty())
                                            currentFile = fileName;
                                        currentMsgFile = fileName;
                                    }
                                    const QString lin = atts.value(strline).toString();
                                    if (lin.isEmpty()) {
                                        translator.setLocationsType(Translator::RelativeLocations);
                                        refs.append(TranslatorMessage::Reference(fileName, -1));
                                    } else {
                                        bool bOK;
                                        int lineNo = lin.toInt(&bOK);
                                        if (bOK) {
                                            if (lin.startsWith(QLatin1Char('+')) || lin.startsWith(QLatin1Char('-'))) {
                                                lineNo = (currentLine[fileName] += lineNo);
                                                translator.setLocationsType(Translator::RelativeLocations);
                                            } else {
                                                translator.setLocationsType(Translator::AbsoluteLocations);
                                            }
                                            refs.append(TranslatorMessage::Reference(fileName, lineNo));
                                        }
                                    }
                                    readContents();
                                } else if (elementStarts(strcomment)) {
                                    // <comment>...</comment>
                                    msg.setComment(readContents());
                                } else if (elementStarts(struserdata)) {
                                    // <userdata>...</userdata>
                                    msg.setUserData(readContents());
                                } else if (elementStarts(strtranslation)) {
                                    // <translation>
                                    QXmlStreamAttributes atts = attributes();
                                    QStringRef type = atts.value(strtype);
                                    if (type == strunfinished)
                                        msg.setType(TranslatorMessage::Unfinished);
                                    else if (type == strobsolete)
                                        msg.setType(TranslatorMessage::Obsolete);
                                    if (msg.isPlural()) {
                                        QStringList translations;
                                        while (!atEnd()) {
                                            readNext();
                                            if (isEndElement()) {
                                                break;
                                            } else if (isWhiteSpace()) {
                                                // ignore these, just whitespace
                                            } else if (elementStarts(strnumerusform)) {
                                                translations.append(readTransContents());
                                            } else {
                                                handleError();
                                                break;
                                            }
                                        }
                                        msg.setTranslations(translations);
                                    } else {
                                        msg.setTranslation(readTransContents());
                                    }
                                    // </translation>
                                } else if (isStartElement()
                                        && name().toString().startsWith(strextrans)) {
                                    // <extra-...>
                                    QString tag = name().toString();
                                    msg.setExtra(tag.mid(6), readContents());
                                    // </extra-...>
                                } else {
                                    handleError();
                                }
                            }
                            // </message>
                        } else {
                            handleError();
                        }
                    }
                    // </context>
                } else {
                    handleError();
                }
            } // </TS>
        } else {
            handleError();
        }
    }
    if (hasError()) {
        m_cd.appendError(errorString());
        return false;
    }
    return true;
}
Beispiel #20
0
bool ZipplXmlReader::read( QIODevice *dev )
{
  setDevice( dev );
  bool res = true;
  bool metaMode = false;
  mCurrParent = 0;
  mCurrSpot = 0;

  QGraphicsScene *scene = mGraphWidget->scene();
  int spotID = 0;

  while (!atEnd()) {
    readNext();

    if( isStartElement() ) {
      qDebug() << "XML name: " << name();

      if( name() == "presentation") {
        // presentation mode: debug & presentation
        QString mode = attributes().value("mode").toString();
        if( !mode.isEmpty() ) mMode = mode;

        mPath = attributes().value("path").toString();
        if( !mPath.endsWith('/') ) mPath += "/";


        qreal dx = qrealAttrib("width") / -2.0;
        qreal dy = qrealAttrib("height") / -2.0;
        QRectF rect( dx, dy, -2.0*dx, -2.0*dy );
        scene->setSceneRect( rect );
      } else if( name() == "meta" ) {
        metaMode = true;
      } else if( name() == "title" && metaMode ) {
        mPresentationTitle = readElementText();
      } else if( name() == "description" && metaMode ) {
        mPresentationDescr = readElementText();
      } else if( name() == "date" && metaMode ) {
        mPresentationDate = readElementText();
      } else if( name() == "name" && metaMode ) {
        mAuthorName = readElementText();
      } else if( name() == "email" && metaMode ) {
        mAuthorEmail = readElementText();
      } else if( name() == "tocentry" ) {
        if( mCurrSpot ) {
          mCurrSpot->setData( TOCENTRY, readElementText() );
        }
      } else if( name() == "spot" ) {
        if( mCurrParent != 0 ) {
          qDebug() << "Strange: Current Parent should be zero here!";
        }
        QGraphicsRectItem *rectItem = new QGraphicsRectItem( );

        rectItem->setPen( pen( rectItem->pen(), QColor("#aeaeae") ));

        mCurrParent = rectItem;
        mCurrSpot = rectItem;
        mCurrParent->setData( ID, QVariant( spotID++ ));

        mCurrParent->setPos( position() );

        rectItem->setBrush( brush( rectItem->brush() ) );

        scene->addItem( mCurrParent );
        mSpots.append( mCurrParent );

        // Prepare the hidden items list
        GraphicsItemList list;
        mHiddenItems.insert( mCurrParent, list );

      } else if( name() == "hidden" ) {
        QGraphicsRectItem *rectItem = new QGraphicsRectItem( mCurrParent, scene );
        rectItem->setPen( QPen( QColor( 240, 240, 240 )));

        // append this hidden item to the list of hiddens of the parent spot.
        GraphicsItemList list = mHiddenItems[mCurrSpot];
        list.append( rectItem );
        mHiddenItems[mCurrSpot] = list;

        mCurrParent = rectItem;
        mCurrParent->setData( ID, QVariant( spotID++ ));

      } else if( name() == "rect" ) {
        if( mCurrParent ) { // within a spot
          qDebug() << "Creating a rectangle!";
          QGraphicsRectItem *rectItem = new QGraphicsRectItem( mCurrParent, scene );

          qreal width = qrealAttrib( "width" );
          qreal height = qrealAttrib( "height" );

          QPointF pos = position();
          if( width > 0 && height > 0 ) {
            rectItem->setRect( pos.x(), pos.y(), width, height );
          } else {
            rectItem->setPos( pos );
          }
          rectItem->setPen( pen( rectItem->pen() ) );

          mCurrParent = rectItem;
        }
      } else if( name() == "circle" ) {
        QPointF pos = position();
        QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem( mCurrParent, scene );
        // ellipse->setBrush( getBrush() );
        qreal r = 2.0 * qrealAttrib( "r" );

        QRectF rect( pos, QSizeF( r, r ) );

        ellipse->setPen( pen( ellipse->pen() ) );

        ellipse->setRect( rect );


      } else if( name() == "text" ) {
        QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem( mCurrParent, scene );

        QString font = attributes().value("font").toString();
        QString size = attributes().value("size").toString();


        QFont currFont = textItem->font();
        if( !font.isEmpty() ) {
          currFont.setFamily( font );
          textItem->setFont( currFont );
        }
        if( !size.isEmpty() ) {
          currFont.setPointSize( size.toInt() );
          textItem->setFont( currFont );
        }

        textItem->setPos( position() );

        // set the brush
        QBrush b( textItem->brush() );
        b.setColor( color() );

        textItem->setBrush( b );

        QString text = readElementText();
        textItem->setText( text );

      } else if( name() == "image" ) {
        if( handleImg( scene ) ) {

        }
      }
    } else if( isEndElement() ) {
      qDebug( ) << "XML CLOSE: " << name().toString();
      if( name() == "spot" || name() == "toc" ) {
        QRectF rect = mCurrParent->childrenBoundingRect();
        rect.setX(0);
        rect.setY(0);
        qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent)->setRect( rect);
        mCurrParent = 0;
      } else if( name() == "rect" ) {
        QGraphicsRectItem *item = qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent);

        if( item->rect().isEmpty() )
          item->setRect( mCurrParent->childrenBoundingRect() );
        mCurrParent = mCurrParent->parentItem();
      } else if( name() == "hidden") {
        mCurrParent->setOpacity( 0.0 );
        mCurrParent = mCurrParent->parentItem();
      } else if( name() == "meta" ) {
        metaMode = false;
      }
    }
  }

  createToc( scene );

  return res;
}
Beispiel #21
0
void XMLimport::readTriggerGroup( TTrigger * pParent )
{
    TTrigger * pT;
    if( pParent )
    {
        pT = new TTrigger( pParent, mpHost );
    }
    else
    {
        pT = new TTrigger( 0, mpHost );
    }
    if (module){
        pT->mModuleMember = true;
    }

    mpHost->getTriggerUnit()->registerTrigger( pT );

    pT->setIsActive( (attributes().value("isActive") == "yes" ) );
    pT->mIsFolder = ( attributes().value("isFolder") == "yes" );
    pT->mIsTempTrigger = ( attributes().value("isTempTrigger") == "yes" );
    pT->mIsMultiline = ( attributes().value("isMultiline") == "yes" );
    pT->mPerlSlashGOption = ( attributes().value("isPerlSlashGOption") == "yes" );
    pT->mIsColorizerTrigger = ( attributes().value("isColorizerTrigger") == "yes" );
    pT->mFilterTrigger = ( attributes().value("isFilterTrigger") == "yes" );
    pT->mSoundTrigger = ( attributes().value("isSoundTrigger") == "yes" );
    pT->mColorTrigger = ( attributes().value("isColorTrigger") == "yes" );
    pT->mColorTriggerBg = ( attributes().value("isColorTriggerBg") == "yes" );
    pT->mColorTriggerFg = ( attributes().value("isColorTriggerFg") == "yes" );

    while( ! atEnd() )
    {
        readNext();
        //qDebug()<<"[INFO] element:"<<name().toString()<<" text:"<<text().toString();
        if( isEndElement() ) break;

        if( isStartElement() )
        {
            if( name() == "name" )
            {

                pT->setName( readElementText() );
                continue;
            }

            else if( name() == "script")
            {
                pT->mScript = readElementText();
                continue;
            }
            else if( name() == "packageName")
            {
                pT->mPackageName = readElementText();
                continue;
            }
            else if( name() == "triggerType" )
            {
                pT->mTriggerType = readElementText().toInt();
                continue;
            }
            else if( name() == "conditonLineDelta" )
            {
                pT->mConditionLineDelta = readElementText().toInt();
                continue;
            }
            else if( name() == "mStayOpen" )
            {
                pT->mStayOpen = readElementText().toInt();
                continue;
            }
            else if( name() == "mCommand" )
            {
                pT->mCommand = readElementText();
                continue;
            }

            else if( name() == "mFgColor")
            {
                pT->mFgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mBgColor")
            {
                pT->mBgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "colorTriggerFgColor")
            {
                pT->mColorTriggerFgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "colorTriggerBgColor")
            {
                pT->mColorTriggerBgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mSoundFile" )
            {
                pT->mSoundFile = readElementText();
                continue;
            }
            else if( name() == "regexCodeList")
            {
                readStringList( pT->mRegexCodeList );
                continue;
            }
            else if( name() == "regexCodePropertyList" )
            {
                readIntegerList( pT->mRegexCodePropertyList );
                continue;
            }

            else if( name() == "TriggerGroup" )
            {
                readTriggerGroup( pT );
            }
            else if( name() == "Trigger" )
            {
                readTriggerGroup( pT );
            }
            else
            {
                readUnknownTriggerElement();
            }
        }
    }

    if( ! pT->setRegexCodeList( pT->mRegexCodeList, pT->mRegexCodePropertyList ) )
    {
        qDebug()<<"IMPORT: ERROR: cant initialize pattern list for trigger "<<pT->getName();
    }
    QString script = pT->mScript;
    if( ! pT->setScript( script ) )
    {
        qDebug()<<"IMPORT: ERROR: trigger script "<< pT->getName()<<" does not compile";
    }
}
Beispiel #22
0
 UCharDirection direction() const { return atEnd() ? U_OTHER_NEUTRAL : u_charDirection(current()); }
Beispiel #23
0
void XMLimport::readAliasGroup( TAlias * pParent )
{
    TAlias * pT;
    if( pParent )
    {
        pT = new TAlias( pParent, mpHost );
    }
    else
    {
        pT = new TAlias( 0, mpHost );
    }

    mpHost->getAliasUnit()->registerAlias( pT );
    pT->setIsActive( ( attributes().value("isActive") == "yes" ) );
    pT->mIsFolder = ( attributes().value("isFolder") == "yes" );
    if (module)
        pT->mModuleMember = true;

    while( ! atEnd() )
    {
        readNext();
        if( isEndElement() ) break;

        if( isStartElement() )
        {
            if( name() == "name" )
            {
                pT->setName( readElementText() );
                continue;
            }
            else if( name() == "packageName")
            {
                pT->mPackageName = readElementText();
                continue;
            }
            else if( name() == "script")
            {
                QString script = readElementText();
                pT->setScript( script );
                continue;
            }
            else if( name() == "command")
            {
                pT->mCommand = readElementText();
                continue;
            }
            else if( name() == "regex")
            {
                pT->setRegexCode( readElementText() );
                continue;
            }
            else if( name() == "AliasGroup" )
            {
                readAliasGroup( pT );
            }
            else if( name() == "Alias" )
            {
                readAliasGroup( pT );
            }
            else
            {
                readUnknownAliasElement();
            }
        }
    }


}
Beispiel #24
0
SExpression * Reader::read()
{
    SExpression * ret = nil_symbol;
    
    ReaderChar val = eatWhitespace();

    if (atEnd())
    {
        return ret;
    }
    
    if (macroHint(val.chr))
    {
        uint32_t val2 = peek().chr;
        uint64_t key2 = ((uint64_t)val.chr << 32) | val2;
        uint64_t key1 = ((uint64_t)val.chr << 32) | INVALID_CHAR;
        if (macros[key2])
        {
            getChar(false);
            return macros[key2]->run(new List);
        }
        else if (macros[key1])
        {
            return macros[key1]->run(new List);
        }
        else
        {
            printf("Couldn't find macro for [%c][%c]!\n", val.chr, val2);
        }
    }
    
    if (tokenType(val.chr) == TOKEN_QUOTE)
    {
        String * str = new String;
        ret = str;
        ret->begin_line = line;
        ret->begin_column = column;
        do
        {
            uint32_t val = getChar().chr;
            if (atEnd())
            {
                printf("Got EOF in middle of string, %d\n", val);
            }
            if (tokenType(val) == TOKEN_QUOTE)
            {
                break;
            }
            str->append(val);
        } while (!atEnd());
        ret->end_line = line;
        ret->end_column = column;
    }
    else if ( (tokenType(val.chr) == TOKEN_NUMERIC) ||
              (tokenType(val.chr) == TOKEN_MINUS
               && tokenType(peek().chr) == TOKEN_NUMERIC) )
    {
        bool is_minus = false;
        bool is_hex = false;

        int save_line = line;
        int save_column = column;
        
        if (tokenType(val.chr) == TOKEN_MINUS)
        {
            is_minus = true;
            val = getChar();
        }
        if (val.chr == '0' && peek().chr == 'x')
        {
            is_hex = true;
            getChar();
        }
        int64_t count_val = val.chr - '0';
        do
        {
            val = getChar();
            
            if (val.chr < '0' || val.chr > '9')
            {
                if (is_hex && (val.chr >= 'a' && val.chr <= 'f'))
                {
                }
                else
                {
                    ret = new Number(is_minus ? -count_val : count_val);
                    ret->begin_line = save_line;
                    ret->begin_column = save_column;
                    ret->end_line = line;
                    ret->end_column = column;
                    reject(val);
                    break;
                }
            }

            if (is_hex)
            {
                if (val.chr >= 'a' && val.chr <= 'f')
                {
                    val.chr -= ('a' - 10);
                }
                else
                {
                    val.chr -= '0';
                }
                count_val *= 16;
                count_val += val.chr;
            }
            else
            {
                val.chr -= '0';
                count_val *= 10;
                count_val += val.chr;
            }

            if (atEnd())
            {
                ret = new Number(is_minus ? -count_val : count_val);
                ret->begin_line = save_line;
                ret->begin_column = save_column;
                ret->end_line = line;
                ret->end_column = column;
            }
        } while (!atEnd());
    } else if (tokenType(val.chr) == TOKEN_ALPHA) {
        String * str = new String;
        str->append(val.chr);
        Symbol * sym = new Symbol(str);
        ret = sym;
        ret->begin_line = line;
        ret->begin_column = column;
        do
        {
            ReaderChar val = getChar();
            if (atEnd() || (tokenType(val.chr) != TOKEN_ALPHA
                            && tokenType(val.chr) != TOKEN_MINUS &&
                            tokenType(val.chr) != TOKEN_NUMERIC))
            {
                reject(val);
                break;
            }
            str->append(val.chr);
        } while (!atEnd());
        ret->end_line = line;
        ret->end_column = column;
    } else if (tokenType(val.chr) == TOKEN_OPEN_BRACE) {
        List * list = new List;
        ret = list;
        ret->begin_line = line;
        ret->begin_column = column;
        do
        {
            ReaderChar next = eatWhitespace();
            
            if (atEnd())
            {
                printf("Got EOF in middle of list, %d\n", next.chr);
                break;
            }
            if (tokenType(next.chr) == TOKEN_CLOSE_BRACE)
            {
                break;
            }

            reject(next);
            SExpression * sep = read();
            list->contents.push_back(sep);
            
        } while(!atEnd());
        ret->end_line = line;
        ret->end_column = column;
    } else if (tokenType(val.chr) == TOKEN_COMMENT) {
        do {
            val = getChar();
        } while (tokenType(val.chr) != TOKEN_NEWLINE && !atEnd());
    } else {
        printf("Didn't expect %d %d!\n", val.chr, tokenType(val.chr));
    }
    
    return ret;
}
Beispiel #25
0
void XMLimport::readScriptGroup( TScript * pParent )
{
    TScript * pT;
    if( pParent )
    {
        pT = new TScript( pParent, mpHost );
    }
    else
    {
        pT = new TScript( 0, mpHost );
    }
    mpHost->getScriptUnit()->registerScript( pT );
    pT->setIsActive( ( attributes().value("isActive") == "yes" ) );
    pT->mIsFolder = ( attributes().value("isFolder") == "yes" );
    if (module)
        pT->mModuleMember = true;

    while( ! atEnd() )
    {
        readNext();
        if( isEndElement() ) break;

        if( isStartElement() )
        {
            if( name() == "name" )
            {
                pT->mName = readElementText();
                continue;
            }
            else if( name() == "packageName")
            {
                pT->mPackageName = readElementText();
                continue;
            }
            else if( name() == "script")
            {
                QString script = readElementText();
                pT->setScript( script );
                continue;
            }
            else if( name() == "eventHandlerList")
            {
                readStringList( pT->mEventHandlerList );
                pT->setEventHandlerList( pT->mEventHandlerList );
                continue;
            }
            else if( name() == "ScriptGroup" )
            {
                readScriptGroup( pT );
            }
            else if( name() == "Script" )
            {
                readScriptGroup( pT );
            }
            else
            {
                readUnknownScriptElement();
            }
        }
    }
}
Beispiel #26
0
void ProjectReader::readProject()
{
  Q_ASSERT(isStartElement() && name() == "project");
  project = new Project();
  bool dirExists;

  //message("readProject");

  QDir::setCurrent(fileinfo.absolutePath());

  // Since we need to load our bitmaps first, we just read in all of the filenames
  // and then load the actual resources last.  That way, if <tilesets> isn't the
  // first section, there won't be any errors.

  while (!atEnd()) {
    readNext();

    if (isEndElement())
      break;

    if (isStartElement()) {
      if (name() == "name")
      {
        project->SetName(readElementText());
        //message("Map name: " + map->GetName());
      }
      else if (name() == "maps")
      {
        readMaps();
      }
      else if (name() == "tilesets")
      {
        readTilesets();
      }
      else if (name() == "sprites")
      {
        readSprites();
      }
      else if (name() == "scripts")
      {
        readScripts();
      }
      else
      {
        readUnknownElement();
      }
    }
  }

  // Load bitmaps
  dirExists = QDir::setCurrent("tilesets");
  BitmapReader bitmapReader;
  while(!tilesetlist.isEmpty()) {
    QString b = tilesetlist.takeFirst();
    // load bitmap
    bitmapReader.read(b);
  }
  if(dirExists) QDir::setCurrent("..");

  // load sprites
  dirExists = QDir::setCurrent("sprites");
  SpriteReader spriteReader;
  while(!spritelist.isEmpty()) {
    QString s = spritelist.takeFirst();
    // load sprite
    spriteReader.read(s);
  }
  if(dirExists) QDir::setCurrent("..");

  // load maps
  dirExists = QDir::setCurrent("maps");
  MapReader mapReader;
  while(!maplist.isEmpty()) {
    QString m = maplist.takeFirst();
    // load map
    mapReader.read(m);
  }
  if(dirExists) QDir::setCurrent("..");

}
Beispiel #27
0
void XMLimport::readRoom()
{
    TRoom * pT = new TRoom;
    pT->id = attributes().value("id").toString().toInt();
    pT->area = attributes().value("area").toString().toInt();
    pT->name = attributes().value("title").toString();
    pT->environment = attributes().value("environment").toString().toInt();

    while( ! atEnd() )
    {
        readNext();

        if( name() == "" ) continue;
        if( name() == "coord" )
        {
            if( attributes().value("x").toString() == "" ) continue;
            pT->x = attributes().value("x").toString().toInt();
            pT->y = attributes().value("y").toString().toInt();
            pT->z = attributes().value("z").toString().toInt();
            continue;
        }
        else if( name() == "exit")
        {
            QString dir = attributes().value("direction").toString();
            int e = attributes().value("target").toString().toInt();
            if( dir == "" ) continue;
            if( dir == "north" )
            {
                pT->north = e;
            }
            if( dir == "south" )
            {
                pT->south = e;
            }
            if( dir == "northwest" )
            {
                pT->northwest = e;
            }
            if( dir == "southwest" )
            {
                pT->southwest = e;
            }
            if( dir == "northeast" )
            {
                pT->northeast = e;
            }
            if( dir == "southeast" )
            {
                pT->southeast = e;
            }
            if( dir == "west" )
            {
                pT->west = e;
            }
            if( dir == "east" )
            {
                pT->east = e;
            }
            if( dir == "up" )
            {
                pT->up = e;
            }
            if( dir == "down" )
            {
                pT->down = e;
            }
            if( dir == "in" )
            {
                pT->in = e;
            }
            if( dir == "out" )
            {
                pT->out = e;
            }
            continue;
        }
        if( isEndElement() )
        {
            break;
        }
    }
    if( pT->id != 0 )
    {
        mpHost->mpMap->rooms[pT->id] = pT;
        maxRooms++;
    }
    else
        delete pT;
}
Beispiel #28
0
void PdmlReader::readPacket()
{
    PcapFileFormat::PcapPacketHeader pktHdr;

    Q_ASSERT(isStartElement() && name() == "packet");

    qDebug("%s: packetNum = %d", __FUNCTION__, packetCount_);

    skipUntilEnd_ = false;

    // XXX: we play dumb and convert each packet to a stream, for now
    prevStream_ = currentStream_;
    currentStream_ = streams_->add_stream();
    currentStream_->mutable_stream_id()->set_id(packetCount_);
    currentStream_->mutable_core()->set_is_enabled(true);

    // Set to a high number; will get reset to correct value during parse
    currentStream_->mutable_core()->set_frame_len(16384); // FIXME: Hard coding!

    expPos_ = 0;

    if (pcap_)
        pcap_->readPacket(pktHdr, pktBuf_);

    while (!atEnd())
    {
        readNext();

        if (isEndElement())
            break;

        if (isStartElement())
        {
            if (skipUntilEnd_)
                skipElement();
            else if (name() == "proto")
                readProto();
            else if (name() == "field")
                readField(NULL, NULL); // TODO: top level field!!!!
            else 
                skipElement();
        }
    }

    currentStream_->mutable_core()->set_name(""); // FIXME

    // If trailing bytes are missing, add those from the pcap 
    if ((expPos_ < pktBuf_.size()) && pcap_)
    {
        OstProto::Protocol *proto = currentStream_->add_protocol();
        OstProto::HexDump *hexDump = proto->MutableExtension(
                OstProto::hexDump);

        proto->mutable_protocol_id()->set_id(
                OstProto::Protocol::kHexDumpFieldNumber);

        qDebug("adding trailing %d bytes starting from %d",
               pktBuf_.size() - expPos_, expPos_); 
        hexDump->set_content(pktBuf_.constData() + expPos_, 
                pktBuf_.size() - expPos_);
        hexDump->set_pad_until_end(false);
    } 

    packetCount_++;
    emit progress(int(characterOffset()*100/device()->size())); // in % 
    if (prevStream_)
        prevStream_->mutable_control()->CopyFrom(currentStream_->control());
    if (stop_ && *stop_)
        raiseError("USER-CANCEL");
}
Beispiel #29
0
void XMLimport::readHostPackage( Host * pT )
{
    pT->mAutoClearCommandLineAfterSend = ( attributes().value("autoClearCommandLineAfterSend") == "yes" );
    pT->mDisableAutoCompletion = ( attributes().value("disableAutoCompletion") == "yes" );
    pT->mPrintCommand = ( attributes().value("printCommand") == "yes" );
    pT->set_USE_IRE_DRIVER_BUGFIX( attributes().value("USE_IRE_DRIVER_BUGFIX") == "yes" );
    pT->mUSE_FORCE_LF_AFTER_PROMPT = ( attributes().value("mUSE_FORCE_LF_AFTER_PROMPT") == "yes" );
    pT->mUSE_UNIX_EOL = ( attributes().value("mUSE_UNIX_EOL") == "yes" );
    pT->mNoAntiAlias = ( attributes().value("mNoAntiAlias") == "yes" );
    pT->mRawStreamDump = ( attributes().value("mRawStreamDump") == "yes" );
    pT->mAlertOnNewData = ( attributes().value("mAlertOnNewData") == "yes" );
    pT->mFORCE_NO_COMPRESSION = ( attributes().value("mFORCE_NO_COMPRESSION") == "yes" );
    pT->mFORCE_GA_OFF = ( attributes().value("mFORCE_GA_OFF") == "yes" );
    pT->mFORCE_SAVE_ON_EXIT = ( attributes().value("mFORCE_SAVE_ON_EXIT") == "yes" );
    pT->mEnableGMCP = ( attributes().value("mEnableGMCP") == "yes" );
    pT->mMapStrongHighlight = ( attributes().value("mMapStrongHighlight") == "yes" );
    pT->mLogStatus = ( attributes().value("mLogStatus") == "yes" );
    pT->mEnableSpellCheck = ( attributes().value("mEnableSpellCheck") == "yes" );
    pT->mShowInfo = ( attributes().value("mShowInfo") == "yes" );
    pT->mAcceptServerGUI = ( attributes().value("mAcceptServerGUI") == "yes" );
    pT->mMapperUseAntiAlias = ( attributes().value("mMapperUseAntiAlias") == "yes" );
    pT->mFORCE_MXP_NEGOTIATION_OFF = ( attributes().value("mFORCE_MXP_NEGOTIATION_OFF") == "yes" );

    while( ! atEnd() )
    {
        readNext();
        if( isEndElement() ) break;

        if( isStartElement() )
        {
            if( name() == "name" )
            {
                pT->mHostName = readElementText();
                continue;
            }
            else if( name() == "mInstalledModules")
            {
                QMap<QString, QStringList> entry;
                readMapList(entry);
                QMapIterator<QString, QStringList> it(entry);
                while (it.hasNext()){
                    it.next();
                    QStringList moduleList;
                    QStringList entryList = it.value();
                    moduleList << entryList[0];
                    moduleList << entryList[1];
                    pT->mInstalledModules[it.key()] = moduleList;
                    pT->mModulePriorities[it.key()] = entryList[2].toInt();

                }
                //readMapList( pT->mInstalledModules );
                continue;
            }
            else if( name() == "mInstalledPackages")
            {
                readStringList( pT->mInstalledPackages );
                continue;
            }
            else if( name() =="url" )
            {
                pT->mUrl = readElementText();
                continue;
            }
            else if( name() =="serverPackageName" )
            {
                pT->mServerGUI_Package_name = readElementText();
                continue;
            }
            else if( name() == "serverPackageVersion")
            {
                pT->mServerGUI_Package_version = readElementText().toInt();
                continue;
            }
            else if( name() == "port")
            {
                pT->mPort = readElementText().toInt();
                continue;
            }
            else if( name() == "borderTopHeight")
            {
                pT->mBorderTopHeight = readElementText().toInt();
                continue;
            }
            else if( name() == "commandLineMinimumHeight")
            {
                pT->commandLineMinimumHeight = readElementText().toInt();
                continue;
            }
            else if( name() == "borderBottomHeight")
            {
                pT->mBorderBottomHeight = readElementText().toInt();
                continue;
            }
            else if( name() == "borderLeftWidth")
            {
                pT->mBorderLeftWidth = readElementText().toInt();
                continue;
            }
            else if( name() == "borderRightWidth")
            {
                pT->mBorderRightWidth = readElementText().toInt();
                continue;
            }
            else if( name() == "wrapAt")
            {
                pT->mWrapAt = readElementText().toInt();
                continue;
            }
            else if( name() == "wrapIndentCount" )
            {
                pT->mWrapIndentCount = readElementText().toInt();
                continue;
            }
            else if( name() == "mCommandSeparator" )
            {
                pT->mCommandSeparator = readElementText();
                continue;
            }
            else if( name() == "mCommandLineFgColor")
            {
                pT->mCommandLineFgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mCommandLineBgColor")
            {
                pT->mCommandLineBgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mFgColor")
            {
                pT->mFgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mBgColor")
            {
                pT->mBgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mCommandFgColor")
            {
                pT->mCommandFgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mCommandBgColor")
            {
                pT->mCommandBgColor.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mBlack")
            {
                pT->mBlack.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightBlack")
            {
                pT->mLightBlack.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mRed")
            {
                pT->mRed.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightRed")
            {
                pT->mLightRed.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mBlue")
            {
                pT->mBlue.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightBlue")
            {
                pT->mLightBlue.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mGreen")
            {
                pT->mGreen.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightGreen")
            {
                pT->mLightGreen.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mYellow")
            {
                pT->mYellow.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightYellow")
            {
                pT->mLightYellow.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mCyan")
            {
                pT->mCyan.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightCyan")
            {
                pT->mLightCyan.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mMagenta")
            {
                pT->mMagenta.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightMagenta")
            {
                pT->mLightMagenta.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mWhite")
            {
                pT->mWhite.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightWhite")
            {
                pT->mLightWhite.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mDisplayFont")
            {
                pT->mDisplayFont.fromString( readElementText() );
                pT->mDisplayFont.setFixedPitch( true );
//                pT->mDisplayFont.setWordSpacing( 0 );
//                pT->mDisplayFont.setLetterSpacing( QFont::AbsoluteSpacing, 0 );
                continue;
            }
            else if( name() == "mCommandLineFont")
            {
                pT->mCommandLineFont.fromString( readElementText() );
                continue;
            }
            else if( name() == "mFgColor2")
            {
                pT->mFgColor_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mBgColor2")
            {
                pT->mBgColor_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mBlack2")
            {
                pT->mBlack_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightBlack2")
            {
                pT->mLightBlack_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mRed2")
            {
                pT->mRed_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightRed2")
            {
                pT->mLightRed_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mBlue2")
            {
                pT->mBlue_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightBlue2")
            {
                pT->mLightBlue_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mGreen2")
            {
                pT->mGreen_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightGreen2")
            {
                pT->mLightGreen_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mYellow2")
            {
                pT->mYellow_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightYellow2")
            {
                pT->mLightYellow_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mCyan2")
            {
                pT->mCyan_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightCyan2")
            {
                pT->mLightCyan_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mMagenta2")
            {
                pT->mMagenta_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightMagenta2")
            {
                pT->mLightMagenta_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mWhite2")
            {
                pT->mWhite_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mLightWhite2")
            {
                pT->mLightWhite_2.setNamedColor( readElementText() );
                continue;
            }
            else if( name() == "mSpellDic")
            {
                pT->mSpellDic = readElementText();
                continue;
            }
            else if( name() == "mRoomSize" )
            {
                pT->mRoomSize = readElementText().toDouble();
            }
            else if( name() == "mLineSize" )
            {
                pT->mLineSize = readElementText().toDouble();
            }
            else
            {
                readUnknownHostElement();
            }
        }
    }
}
Beispiel #30
0
void PdmlReader::readProto()
{
    PdmlProtocol *pdmlProto = NULL;
    OstProto::Protocol *pbProto = NULL;

    Q_ASSERT(isStartElement() && name() == "proto");

    QString protoName;
    int pos = -1;
    int size = -1;

    if (!attributes().value("name").isEmpty())
        protoName = attributes().value("name").toString();
    if (!attributes().value("pos").isEmpty())
        pos = attributes().value("pos").toString().toInt();
    if (!attributes().value("size").isEmpty())
        size = attributes().value("size").toString().toInt();

    qDebug("proto: %s, pos = %d, expPos_ = %d, size = %d", 
            protoName.toAscii().constData(), pos, expPos_, size);

    // This is a heuristic to skip protocols which are not part of
    // this frame, but of a reassembled segment spanning several frames
    //   1. Proto starting pos is 0, but we've already seen some protocols
    //   2. Protocol Size exceeds frame length
    if (((pos == 0) && (currentStream_->protocol_size() > 0))
        || ((pos + size) > int(currentStream_->core().frame_len())))
    {
        skipElement();
        return;
    }

    if (isDontCareProto())
    {
        skipElement();
        return;
    }

    // if we detect a gap between subsequent protocols, we "fill-in"
    // with a "hexdump" from the pcap
    if (pos > expPos_ && pcap_)
    {
        appendHexDumpProto(expPos_, pos - expPos_);
        expPos_ = pos;
    }

    // for unknown protocol, read a hexdump from the pcap
    if (!factory_.contains(protoName) && pcap_)
    {
        int size = -1;

        if (!attributes().value("size").isEmpty())
            size = attributes().value("size").toString().toInt();

        // Check if this proto is a subset of previous proto - if so, do nothing
        if ((pos >= 0) && (size > 0) && ((pos + size) <= expPos_))
        {
            qDebug("subset proto");
            skipElement();
            return;
        }

        if (pos >= 0 && size > 0 
                && ((pos + size) <= pktBuf_.size()))
        {
            appendHexDumpProto(pos, size);
            expPos_ += size;

            skipElement();
            return;
        }
    }

    pdmlProto = appendPdmlProto(protoName, &pbProto);

    qDebug("%s: preProtocolHandler(expPos = %d)", 
            protoName.toAscii().constData(), expPos_);
    pdmlProto->preProtocolHandler(protoName, attributes(), expPos_, pbProto,
            currentStream_);

    while (!atEnd())
    {
        readNext();

        if (isEndElement())
            break;

        if (isStartElement())
        {
            if (name() == "proto")
            {
                // an embedded proto
                qDebug("embedded proto: %s\n", attributes().value("name")
                        .toString().toAscii().constData());

                if (isDontCareProto())
                {
                    skipElement();
                    continue;
                }

                // if we are in the midst of processing a protocol, we
                // end it prematurely before we start processing the 
                // embedded protocol
                //
                // XXX: pdmlProto may be NULL for a sequence of embedded protos
                if (pdmlProto)
                {
                    int endPos = -1;

                    if (!attributes().value("pos").isEmpty())
                        endPos = attributes().value("pos").toString().toInt();

                    pdmlProto->prematureEndHandler(endPos, pbProto,
                            currentStream_);
                    pdmlProto->postProtocolHandler(pbProto, currentStream_);

                    StreamBase s;
                    s.protoDataCopyFrom(*currentStream_);
                    expPos_ = s.frameProtocolLength(0);
                }

                readProto();

                pdmlProto = NULL;
                pbProto = NULL;
            }
            else if (name() == "field")
            {
                if ((protoName == "fake-field-wrapper") &&
                        (attributes().value("name") == "tcp.segments"))
                {
                    skipElement();
                    qDebug("[skipping reassembled tcp segments]");

                    skipUntilEnd_ = true;
                    continue;
                }

                if (pdmlProto == NULL)
                {
                    pdmlProto = appendPdmlProto(protoName, &pbProto);

                    qDebug("%s: preProtocolHandler(expPos = %d)", 
                            protoName.toAscii().constData(), expPos_);
                    pdmlProto->preProtocolHandler(protoName, attributes(), 
                            expPos_, pbProto, currentStream_);
                }

                readField(pdmlProto, pbProto);
            }
            else 
                skipElement();
        }
    }

    // Close-off current protocol
    if (pdmlProto)
    {
        pdmlProto->postProtocolHandler(pbProto, currentStream_);
        freePdmlProtocol(pdmlProto);

        StreamBase s;
        s.protoDataCopyFrom(*currentStream_);
        expPos_ = s.frameProtocolLength(0);
    }
}