コード例 #1
0
ファイル: TokenTreeView.cpp プロジェクト: nihilus/BinClone
void TokenTreeView::initTreeView(const CString &                        p_searchToken,
                                 const CloneFiles &                     p_cloneFiles,
                                 const CloneFiles::TokenRefsVector_t &  p_tokenRefsVec)

{
    CTreeCtrl & mytreectrl  = GetTreeCtrl();
    // initialize the assembly filename index map
    p_cloneFiles.getAsmFilesMap(m_asmFilesMap);

    CString root;
    root.Format(_T("Search Token string: \"%s\""),p_searchToken);
    HTREEITEM rootHitem = mytreectrl.InsertItem(root);

    CloneFiles::TokenRefsVector_t::const_iterator tokenRefVectItr    = p_tokenRefsVec.begin();
    CloneFiles::TokenRefsVector_t::const_iterator tokenRefVectEndItr = p_tokenRefsVec.end();
    for( ; tokenRefVectItr != tokenRefVectEndItr; ++tokenRefVectItr)
    {
        CString type(tokenRefVectItr->m_type);
        HTREEITEM refHitem = mytreectrl.InsertItem(type,rootHitem);

        // insert the token index nodes
        std::vector<IndexToken>::const_iterator tokenIdxItr    = tokenRefVectItr->m_indexTokenVector.begin();
        std::vector<IndexToken>::const_iterator tokenIdxEndItr = tokenRefVectItr->m_indexTokenVector.end();
        for(; tokenIdxItr != tokenIdxEndItr; ++tokenIdxItr)
        {
            CString token(tokenIdxItr->m_token);
            HTREEITEM tokeIdxHitem = mytreectrl.InsertItem(token,refHitem);

            // insert the reference nodes
            std::vector<Reference>::const_iterator referenceItr    = tokenIdxItr->m_reference.begin();
            std::vector<Reference>::const_iterator referenceEndItr = tokenIdxItr->m_reference.end();
            for(; referenceItr != referenceEndItr; ++referenceItr)
            {
                // get the fileId and line
                int fileId(referenceItr->m_fileId);
                int line(referenceItr->m_line);
                CString asmFile(m_asmFilesMap[fileId]);
                asmFile = asmFile.Mid(asmFile.ReverseFind(_T('\\'))+1);

                // format the item to be shown on a tree leap
                CString ref;
                ref.Format(_T("file=%s, line=%d"),asmFile,line);

                // add to the tree and our own m_refMap
                HTREEITEM refHitem = mytreectrl.InsertItem(ref,tokeIdxHitem);
                m_refMap.insert(std::make_pair(refHitem,*(referenceItr))); //refObj));
            }
        }
        mytreectrl.Expand(refHitem,TVE_EXPAND);
    }
}
コード例 #2
0
ファイル: AsmMain.cpp プロジェクト: doniexun/OrangeC
int AsmMain::Run(int argc, char *argv[])
{
    int rv = 0;
    Utils::banner(argv[0]);
    CmdSwitchFile internalConfig(SwitchParser);
    std::string configName = Utils::QualifiedFile(argv[0], ".cfg");
    std::fstream configTest(configName.c_str(), std::ios::in);
    if (configTest != NULL)
    {
        configTest.close();
        if (!internalConfig.Parse(configName.c_str()))
            Utils::fatal("Corrupt configuration file");
    }
    if (!SwitchParser.Parse(&argc, argv) || (argc == 1 && File.GetCount() <= 1))
    {
        Utils::usage(argv[0], usageText);
    }
    CmdFiles files(argv+1);
    if (File.GetValue())
        files.Add(File.GetValue() + 1);
    if (files.GetSize() > 1 && OutputFile.GetValue().size())
        Utils::fatal("Cannot specify output file for multiple input files");
    std::string sysSrchPth;
    std::string srchPth;
    if (includePath.GetValue().size())
    {
        size_t n = includePath.GetValue().find_first_of(';');
        if (n == std::string::npos)
        {
            sysSrchPth = includePath.GetValue();
        }
        else
        {
            sysSrchPth = includePath.GetValue().substr(0, n);
            srchPth = includePath.GetValue().substr(n+1);
        }
    }
    for (CmdFiles::FileNameIterator it = files.FileNameBegin(); it != files.FileNameEnd(); ++it)
    {
        std::string inName = (*it)->c_str();
        int npos = inName.find_last_of(".");
        if (npos == std::string::npos || npos && inName[npos-1] == '.' || (npos != inName.size()-1 && inName[npos+1] == CmdFiles::DIR_SEP[0]))
        {
            inName = Utils::QualifiedFile( (*it)->c_str(), ".asm");
        }
        PreProcessor pp(inName, srchPth, sysSrchPth,
                 false, false, '%', false, false, true);
        int n = Defines.GetCount();
        for (int i=0; i < n; i++)
        {
            CmdSwitchDefine::define *v = Defines.GetValue(i);
            pp.Define(v->name, v->value, false);
        }
        std::string outName;
        if (OutputFile.GetValue().size() != 0)
            outName = OutputFile.GetValue();
        else
            outName = Utils::QualifiedFile( (*it)->c_str(), ".o");
        if (PreprocessOnly.GetValue())
        {
            std::string working = Utils::QualifiedFile((*it)->c_str(), ".i");
            std::fstream out(working.c_str(), std::ios::out);
            if (out == NULL)
            {
                Utils::fatal(std::string(std::string("Could not open ") + working.c_str() + " for write.").c_str());
            }
            else
            {
                while (pp.GetLine(working))
                {
                    CheckAssign(working, pp);
                    out << working << std::endl;
                }
            }
            out.close();
        }
        else
        {
            Listing listing;
            AsmFile asmFile(pp, CaseInsensitive.GetValue(), listing);
            if (asmFile.Read())
            {
                if (!asmFile.Write(outName, inName) || Errors::ErrorCount())
                {
                    rv = 1;
                }
                else if (CreateListFile.GetValue())
                {
                    std::string listingName = Utils::QualifiedFile( (*it)->c_str(), ".lst");
                    if (!listing.Write(listingName, inName, CreateListFile.GetValue('m')))
                    {
                        rv = 1;
                    }
                }
            }
            else
            {
                rv = 1;
            }
        if (rv)
            unlink(outName.c_str());
        }
    }
    return rv;
}