⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configtool.cpp

📁 ecos实时嵌入式操作系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    rc=(! bWithBuildTools) || GetSettings().m_arstrBinDirs.Find(strPrefix, strBinDir);    if(!rc)    {        // Use fallback of previously-entered build tools directory, if available        if (!GetSettings().m_buildToolsDir.IsEmpty())        {            strBinDir = GetSettings().m_buildToolsDir ;            rc = TRUE;        }        else        {            wxCommandEvent event;            GetMainFrame()->OnBuildToolsPath(event);            rc = GetSettings().m_arstrBinDirs.Find(strPrefix, strBinDir);        }    }        if (rc)    {        if (!strBinDir.IsEmpty())        {            (* cmdLine) += wxString(wxT("export PATH=")) + wxString(strBinDir) + wxT(":$PATH; ");                        // Also set the path            wxString oldPath(wxGetenv(wxT("PATH")));            wxString path(strBinDir);            if (!oldPath.IsEmpty())            {                path += wxT(":");                path += oldPath;            }            wxSetEnv(wxT("PATH"), path);        }        (* cmdLine) += wxString(wxT("unset GDBTK_LIBRARY; ")) ;        wxUnsetEnv(wxT("GDBTK_LIBRARY"));                (* cmdLine) += wxString(wxT("unset GCC_EXEC_PREFIX; ")) ;        wxUnsetEnv(wxT("GCC_EXEC_PREFIX"));                (* cmdLine) += wxString(wxT("export ECOS_REPOSITORY=")) + wxString(pDoc->GetPackagesDir()) + wxT("; ");        wxSetEnv(wxT("ECOS_REPOSITORY"), pDoc->GetPackagesDir());        #if 0        ecFileName strUserBinDir(GetSettings().m_userToolsDir);        if(strUserBinDir.IsEmpty())        {            if ( 1 == GetSettings().m_userToolPaths.GetCount() )            {                GetSettings().m_userToolsDir = GetSettings().m_userToolPaths[0];            } else            {                wxCommandEvent event;                GetMainFrame()->OnUserToolsPath(event);            }            strUserBinDir = GetSettings().m_userToolsDir;        }        if ( !strUserBinDir.IsEmpty() )        {            // calculate the directory of the host tools from this application's module name            ecFileName strHostToolsBinDir(this->argv[0]);            strHostToolsBinDir = strHostToolsBinDir.Head ();                        // tools directories are in the order host-tools, user-tools, comp-tools, install/bin (if present), contrib-tools (if present) on the path                        // TODO: is this right? Assuming that the user tools are already in the user's path.            // const ecFileName strContribBinDir(strUserBinDir, wxT("..\\contrib\\bin"));            // const ecFileName strUsrBinDir(strUserBinDir, wxT("..\\usr\\bin"));            const ecFileName strInstallBinDir(pDoc->GetInstallTree (), wxT("bin"));                        (* cmdLine) += wxString(wxT("export PATH=")) + wxString(strInstallBinDir) + wxT(":$PATH; ");            (* cmdLine) += wxString(wxT("unset GDBTK_LIBRARY; ")) ;            (* cmdLine) += wxString(wxT("unset GCC_EXEC_PREFIX; ")) ;            (* cmdLine) += wxString(wxT("export ECOS_REPOSITORY=")) + wxString(pDoc->GetPackagesDir()) + wxT("; ");        }#endif    }    return rc;#endif}void ecApp::CygMount(wxChar c){    // May not be alpha if it's e.g. a UNC network path    if (!wxIsalpha(c))        return;        c = wxTolower(c);        if(!sm_arMounted[c-_TCHAR('a')])    {        sm_arMounted[c-wxChar('a')]=true;        wxString strCmd;        String strOutput;                strCmd.Printf(wxT("mount -t -u %c: /ecos-%c"),c,c);        CSubprocess sub;        sub.Run(strOutput,strCmd);    }    // Doing it with wxExecute results in a flashing DOS box unfortunately#if 0    wxASSERT(wxIsalpha(c));    c = wxTolower(c);    if(!sm_arMounted[c-wxChar('a')])    {        sm_arMounted[c-wxChar('a')] = TRUE;        wxString strCmd;                strCmd.Printf(wxT("mount.exe %c: /%c"),c,c);        wxExecute(strCmd, TRUE);    }#endif}// Fiddling directly with the registry DOESN'T WORK because Cygwin mount tables// get out of synch with the registryvoid ecApp::CygMountText(wxChar c){    wxASSERT(wxIsalpha(c));    c = wxTolower(c);//    if(!sm_arMounted[c-wxChar('a')])    {//        sm_arMounted[c-wxChar('a')] = TRUE;#if 0                wxString strCmd;                strCmd.Printf(wxT("mount.exe %c: /ecos-%c"),c,c);        wxExecute(strCmd, TRUE);#else        wxString key, value;        key.Printf(wxT("/ecos-%c"), c);        value.Printf(wxT("%c:"), c);        // Mount by fiddling with registry instead, so we don't see ugly flashing windows#ifdef __WXMSW__        HKEY hKey = 0;        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Cygnus Solutions\\Cygwin\\mounts v2",            0, KEY_READ, &hKey))        {            DWORD disposition;            HKEY hSubKey = 0;            if (ERROR_SUCCESS == RegCreateKeyEx(hKey, key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,                NULL, & hSubKey, & disposition))            {                RegSetValueEx(hSubKey, "native", 0, REG_SZ, (unsigned char*) (const wxChar*) value, value.Length() + 1);                RegCloseKey(hSubKey);            }                        RegCloseKey(hKey);        }#endif#endif    }}void ecApp::Build(const wxString &strWhat /*=wxT("")*/ ){    if (m_pipedProcess)        return;    ecConfigToolDoc* pDoc = GetConfigToolDoc();    if (!pDoc)        return;    if (!wxGetApp().GetMainFrame()->GetOutputWindow()->IsShown())    {        wxGetApp().GetMainFrame()->ToggleWindow(ecID_TOGGLE_OUTPUT);    }    if (!pDoc->GetDocumentSaved())    {        pDoc->SaveAs();    }/*    if (pDoc->IsModified() && !wxDirExists(pDoc->GetBuildTree()))    {        pDoc->SaveAs();    }*///    if ( !(pDoc->IsModified() || !wxDirExists(pDoc->GetBuildTree())) ) // verify the save worked    if ( pDoc->GetDocumentSaved() )    {        //wxString strCmd (wxT("c:\\bin\\testmake.bat"));        wxString strCmd (wxT("make"));        if(!strWhat.IsEmpty())        {            strCmd += wxT(' ');            strCmd += strWhat;        }        if(!GetSettings().m_strMakeOptions.IsEmpty())        {            strCmd += wxT(' ');            strCmd += GetSettings().m_strMakeOptions;        }        strCmd += wxT(" --directory ");        // Quoting the name may not mix with the 'sh' command on Unix, so only do it        // under Windows where it's more likely there will be spaces needing quoting.#ifdef __WXMSW__        wxString buildDir(pDoc->GetBuildTree());#if ecUSE_ECOS_X_NOTATION        std::string cPath = cygpath(std::string(pDoc->GetBuildTree()));        buildDir = cPath.c_str();#endif        strCmd += wxString(wxT("\"")) + buildDir + wxString(wxT("\""));#else        strCmd += wxString(pDoc->GetBuildTree()) ;#endif        wxString variableSettings;        if (PrepareEnvironment(TRUE, & variableSettings))        {#ifdef __WXMSW__            // strCmd is all we need#else            // strCmd has to invoke a shell with variables and make invocation            strCmd = wxString(wxT("sh -c \"")) + variableSettings + strCmd + wxString(wxT("\""));#endif            // Output the command so we know what we're doing            Log(strCmd);            Log(wxT("\n"));            // No: pass --directory            // wxSetWorkingDirectory(pDoc->GetBuildTree());            m_pipedProcess = new ecPipedProcess;            long pid = wxExecute(strCmd, FALSE, m_pipedProcess);            if ( pid )            {                m_pipedProcess->SetPid(pid);                // wxLogStatus(_T("Process %ld (%s) launched."), pid, cmd.c_str());            }            else            {                wxLogError(_T("Execution of '%s' failed."), strCmd.c_str());                                delete m_pipedProcess;                m_pipedProcess  = NULL;            }        }#if 0                if(PrepareEnvironment())        {            m_strBuildTarget=strWhat;            SetThermometerMax(250); // This is just a guess.  The thread we are about to spawn will work out the correct answer            m_nLogicalLines=0;            UpdateThermometer(0);            CloseHandle(CreateThread(NULL, 0, ThreadFunc, this, 0 ,&m_dwThreadId));            CString strMsg;            strMsg.Format(_T("Building %s"),strWhat);            SetIdleMessage(strMsg);                        SetTimer(42,1000,0); // This timer checks for process completion            SetCurrentDirectory(pDoc->BuildTree());            m_sp.Run(SubprocessOutputFunc, this, strCmd, false);            SetIdleMessage();        }#endif    }#if 0        if(pDoc->IsModified()||pDoc->BuildTree().IsEmpty()){        SendMessage (WM_COMMAND, ID_FILE_SAVE);    }        if(!(pDoc->IsModified()||pDoc->BuildTree().IsEmpty())){ // verify the save worked        CString strCmd (_T("make"));        if(!strWhat.IsEmpty()){            strCmd+=_TCHAR(' ');            strCmd+=strWhat;        }        if(!GetApp()->m_strMakeOptions.IsEmpty()){            strCmd+=_TCHAR(' ');            strCmd+=GetApp()->m_strMakeOptions;        }                if(PrepareEnvironment()){            m_strBuildTarget=strWhat;            SetThermometerMax(250); // This is just a guess.  The thread we are about to spawn will work out the correct answer            m_nLogicalLines=0;            UpdateThermometer(0);            CloseHandle(CreateThread(NULL, 0, ThreadFunc, this, 0 ,&m_dwThreadId));            CString strMsg;            strMsg.Format(_T("Building %s"),strWhat);            SetIdleMessage(strMsg);                        SetTimer(42,1000,0); // This timer checks for process completion            SetCurrentDirectory(pDoc->BuildTree());            m_sp.Run(SubprocessOutputFunc, this, strCmd, false);            SetIdleMessage();        }    }#endif}void ecApp::OnProcessTerminated(wxProcess* process){    m_pipedProcess = NULL;}// ----------------------------------------------------------------------------// ecPipedProcess// ----------------------------------------------------------------------------bool ecPipedProcess::HasInput(){    bool hasInput = FALSE;    wxInputStream& is = *GetInputStream();    if ( IsInputAvailable() )    {        wxTextInputStream tis(is);        // this assumes that the output is always line buffered        wxString msg;        msg << tis.ReadLine();        wxGetApp().Log(msg);        hasInput = TRUE;    }    wxInputStream& es = *GetErrorStream();    if ( IsErrorAvailable() )    {        wxTextInputStream tis(es);        // this assumes that the output is always line buffered        wxString msg;        msg << tis.ReadLine();        wxGetApp().Log(msg);        hasInput = TRUE;    }    return hasInput;}void ecPipedProcess::OnTerminate(int pid, int status){    // show the rest of the output    while ( HasInput() )        ;    wxGetApp().OnProcessTerminated(this);    //wxLogStatus(m_parent, _T("Process %u ('%s') terminated with exit code %d."),    //            pid, m_cmd.c_str(), status);    // we're not needed any more    delete this;}void ecPingTimer::Notify(){    static bool s_inNotify = FALSE;    if (s_inNotify)        return;    s_inNotify = TRUE;    // On Windows, simply having the timer going will ping the message queue    // and cause idle processing to happen.    // On Unix, this doesn't happen so we have to do the processing explicitly.#ifdef __WXMSW__    // Nothing to do#else    // Get some input    if ( wxGetApp().m_pipedProcess )        while (wxGetApp().m_pipedProcess->HasInput())        {            // Loop while there is still input        }#endif    s_inNotify = FALSE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -