float DocumentList::ComputeContainment (int doc_i, int doc_j) { float num_matches = (float)(doc_j > doc_i ? CountMatches (doc_i, doc_j) : CountMatches (doc_j, doc_i)); float target_trigrams = (float)(CountTrigrams (doc_j)); if (target_trigrams == 0.0) return 0.0; // check for divide by zero return num_matches/target_trigrams; }
float DocumentList::ComputeResemblance (int doc_i, int doc_j) { float num_matches = (float)CountMatches (doc_i, doc_j); float total_trigrams = (float)(CountTrigrams (doc_i) + CountTrigrams (doc_j) - CountMatches (doc_i, doc_j)); if (total_trigrams == 0.0) return 0.0; // check for divide by zero return num_matches/total_trigrams; }
CString GitPatch::CheckPatchPath(const CString& path) { // first check if the path already matches if (CountMatches(path) > (GetNumberOfFiles() / 3)) return path; CSysProgressDlg progress; CString tmp; progress.SetTitle(IDS_PATCH_SEARCHPATHTITLE); progress.SetShowProgressBar(false); tmp.LoadString(IDS_PATCH_SEARCHPATHLINE1); progress.SetLine(1, tmp); progress.ShowModeless(AfxGetMainWnd()); // now go up the tree and try again CString upperpath = path; while (upperpath.ReverseFind('\\')>0) { upperpath = upperpath.Left(upperpath.ReverseFind('\\')); progress.SetLine(2, upperpath, true); if (progress.HasUserCancelled()) return path; if (CountMatches(upperpath) > (GetNumberOfFiles()/3)) return upperpath; } // still no match found. So try sub folders bool isDir = false; CString subpath; CDirFileEnum filefinder(path); while (filefinder.NextFile(subpath, &isDir)) { if (progress.HasUserCancelled()) return path; if (!isDir) continue; if (GitAdminDir::IsAdminDirPath(subpath)) continue; progress.SetLine(2, subpath, true); if (CountMatches(subpath) > (GetNumberOfFiles()/3)) return subpath; } // if a patch file only contains newly added files // we can't really find the correct path. // But: we can compare paths strings without the filenames // and check if at least those match upperpath = path; while (upperpath.ReverseFind('\\')>0) { upperpath = upperpath.Left(upperpath.ReverseFind('\\')); progress.SetLine(2, upperpath, true); if (progress.HasUserCancelled()) return path; if (CountDirMatches(upperpath) > (GetNumberOfFiles()/3)) return upperpath; } return path; }
BOOL CPatch::StripPrefixes(const CString& path) { int nSlashesMax = 0; for (int i=0; i<GetNumberOfFiles(); i++) { CString filename = GetFilename(i); filename.Replace('/','\\'); int nSlashes = filename.Replace('\\','/'); nSlashesMax = max(nSlashesMax,nSlashes); } for (int nStrip=1;nStrip<nSlashesMax;nStrip++) { m_nStrip = nStrip; if ( CountMatches(path) > GetNumberOfFiles()/3 ) { // Use current m_nStrip return TRUE; } } // Stripping doesn't help so reset it again m_nStrip = 0; return FALSE; }
CString CPatch::CheckPatchPath(const CString& path) { //first check if the path already matches if (CountMatches(path) > (GetNumberOfFiles()/3)) return path; //now go up the tree and try again CString upperpath = path; while (upperpath.ReverseFind('\\')>0) { upperpath = upperpath.Left(upperpath.ReverseFind('\\')); if (CountMatches(upperpath) > (GetNumberOfFiles()/3)) return upperpath; } //still no match found. So try sub folders bool isDir = false; CString subpath; CDirFileEnum filefinder(path); while (filefinder.NextFile(subpath, &isDir)) { if (!isDir) continue; if (g_GitAdminDir.IsAdminDirPath(subpath)) continue; if (CountMatches(subpath) > (GetNumberOfFiles()/3)) return subpath; } // if a patch file only contains newly added files // we can't really find the correct path. // But: we can compare paths strings without the filenames // and check if at least those match upperpath = path; while (upperpath.ReverseFind('\\')>0) { upperpath = upperpath.Left(upperpath.ReverseFind('\\')); if (CountDirMatches(upperpath) > (GetNumberOfFiles()/3)) return upperpath; } return path; }
BOOL Win32PopupDialog::ShowMessageBox(HWND hwnd) { BOOL fSuccess = FALSE; HDC hdc = GetDC(hwnd); if (hdc) { NONCLIENTMETRICSW nonClientMetrics = { sizeof(NONCLIENTMETRICSW) }; if (SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, 0, &nonClientMetrics, 0)) { DialogTemplate tmp; std::wstring wideTitle(::UTF8ToWide(title)); std::wstring wideInputText; if (this->showInputText) wideInputText.assign(::UTF8ToWide(inputText)); int controlCount = 2; // at minimum, static label and OK button if (this->showCancelButton) controlCount++; if (this->showInputText) controlCount++; int messageLines = 0; int newlines = CountMatches(message, "\n"); int tabs = CountMatches(message, "\t"); int spaces = CountMatches(message, " "); if (newlines == 0 && tabs == 0 && spaces == 0) { std::string tempMessage(message); if (tempMessage.length() != 0) { int insertAt = 60; int count = 0; std::string::iterator it = tempMessage.begin(); for (; it < tempMessage.end(); it++) { count++; if (count == 60) { count = 0; message.insert(insertAt, "\n"); insertAt += 60; } } } } std::wstring wideMessage(::UTF8ToWide(message)); messageLines = message.length() / 60; messageLines += ((int) ceil((double)tabs / 14)); messageLines += newlines; if (tabs == 0 || newlines == 0) messageLines++; int labelHeight = 14; int width = 200; int margin = 10; int buttonWidth = 50; int buttonHeight = 14; int inputHeight = 14; int messageHeight = (messageLines * 12) + (messageLines * margin); int height = messageHeight + 56; if (!this->showInputText) { height -= (inputHeight + margin); } // Write out the extended dialog template header tmp.Write<WORD>(1); // dialog version tmp.Write<WORD>(0xFFFF); // extended dialog template tmp.Write<DWORD>(0); // help ID tmp.Write<DWORD>(0); // extended style tmp.Write<DWORD>(WS_CAPTION | WS_BORDER | DS_ABSALIGN | DS_SETFONT); tmp.Write<WORD>(controlCount); // number of controls tmp.Write<WORD>(32); // X tmp.Write<WORD>(32); // Y tmp.Write<WORD>(width); // width tmp.Write<WORD>(height); // height tmp.WriteString(L""); // no menu tmp.WriteString(L""); // default dialog class //tmp.WriteString(pszTitle); // title tmp.WriteString(wideTitle.c_str()); // title // Next comes the font description. // See text for discussion of fancy formula. if (nonClientMetrics.lfMessageFont.lfHeight < 0) { int dpi = GetDeviceCaps(hdc, LOGPIXELSY); nonClientMetrics.lfMessageFont.lfHeight = -MulDiv(nonClientMetrics.lfMessageFont.lfHeight, 72, dpi); } tmp.Write<WORD>((WORD)nonClientMetrics.lfMessageFont.lfHeight); // point tmp.Write<WORD>((WORD)nonClientMetrics.lfMessageFont.lfWeight); // weight tmp.Write<BYTE>(nonClientMetrics.lfMessageFont.lfItalic); // Italic tmp.Write<BYTE>(nonClientMetrics.lfMessageFont.lfCharSet); // CharSet tmp.WriteString(nonClientMetrics.lfMessageFont.lfFaceName); // First control - static label tmp.AlignToDword(); tmp.Write<DWORD>(0); // help id tmp.Write<DWORD>(0); // window extended style tmp.Write<DWORD>(WS_CHILD | WS_VISIBLE | SS_LEFT); // style tmp.Write<WORD>(margin); // x tmp.Write<WORD>(margin); // y tmp.Write<WORD>(width - (2 * margin)); // width //tmp.Write<WORD>(labelHeight); // height tmp.Write<WORD>(messageHeight); // height tmp.Write<DWORD>(-1); // control ID tmp.Write<DWORD>(0x0082FFFF); // static //tmp.Write<DWORD>(SS_LEFT); tmp.WriteString(wideMessage.c_str()); // text tmp.Write<WORD>(0); // no extra data // Second control - the OK button. tmp.AlignToDword(); tmp.Write<DWORD>(0); // help id tmp.Write<DWORD>(0); // window extended style tmp.Write<DWORD>(WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | BS_DEFPUSHBUTTON); // style tmp.Write<WORD>(width - margin - buttonWidth); // x tmp.Write<WORD>(height - margin - buttonHeight); // y tmp.Write<WORD>(buttonWidth); // width tmp.Write<WORD>(buttonHeight); // height tmp.Write<DWORD>(IDCANCEL); // control ID tmp.Write<DWORD>(0x0080FFFF); // button class atom tmp.WriteString(L"Cancel"); // text tmp.Write<WORD>(0); // no extra data if (this->showCancelButton) { // The Cancel button tmp.AlignToDword(); tmp.Write<DWORD>(0); // help id tmp.Write<DWORD>(0); // window extended style tmp.Write<DWORD>(WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | BS_DEFPUSHBUTTON); // style tmp.Write<WORD>(width - 2 * margin - 2 * buttonWidth); // x tmp.Write<WORD>(height - margin - buttonHeight); // y tmp.Write<WORD>(buttonWidth); // width tmp.Write<WORD>(buttonHeight); // height tmp.Write<DWORD>(IDOK); // control ID tmp.Write<DWORD>(0x0080FFFF); // button class atom tmp.WriteString(L"OK"); // text tmp.Write<WORD>(0); // no extra data } if (this->showInputText) { // The input field tmp.AlignToDword(); tmp.Write<DWORD>(0); // help id tmp.Write<DWORD>(0); // window extended style tmp.Write<DWORD>(ES_LEFT | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE); // style tmp.Write<WORD>(margin); // x tmp.Write<WORD>(margin + labelHeight + margin); // y tmp.Write<WORD>(width - (2 * margin)); // width tmp.Write<WORD>(inputHeight); // height tmp.Write<DWORD>(ID_INPUT_FIELD); // control ID tmp.Write<DWORD>(0x0081FFFF); // edit class atom tmp.WriteString(wideInputText.c_str()); // text tmp.Write<WORD>(0); // no extra data } // Template is ready - go display it. fSuccess = DialogBoxIndirect( GetModuleHandle(NULL), tmp.Template(), hwnd, &Win32PopupDialog::Callback) >= 0; } ReleaseDC(NULL, hdc); // fixed 11 May } return fSuccess; }