Exemplo n.º 1
0
///////////////////////////////////////////////////////////////////////////////
// Execute
///////////////////////////////////////////////////////////////////////////////
void cDbExplore::Execute( cFCODatabaseFileIter& dbIter )
{
    ASSERT( ! dbIter.Done() );

    cDbDataSourceIter* pIter        = new cDbDataSourceIter( &dbIter.GetDb(), dbIter.GetGenre() );
    const iFCOPropDisplayer* pDisplayer = dbIter.GetGenreHeader().GetPropDisplayer();

    ////////////////////////////
    // the main event loop...
    ////////////////////////////
    while( true )
    {
        TSTRING verb, noun;
        TCOUT << _T(">>");
        TCIN >> verb;
        //
        // ok, now we switch on the command...
        //
        //-----------------------------------------------------------------
        // quit
        //-----------------------------------------------------------------
        if( verb.compare( _T("quit") ) == 0 )
        {
            // the quit command...
            break;
        }
        //-----------------------------------------------------------------
        // print
        //-----------------------------------------------------------------
        if( verb.compare( _T("print") ) == 0 )
        {
            GetNoun(noun);
            if( SeekTo( pIter, noun ) )
            {
                if( pIter->HasFCOData() )
                {
                    iFCO* pFCO = pIter->CreateFCO();
                    PrintFCO( pFCO, pDisplayer );
                    pFCO->Release();
                }
                else
                {
                    TCOUT << _T("Object has no data associated with it.") << std::endl;
                }
            }
            else
            {
                TCOUT << _T("Unable to find object ") << noun << std::endl;
            }
        }
        //-----------------------------------------------------------------
        // pwd
        //-----------------------------------------------------------------
        else if( verb.compare( _T("pwd") ) == 0 )
        {
            TCOUT << iTWFactory::GetInstance()->GetNameTranslator()->ToStringDisplay( pIter->GetParentName() ) << std::endl;
        }
        //-----------------------------------------------------------------
        // ls
        //-----------------------------------------------------------------
        else if( verb.compare( _T("ls") ) == 0 )
        {
            int cnt = 0;
            for( pIter->SeekBegin(); ! pIter->Done(); pIter->Next(), cnt++ )
            {
                TCOUT << _T("[") << cnt ;
                if( pIter->CanDescend() )
                {
                    TCOUT << _T("]*\t") ;
                }
                else
                {
                    TCOUT << _T("]\t") ;
                }
                TCOUT << pIter->GetShortName() << std::endl;
            }
        }
        //-----------------------------------------------------------------
        // cd
        //-----------------------------------------------------------------
        else if( verb.compare( _T("cd") ) == 0 )
        {
            GetNoun(noun);
            std::vector<TSTRING> vDirs;
            SplitString( noun, pIter->GetParentName().GetDelimiter(), vDirs );
            for( std::vector<TSTRING>::iterator i = vDirs.begin(); i != vDirs.end(); i++ )
            {
                
                if( i->compare( _T("..") ) == 0 )
                {
                    if( pIter->AtRoot() )
                    {
                        TCOUT << _T("Can't ascend above root.") << std::endl;
                        break;
                    }
                    else
                    {
                        TCOUT << _T("Ascending...") << std::endl;
                        pIter->Ascend();
                    }
                }
                else
                {
                    if( SeekTo( pIter, *i ) )
                    {
                        if( pIter->CanDescend() )
                        {
                            TCOUT << _T("Descending into ") << *i << std::endl;
                            pIter->Descend();
                        }
                        else
                        {
                            TCOUT << *i << _T(" has no children; can't descend.") << std::endl;
                            break;
                        }
                    }
                    else
                    {
                        TCOUT << _T("Unable to find object ") << *i << std::endl;
                        break;
                    }
                }
            }
        }
        //-----------------------------------------------------------------
        // cg
        //-----------------------------------------------------------------
        else if( verb.compare( _T("cg") ) == 0 )
        {
            GetNoun(noun);

            cGenre::Genre newGenre = cGenreSwitcher::GetInstance()->StringToGenre( noun.c_str() );

            if (newGenre != cGenre::GENRE_INVALID)
            {
                dbIter.SeekToGenre( newGenre );
                if( !dbIter.Done() )
                {
                    TCOUT << _T("Changing to Genre ") << noun << std::endl;
                    //
                    // create a new db iter for the new genre (db iters can only be
                    // assocaited with a single genre :-( )
                    //
                    delete pIter;
                    pIter = new cDbDataSourceIter( &dbIter.GetDb(), newGenre );
                }
                else
                {
                    TCOUT << _T("Unable to find Genre ") << noun << std::endl;
                }
            }
            else
            {
                TCOUT << _T("Invalid Genre ") << noun << std::endl;
            }
        }
        //-----------------------------------------------------------------
        // pwg
        //-----------------------------------------------------------------
        else if( verb.compare( _T("pwg") ) == 0 )
        {
            TCOUT << _T("Current Genre: ") << cGenreSwitcher::GetInstance()->GenreToString( (cGenre::Genre)dbIter.GetGenre(), true ) << std::endl;
        }

        //-----------------------------------------------------------------
        // help
        //-----------------------------------------------------------------
        if( verb.compare( _T("help") ) == 0 )
        {
            TCOUT   << _T("Commands: ")             << std::endl
                    << _T(" cd <dir_name>")         << std::endl
                    << _T(" pwd ")                  << std::endl
                    << _T(" ls ")                   << std::endl
                    << _T(" print <object_name>")   << std::endl
                    << _T(" cg (FS | NTFS | NTREG)")<< std::endl
                    << _T(" pwg")                   << std::endl
                    << _T(" quit")                  << std::endl;
        }

        // make sure the file is still valid...
        //
    /*
#ifdef _BLOCKFILE_DEBUG
        db.AssertAllBlocksValid() ;
#endif
    */
    }

    delete pIter;
    TCOUT << _T("Exiting...") << std::endl;

}
Exemplo n.º 2
0
std::string en::GetNounString(Noun* NounObj, bool ObjCase)
{
	if (NounObj->ID==0) return "";
	//Create the final string that will be returned. (Empty for now).
	std::string NounString = "";

	//Create the string that will be inserted before the articles (so that we can correctly turn 'a' into 'an' if this begins with a vowel)
	std::string NounResult;
	
	//Prepend all the adjectives to the NounResult, if the adjectives exist.
	for (int i = 0; i < 16; ++i)
	{
		std::string Adjective = GetAdjective(NounObj->Adjectives[i]);
		if (Adjective.compare("")!=0)
			NounResult += Adjective + " ";
	}

	//Prepend the Noun to NounResult.
	NounResult += GetNoun(NounObj,ObjCase);

	//Get the string of the article, telling it to turn 'a' into 'an' if NounResult begins with a vowel.
	std::string Article = GetArticle(NounObj,IsVowel(NounResult[0]));

	//Get the numberal
	std::string Numeral = GetNumeral(NounObj,false);

	//Get the preposition
	std::string Prepos = GetPrepos(NounObj->PreposNum);

	//Start the NounString with the preposition if necessary
	if (Prepos.compare("")!=0)
		NounString+=Prepos + " ";

	//Add the article
	if (Article.compare("")!=0)
		NounString+=Article + " ";

	//Add the Numeral. This is not currently added to noun result, and shouldn't matter as you shouldn't be adding a numeral when you use a/an
	if (Numeral.compare("")!=0)
		NounString+=Numeral + " ";

	//Add the noun result to the noun string (adjectives, and noun)
	NounString+=NounResult;

	//If there is a genitive object, add it.
	if (NounObj->ShouldUseGenitive)
	{
		NounString += " " + GenitiveMarker + " ";
		NounString += GetNounString(NounObj->GenitiveNoun,true);
	}

	//If there is a relative clause, add it.
	if (NounObj->ShouldUseRelativeClause)
	{
		NounObj->RelativeClause->IsClause = true;
		
		//If the relative clause is about a persion, use "who"
		int NounType = GetNounType(NounObj->ID);
		if (NounType == 'm' || NounType == 'f' || NounType == 'p' || NounType == 'd')
		{
			NounString += " " + RClausePersonalMarker;	
		}
		//Otherwise if the relative clause is essential use "that"
		else if (NounObj->IsRelativeClauseEssential) NounString += " " + RClauseEssentialMarker;
		//Otherwise (non essential) use "which"
		else NounString += " " + RClauseNonEssentialMarker;
		
		//Append the clause
		NounString += " " + NounObj->RelativeClause->createSentence();
	}

	//Return the result.
	return NounString;
}