/* Top level routine.  Read PGM images and keypoints from files given
   in command line arguments, then call FindMatches.
*/
int main (int argc, char **argv)
{
    int arg = 0;
    Image im1 = NULL, im2 = NULL;
    Keypoint k1 = NULL, k2 = NULL;

    /* Parse command line arguments and read given files.  The command
       line must specify two input images and two files of keypoints
       using command line arguments as follows:
          match -im1 i1.pgm -k1 k1.key -im2 i2.pgm -k2 k2.key > result.v
    */
    while (++arg < argc) {
      if (! strcmp(argv[arg], "-im1")) 
	im1 = ReadPGMFile(argv[++arg]);
      else if (! strcmp(argv[arg], "-im2")) 
	im2 = ReadPGMFile(argv[++arg]);
      else if (! strcmp(argv[arg], "-k1"))
	k1 = ReadKeyFile(argv[++arg]);
      else if (! strcmp(argv[arg], "-k2"))
	k2 = ReadKeyFile(argv[++arg]);
      else
	FatalError("Invalid command line argument: %s", argv[arg]);
    }
    if (im1 == NULL || im2 == NULL || k1 == NULL || k2 == NULL)
      FatalError("Command line does not specify all images and keys.");

    FindMatches(im1, k1, im2, k2);
    exit(0);
}
Ejemplo n.º 2
0
list* SearchSignatureDatabase(signature_db* SignatureDatabase, trie_unit* Data, size_t DataSize)
{
  size_t NumMatches;
  if (!SignatureDatabase || !Data || !DataSize)
   return NULL;

  if (!SignatureDatabase->SearchMachine)
    return NULL;

  match* Matches = FindMatches(SignatureDatabase->SearchMachine, Data, DataSize, &NumMatches);

  // Translate signature identifiers to signatures
  list* MatchingSignatures = NULL;
  for (size_t MatchIndex = 0; MatchIndex < NumMatches; ++MatchIndex)
  {
    list* MatchList = Matches[MatchIndex].List;
    for (; MatchList; MatchList = MatchList->Next)
    {
      for (size_t SignatureDatabaseIndex = 0; SignatureDatabaseIndex < SignatureDatabase->SignatureCount; ++SignatureDatabaseIndex)
      {
        if (memcmp(SignatureDatabase->Signatures[SignatureDatabaseIndex]->Data,
              MatchList->Value,
              SignatureDatabase->Signatures[SignatureDatabaseIndex]->DataSize) == 0)
        {
          if (!MatchingSignatures)
            AllocateAndInitializeListHead(&MatchingSignatures, SignatureDatabase->Signatures[SignatureDatabaseIndex]);
          else
            UniqAppendToList(MatchingSignatures, SignatureDatabase->Signatures[SignatureDatabaseIndex]);
        }
      }
    }
  }

  return MatchingSignatures;
}
Ejemplo n.º 3
0
void PasswordSafeSearch::OnDoSearchT(Iter begin, Iter end, Accessor afn)
{
  wxASSERT(m_toolbar);

  wxSearchCtrl* txtCtrl = wxDynamicCast(m_toolbar->FindControl(ID_FIND_EDITBOX), wxSearchCtrl);
  wxASSERT(txtCtrl);

  const wxString searchText = txtCtrl->GetLineText(0);

  if (searchText.IsEmpty())
    return;

  if (m_criteria->IsDirty() || txtCtrl->IsModified() || m_searchPointer.IsEmpty())  {
      m_searchPointer.Clear();

      if (!m_toolbar->GetToolState(ID_FIND_ADVANCED_OPTIONS))
        FindMatches(tostringx(searchText), m_toolbar->GetToolState(ID_FIND_IGNORE_CASE), m_searchPointer, begin, end, afn);
      else
        FindMatches(tostringx(searchText), m_toolbar->GetToolState(ID_FIND_IGNORE_CASE), m_searchPointer,
                      m_criteria->GetSelectedFields(), m_criteria->HasSubgroupRestriction(), m_criteria->SubgroupSearchText(),
                      m_criteria->SubgroupObject(), m_criteria->SubgroupFunction(),
                      m_criteria->CaseSensitive(), begin, end, afn);

      m_criteria->Clean();
      txtCtrl->SetModified(false);
      m_searchPointer.InitIndex();
  }
  else {
      ++m_searchPointer;
  }

  UpdateView();

  // Replace the "Find" menu item under Edit menu by "Find Next" and "Find Previous"
  wxMenu* editMenu = 0;
  wxMenuItem* findItem = m_parentFrame->GetMenuBar()->FindItem(wxID_FIND, &editMenu);
  if (findItem && editMenu)  {
      //Is there a way to do this without hard-coding the insert position?
    if (!m_parentFrame->GetMenuBar()->FindItem(ID_EDITMENU_FIND_NEXT) ) {
      editMenu->Insert(FIND_MENU_POSITION, ID_EDITMENU_FIND_NEXT, _("&Find next...\tF3"), wxT(""), wxITEM_NORMAL);
    }
    if (!m_parentFrame->GetMenuBar()->FindItem(ID_EDITMENU_FIND_PREVIOUS) ) {
      editMenu->Insert(FIND_MENU_POSITION+1, ID_EDITMENU_FIND_PREVIOUS, _("&Find previous...\tSHIFT+F3"), wxT(""), wxITEM_NORMAL);
    }
  }
}
Ejemplo n.º 4
0
void PasswordSafeSearch::FindMatches(const StringX& searchText, bool fCaseSensitive, SearchPointer& searchPtr, Iter begin, Iter end, Accessor afn)
{
  searchPtr.Clear();
  //As per original Windows code, default search is for all text fields
  CItemData::FieldBits bsFields;
  bsFields.set();

  return FindMatches(searchText, fCaseSensitive, searchPtr, bsFields, false, wxEmptyString, CItemData::END, PWSMatch::MR_INVALID, false, begin, end, afn);
}
Ejemplo n.º 5
0
void TokensTree::RecalcData()
{
    TRACE(cc_text("RecalcData() : Calculating full inheritance tree."));
    // first loop to convert ancestors string to token indices for each token
    for (size_t i = 0; i < size(); ++i)
    {
        Token* token = at(i);
        if (!token)
            continue;

        if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum)))
            continue;
        if (token->m_AncestorsString.empty())
            continue;
        // only local symbols might change inheritance
