bool AbstractDecklistCardNode::compareTotalPrice(AbstractDecklistNode *other) const { AbstractDecklistCardNode *other2 = dynamic_cast<AbstractDecklistCardNode *>(other); if (other2) { int p1 = 100*getTotalPrice(); int p2 = 100*other2->getTotalPrice(); return (p1 != p2) ? (p1 > p2) : compareName(other); } else { return true; } }
bool AbstractDecklistCardNode::compareNumber(AbstractDecklistNode *other) const { AbstractDecklistCardNode *other2 = dynamic_cast<AbstractDecklistCardNode *>(other); if (other2) { int n1 = getNumber(); int n2 = other2->getNumber(); return (n1 != n2) ? (n1 > n2) : compareName(other); } else { return true; } }
bool InnerDecklistNode::comparePrice(AbstractDecklistNode *other) const { InnerDecklistNode *other2 = dynamic_cast<InnerDecklistNode *>(other); if (other2) { int p1 = 100*recursivePrice(true); int p2 = 100*other2->recursivePrice(true); return (p1 != p2) ? (p1 > p2) : compareName(other); } else { return false; } }
bool InnerDecklistNode::compareNumber(AbstractDecklistNode *other) const { InnerDecklistNode *other2 = dynamic_cast<InnerDecklistNode *>(other); if (other2) { int n1 = recursiveCount(true); int n2 = other2->recursiveCount(true); return (n1 != n2) ? (n1 > n2) : compareName(other); } else { return false; } }
bool compareFullyQualifiedName(const QList<const Name *> &path, const QList<const Name *> &other) { if (path.length() != other.length()) return false; for (int i = 0; i < path.length(); ++i) { if (! compareName(path.at(i), other.at(i))) return false; } return true; }
bool AbstractDecklistCardNode::compare(AbstractDecklistNode *other) const { switch (sortMethod) { case ByNumber: return compareNumber(other); case ByName: return compareName(other); case ByPrice: return compareTotalPrice(other); } return 0; }
bool InnerDecklistNode::compare(AbstractDecklistNode *other) const { switch (sortMethod) { case 0: return compareNumber(other); case 1: return compareName(other); case 2: return comparePrice(other); } return 0; }
/* * specialMenu - check if a name is a special menu name */ static menu *specialMenu( const char *name ) { menu *m; special_menu *s; int i; /* this is a little gross... */ m = NULL; s = &specialMenus[0]; for( i = 0; i < sizeof( specialMenus ) / sizeof( special_menu ); i++, s++ ) { if( compareName( name, s->name ) ) { m = s->m; break; } } return( m ); } /* specialMenu */
/** * Searches in the "name" directory for the "find" file, * if file is found and the user wanted to find that filetype * the path is added to a list that will be printed at the end. * Also puts all directories found in a list for it to be * searched. */ bool searchForFile(char* name, char *find, int t, struct Node* list) { DIR *dir; struct dirent *ent; struct stat f_info; bool foundFile = false; if (openDir(&dir, name, &ent)) { do { if ((lstat(ent->d_name, &f_info)) < 0) { fprintf(stderr, "lstat error: "); perror(ent->d_name); } else { if (t == 0 && compareName(ent->d_name, find)) { foundFile = true; } else if (checkDir(t, f_info, ent->d_name, find)) { foundFile = true; } else if (checkReg(t, f_info, ent->d_name, find)) { foundFile = true; } else if (checkLink(t, f_info, ent->d_name, find)) { foundFile = true; } if (checkDirAndRights(f_info) && !isDot(ent->d_name)) { int l = strlen(name) + strlen(ent->d_name); char *str = calloc(1, sizeof(char[l + 2])); strcpy(str, name); strcat(str, "/"); strcat(str, ent->d_name); insert(list, str); } } } while ((ent = readdir(dir))); } closedir(dir); return foundFile; }
DWORD Application_InternetExplorer::closeAllInternetExplorers(IClassFactory* internet_explorer_factory) { DWORD iReturnVal; iReturnVal = 0; // Create another fake IE instance so that we can close the process IWebBrowser2* pInternetExplorer; HRESULT hr = internet_explorer_factory->CreateInstance(NULL, IID_IWebBrowser2, (void**)&pInternetExplorer); if( hr == S_OK ) { OutputDebugStringA("IE CloseAll created fake IE instance.\n"); HWND hwndIE; DWORD dProcessId; pInternetExplorer->get_HWND((SHANDLE_PTR*)&hwndIE); GetWindowThreadProcessId(hwndIE, &dProcessId); // Close the IE process - try 1 EnumWindows(Application_InternetExplorer::EnumWindowsProc, (LPARAM)dProcessId); // Close the IE process - try 2 HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, dProcessId); DWORD tempProcessId = GetProcessId(hProc); if(tempProcessId == dProcessId) { if(!TerminateProcess(hProc, 0)) { iReturnVal = GetLastError(); OutputDebugStringA("IE CloseAll unable to terminate 1.\n"); } } if( hProc != NULL) { CloseHandle( hProc ); } } if(pInternetExplorer!=NULL) { pInternetExplorer->Release(); } //then all processes that match the exe DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) { OutputDebugStringA("IE CloseAll couldn't enum processes.\n"); iReturnVal = -1; } // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); for ( i = 0; i < cProcesses; i++ ) { if( aProcesses[i] != 0 ) { std::wstring processName = L"c:\\Program Files\\Internet Explorer\\iexplore.exe"; size_t iPos = processName.find_last_of(L"\\"); processName.erase(0, iPos +1); if(compareName(aProcesses[i], processName)==0) { OutputDebugStringA("IE CloseAll IE process left over. Closing....\n"); EnumWindows(Application_InternetExplorer::EnumWindowsCloseAppProc, (LPARAM) aProcesses[i]); HANDLE hPro = OpenProcess(PROCESS_TERMINATE,TRUE, aProcesses[i]); if(!TerminateProcess(hPro, 0)) { iReturnVal = GetLastError(); OutputDebugStringA("IE CloseAll unable to terminate 2.\n"); } if( hPro != NULL ) { CloseHandle (hPro); } } } } return iReturnVal; }
/** * Checks if the filename is "." or ".." returns true if it is */ bool isDot(char* name) { return compareName(name, ".") || compareName(name, ".."); }
/** * Checks if file is a link and that the user searches for this filetype * and if the name for the file is the same as the name file searched for. */ bool checkLink(int t, struct stat f_info, char* d_name, char* name) { return (t == 3 && S_ISLNK(f_info.st_mode) && compareName(d_name, name)); }
/** * Checks if file is a regular file and that the user searches for this filetype * and if the name for the file is the same as the name file searched for. */ bool checkReg(int t, struct stat f_info, char* d_name, char* name) { return (t == 2 && S_ISREG(f_info.st_mode) && compareName(d_name, name)); }
/** * Checks if file is a directory and that the user searches for this filetype * and if the name for the file is the same as the name file searched for. */ bool checkDir(int t, struct stat f_info, char* d_name, char* name) { return (t == 1 && S_ISDIR(f_info.st_mode) && compareName(d_name, name)); }
void CProfileOptions::AddOption(const char* name, const char* value, const char* cvar /*= NULL*/, const bool preview /*= false*/, const bool confirmation /*= false*/, const bool restart /*= false*/, const bool writeToConfig /*= false*/) { if(!name || !name[0]) return; if(!value) return; ScopedSwitchToGlobalHeap globalHeap; COption* pOption = NULL; CryFixedStringT<64> tmpName(name); CryFixedStringT<64> compareName("SysSpec"); if(tmpName.find(compareName.c_str())==0) { if(compareName.length() == tmpName.length()) { pOption = new CSysSpecAllOption(name, value, cvar); } else { pOption = new CSysSpecOption(name, value, cvar); } } else if(IsCVar(cvar)) { pOption = new CCVarOption(name, value, cvar); } else if(!strcmp(name, "Resolution")) { pOption = new CScreenResolutionOption(name, value); } else { pOption = new COption(name, value); } pOption->SetPreview(preview); pOption->SetConfirmation(confirmation); pOption->SetRequiresRestart(restart); pOption->SetWriteToConfig(writeToConfig); if(pOption) { if(IPlayerProfileManager* profileManager = g_pGame->GetIGameFramework()->GetIPlayerProfileManager()) { if(IPlayerProfile *profile = profileManager->GetCurrentProfile(profileManager->GetCurrentUser())) { pOption->SetPlayerProfile(profile); pOption->InitializeFromProfile(); } if(!m_bLoadingProfile) { m_allOptions.push_back(pOption); } else { CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Adding \"%s\" option while loading values from profile, option might not be initialized properly. Consider adding to attributes.xml", name); } } } }
int main(void) { printf("\n"); printf("\t --TESTING TREESUPPLEMENT--\n"); printf("\n"); /* Testing createTreeNode */ printf("-- CREATETREENODE\n"); printf("Input to createTreeNode: (\"McDonalds\", \"Fast food\", 3)\n"); void * testNode; testNode = createTreeNode("McDonalds", "Fast food", 3); printf("Output: %p - A pointer address\n", testNode); int x; int correctMembers; correctMembers = 0; char * testName = "McDonalds."; for (x = 0; ((restaurantTNode*)testNode)->name[x] == testName[x]; ++x); if (x == 9) ++correctMembers; else printf("FAILED to copy name\n"); char * testFType = "Fast food."; for (x = 0; ((restaurantTNode*)testNode)->foodType[x] == testFType[x]; ++x); if (x == 9) ++correctMembers; else printf("FAILED to copy foodType\n"); if (((restaurantTNode*)testNode)->rating == 3) ++correctMembers; else printf("FAILED to copy rating\n"); if (correctMembers == 3) printf("-- SUCCESS\n"); else printf("-- FAIL\n"); printf("\n"); /* End of testing createTreeNode */ /* Testing compareName */ printf("-- COMPARENAME\n"); int correctNums; correctNums = 0; printf("creating new tree node with createTreeNode(\"Burger King\", \"Fast food\", 4)\n"); void * testNode2; testNode2 = createTreeNode("Burger King", "Fast food", 4); printf("Input to compareName: (%p, %p)\n", testNode, testNode2); printf("{First arguement is the first tree node we created (McDonalds) and second is the new one (Burger King)}\n"); int resultOutput; resultOutput = compareName(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: -1\n"); if (resultOutput == -1) ++correctNums; else printf("FAILED to compare names\n"); printf("Shortening \"Burger King\" to \"Burger Ki\" (equal in length to McDonalds)\n"); ((restaurantTNode*)testNode2)->name[9] = '\0'; printf("Reinputting the original node and the altered node\n"); resultOutput = compareName(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: 0\n"); if (resultOutput == 0) ++correctNums; else printf("FAILED to compare names\n"); printf("Shortening \"Burger Ki\" to \"Burger\" (less than the length of McDonalds)\n"); ((restaurantTNode*)testNode2)->name[6] = '\0'; printf("Reinputting the original node and the again altered node\n"); resultOutput = compareName(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: 1\n"); if (resultOutput == 1) ++correctNums; else printf("FAILED to compare names\n"); if (correctNums == 3) printf("-- SUCCESS\n"); else printf("-- FAIL\n"); printf("\n"); /* End of testing compareName */ /* Testing compareRating */ printf("-- COMPARERATING\n"); correctNums = 0; printf("Input to compareRating: (%p, %p)\n", testNode, testNode2); printf("{First arguement is the first tree node we created, McDonalds (Rating: 3) and second is Burger King (Rating: 4)\n"); resultOutput = compareRating(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: -1\n"); if (resultOutput == -1) ++correctNums; else printf("FAILED to compare rating\n"); printf("Changing Burger King's rating to 3\n"); ((restaurantTNode*)testNode2)->rating = 3; printf("Reinputting the original node and the altered node\n"); resultOutput = compareRating(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: 0\n"); if (resultOutput == 0) ++correctNums; else printf("FAILED to compare rating\n"); printf("Changing Burger King's rating to 2\n"); ((restaurantTNode*)testNode2)->rating = 2; printf("Reinputting the original node and the altered node\n"); resultOutput = compareRating(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: 1\n"); if (resultOutput == 1) ++correctNums; else printf("FAILED to compare rating\n"); if (correctNums == 3) printf("-- SUCCESS\n"); else printf("-- FAIL\n"); printf("\n"); /* End of testing compareRating */ printf("\t --END OF TESTING TREESUPPLEMENT--\n"); printf("\n"); return 0; }