void CFileScore::ShowRank(int ClientID, const char* pName, bool Search) { CPlayerScore *pScore; int Pos; char aBuf[512]; if(!Search) pScore = SearchScore(ClientID, &Pos); else pScore = SearchName(pName, &Pos, 1); if(pScore && Pos > -1) { float Time = pScore->m_Score; char aClientName[128]; str_format(aClientName, sizeof(aClientName), " (%s)", Server()->ClientName(ClientID)); if(g_Config.m_SvHideScore) str_format(aBuf, sizeof(aBuf), "Your time: %d minute(s) %5.2f second(s)", (int)Time/60, Time-((int)Time/60*60)); else str_format(aBuf, sizeof(aBuf), "%d. %s Time: %d minute(s) %5.2f second(s)", Pos, pScore->m_aName, (int)Time/60, Time-((int)Time/60*60)); if (!Search) GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, ClientID); else GameServer()->SendChatTarget(ClientID, aBuf); return; } else if(Pos == -1) str_format(aBuf, sizeof(aBuf), "Several players were found."); else str_format(aBuf, sizeof(aBuf), "%s is not ranked", Search?pName:Server()->ClientName(ClientID)); GameServer()->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "rank", aBuf); }
//----------------------------------------------------------------------------- //Function Name : void* DlSymByDependencyOrdering(const void* aHandle, // const char* aName) //Description : To search for Symbol named name in statically dependent dll // on aSymInfoHeader, is dependencies, also dependencies of // dependencies using Dependency-ordering. //Return Value : Valid address if name found otherwise NULL //----------------------------------------------------------------------------- void* DlSymByDependencyOrdering(const void* aHandle,const char* aName) { //Get 0th ordinal datastructure of dll denoted by handle. LoadedDlls()->Lock(); TInt idx = LoadedDlls()->Find(aHandle); //check if handle not found if ( KErrNotFound == idx ) { LoadedDlls()->UnLock(); SetError(KDlSymErrBadHandle); return NULL; } TDllEntry& dllEntry = LoadedDlls()->At(idx); TE32ExpSymInfoHdr* symInfoHeader = dllEntry.iSymbolHeader; // The below 'if' condition prevents the symbol lookup on non-STDDLL // Check for the symbol information, if not found // return with KDlSymErrNoSupport if( !dllEntry.iSymbolHeader ) { LoadedDlls()->UnLock(); SetError(KDlSymErrNoSupport); return NULL; } TBuf8<KMaxFileName> fileName; fileName.Copy(dllEntry.iLibrary.FileName()); //Queue for using Breadthfirst search / Dependency ordering. RPointerArray<TE32ExpSymInfoHdr> dependentDllQue; //add first item in queue TInt err = dependentDllQue.Append(symInfoHeader); if ( KErrNone != err ) { LoadedDlls()->UnLock(); dependentDllQue.Close(); SetError(KDlSymErrNoMemory); return NULL; } TUint8* dependencyTableOffset; TE32ExpSymInfoHdr* tempSymInfoHeader = NULL; //Array of searched dlls. Used to check circular dependency RPointerArray<TE32ExpSymInfoHdr> searchedDlls; void* symAddr = NULL; //Breath First search for Dependancy ordering. while(dependentDllQue.Count()) { symInfoHeader = dependentDllQue[0]; dependentDllQue.Remove(0); // The below 'if' condition prevents the symbol lookup on dependent non-STDDLL if(!symInfoHeader) { continue; } //Search in this dll's symbol table symAddr = SearchName(symInfoHeader, aName); if( symAddr ) { LoadedDlls()->UnLock(); dependentDllQue.Close(); searchedDlls.Close(); return symAddr; } //Insert this to searched list err = searchedDlls.Append(symInfoHeader); if ( KErrNone != err ) { LoadedDlls()->UnLock(); dependentDllQue.Close(); searchedDlls.Close(); SetError(KDlSymErrNoMemory); return NULL; } //Add list of dependencies dependencyTableOffset = (TUint8*) symInfoHeader + symInfoHeader->iDepDllZeroOrdTableOffset; //Add at last to make it Queue, needed for Dependency ordering for (TInt i = 0; i < symInfoHeader->iDllCount; i++) { //get i'th dependency tempSymInfoHeader = *( (TE32ExpSymInfoHdr**) (dependencyTableOffset + (KFourByteOffset*i))); //check i'th dependency is OE dll e.i. equal to zero or not //and also its not already searched if ( tempSymInfoHeader && searchedDlls.Find(tempSymInfoHeader) == KErrNotFound ) { err = dependentDllQue.Append(tempSymInfoHeader); if ( KErrNone != err ) { LoadedDlls()->UnLock(); dependentDllQue.Close(); searchedDlls.Close(); SetError(KDlSymErrNoMemory); return NULL; } } } } LoadedDlls()->UnLock(); dependentDllQue.Close(); searchedDlls.Close(); //Symbol not found return NULL SetError(KDlSymErrNotFound); return NULL; }
/************************************************************************* * Parallel Arrays * ----------------------------------------------------------------------- * This program will receive as input the nam of an input file and an * output file. It will the rean in a list of names, id #'s, and balances * form the input file.This program then will prompt the user for a name * to search for, when it finds the name it will output to a file the * person's id #, name, and balance.The program will prompt for another * name until the word "done" is entered. * * Inputs : * inFileName - It will store the name of the file the program will * read from * outFileName - It will store the name of the file the program will * output to * searchItem - It will store the item name the user wants to search * Outputs : * It will output all the information the user wants to know from the * file read ************************************************************************/ int main() { //Declare the Input file in console ifstream inFile; ofstream outFile; string inFileName; //Variable used to store the User's input file string outFileName; //Variable used to store the user's output file const int ARR_SIZE = 10; // CALC - The number of items in an // array string namesAr[ARR_SIZE]; // CALC & OUT - Store names in the array int idsAr[ARR_SIZE]; // CALC & OUT - Store id #'s float balanceAr[ARR_SIZE]; // CALC & OUT - Store the balance of the // student string searchItem; // IN & CALC - Stores the name the user // wants to search int foundAt; // CALC - Store the index of the item // found //Declare the Input file in console cout << left << setw(42); cout << "What input file would you like to use?: "; getline(cin, inFileName); inFile.open(inFileName.c_str()); //Declare the Output File in console cout << setw(42); cout << "What output file would you like to use?:"; getline(cin, outFileName); outFile.open(outFileName.c_str()); PrintHeader(outFile); ReadInputs ( namesAr, idsAr, balanceAr, ARR_SIZE, inFile); //The heading of the output File outFile << left; outFile << setw(9) << "ID #"; outFile << setw(25) <<"NAME" << "BALANCE DUE"; outFile << setw(10) << "\n----" ; outFile << setw(25) << "--------------------"; outFile << "-----------"; //Asking user to search for a name until "done" is entered cout << setw(52) << "\nWho do you want to search for(enter done to exit):"; getline(cin, searchItem); //While-loop will stop when user enters "done" while(searchItem != "done") { foundAt= SearchName(namesAr, ARR_SIZE, searchItem); PrintToOutput( namesAr, idsAr, balanceAr, ARR_SIZE, foundAt, outFile); cout << setw(52) << "\nWho do you want to search for(enter " "done to exit):"; getline(cin, searchItem); } cout <<"\nThank you for using my program."; // Close files when the program is done inFile.close(); outFile.close(); return 0; }
//----------------------------------------------------------------------------- //Function Name : TInt SearchSymbolByLoadordering(TE32ExpSymInfoHdr* symInfoHeader // , char* aFileName, const char* aName, // RPointerArray<TE32ExpSymInfoHdr>& aSearchedDlls, // void*& aSymAddress) //Description : To search for Symbol named name in statically dependent dll // on aSymInfoHeader, it may be belonging to EXE or a DLL, also // dependencies of dependencies using Load-ordering. It also sets // valid address in aSymAddress if name found, and all sll it searched in // aSearchedDlls param. //Return Value : KErrNone if symbol found otherwise system wide error codes. //----------------------------------------------------------------------------- TInt SearchSymbolByLoadordering(const TE32ExpSymInfoHdr* aSymInfoHeader, const char* aName, RPointerArray<TE32ExpSymInfoHdr>& aSearchedDlls, void*& aSymAddress) { //This is used as stack for Load-ordering or Depthfirst search. RPointerArray<TE32ExpSymInfoHdr> dependentDllStack; aSymAddress = NULL; //Add exe on the stack TInt err = dependentDllStack.Append(aSymInfoHeader); if ( KErrNone != err ) { dependentDllStack.Close(); return KErrNoMemory; } TE32ExpSymInfoHdr* symInfoHeader; //temporary pointer to TUint8* dependencyTableOffset; TE32ExpSymInfoHdr* tempSymInfoHeader = NULL; TInt lastIdx = 0; //Retunn address would be stored in this void* symAddr = NULL; //Depth First search for Load-ordering. Intentional use of "=" while ( lastIdx >= 0 ) { //Take first dll on the stack i.e. topmost symInfoHeader = dependentDllStack[lastIdx]; //Remove from stack dependentDllStack.Remove(lastIdx); if(!symInfoHeader) { //skip non-std binaries... lastIdx = dependentDllStack.Count() - 1; continue; } //Search in current dll Symbol table. symAddr = SearchName(symInfoHeader, aName); //Check if Symbol is found if( symAddr ) { dependentDllStack.Close(); aSymAddress = symAddr; return KErrNone; } //Add this dll to list of searched dlls err = aSearchedDlls.Append(symInfoHeader); if ( KErrNone != err ) { dependentDllStack.Close(); return KErrNoMemory; } dependencyTableOffset = (TUint8*) symInfoHeader + symInfoHeader->iDepDllZeroOrdTableOffset; //All all the dependent dll for current dll/exe for (TInt i = symInfoHeader->iDllCount - 1; i >= 0; --i) { tempSymInfoHeader = *((TE32ExpSymInfoHdr**) (dependencyTableOffset + (KFourByteOffset * i))); if ( tempSymInfoHeader && aSearchedDlls.Find(tempSymInfoHeader) == KErrNotFound ) { err = dependentDllStack.Append(tempSymInfoHeader); if ( KErrNone != err ) { dependentDllStack.Close(); return KErrNoMemory; } } } lastIdx = dependentDllStack.Count() - 1; } dependentDllStack.Close(); return KErrNotFound; }