//        if (!token->m_IsLocal)
//            continue;

        token->m_DirectAncestors.clear();
        token->m_Ancestors.clear();

        TRACE(cc_text("RecalcData() : Token %s, Ancestors %s"),
              token->m_Name.wx_str(),
              token->m_AncestorsString.wx_str());

        StringTokenizer tkz(token->m_AncestorsString, cc_text(","));
        while (tkz.HasMoreTokens())
        {
            cc_string ancestor = tkz.GetNextToken();
            if (ancestor.empty() || ancestor == token->m_Name)
                continue;

            TRACE(cc_text("RecalcData() : Ancestor %s"), ancestor.wx_str());

            // ancestors might contain namespaces, e.g. NS::Ancestor
            if (ancestor.find(cc_text("::")) != cc_string::npos)
            {
                Token* ancestorToken = 0;
                StringTokenizer anctkz(ancestor, cc_text("::"));
                while (anctkz.HasMoreTokens())
                {
                    cc_string ns = anctkz.GetNextToken();
                    if (!ns.empty())
                    {
                        int ancestorIdx = TokenExists(ns, ancestorToken ? ancestorToken->GetSelf() : -1, tkNamespace | tkClass | tkTypedef);
                        ancestorToken = at(ancestorIdx);
//                        ancestorToken = token->HasChildToken(ns, tkNamespace | tkClass);
                        if (!ancestorToken) // unresolved
                            break;
                    }
                }
                if (ancestorToken && ancestorToken != token && ancestorToken->m_TokenKind == tkClass)// && !ancestorToken->m_IsTypedef)
                {
                    TRACE(cc_text("RecalcData() : Resolved to %s"), ancestorToken->m_Name.wx_str());
                    token->m_Ancestors.insert(ancestorToken->GetSelf());
                    ancestorToken->m_Descendants.insert(i);
                    TRACE(cc_text("RecalcData() :  + '%s'"), ancestorToken->m_Name.wx_str());

                }
                else
                    TRACE(cc_text("RecalcData() :  ! '%s' (unresolved)"), ancestor.wx_str());
            }
            else // no namespaces in ancestor
            {
                // accept multiple matches for inheritance
                TokenIdxSet result;
                FindMatches(ancestor, result, true, false);
                for (TokenIdxSet::iterator it = result.begin(); it != result.end(); it++)
                {
                    Token* ancestorToken = at(*it);
                    // only classes take part in inheritance
                    if (   ancestorToken
                        && (ancestorToken != token)
                        && (   (ancestorToken->m_TokenKind == tkClass)
                            || (ancestorToken->m_TokenKind == tkEnum)
                            || (ancestorToken->m_TokenKind == tkTypedef) ) ) // && !ancestorToken->m_IsTypedef)
                    {
                        token->m_Ancestors.insert(*it);
                        ancestorToken->m_Descendants.insert(i);
                        TRACE(cc_text("RecalcData() :  + '%s'"), ancestorToken->m_Name.wx_str());
                    }
                }
#if TOKEN_DEBUG_OUTPUT
                if (result.empty())
                    TRACE(_T("RecalcData() :  ! '%s' (unresolved)"), ancestor.wx_str());
#endif
            }
        }

        token->m_DirectAncestors = token->m_Ancestors;

        if (!token->m_IsLocal) // global symbols are linked once
        {
            TRACE(cc_text("RecalcData() : Removing ancestor string from %s"), token->m_Name.wx_str(), token->m_Name.wx_str());
            token->m_AncestorsString.clear();
        }
    }

    // second loop to calculate full inheritance for each token
    for (size_t i = 0; i < size(); ++i)
    {
        Token* token = at(i);
        if (!token)
            continue;

        if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum)))
            continue;

        // recalc
        TokenIdxSet result;
        for (TokenIdxSet::iterator it = token->m_Ancestors.begin(); it != token->m_Ancestors.end(); it++)
            RecalcFullInheritance(*it, result);

        // now, add the resulting set to ancestors set
        for (TokenIdxSet::iterator it = result.begin(); it != result.end(); it++)
        {
            Token* ancestor = at(*it);
            if (ancestor)
            {
                token->m_Ancestors.insert(*it);
                ancestor->m_Descendants.insert(i);
            }
        }

