float getSimilarity(char* str1,char* str2) { //printf("Comparing %s to the word %s\n",str1,str2); int matched=0; int toplen=strlen(str1); int botlen=strlen(str2); int topdist=0; int botdist=0; int total=toplen+botlen; int top=0; int bottom=0; while(top<toplen&&bottom<botlen) { //printf("Looping, top is %d and bottom is %d\n",top,bottom); if(str1[top]==str2[bottom]) { //printf("Matched %c at %d with %c at %d\n",str1[top],top,str2[bottom],bottom); matched+=2; top++; bottom++; } else { // printf("Checking topdist-searching %s from %d for %c\n",str1,top,str2[bottom]); topdist=SearchForward(top,str1,str2[bottom]); //printf("Checking botdist-searching %s from %d for %c\n",str2,bottom,str1[top]); botdist=SearchForward(bottom,str2,str1[top]); //printf("topdist is %d while botdist is %d\n",topdist,botdist); if(topdist<botdist&&topdist>0) { top+=topdist; } else if (botdist>0) { bottom+=botdist; } else { break; } } } //printf("Matched %d out of %d\n",matched,total); return (float)matched/(float)total; }
BOOL CScintillaBibWnd::SearchText(LPCSTR lpText) { m_FindText = lpText; m_nSearchflags = 0; if (m_WholeWords) m_nSearchflags |= SCFIND_WHOLEWORD; if (m_MatchCase) m_nSearchflags |= SCFIND_MATCHCASE; if (m_RegExpr) m_nSearchflags |= SCFIND_REGEXP; if (!m_SearchBackward) return SearchForward(lpText); else return SearchBackward(lpText); }
MRESULT ProcessCommandMsg ( HWND hwndWnd, ULONG ulMsg, MPARAM mpParm1, MPARAM mpParm2 ) { switch ( SHORT1FROMMP( mpParm1 ) ) { /* * First, the menu selections. */ case IDM_FILE_OPEN: if ( QueryAbandonChanges( hwndWnd ) ) { if ( FileOpenDialog( hwndWnd, NULL ) ) { SetWindowTitle( hwndWnd ); UpdateScreenLimits( hwndWnd, TRUE ); } } break; case IDM_FILE_SAVE: FileSaveDialog( hwndWnd, szFileName ); SetWindowTitle( hwndWnd ); break; case IDM_FILE_SAVE_AS: FileSaveDialog( hwndWnd, NULL ); SetWindowTitle( hwndWnd ); break; case IDM_FILE_CLEAR: if ( QueryAbandonChanges( hwndWnd ) ) { ClearFile( hwndWnd ); SetWindowTitle( hwndWnd ); UpdateScreenLimits( hwndWnd, TRUE ); } break; case IDM_FILE_ALLOCATE: if ( QueryAbandonChanges( hwndWnd ) ) { if ( FileAllocateDialog( hwndWnd ) ) { SetWindowTitle( hwndWnd ); UpdateScreenLimits( hwndWnd, TRUE ); } } break; case IDM_FILE_RESIZE: if ( FileResizeDialog( hwndWnd ) ) { UpdateScreenLimits( hwndWnd, TRUE ); } break; case IDM_FILE_EXIT: if ( QueryAbandonChanges( hwndWnd ) ) { ClearFile( hwndWnd ); WinPostMsg(hwndWnd, WM_QUIT, 0L, 0L); } break; case IDM_EDIT_CUT: if ( EditCut( hwndWnd ) ) { SetWindowTitle( hwndWnd ); UpdateScreenLimits( hwndWnd, TRUE ); } break; case IDM_EDIT_COPY: if ( EditCopy( hwndWnd ) ) { SetWindowTitle( hwndWnd ); UpdateScreenLimits( hwndWnd, TRUE ); } break; case IDM_EDIT_PASTE: if ( EditPaste( hwndWnd ) ) { SetWindowTitle( hwndWnd ); UpdateScreenLimits( hwndWnd, TRUE ); } break; case IDM_EDIT_DELETE: if ( EditDelete( hwndWnd ) ) { SetWindowTitle( hwndWnd ); UpdateScreenLimits( hwndWnd, TRUE ); } break; case IDM_EDIT_INSERT: if ( EditInsert( hwndWnd ) ) { SetWindowTitle( hwndWnd ); UpdateScreenLimits( hwndWnd, TRUE ); } break; case IDM_SEARCH_FORWARD: SearchForward( hwndWnd ); break; case IDM_SEARCH_BACKWARD: SearchBackward( hwndWnd ); break; case IDM_SEARCH_AGAIN: SearchAgain( hwndWnd ); break; case IDM_REPLACE_FORWARD: ReplaceForward( hwndWnd ); break; case IDM_REPLACE_BACKWARD: ReplaceBackward( hwndWnd ); break; case IDM_REPLACE_AGAIN: ReplaceAgain( hwndWnd ); break; case IDM_GOTO_OFFSET: GotoOffset( hwndWnd ); break; case IDM_OPTIONS_FONT: FontSelectDialog( hwndWnd ); break; case IDM_OPTIONS_READONLY: bReadOnly ^= TRUE; WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_OPTIONS_READONLY, TRUE ), MPFROM2SHORT( MIA_CHECKED, bReadOnly ? MIA_CHECKED : 0 ) ); break; case IDM_OPTIONS_AUTORESIZE: bAutoResize ^= TRUE; WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_OPTIONS_AUTORESIZE, TRUE ), MPFROM2SHORT( MIA_CHECKED, bAutoResize ? MIA_CHECKED : 0 ) ); if ( bAutoResize ) UpdateScreenLimits( hwndWnd, TRUE ); break; case IDM_OPTIONS_REGISTER: DisplayRegistrationPanel( hwndWnd ); break; case IDM_DISPLAY: DisplayModeDialog( hwndWnd ); break; /* * Next, the DISPLAY dialog accelerator keys */ case IDD_DISPLAY_OFFSET_OCTAL: case IDD_DISPLAY_OFFSET_DECIMAL: case IDD_DISPLAY_OFFSET_HEX: case IDD_DISPLAY_ENTITY_OCTAL: case IDD_DISPLAY_ENTITY_DECIMAL: case IDD_DISPLAY_ENTITY_HEX: case IDD_DISPLAY_1_BYTE: case IDD_DISPLAY_2_BYTE: case IDD_DISPLAY_4_BYTE: DisplayModeAccelKey( hwndWnd, SHORT1FROMMP( mpParm1 ) ); break; /* * And the default */ default: return WinDefWindowProc( hwndWnd, ulMsg, mpParm1, mpParm2 ); break; } return MRFROMSHORT ( FALSE ) ; }