void DoSearch ( CSphIndex * pIndex ) { printf ( "---\nsearching... " ); CSphQuery tQuery; CSphQueryResult tResult; tQuery.m_sQuery = "@title cat"; ISphMatchSorter * pSorter = sphCreateQueue ( &tQuery, pIndex->GetMatchSchema(), tResult.m_sError, false ); if ( !pSorter ) { printf ( "failed to create sorter; error=%s", tResult.m_sError.cstr() ); } else if ( !pIndex->MultiQuery ( &tQuery, &tResult, 1, &pSorter, NULL ) ) { printf ( "query failed; error=%s", pIndex->GetLastError().cstr() ); } else { sphFlattenQueue ( pSorter, &tResult, 0 ); printf ( "%d results found in %d.%03d sec!\n", tResult.m_dMatches.GetLength(), tResult.m_iQueryTime/1000, tResult.m_iQueryTime%1000 ); ARRAY_FOREACH ( i, tResult.m_dMatches ) printf ( "%d. id=" DOCID_FMT ", weight=%d\n", 1+i, tResult.m_dMatches[i].m_iDocID, tResult.m_dMatches[i].m_iWeight ); } SafeDelete ( pSorter ); printf ( "---\n" ); }
void XQNode_t::ClearFieldMask () { m_uFieldMask = 0xFFFFFFFFUL; ARRAY_FOREACH ( i, m_dChildren ) m_dChildren[i]->ClearFieldMask(); }
uint64_t XQNode_t::GetHash() const { if ( m_iMagicHash ) return m_iMagicHash; XQOperator_e dZeroOp[2]; dZeroOp[0] = m_eOp; dZeroOp[1] = (XQOperator_e) 0; ARRAY_FOREACH ( i, m_dWords ) m_iMagicHash = 100 + ( m_iMagicHash ^ sphFNV64 ( (const BYTE*)m_dWords[i].m_sWord.cstr() ) ); ///< +100 to make it non-transitive ARRAY_FOREACH ( j, m_dChildren ) m_iMagicHash = 100 + ( m_iMagicHash ^ m_dChildren[j]->GetHash() ); ///< +100 to make it non-transitive m_iMagicHash += 1000000; ///< to immerse difference between parents and children m_iMagicHash ^= sphFNV64 ( (const BYTE*)dZeroOp ); return m_iMagicHash; }
void XQNode_t::SetFieldSpec ( DWORD uMask, int iMaxPos ) { // set it, if we do not yet have one if ( !m_bFieldSpec ) { m_bFieldSpec = true; m_uFieldMask = uMask; m_iFieldMaxPos = iMaxPos; } // some of the children might not yet have a spec, even if the node itself has // eg. 'hello @title world' (whole node has '@title' spec but 'hello' node does not have any!) ARRAY_FOREACH ( i, m_dChildren ) m_dChildren[i]->SetFieldSpec ( uMask, iMaxPos ); }
/** * Send an event to the listener attached to this p_em. */ void vlc_event_send( vlc_event_manager_t * p_em, vlc_event_t * p_event ) { vlc_event_listeners_group_t *slot = &p_em->events[p_event->type]; vlc_event_listener_t * listener; /* Fill event with the sending object now */ p_event->p_obj = p_em->p_obj; vlc_mutex_lock( &p_em->lock ) ; ARRAY_FOREACH( listener, slot->listeners ) listener->pf_callback( p_event, listener->p_user_data ); vlc_mutex_unlock( &p_em->lock ); }
/** * Destroy the event manager */ void vlc_event_manager_fini( vlc_event_manager_t * p_em ) { struct vlc_event_listener_t * listener; vlc_mutex_destroy( &p_em->lock ); for( size_t i = 0; i < ARRAY_SIZE(p_em->events); i++ ) { struct vlc_event_listeners_group_t *slot = p_em->events + i; ARRAY_FOREACH( listener, slot->listeners ) free( listener ); ARRAY_RESET( slot->listeners ); } }
static void handle_irc_line (struct network *net, char *line) { struct reply_handler *hand; struct irc_reply *rpl; int index; network_write_raw(net, line); rpl = irc_parse_line(line); if(rpl == NULL) DEBUG_PRINT("!!!!ERROR!!!!"); DEBUG_PRINT("Reply:"); DEBUG_PRINT("Prefix: %s", rpl->prefix.raw); DEBUG_PRINT("Prefix User: %s", rpl->prefix.user); DEBUG_PRINT("Prefix Host: %s", rpl->prefix.host); DEBUG_PRINT("Code: %d", rpl->code); DEBUG_PRINT("Cmd: %s", rpl->cmd); ARRAY_FOREACH(rpl->lines, index) DEBUG_PRINT("Line %d: %s", index, rpl->lines.arr[index]); DEBUG_PRINT("Colon: %s", rpl->colon); for (hand = reply_handler_list; hand->handler != NULL; hand++) { if (hand->cmd && rpl->cmd) { if (strcmp(hand->cmd, rpl->cmd) == 0) { DEBUG_PRINT("Handler: %p", hand->handler); (hand->handler) (net, rpl); goto cleanup; } } else if (hand->code > 0) { if (hand->code == rpl->code) { DEBUG_PRINT("Handler: %p", hand->handler); (hand->handler) (net, rpl); goto cleanup; } } } if (hand->handler == NULL) (reply_handler_list[0].handler) (net, rpl); cleanup: irc_reply_free(rpl); }
bool XQNode_t::IsEqualTo ( const XQNode_t * pNode ) { if ( !pNode || pNode->GetHash()!=GetHash() || pNode->GetOp()!=GetOp() ) return false; if ( m_dWords.GetLength() ) { // two plain nodes. let's compare the keywords if ( pNode->m_dWords.GetLength()!=m_dWords.GetLength() ) return false; if ( !m_dWords.GetLength() ) return true; SmallStringHash_T<int> hSortedWords; ARRAY_FOREACH ( i, pNode->m_dWords ) hSortedWords.Add ( 0, pNode->m_dWords[i].m_sWord ); ARRAY_FOREACH ( i, m_dWords ) if ( !hSortedWords.Exists ( m_dWords[i].m_sWord ) ) return false; return true; } // two non-plain nodes. let's compare the children if ( pNode->m_dChildren.GetLength()!=m_dChildren.GetLength() ) return false; if ( !m_dChildren.GetLength() ) return true; ARRAY_FOREACH ( i, m_dChildren ) if ( !pNode->m_dChildren[i]->IsEqualTo ( m_dChildren[i] ) ) return false; return true; }
int main ( int iArgs, char ** dArgs ) { OutputMode_e eMode = M_DEFAULT; bool bUseCustomCharset = false; CSphString sDict, sAffix, sLocale, sCharsetFile, sResult = "result.txt"; printf ( "spelldump, an ispell dictionary dumper\n\n" ); int i = 1; for ( ; i < iArgs; i++ ) { if ( !strcmp ( dArgs[i], "-c" ) ) { if ( ++i==iArgs ) break; bUseCustomCharset = true; sCharsetFile = dArgs[i]; } else if ( !strcmp ( dArgs[i], "-m" ) ) { if ( ++i==iArgs ) break; char * sMode = dArgs[i]; if ( !strcmp ( sMode, "debug" ) ) { eMode = M_DEBUG; continue; } if ( !strcmp ( sMode, "duplicates" ) ) { eMode = M_DUPLICATES; continue; } if ( !strcmp ( sMode, "last" ) ) { eMode = M_LAST; continue; } if ( !strcmp ( sMode, "default" ) ) { eMode = M_DEFAULT; continue; } printf ( "Unrecognized mode: %s\n", sMode ); return 1; } else break; } switch ( iArgs - i ) { case 4: sLocale = dArgs[i + 3]; case 3: sResult = dArgs[i + 2]; case 2: sAffix = dArgs[i + 1]; sDict = dArgs[i]; break; default: printf ( "Usage: spelldump [options] <dictionary> <affix> [result] [locale-name]\n\n" "Options:\n" "-c <file>\tuse case convertion defined in <file>\n" "-m <mode>\toutput (conflict resolution) mode:\n" "\t\tdefault - try to guess the best way to resolve a conflict\n" "\t\tlast - choose last entry\n" "\t\tdebug - dump all mappings (with rules)\n" "\t\tduplicates - dump duplicate mappings only (with rules)\n" ); if ( iArgs>1 ) { printf ( "\n" "Examples:\n" "spelldump en.dict en.aff\n" "spelldump ru.dict ru.aff ru.txt ru_RU.CP1251\n" "spelldump ru.dict ru.aff ru.txt .1251\n" ); } return 1; } printf ( "Loading dictionary...\n" ); CISpellDict Dict; if ( !Dict.Load ( sDict.cstr () ) ) sphDie ( "Error loading dictionary file '%s'\n", sDict.IsEmpty () ? "" : sDict.cstr () ); printf ( "Loading affix file...\n" ); CISpellAffix Affix ( sLocale.cstr (), bUseCustomCharset ? sCharsetFile.cstr () : NULL ); if ( !Affix.Load ( sAffix.cstr () ) ) sphDie ( "Error loading affix file '%s'\n", sAffix.IsEmpty () ? "" : sAffix.cstr () ); if ( sResult.IsEmpty () ) sphDie ( "No result file specified\n" ); FILE * pFile = fopen ( sResult.cstr (), "wt" ); if ( !pFile ) sphDie ( "Unable to open '%s' for writing\n", sResult.cstr () ); if ( eMode!=M_DEFAULT ) printf ( "Output mode: %s\n", dModeName[eMode] ); Dict.IterateStart (); WordMap_t tWordMap; const CISpellDict::CISpellDictWord * pWord = NULL; int nDone = 0; while ( ( pWord = Dict.IterateNext () )!=NULL ) { EmitResult ( tWordMap, pWord->m_sWord, pWord->m_sWord ); if ( ( ++nDone % 10 )==0 ) { printf ( "\rDictionary words processed: %d", nDone ); fflush ( stdout ); } if ( pWord->m_sFlags.IsEmpty() ) continue; CSphString sWord, sWordForCross; int iFlagLen = strlen ( pWord->m_sFlags.cstr () ); for ( int iFlag1 = 0; iFlag1 < iFlagLen; ++iFlag1 ) for ( int iRule1 = 0; iRule1 < Affix.GetNumRules (); ++iRule1 ) { CISpellAffixRule * pRule1 = Affix.GetRule ( iRule1 ); if ( pRule1->Flag()!=pWord->m_sFlags.cstr()[iFlag1] ) continue; sWord = pWord->m_sWord; if ( !pRule1->Apply ( sWord ) ) continue; EmitResult ( tWordMap, sWord, pWord->m_sWord, pRule1->Flag() ); // apply other rules if ( !Affix.CheckCrosses() ) continue; if ( !pRule1->IsCrossProduct() ) continue; for ( int iFlag2 = iFlag1 + 1; iFlag2 < iFlagLen; ++iFlag2 ) for ( int iRule2 = 0; iRule2 < Affix.GetNumRules (); ++iRule2 ) { CISpellAffixRule * pRule2 = Affix.GetRule ( iRule2 ); if ( !pRule2->IsCrossProduct () || pRule2->Flag()!=pWord->m_sFlags.cstr()[iFlag2] || pRule2->IsPrefix()==pRule1->IsPrefix() ) continue; sWordForCross = sWord; if ( pRule2->Apply ( sWordForCross ) ) EmitResult ( tWordMap, sWordForCross, pWord->m_sWord, pRule1->Flag(), pRule2->Flag() ); } } } printf ( "\rDictionary words processed: %d\n", nDone ); // output CSphVector<const char *> dKeys; tWordMap.IterateStart(); while ( tWordMap.IterateNext() ) dKeys.Add ( tWordMap.IterateGetKey().cstr() ); dKeys.Sort ( WordLess() ); ARRAY_FOREACH ( iKey, dKeys ) { const CSphVector<MapInfo_t> & dWords = tWordMap[dKeys[iKey]]; const char * sKey = dKeys[iKey]; switch ( eMode ) { case M_LAST: fprintf ( pFile, "%s > %s\n", sKey, dWords.Last().m_sWord.cstr() ); break; case M_EXACT_OR_LONGEST: { int iMatch = 0; int iLength = 0; ARRAY_FOREACH ( i, dWords ) { if ( dWords[i].m_sWord==sKey ) { iMatch = i; break; } int iWordLength = strlen ( dWords[i].m_sWord.cstr() ); if ( iWordLength>iLength ) { iLength = iWordLength; iMatch = i; } } fprintf ( pFile, "%s > %s\n", sKey, dWords[iMatch].m_sWord.cstr() ); break; } case M_DUPLICATES: if ( dWords.GetLength()==1 ) break; case M_DEBUG: ARRAY_FOREACH ( i, dWords ) fprintf ( pFile, "%s > %s %s/%d\n", sKey, dWords[i].m_sWord.cstr(), dWords[i].m_sRules, dWords.GetLength() ); break; } } fclose ( pFile ); return 0; }