#if TOKEN_DEBUG_OUTPUT
        // debug loop
        TRACE(_T("RecalcData() : Ancestors for %s:"),token->m_Name.wx_str());
        for (TokenIdxSet::iterator it = token->m_Ancestors.begin(); it != token->m_Ancestors.end(); it++)
            TRACE(_T("RecalcData() :  + %s"), at(*it)->m_Name.wx_str());
#endif
    }
    TRACE(cc_text("RecalcData() : Full inheritance calculated."));
}
Ejemplo n.º 6
0
void
DoProcessCheck(struct Process *pp,struct Item *procdata)
{
    char line[CF_BUFSIZE];
    int matches=0,dosignals=true;
    mode_t maskval;
    struct stat statbuf;
    struct Item *killlist = NULL;

    matches = FindMatches(pp,procdata,&killlist);

    if (matches > 0) {
        Verbose("Defining classes %s\n",pp->defines);
        AddMultipleClasses(pp->defines);
    } else {
        Verbose("Defining classes %s\n",pp->elsedef);
        AddMultipleClasses(pp->elsedef);
    }

    if (pp->matches >= 0) {
        if (pp->action == 'm') {
            dosignals = false;
        }

        switch (pp->comp) {
        case '=':
            if (matches != (int)pp->matches) {
                snprintf(g_output,CF_BUFSIZE*2,
                        "%d processes matched %s (should be %d)\n",
                        matches,pp->expr,pp->matches);
                CfLog(cferror,g_output,"");
                if (pp->action == 'm') {
                    dosignals = true;
                }
            }
            break;

        case '>':
            if (matches < (int)pp->matches) {

                snprintf(g_output,CF_BUFSIZE*2,
                        "%d processes matched %s (should be >=%d)\n",
                        matches,pp->expr,pp->matches);

                CfLog(cferror,g_output,"");
                if (pp->action == 'm') {
                    dosignals = true;
                }
            }
            break;

        case '<':
            if (matches > (int)pp->matches) {

                snprintf(g_output,CF_BUFSIZE*2,
                        "%d processes matched %s (should be <=%d)\n",
                        matches,pp->expr,pp->matches);

                CfLog(cferror,g_output,"");
                if (pp->action == 'm') {
                    dosignals = true;
                }
            }
        }
    }

    if (dosignals) {
        DoSignals(pp,killlist);
    }

    DeleteItemList(killlist);

    if ((pp->action == 'm') && !dosignals && (matches != 0)) {
        Verbose("%s: Process matches found for %s - no restart necessary\n",
                g_vprefix,pp->expr);
        return;
    }

    if (strlen(pp->restart) != 0) {
        char argz[256];

        Verbose("Existing restart sequence found (%s)\n",pp->restart);

        if ((matches != 0) && (pp->signal != cfkill) &&
                (pp->signal != cfterm)) {
            Verbose("%s: Process matches found for %s - "
                    "no restart necessary\n",
                    g_vprefix,pp->expr);
            return;
        }

        sscanf(pp->restart,"%255s",argz);

        if ((stat(argz,&statbuf) != -1) && (statbuf.st_mode & 0111 == 0)) {

            snprintf(g_output, CF_BUFSIZE,
                    "Restart sequence %s could not be executed "
                    "(mode=%o), while searching (%s)",
                    pp->restart, statbuf.st_mode & 7777, pp->expr);

            CfLog(cferror,g_output,"");
            return;
        }

        snprintf(g_output, CF_BUFSIZE*2, 
                "Executing shell command: %s\n", pp->restart);
        CfLog(cfinform,g_output,"");

        if (g_dontdo) {
            return;
        }

        Verbose ("(Setting umask to %o)\n",pp->umask);
        maskval = umask(pp->umask);

        if (pp->umask == 0) {
            snprintf(g_output,CF_BUFSIZE*2,
                    "Programming %s running with umask 0! Use umask= to set\n",
                    pp->restart);
            CfLog(cfsilent,g_output,"");
        }

        if (pp->useshell == 'y') {
            if ((PIPE = cfpopen_shsetuid(pp->restart,"r",
                            pp->uid,pp->gid,pp->chdir,pp->chroot)) == NULL) {
                snprintf(g_output,CF_BUFSIZE*2,
                    "Process restart execution failed on %s\n",pp->restart);
                CfLog(cferror,g_output,"popen");
                return;
            }
        } else {
            if ((PIPE = cfpopensetuid(pp->restart,"r",pp->uid,pp->gid,
                            pp->chdir,pp->chroot)) == NULL) {
                snprintf(g_output,CF_BUFSIZE*2,
                    "Process restart execution failed on %s\n",pp->restart);
                CfLog(cferror,g_output,"popen");
                return;
            }
        }

        DEADLOCK = false;

        while (!feof(PIPE)) {
            /* dumb shell */
            if (pp->useshell == 'd') {
                fgets(line,1,PIPE);
                break;
            }

            ReadLine(line,CF_BUFSIZE,PIPE);

            if (feof(PIPE) || ferror(PIPE)) {
                break;
            }

            if (strstr(line,"cfengine-die")) {
                break;
            }

            /* patch for ERESTARTSYSTEM bug in popen */

            if (strstr(line,"cfd: start") || DEADLOCK) {
                break;
            }

            snprintf(g_output,CF_BUFSIZE*2,"Restart: %s",line);
            CfLog(cfinform,g_output,"");
        }

        if (pp->useshell == 'y') {
            pclose(PIPE);
        } else {
            cfpclose(PIPE);
        }

        snprintf(g_output,CF_BUFSIZE*2,"(Done with %s)\n",pp->restart);
        CfLog(cfinform,g_output,"");
        umask(maskval);
    }
}
Ejemplo n.º 7
0
void TokenTree::RecalcInheritanceChain(Token* token)
{
    if (!token)
        return;
    if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum | tkNamespace)))
        return;
    if (token->m_AncestorsString.IsEmpty())
        return;

    token->m_DirectAncestors.clear();
    token->m_Ancestors.clear();

    wxStringTokenizer tkz(token->m_AncestorsString, _T(","));
    TRACE(_T("RecalcInheritanceChain() : Token %s, Ancestors %s"), token->m_Name.wx_str(),
          token->m_AncestorsString.wx_str());
    TRACE(_T("RecalcInheritanceChain() : Removing ancestor string from %s"), token->m_Name.wx_str());
    token->m_AncestorsString.Clear();

    while (tkz.HasMoreTokens())
    {
        wxString ancestor = tkz.GetNextToken();
        if (ancestor.IsEmpty() || ancestor == token->m_Name)
            continue;

        TRACE(_T("RecalcInheritanceChain() : Ancestor %s"), ancestor.wx_str());

        // ancestors might contain namespaces, e.g. NS::Ancestor
        if (ancestor.Find(_T("::")) != wxNOT_FOUND)
        {
            Token* ancestorToken = 0;
            wxStringTokenizer anctkz(ancestor, _T("::"));
            while (anctkz.HasMoreTokens())
            {
                wxString ns = anctkz.GetNextToken();
                if (!ns.IsEmpty())
                {
                    int ancestorIdx = TokenExists(ns, ancestorToken ? ancestorToken->m_Index : -1,
                                                  tkNamespace | tkClass | tkTypedef);
                    ancestorToken = at(ancestorIdx);
                    if (!ancestorToken) // unresolved
                        break;
                }
            }
            if (   ancestorToken
                && ancestorToken != token
                && (ancestorToken->m_TokenKind == tkClass || ancestorToken->m_TokenKind == tkNamespace) )
            {
                TRACE(_T("RecalcInheritanceChain() : Resolved to %s"), ancestorToken->m_Name.wx_str());
                RecalcInheritanceChain(ancestorToken);
                token->m_Ancestors.insert(ancestorToken->m_Index);
                ancestorToken->m_Descendants.insert(token->m_Index);
                TRACE(_T("RecalcInheritanceChain() :  + '%s'"), ancestorToken->m_Name.wx_str());
            }
            else
            {
                TRACE(_T("RecalcInheritanceChain() :  ! '%s' (unresolved)"), ancestor.wx_str());
            }
        }
        else // no namespaces in ancestor
        {
            // accept multiple matches for inheritance
            TokenIdxSet result;
            FindMatches(ancestor, result, true, false);
            for (TokenIdxSet::const_iterator it = result.begin(); it != result.end(); ++it)
            {
                Token* ancestorToken = at(*it);
                // only classes take part in inheritance
                if (   ancestorToken
                    && (ancestorToken != token)
                    && (   (ancestorToken->m_TokenKind == tkClass)
                        || (ancestorToken->m_TokenKind == tkEnum)
                        || (ancestorToken->m_TokenKind == tkTypedef)
                        || (ancestorToken->m_TokenKind == tkNamespace) ) )
                {
                    RecalcInheritanceChain(ancestorToken);
                    token->m_Ancestors.insert(*it);
                    ancestorToken->m_Descendants.insert(token->m_Index);
                    TRACE(_T("RecalcInheritanceChain() :  + '%s'"), ancestorToken->m_Name.wx_str());
                }
            }
#if defined(CC_TOKEN_DEBUG_OUTPUT)
    #if CC_TOKEN_DEBUG_OUTPUT
            if (result.empty())
                TRACE(_T("RecalcInheritanceChain() :  ! '%s' (unresolved)"), ancestor.wx_str());
    #endif
#endif
        }

        // Now, we have calc all the direct ancestors
        token->m_DirectAncestors = token->m_Ancestors;
    }

