void ExecuteSimpleColouredSearch(const char* archiveName, const char* options, const char* regex, const char* secondPhaseRegex, const char* colour) { GrepParams params; bool printSummary; PopulateParamsForSimpleColouredSearch(¶ms, &printSummary, archiveName, options, regex, secondPhaseRegex, colour); ExecuteSearch(¶ms); if (printSummary) { printf("Search complete, found %d matches\n", gHitCount); } }
BOOL CSearchPanel::PreTranslateMessage(MSG* pMsg) { if ( pMsg->message == WM_KEYDOWN ) { if ( pMsg->wParam == VK_RETURN ) { ExecuteSearch(); return TRUE; } } return CTaskPanel::PreTranslateMessage( pMsg ); }
// arg is a table with the following elements // project - string name of the project // callback - function(filename, linenumber, linestring) // regex - regex to search for // caseSensitive - optional // regexIsLiteral - optional int C_executeSearch(lua_State* L) { const int arg_table = 1; lua_getfield(L, arg_table, "project"); /* idx:2 */ test_error(lua_isstring(L, -1), "execute_search needs a key of 'project' which must be a string"); const char* project = luaL_checkstring(L, 2); char projectFile[1024]; GetProjectFileName(projectFile, project); if (FileExists(projectFile)) { // unpack the rest of the table lua_getfield(L, arg_table, "regex"); /* idx:3 */ test_error(lua_isstring(L, -1), "execute_search needs a key of 'regex' which must be a string"); lua_getfield(L, arg_table, "caseSensitive"); /* idx:4 */ lua_getfield(L, arg_table, "regexIsLiteral"); /* idx:5 */ lua_getfield(L, arg_table, "ignoreTrigrams"); /* idx:6 */ // MUST leave the callback on the top of the stack lua_getfield(L, arg_table, "callback"); /* idx:7 */ test_error(lua_isfunction(L, -1), "execute_search needs a key of 'callback' which must be a lua function"); // marshal into C data const char* regex = luaL_checkstring(L, 3); bool caseSensitive = lua_isnil(L, 4) || lua_toboolean(L, 4); bool regexIsLiteral = lua_toboolean(L, 5); bool ignoreTrigrams = lua_toboolean(L, 6); GrepParams params; memset(¶ms, 0, sizeof(params)); // standard parms params.streamBlockSize = 1 * 1024 * 1024; params.streamBlockCount = 10; params.searchFilenames = false; // custom parms params.sourceArchiveName = projectFile; params.callbackFunction = luaHitCallback; params.caseSensitive = caseSensitive; params.regexIsLiteral = regexIsLiteral; params.ignoreTrigrams = ignoreTrigrams; params.searchPattern = regex; params.callbackContext = (void*)L; ExecuteSearch(¶ms); } else { lua_ProjectExistsOrDie(project); printf("Project is registered, but archive does not exist.\n"); printf("Run 'qgrep build %s' to generate archive\n", project); } return 0; }
int CSearchWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if ( CBaseMatchWnd::OnCreate( lpCreateStruct ) == -1 ) return -1; m_wndPanel.Create( this ); m_wndDetails.Create( this ); CQuerySearchPtr pSearch = GetLastSearch(); if ( pSearch && pSearch->m_pSchema != NULL ) { CList< CSchemaMember* > pColumns; CSchemaColumnsDlg::LoadColumns( pSearch->m_pSchema, &pColumns ); m_wndList.SelectSchema( pSearch->m_pSchema, &pColumns ); } else if ( CSchemaPtr pSchema = SchemaCache.Get( Settings.Search.BlankSchemaURI ) ) { CList< CSchemaMember* > pColumns; CSchemaColumnsDlg::LoadColumns( pSchema, &pColumns ); m_wndList.SelectSchema( pSchema, &pColumns ); } LoadState( _T("CSearchWnd"), TRUE ); ExecuteSearch(); if ( ! pSearch || ! pSearch->m_bAutostart ) { m_wndPanel.ShowSearch( NULL ); } else { m_wndPanel.Disable(); if ( m_bPanel && Settings.Search.HideSearchPanel ) m_bPanel = FALSE; } PostMessage( WM_TIMER, 1 ); return 0; }
void CSearchWnd::OnSearchSearch() { if ( ! Network.IsWellConnected() ) Network.Connect( TRUE ); SetModified(); // The 'Search More' situation if ( ! m_bPaused && m_bWaitMore ) { CQuickLock pLock( m_pMatches->m_pSection ); if ( ! empty() ) { CSearchPtr pManaged = m_oSearches.back(); // Re-activate search window theApp.Message( MSG_DEBUG, _T("Resuming Search") ); pManaged->SetActive( TRUE ); m_bWaitMore = FALSE; // Resume G2 search m_nMaxResults = m_pMatches->m_nGnutellaHits + Settings.Gnutella.MaxResults; m_nMaxQueryCount = pManaged->m_nQueryCount + Settings.Gnutella2.QueryLimit; // Resume ED2K search m_nMaxED2KResults = m_pMatches->m_nED2KHits + Settings.eDonkey.MaxResults; pManaged->m_tLastED2K = GetTickCount(); pManaged->m_tMoreResults = 0; if ( ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) == 0x8000 ) pManaged->SetPriority( CManagedSearch::spMedium ); m_bUpdate = TRUE; UpdateMessages(); return; } } // End of 'Search More' // Check if user mistakenly pasted download link to search input box CString strText; m_wndPanel.m_boxSearch.m_wndSearch.GetWindowText( strText ); if ( theApp.OpenURL( strText, TRUE ) ) { m_wndPanel.m_boxSearch.m_wndSearch.SetWindowText( _T("") ); return; } if ( m_pMatches->m_nFiles > 0 ) { if ( MsgBox( IDS_SEARCH_CLEAR_PREVIOUS, MB_ICONQUESTION | MB_YESNO, 0, &Settings.Search.ClearPrevious ) == IDYES ) { CQuickLock oLock( m_pMatches->m_pSection ); m_pMatches->Clear(); m_bUpdate = TRUE; PostMessage( WM_TIMER, 2 ); } } CSearchPtr pManaged; if ( m_wndPanel.m_bSendSearch ) { // Create new search pManaged = m_wndPanel.GetSearch(); CQuerySearchPtr pSearch = pManaged->GetSearch(); if ( m_pMatches->m_nFiles == 0 && pSearch->m_pSchema != NULL ) { CList< CSchemaMember* > pColumns; CSchemaColumnsDlg::LoadColumns( pSearch->m_pSchema, &pColumns ); m_wndList.SelectSchema( pSearch->m_pSchema, &pColumns ); } } else { CNewSearchDlg dlg( NULL, GetLastSearch(), FALSE, TRUE ); if ( dlg.DoModal() != IDOK ) return; pManaged = new CManagedSearch( dlg.GetSearch() ); } pManaged->CreateGUID(); { CQuickLock oLock( m_pMatches->m_pSection ); if ( ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) != 0x8000 ) for_each( begin(), end(), std::mem_fun( &CManagedSearch::Stop ) ); m_oSearches.push_back( pManaged ); } ExecuteSearch(); }