#if defined(CC_TOKEN_DEBUG_OUTPUT)
    #if CC_TOKEN_DEBUG_OUTPUT
    wxStopWatch sw;
    TRACE(_T("RecalcInheritanceChain() : First iteration took : %ld ms"), sw.Time());
    sw.Start();
    #endif
#endif

    // recalc
    TokenIdxSet result;
    for (TokenIdxSet::const_iterator it = token->m_Ancestors.begin(); it != token->m_Ancestors.end(); ++it)
        RecalcFullInheritance(*it, result);

    // now, add the resulting set to ancestors set
    for (TokenIdxSet::const_iterator it = result.begin(); it != result.end(); ++it)
    {
        Token* ancestor = at(*it);
        if (ancestor)
        {
            token->m_Ancestors.insert(*it);
            ancestor->m_Descendants.insert(token->m_Index);
        }
    }

#if defined(CC_TOKEN_DEBUG_OUTPUT)
    #if CC_TOKEN_DEBUG_OUTPUT
    if (token)
    {
        // debug loop
        TRACE(_T("RecalcInheritanceChain() : Ancestors for %s:"), token->m_Name.wx_str());
        for (TokenIdxSet::const_iterator it = token->m_Ancestors.begin(); it != token->m_Ancestors.end(); ++it)
        {
            const Token* anc_token = at(*it);
            if (anc_token)
                TRACE(_T("RecalcInheritanceChain() :  + %s"), anc_token->m_Name.wx_str());
            else
                TRACE(_T("RecalcInheritanceChain() :  + NULL?!"));
        }
    }
    #endif
#endif

#if defined(CC_TOKEN_DEBUG_OUTPUT)
    #if CC_TOKEN_DEBUG_OUTPUT
    TRACE(_T("RecalcInheritanceChain() : Second iteration took : %ld ms"), sw.Time());
    #endif
#endif

    TRACE(_T("RecalcInheritanceChain() : Full inheritance calculated."));
}
Ejemplo n.º 8
0
void TokensTree::RecalcData()
{
//    Manager::Get()->GetMessageManager()->DebugLog(_T("Calculating full inheritance tree"));

    // first loop to convert ancestors string to token indices for each token
    for (size_t i = 0; i < size(); ++i)
    {
        Token* token = at(i);
        if (!token)
            continue;

        if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum)))
            continue;
        if (token->m_AncestorsString.IsEmpty())
            continue;
        // only local symbols might change inheritance
//        if (!token->m_IsLocal)
//            continue;

        token->m_DirectAncestors.clear();
        token->m_Ancestors.clear();
//        Manager::Get()->GetMessageManager()->DebugLog(_T(" : '%s'"), token->m_Name.c_str());

        //Manager::Get()->GetMessageManager()->DebugLog("Token %s, Ancestors %s", token->m_Name.c_str(), token->m_AncestorsString.c_str());
        wxStringTokenizer tkz(token->m_AncestorsString, _T(","));
        while (tkz.HasMoreTokens())
        {
            wxString ancestor = tkz.GetNextToken();
            if (ancestor.IsEmpty() || ancestor == token->m_Name)
                continue;
//            Manager::Get()->GetMessageManager()->DebugLog(_T("Ancestor %s"), ancestor.c_str());
            // ancestors might contain namespaces, e.g. NS::Ancestor
            if (ancestor.Find(_T("::")) != wxNOT_FOUND)
            {
                Token* ancestorToken = 0;
                wxStringTokenizer anctkz(ancestor, _T("::"));
                while (anctkz.HasMoreTokens())
                {
                    wxString ns = anctkz.GetNextToken();
                    if (!ns.IsEmpty())
                    {
                        int ancestorIdx = TokenExists(ns, ancestorToken ? ancestorToken->GetSelf() : -1, tkNamespace | tkClass | tkTypedef);
                        ancestorToken = at(ancestorIdx);
//                        ancestorToken = token->HasChildToken(ns, tkNamespace | tkClass);
                        if (!ancestorToken) // unresolved
                            break;
                    }
                }
                if (ancestorToken && ancestorToken != token && ancestorToken->m_TokenKind == tkClass)// && !ancestorToken->m_IsTypedef)
                {
//                    Manager::Get()->GetMessageManager()->DebugLog(_T("Resolved to %s"), ancestorToken->m_Name.c_str());
                    token->m_Ancestors.insert(ancestorToken->GetSelf());
                    ancestorToken->m_Descendants.insert(i);
//                    Manager::Get()->GetMessageManager()->DebugLog(_T("   + '%s'"), ancestorToken->m_Name.c_str());
                }
//                else
//                    Manager::Get()->GetMessageManager()->DebugLog(_T("   ! '%s' (unresolved)"), ancestor.c_str());
            }
            else // no namespaces in ancestor
            {
                // accept multiple matches for inheritance
                TokenIdxSet result;
                FindMatches(ancestor, result, true, false);
                for (TokenIdxSet::iterator it = result.begin(); it != result.end(); it++)
                {
                    Token* ancestorToken = at(*it);
                    // only classes take part in inheritance
                    if (ancestorToken && ancestorToken != token && (ancestorToken->m_TokenKind == tkClass || ancestorToken->m_TokenKind == tkEnum))// && !ancestorToken->m_IsTypedef)
                    {
                        token->m_Ancestors.insert(*it);
                        ancestorToken->m_Descendants.insert(i);
//                        Manager::Get()->GetMessageManager()->DebugLog(_T("   + '%s'"), ancestorToken->m_Name.c_str());
                    }
                }
//                if (result.empty())
//                    Manager::Get()->GetMessageManager()->DebugLog(_T("   ! '%s' (unresolved)"), ancestor.c_str());
            }
        }

        token->m_DirectAncestors = token->m_Ancestors;

        if (!token->m_IsLocal) // global symbols are linked once
        {
            //Manager::Get()->GetMessageManager()->DebugLog("Removing ancestor string from %s", token->m_Name.c_str(), token->m_Name.c_str());
            token->m_AncestorsString.Clear();
        }
    }

    // second loop to calculate full inheritance for each token
    for (size_t i = 0; i < size(); ++i)
    {
        Token* token = at(i);
        if (!token)
            continue;

        if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum)))
            continue;

        // recalc
        TokenIdxSet result;
        for (TokenIdxSet::iterator it = token->m_Ancestors.begin(); it != token->m_Ancestors.end(); it++)
            RecalcFullInheritance(*it, result);

        // now, add the resulting set to ancestors set
        for (TokenIdxSet::iterator it = result.begin(); it != result.end(); it++)
        {
            Token* ancestor = at(*it);
            if (ancestor)
            {
                token->m_Ancestors.insert(*it);
                ancestor->m_Descendants.insert(i);
            }
        }

//        // debug loop
//        Manager::Get()->GetMessageManager()->DebugLog(_T("Ancestors for %s:"),token->m_Name.c_str());
//        for (TokenIdxSet::iterator it = token->m_Ancestors.begin(); it != token->m_Ancestors.end(); it++)
//            Manager::Get()->GetMessageManager()->DebugLog(_T(" + %s"), at(*it)->m_Name.c_str());
    }
//    Manager::Get()->GetMessageManager()->DebugLog(_T("Full inheritance calculated."));
}
Ejemplo n.º 9
0
/*
 *	Send a caret position message.
 */
void SendCaretMessage( LPCLASSDATA lpcd )
{
	NMCARETPOSITION		nmcp;
	HWND			hParent;

	/*
	 *	Do we have a parent?
	 */
	if (( hParent = GetParent( lpcd->hWnd )) != NULL )
	{
		/*
		 *	Fill in the structure.
		 */
		nmcp.hdr.code		= NMBC_CARETPOSITION;
		nmcp.hdr.hwndFrom	= lpcd->hWnd;
		nmcp.hdr.idFrom		= GetWindowLong( lpcd->hWnd, GWL_ID );
		nmcp.ptCaretPos		= lpcd->ptCaretPos;

		/*
		 *	Convert to screen coordinates.
		 */
		nmcp.ptCaretPos.x = GetCaretOffset( lpcd, nmcp.ptCaretPos.x );
		nmcp.ptCaretPos.x++;
		nmcp.ptCaretPos.y++;

		/*
		 *	Send the notification if the
		 *	position really changed.
		 */
		if ( nmcp.ptCaretPos.x != lpcd->ptLastPositionSent.x ||
		     nmcp.ptCaretPos.y != lpcd->ptLastPositionSent.y )
		{
			SendMessage( hParent, WM_NOTIFY, nmcp.hdr.idFrom, ( LPARAM )&nmcp );
			lpcd->ptLastPositionSent = nmcp.ptCaretPos;
		}
	}


	/*
	 *	Re-render the line if current line
	 *	highlighting is on.
	 */
	if ( Parser->bHighlightCurrentLine )
	{
		if ( lpcd->ptCaretPos.y != Parser->nHighlighted ) RenderLine( lpcd, Parser->nHighlighted );
		RenderLine( lpcd, lpcd->ptCaretPos.y );
		Parser->nHighlighted = lpcd->ptCaretPos.y;
	}

	/*
	 *	Higlight brackets?
	 */
	if ( Parser->bColorBracketMatches )
	{
		/*
		 *	Render previous match ( if any )
		 */
		if ( lpcd->ptBracket1.y >= 0 ) RenderLine( lpcd, lpcd->ptBracket1.y );
		if ( lpcd->ptBracket2.y != lpcd->ptBracket1.y && lpcd->ptBracket2.y >= 0 ) RenderLine( lpcd, lpcd->ptBracket2.y );

		/*
		 *	Find match.
		 */
		if ( FindMatches( lpcd, &lpcd->ptBracket1, &lpcd->ptBracket2, TRUE ) < 0 )
		{
			/*
			 *	No match found. 
			 */
			lpcd->ptBracket1.x = lpcd->ptBracket1.y = -1;
			lpcd->ptBracket2.x = lpcd->ptBracket2.y = -1;
		}

		/*
		 *	Render the lines on which the
		 *	matches are found.
		 */
		if ( lpcd->ptBracket1.y >= 0 ) RenderLine( lpcd, lpcd->ptBracket1.y );
		if ( lpcd->ptBracket2.y != lpcd->ptBracket1.y && lpcd->ptBracket2.y >= 0 ) RenderLine( lpcd, lpcd->ptBracket2.y );
	}
}