void DbgGdb::GetDebugeePID(const wxString& line) { if(m_debuggeePid == wxNOT_FOUND) { if(GetIsRemoteDebugging()) { m_debuggeePid = m_gdbProcess->GetPid(); } else { static wxRegEx reDebuggerPidWin(wxT("New Thread ([0-9]+)\\.(0[xX][0-9a-fA-F]+)")); static wxRegEx reGroupStarted(wxT("id=\"([0-9]+)\"")); static wxRegEx reSwitchToThread(wxT("Switching to process ([0-9]+)")); // test for the debuggee PID // in the line with the following pattern: // =thread-group-started,id="i1",pid="15599" if(m_debuggeePid < 0 && !line.IsEmpty()) { wxString debuggeePidStr; if(line.Contains(wxT("=thread-group-started")) && reGroupStarted.Matches(line)) { debuggeePidStr = reGroupStarted.GetMatch(line, 1); } else if(line.Contains(wxT("=thread-group-created")) && reGroupStarted.Matches(line)) { debuggeePidStr = reGroupStarted.GetMatch(line, 1); } else if(reDebuggerPidWin.Matches(line)) { debuggeePidStr = reDebuggerPidWin.GetMatch(line, 1); } else if(reSwitchToThread.Matches(line)) { debuggeePidStr = reSwitchToThread.GetMatch(line, 1); } if(!debuggeePidStr.IsEmpty()) { long iPid(0); if(debuggeePidStr.ToLong(&iPid)) { m_debuggeePid = iPid; wxString msg; msg << wxT(">> Debuggee process ID: ") << m_debuggeePid; m_observer->UpdateAddLine(msg); // Now there's a known pid, the debugger can be interrupted to let any to-be-disabled bps be // disabled. So... m_observer->DebuggerPidValid(); } } } } } }
double clClangFormatLocator::GetVersion(const wxString& clangFormat) const { double double_version = 3.3; #ifdef __WXGTK__ // Ubuntu clang-format version 3.5.0-4ubuntu2~trusty2 (tags/RELEASE_350/final) (based on LLVM 3.5.0) // Linux // LLVM version 3.3 // Linux, old format // clang-format version 3.6.0 (217570) // Windows double_version = 3.3; static wxRegEx reClangFormatVersion("version ([0-9]+\\.[0-9]+)"); wxString command; command << clangFormat; ::WrapWithQuotes(command); command << " --version"; wxString output = ProcUtils::SafeExecuteCommand(command); wxArrayString lines = ::wxStringTokenize(output, "\n", wxTOKEN_STRTOK); for(size_t i = 0; i < lines.GetCount(); ++i) { if(reClangFormatVersion.Matches(lines.Item(i))) { wxString version = reClangFormatVersion.GetMatch(lines.Item(i), 1); //wxLogMessage("clang-format version is %s", version); version.ToCDouble(&double_version); return double_version; } } #elif defined(__WXMSW__) double_version = 3.6; #else double_version = 3.5; #endif return double_version; // Default }
void CodeLiteApp::AdjustPathForCygwinIfNeeded() { #ifdef __WXMSW__ CL_DEBUG("AdjustPathForCygwinIfNeeded called"); if(!::clIsCygwinEnvironment()) { CL_DEBUG("Not running under Cygwin - nothing be done"); return; } CL_SYSTEM("Cygwin environment detected"); wxString cygwinRootDir; CompilerLocatorCygwin cygwin; if(cygwin.Locate()) { // this will return the base folder for cygwin (e.g. D:\cygwin) cygwinRootDir = (*cygwin.GetCompilers().begin())->GetInstallationPath(); } // Running under Cygwin // Adjust the PATH environment variable wxString pathEnv; ::wxGetEnv("PATH", &pathEnv); // Always add the default paths wxArrayString paths; if(!cygwinRootDir.IsEmpty()) { CL_SYSTEM("Cygwin root folder is: %s", cygwinRootDir); wxFileName cygwinBinFolder(cygwinRootDir, ""); cygwinBinFolder.AppendDir("bin"); paths.Add(cygwinBinFolder.GetPath()); } paths.Add("/usr/local/bin"); paths.Add("/usr/bin"); paths.Add("/usr/sbin"); paths.Add("/bin"); paths.Add("/sbin"); // Append the paths from the environment variables wxArrayString userPaths = ::wxStringTokenize(pathEnv, ";", wxTOKEN_STRTOK); paths.insert(paths.end(), userPaths.begin(), userPaths.end()); wxString fixedPath; for(size_t i = 0; i < paths.GetCount(); ++i) { wxString& curpath = paths.Item(i); static wxRegEx reCygdrive("/cygdrive/([A-Za-z])"); if(reCygdrive.Matches(curpath)) { // Get the drive letter wxString volume = reCygdrive.GetMatch(curpath, 1); volume << ":"; reCygdrive.Replace(&curpath, volume); } fixedPath << curpath << ";"; } CL_DEBUG("Setting PATH environment variable to:\n%s", fixedPath); ::wxSetEnv("PATH", fixedPath); #endif }
/** * Compare two references (e.g. "R100", "R19") and perform a 'natural' sort * This sorting must preserve numerical order rather than alphabetical * e.g. "R100" is lower (alphabetically) than "R19" * BUT should be placed after R19 */ int BOM_TABLE_GROUP::SortReferences( const wxString& aFirst, const wxString& aSecond ) { // Default sorting int defaultSort = aFirst.Cmp( aSecond ); static const wxString REGEX_STRING = "^([a-zA-Z]+)(\\d+)$"; // Compile regex statically static wxRegEx regexFirst( REGEX_STRING, wxRE_ICASE | wxRE_ADVANCED ); static wxRegEx regexSecond( REGEX_STRING, wxRE_ICASE | wxRE_ADVANCED ); if( !regexFirst.Matches( aFirst ) || !regexSecond.Matches( aSecond ) ) { return defaultSort; } // First priority is to order by prefix wxString prefixFirst = regexFirst.GetMatch( aFirst, 1 ); wxString prefixSecond = regexSecond.GetMatch( aSecond, 1 ); if( prefixFirst.CmpNoCase( prefixSecond ) != 0 ) // Different prefixes! { return defaultSort; } wxString numStrFirst = regexFirst.GetMatch( aFirst, 2 ); wxString numStrSecond = regexSecond.GetMatch( aSecond, 2 ); // If either match failed, just return normal string comparison if( numStrFirst.IsEmpty() || numStrSecond.IsEmpty() ) { return defaultSort; } // Convert each number string to an integer long numFirst = 0; long numSecond = 0; // If either conversion fails, return normal string comparison if( !numStrFirst.ToLong( &numFirst ) || !numStrSecond.ToLong( &numSecond ) ) { return defaultSort; } return (int) (numFirst - numSecond); }
void clTernServer::OnTernOutput(clProcessEvent& event) { static wxRegEx rePort("Listening on port ([0-9]+)"); if(rePort.IsValid() && rePort.Matches(event.GetOutput())) { wxString strPort = rePort.GetMatch(event.GetOutput(), 1); strPort.ToCLong(&m_port); } PrintMessage(event.GetOutput()); }
wxString CompilerLocatorCygwin::GetGCCVersion(const wxString& gccBinary) { static wxRegEx reVersion("([0-9]+\\.[0-9]+\\.[0-9]+)"); wxString command; command << gccBinary << " --version"; wxString versionString = ProcUtils::SafeExecuteCommand(command); if ( !versionString.IsEmpty() && reVersion.Matches( versionString ) ) { return reVersion.GetMatch( versionString ); } return wxEmptyString; }
void CppCheckReportPage::AppendLine(const wxString& line) { wxString tmpLine(line); // Locate status messages: // 6/7 files checked 85% done static wxRegEx reProgress(wxT("([0-9]+)/([0-9]+)( files checked )([0-9]+%)( done)")); static wxRegEx reFileName(wxT("(Checking )([a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)")); // Locate the progress messages and update our progress bar wxArrayString arrLines = wxStringTokenize(tmpLine, wxT("\n\r"), wxTOKEN_STRTOK); for(size_t i = 0; i < arrLines.GetCount(); i++) { if(reProgress.Matches(arrLines.Item(i))) { // Get the current progress wxString currentLine = reProgress.GetMatch(arrLines.Item(i), 1); long fileNo(0); currentLine.ToLong(&fileNo); } if(reFileName.Matches(arrLines.Item(i))) { // Get the file name wxString filename = reFileName.GetMatch(arrLines.Item(i), 2); m_mgr->SetStatusMessage("CppCheck: checking file " + filename); } } // Remove progress messages from the printed output reProgress.ReplaceAll(&tmpLine, wxEmptyString); tmpLine.Replace(wxT("\r"), wxT("")); tmpLine.Replace(wxT("\n\n"), wxT("\n")); m_stc->SetReadOnly(false); m_stc->AppendText(tmpLine); m_stc->SetReadOnly(true); m_stc->ScrollToLine(m_stc->GetLineCount() - 1); }
void OpenResourceDialog::GetLineNumberFromFilter(const wxString& filter, wxString& modFilter, long& lineNumber) { modFilter = filter; lineNumber = -1; static wxRegEx reNumber(":([0-9]+)", wxRE_ADVANCED); if(reNumber.IsValid() && reNumber.Matches(modFilter)) { wxString strLineNumber; strLineNumber = reNumber.GetMatch(modFilter, 1); strLineNumber.ToCLong(&lineNumber); reNumber.Replace(&modFilter, ""); } }
Falcon::Falcon(const std::string& ip) { _ip = ip; _http.SetMethod("GET"); _connected = _http.Connect(_ip); if (_connected) { std::string versionxml = GetURL("/status.xml"); std::string version = GetURL("/index.htm"); if (versionxml != "") { static wxRegEx versionregex("(\\<v\\>)([0-9]+\\.[0-9]+)\\<\\/v\\>", wxRE_ADVANCED | wxRE_NEWLINE); if (versionregex.Matches(wxString(versionxml))) { _version = versionregex.GetMatch(wxString(versionxml), 2).ToStdString(); } } else { //<title>F4V2 - v1.10</title> static wxRegEx versionregex("(title.*?v)([0-9]+\\.[0-9]+)\\<\\/title\\>", wxRE_ADVANCED | wxRE_NEWLINE); if (versionregex.Matches(wxString(version))) { _version = versionregex.GetMatch(wxString(version), 2).ToStdString(); } } static wxRegEx modelregex("(SW Version:.*?\\>)(F[0-9]+V[0-9]+)", wxRE_ADVANCED); if (modelregex.Matches(wxString(version))) { _model = modelregex.GetMatch(wxString(version), 2).ToStdString(); } } else { static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base")); logger_base.error("Error connecting to falcon controller on %s.", (const char *)_ip.c_str()); } }
void CppCheckReportPage::DoOpenLine(int outputLine) { static wxRegEx gccPattern(wxT("^([^ ][a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)([0-9]*)(:)([a-zA-Z ]*)")); static int fileIndex = 1; static int lineIndex = 3; wxString txt = m_stc->GetLine(outputLine); if(gccPattern.Matches(txt)) { wxString file = gccPattern.GetMatch(txt, fileIndex); wxString lineNumber = gccPattern.GetMatch(txt, lineIndex); if(file.IsEmpty() == false) { long n(0); lineNumber.ToCLong(&n); // Zero based line number if(n) n--; m_mgr->OpenFile(file, wxEmptyString, n); } } }
bool PHPEditorContextMenu::IsIncludeOrRequireStatement(wxString& includeWhat) { // Do a basic check to see whether this line is include statement or not. // Don't bother in full parsing the file since it can be a quite an expensive operation // (include|require_once|require|include_once)[ \t\\(]*(.*?)[\\) \t)]*; static wxRegEx reInclude(wxT("(include|require_once|require|include_once)[ \t\\(]*(.*?)[\\) \t]*;"), wxRE_ADVANCED); IEditor* editor = m_manager->GetActiveEditor(); if(!editor) return false; wxString line = editor->GetCtrl()->GetLine(editor->GetCurrentLine()); if(reInclude.IsValid() && reInclude.Matches(line)) { includeWhat = reInclude.GetMatch(line, 2); return true; } return false; }
wxString Compiler::GetGCCVersion() const { // Get the compiler version static wxRegEx reVersion("([0-9]+\\.[0-9]+\\.[0-9]+)"); wxString command; command << GetTool("CXX") << " --version"; wxArrayString out; ProcUtils::SafeExecuteCommand(command, out); if(out.IsEmpty()) { return ""; } if(reVersion.Matches(out.Item(0))) { return reVersion.GetMatch(out.Item(0)); } return ""; }
// When a a breakpoint is hit, see if it's got a command-list that needs faking void BreakptMgr::BreakpointHit(int id) { int index = FindBreakpointById(id, m_bps); if ((index == wxNOT_FOUND) || (index >= FIRST_INTERNAL_ID)) { return; } BreakpointInfo bp = m_bps.at(index); if (! bp.commandlist.IsEmpty()) { IDebugger *dbgr = DebuggerMgr::Get().GetActiveDebugger(); if (dbgr && dbgr->IsRunning()) { // A likely command, presumably at the end of the command-list, is 'continue' or 'cont' // Filter this out and do it separately, otherwise Manager::UpdateLostControl isn't called to blank the indicator static wxRegEx reContinue(wxT("(([[:space:]]|(^))((cont$)|(continue)))")); bool needsCont = false; wxString commands = bp.commandlist; if (reContinue.IsValid() && reContinue.Matches(commands)) { size_t start, len; if (reContinue.GetMatch(&start,&len)) { commands = commands.Left(start); needsCont = true; } } if (! commands.IsEmpty()) { // Just in case someone's _only_ command is 'continue' ! dbgr->ExecuteCmd(commands); } if (needsCont) { dbgr->Continue(); } } } if (bp.bp_type == BP_type_tempbreak) { // If this is a temporary bp, remove it from m_bps now it's been hit // Otherwise it will be treated as a 'Pending' bp, the button will be displayed // and, if clicked, the bp will be resurrected. int index = FindBreakpointById(id, m_bps); if (index != wxNOT_FOUND) { m_bps.erase(m_bps.begin()+index); } } }
inline int DetectRepeatingSymbols(wxString const &str, int pos) { int newPos = -1, currPos = pos; while (1) { if (currPos + 4 >= static_cast<int>(str.length())) break; if (str[currPos + 1] != wxT(',')) break; if (str[currPos + 3] == wxT('\'')) { const wxString &s = str.substr(currPos + 3, str.length() - (currPos + 3)); if (regexRepeatedChars.Matches(s)) { size_t start, length; regexRepeatedChars.GetMatch(&start, &length, 0); newPos = currPos + 3 + length; if ((newPos + 4 < static_cast<int>(str.length())) && str[newPos] == wxT(',') && str[newPos + 2] == wxT('"')) { newPos += 3; while (newPos < static_cast<int>(str.length()) && str[newPos] != wxT('"')) ++newPos; if (newPos + 1 < static_cast<int>(str.length()) && str[newPos] == wxT('"')) ++newPos; } currPos = newPos; } else break; } else break; // move the current position to point at the '"' character currPos--; } return newPos; }
IDbType* MySqlDbAdapter::parseTypeString(const wxString& typeString) { static wxRegEx reType(wxT("([a-zA-Z]+)(\\([0-9]+\\))?")); IDbType* type(NULL); if(reType.Matches(typeString)) { wxString typeName = reType.GetMatch(typeString, 1); wxString strSize = reType.GetMatch(typeString, 2); typeName.MakeUpper(); type = this->GetDbTypeByName(typeName); if(type) { strSize.Trim().Trim(false); if(strSize.StartsWith(wxT("("))) { strSize.Remove(0, 1); } if(strSize.EndsWith(wxT(")"))) { strSize.RemoveLast(); } long size = 0; if(strSize.ToLong(&size)){ type->SetSize(size); } } } return type; }
void AddIncludeFileDlg::OnButtonOK(wxCommandEvent &e) { wxUnusedVar(e); //get the include file to add wxString fullpath = m_textCtrlFullPath->GetValue(); static wxRegEx reIncludeFile(wxT("include *[\\\"\\<]{1}([a-zA-Z0-9_/\\.]*)")); wxString relativePath; if (reIncludeFile.Matches(m_textCtrlLineToAdd->GetValue())) { relativePath = reIncludeFile.GetMatch(m_textCtrlLineToAdd->GetValue(), 1); } fullpath.Replace(wxT("\\"), wxT("/")); relativePath.Replace(wxT("\\"), wxT("/")); wxFileName fn(fullpath); wxString inclPath; if (fullpath.EndsWith(relativePath, &inclPath) && fullpath != relativePath && //dont save the '.' path this is done by default fn.GetFullName() != relativePath) { //if the relative path is only file name, nothing to cache m_includePath.Add(inclPath); } EndModal(wxID_OK); }
LEditor* MainBook::OpenFile(const wxString& file_name, const wxString& projectName, int lineno, long position, OF_extra extra /*=OF_AddJump*/, bool preserveSelection /*=true*/) { wxFileName fileName(file_name); fileName.MakeAbsolute(); #ifdef __WXMSW__ // Handle cygwin paths wxString curpath = fileName.GetFullPath(); static wxRegEx reCygdrive("/cygdrive/([A-Za-z])"); if(reCygdrive.Matches(curpath)) { // Replace the /cygdrive/c with volume C: wxString volume = reCygdrive.GetMatch(curpath, 1); volume << ":"; reCygdrive.Replace(&curpath, volume); fileName = curpath; } #endif if(!IsFileExists(fileName)) { wxLogMessage(wxT("Failed to open: %s: No such file or directory"), fileName.GetFullPath().c_str()); return NULL; } if(FileExtManager::GetType(fileName.GetFullName()) == FileExtManager::TypeBmp) { // a bitmap file, open it using an image viewer DoOpenImageViewer(fileName); return NULL; } wxString projName = projectName; if(projName.IsEmpty()) { // try to match a project name to the file. otherwise, CC may not work projName = ManagerST::Get()->GetProjectNameByFile(fileName.GetFullPath()); } LEditor* editor = GetActiveEditor(true); BrowseRecord jumpfrom = editor ? editor->CreateBrowseRecord() : BrowseRecord(); editor = FindEditor(fileName.GetFullPath()); if(editor) { editor->SetProject(projName); } else if(fileName.IsOk() == false) { wxLogMessage(wxT("Invalid file name: ") + fileName.GetFullPath()); return NULL; } else if(!fileName.FileExists()) { wxLogMessage(wxT("File: ") + fileName.GetFullPath() + wxT(" does not exist!")); return NULL; } else { // A Nice trick: hide the notebook, open the editor // and then show it bool hidden(false); if(m_book->GetPageCount() == 0) hidden = GetSizer()->Hide(m_book); editor = new LEditor(m_book); editor->Create(projName, fileName); int sel = m_book->GetSelection(); if((extra & OF_PlaceNextToCurrent) && (sel != wxNOT_FOUND)) { AddPage(editor, fileName.GetFullName(), fileName.GetFullPath(), wxNullBitmap, false, sel + 1); } else { AddPage(editor, fileName.GetFullName(), fileName.GetFullPath()); } editor->SetSyntaxHighlight(); // mark the editor as read only if neede MarkEditorReadOnly(editor); // SHow the notebook if(hidden) GetSizer()->Show(m_book); if(position == wxNOT_FOUND && lineno == wxNOT_FOUND && editor->GetContext()->GetName() == wxT("C++")) { // try to find something interesting in the file to put the caret at // for now, just skip past initial blank lines and comments for(lineno = 0; lineno < editor->GetLineCount(); lineno++) { switch(editor->GetStyleAt(editor->PositionFromLine(lineno))) { case wxSTC_C_DEFAULT: case wxSTC_C_COMMENT: case wxSTC_C_COMMENTDOC: case wxSTC_C_COMMENTLINE: case wxSTC_C_COMMENTLINEDOC: continue; } // if we got here, it's a line to stop on break; } if(lineno == editor->GetLineCount()) { lineno = 1; // makes sure a navigation record gets saved } } } if(position != wxNOT_FOUND) { editor->SetEnsureCaretIsVisible(position, preserveSelection); editor->SetLineVisible(editor->LineFromPosition(position)); } else if(lineno != wxNOT_FOUND) { editor->CenterLine(lineno); } if(m_reloadingDoRaise) { if(GetActiveEditor() == editor) { editor->SetActive(); } else { SelectPage(editor); } } // Add this file to the history. Don't check for uniqueness: // if it's already on the list, wxFileHistory will move it to the top // Also, sync between the history object and the configuration file m_recentFiles.AddFileToHistory(fileName.GetFullPath()); clConfig::Get().AddRecentFile(fileName.GetFullPath()); if(extra & OF_AddJump) { BrowseRecord jumpto = editor->CreateBrowseRecord(); NavMgr::Get()->AddJump(jumpfrom, jumpto); } #if !CL_USE_NATIVEBOOK if(m_book->GetPageCount() == 1) { m_book->GetSizer()->Layout(); } #endif return editor; }
wxString TagEntry::FormatComment() { if(m_isCommentForamtted) return m_formattedComment; m_isCommentForamtted = true; m_formattedComment.Clear(); // Send the plugins an event requesting tooltip for this tag if(IsMethod()) { if(IsConstructor()) m_formattedComment << wxT("<b>[Constructor]</b>\n"); else if(IsDestructor()) m_formattedComment << wxT("<b>[Destructor]</b>\n"); TagEntryPtr p(new TagEntry(*this)); m_formattedComment << wxT("<code>") << TagsManagerST::Get()->FormatFunction(p, FunctionFormat_WithVirtual | FunctionFormat_Arg_Per_Line) << wxT("</code>\n"); m_formattedComment.Replace(GetName(), wxT("<b>") + GetName() + wxT("</b>")); } else if(IsClass()) { m_formattedComment << wxT("<b>Kind:</b> "); m_formattedComment << GetKind() << "\n"; if(GetInheritsAsString().IsEmpty() == false) { m_formattedComment << wxT("<b>Inherits:</b> "); m_formattedComment << GetInheritsAsString() << wxT("\n"); } } else if(IsMacro() || IsTypedef() || IsContainer() || GetKind() == wxT("member") || GetKind() == wxT("variable")) { m_formattedComment << wxT("<b>Kind:</b> "); m_formattedComment << GetKind() << "\n"; m_formattedComment << wxT("<b>Match Pattern:</b> "); // Prettify the match pattern wxString matchPattern(GetPattern()); matchPattern.Trim().Trim(false); if(matchPattern.StartsWith(wxT("/^"))) { matchPattern.Replace(wxT("/^"), wxT("")); } if(matchPattern.EndsWith(wxT("$/"))) { matchPattern.Replace(wxT("$/"), wxT("")); } matchPattern.Replace(wxT("\t"), wxT(" ")); while(matchPattern.Replace(wxT(" "), wxT(" "))) { } matchPattern.Trim().Trim(false); // BUG#3082954: limit the size of the 'match pattern' to a reasonable size (200 chars) matchPattern = TagsManagerST::Get()->WrapLines(matchPattern); matchPattern.Replace(GetName(), wxT("<b>") + GetName() + wxT("</b>")); m_formattedComment << wxT("<code>") << matchPattern << wxT("</code>\n"); } // Add comment section wxString tagComment; if(!GetFile().IsEmpty()) { CommentParseResult comments; ::ParseComments(GetFile().mb_str(wxConvUTF8).data(), comments); // search for comment in the current line, the line above it and 2 above it // use the first match we got for(size_t i = 0; i < 3; i++) { wxString comment = comments.getCommentForLine(GetLine()-i); if(!comment.IsEmpty()) { SetComment(comment); break; } } } if(!GetComment().IsEmpty()) { wxString theComment; theComment = GetComment(); theComment = TagsManagerST::Get()->WrapLines(theComment); theComment.Trim(false); wxString tagComment = wxString::Format(wxT("%s\n"), theComment.c_str()); if(m_formattedComment.IsEmpty() == false) { m_formattedComment.Trim().Trim(false); m_formattedComment << wxT("\n<hr>"); } m_formattedComment << tagComment; } // Update all "doxy" comments and surround them with <green> tags static wxRegEx reDoxyParam("([@\\\\]{1}param)[ \t]+([_a-z][a-z0-9_]*)?", wxRE_DEFAULT | wxRE_ICASE); static wxRegEx reDoxyBrief("([@\\\\]{1}(brief|details))[ \t]*", wxRE_DEFAULT | wxRE_ICASE); static wxRegEx reDoxyThrow("([@\\\\]{1}(throw|throws))[ \t]*", wxRE_DEFAULT | wxRE_ICASE); static wxRegEx reDoxyReturn("([@\\\\]{1}(return|retval|returns))[ \t]*", wxRE_DEFAULT | wxRE_ICASE); static wxRegEx reDoxyToDo("([@\\\\]{1}todo)[ \t]*", wxRE_DEFAULT | wxRE_ICASE); static wxRegEx reDoxyRemark("([@\\\\]{1}(remarks|remark))[ \t]*", wxRE_DEFAULT | wxRE_ICASE); static wxRegEx reDate("([@\\\\]{1}date)[ \t]*", wxRE_DEFAULT | wxRE_ICASE); static wxRegEx reFN("([@\\\\]{1}fn)[ \t]*", wxRE_DEFAULT | wxRE_ICASE); if(reDoxyParam.IsValid() && reDoxyParam.Matches(m_formattedComment)) { reDoxyParam.ReplaceAll(&m_formattedComment, "\n<b>Parameter</b>\n<i>\\2</i>"); } if(reDoxyBrief.IsValid() && reDoxyBrief.Matches(m_formattedComment)) { reDoxyBrief.ReplaceAll(&m_formattedComment, ""); } if(reDoxyThrow.IsValid() && reDoxyThrow.Matches(m_formattedComment)) { reDoxyThrow.ReplaceAll(&m_formattedComment, "\n<b>Throws</b>\n"); } if(reDoxyReturn.IsValid() && reDoxyReturn.Matches(m_formattedComment)) { reDoxyReturn.ReplaceAll(&m_formattedComment, "\n<b>Returns</b>\n"); } if(reDoxyToDo.IsValid() && reDoxyToDo.Matches(m_formattedComment)) { reDoxyToDo.ReplaceAll(&m_formattedComment, "\n<b>TODO</b>\n"); } if(reDoxyRemark.IsValid() && reDoxyRemark.Matches(m_formattedComment)) { reDoxyRemark.ReplaceAll(&m_formattedComment, "\n "); } if(reDate.IsValid() && reDate.Matches(m_formattedComment)) { reDate.ReplaceAll(&m_formattedComment, "<b>Date</b> "); } if(reFN.IsValid() && reFN.Matches(m_formattedComment)) { size_t fnStart, fnLen, fnEnd; if(reFN.GetMatch(&fnStart, &fnLen)) { fnEnd = m_formattedComment.find('\n', fnStart); if(fnEnd != wxString::npos) { // remove the string from fnStart -> fnEnd (including ther terminating \n) m_formattedComment.Remove(fnStart, (fnEnd - fnStart) + 1); } } } // if nothing to display skip this m_formattedComment.Trim().Trim(false); return m_formattedComment; }
void DebuggerTree::ParseEntry(WatchTreeEntry& entry, Watch* watch, wxString& text, long array_index) { if (text.IsEmpty()) return; // Manager::Get()->GetLogManager()->DebugLog(F(_T("DebuggerTree::ParseEntry(): %s"), text.c_str())); while (1) { // trim the string from left and right text.Trim(true); text.Trim(false); // find position of '{', '}' and ',' ***outside*** of any quotes. // decide which is nearer to the start int braceOpenPos = FindCharOutsideQuotes(text, _T('{')); if (braceOpenPos == -1) braceOpenPos = 0xFFFFFE; int braceClosePos = FindCharOutsideQuotes(text, _T('}')); if (braceClosePos == -1) braceClosePos = 0xFFFFFE; int commaPos = FindCommaPos(text); if (commaPos == -1) commaPos = 0xFFFFFE; int pos = std::min(commaPos, std::min(braceOpenPos, braceClosePos)); if (pos == 0xFFFFFE) { // no comma, opening or closing brace if (text.Right(3).Matches(_T(" = "))) text.Truncate(text.Length() - 3); if (!text.IsEmpty()) { entry.AddChild(text, watch); text.Clear(); } break; } else { // display array on a single line? // normal (multiple lines) display is taken care below, with array indexing if (watch && watch->is_array && braceOpenPos != 0xFFFFFE && braceClosePos != 0xFFFFFE) { wxString tmp = text.Left(braceClosePos + 1); // if more than one opening/closing brace, then it's a complex array so // ignore single-line if (text.Freq(_T('{')) == 1 && text.Freq(_T('}')) == 1) { // array on single line for up to 8 (by default) elements // if more elements, fall through to the multi-line display int commas = Manager::Get()->GetConfigManager(_T("debugger"))->ReadInt(_T("/single_line_array_elem_count"), 8); if (tmp.Freq(_T(',')) < commas) { // array watch type tmp[braceOpenPos] = _T('['); tmp.Last() = _T(']'); entry.AddChild(tmp, watch); text.Remove(0, braceClosePos + 1); continue; } } } wxString tmp = text.Left(pos); WatchTreeEntry* newchild = 0; if (tmp.Right(3).Matches(_T(" = "))) tmp.Truncate(tmp.Length() - 3); // remove " = " if last in string if (!tmp.IsEmpty()) { // take array indexing into account (if applicable) if (array_index != -1) { tmp.Prepend(wxString::Format(_T("[%ld]: "), array_index)); // if array element would occur multiple times, gdb adds as default "<repeated xx times> to the output // so we have to look for it and increase the array_index correctly // as default we increase by 1 long incIndex = 1; if (reRepeatedElements.Matches(tmp)) { reRepeatedElements.GetMatch(tmp, 1).ToLong(&incIndex); } array_index += incIndex; } newchild = &entry.AddChild(tmp, watch); } text.Remove(0, pos + 1); if (pos == braceOpenPos) { if (!newchild) newchild = &entry; // enable array indexing (if applicable) bool no_indexing = array_index == -1; if (watch && watch->is_array && no_indexing && text.Freq(_T('{')) == 0 && text.Freq(_T('}')) == 1) // don't index complex arrays { array_index = 0; } ParseEntry(*newchild, watch, text, array_index); // proceed one level deeper // reset array indexing if (no_indexing) array_index = -1; } else if (pos == braceClosePos) break; // return one level up } } }
void DbgGdb::Poke() { static wxRegEx reCommand( wxT( "^([0-9]{8})" ) ); //poll the debugger output wxString curline; if ( !m_gdbProcess || m_gdbOutputArr.IsEmpty() ) { return; } while ( DoGetNextLine( curline ) ) { GetDebugeePID(curline); // For string manipulations without damaging the original line read wxString tmpline ( curline ); StripString( tmpline ); tmpline.Trim().Trim( false ); if ( m_info.enableDebugLog ) { //Is logging enabled? if ( curline.IsEmpty() == false && !tmpline.StartsWith( wxT( ">" ) ) ) { wxString strdebug( wxT( "DEBUG>>" ) ); strdebug << curline; #if DBG_LOG if(gfp.IsOpened()) { gfp.Write(strdebug); gfp.Flush(); } #else m_observer->UpdateAddLine( strdebug ); #endif } } if ( reConnectionRefused.Matches( curline ) ) { StripString( curline ); #ifdef __WXGTK__ m_consoleFinder.FreeConsole(); #endif m_observer->UpdateAddLine( curline ); m_observer->UpdateGotControl( DBG_EXITED_NORMALLY ); return; } // Check for "Operation not permitted" usually means // that the process does not have enough permission to // attach to the process if( curline.Contains(wxT("Operation not permitted")) ) { #ifdef __WXGTK__ m_consoleFinder.FreeConsole(); #endif m_observer->UpdateAddLine( _("Failed to start debugger: permission denied") ); m_observer->UpdateGotControl( DBG_EXITED_NORMALLY ); return; } if( tmpline.StartsWith( wxT( ">" ) ) ) { // Shell line, probably user command line continue; } if ( curline.StartsWith( wxT( "~" ) ) || curline.StartsWith( wxT( "&" ) ) || curline.StartsWith("@") ) { // lines starting with ~ are considered "console stream" message // and are important to the CLI handler bool consoleStream( false ); bool targetConsoleStream(false); if ( curline.StartsWith( wxT( "~" ) ) ) { consoleStream = true; } if ( curline.StartsWith( wxT( "@" ) ) ) { targetConsoleStream = true; } // Filter out some gdb error lines... if ( FilterMessage( curline ) ) { continue; } StripString( curline ); // If we got a valid "CLI Handler" instead of writing the output to // the output view, concatenate it into the handler buffer if ( targetConsoleStream ) { m_observer->UpdateAddLine( curline ); } else if ( consoleStream && GetCliHandler()) { GetCliHandler()->Append( curline ); } else if ( consoleStream ) { // log message m_observer->UpdateAddLine( curline ); } } else if ( reCommand.Matches( curline ) ) { //not a gdb message, get the command associated with the message wxString id = reCommand.GetMatch( curline, 1 ); if ( GetCliHandler() && GetCliHandler()->GetCommandId() == id ) { // probably the "^done" message of the CLI command GetCliHandler()->ProcessOutput( curline ); SetCliHandler( NULL ); // we are done processing the CLI } else { //strip the id from the line curline = curline.Mid( 8 ); DoProcessAsyncCommand( curline, id ); } } else if ( curline.StartsWith( wxT( "^done" ) ) || curline.StartsWith( wxT( "*stopped" ) ) ) { //Unregistered command, use the default AsyncCommand handler to process the line DbgCmdHandlerAsyncCmd cmd( m_observer, this ); cmd.ProcessOutput( curline ); } else { //Unknow format, just log it if( m_info.enableDebugLog && !FilterMessage( curline ) ) { m_observer->UpdateAddLine( curline ); } } } }
void FindResultsTab::StyleText(wxStyledTextCtrl* ctrl, wxStyledTextEvent& e) { int startPos = ctrl->GetEndStyled(); int endPos = e.GetPosition(); wxString text = ctrl->GetTextRange(startPos, endPos); wxArrayString lines = ::wxStringTokenize(text, wxT("\r\n"), wxTOKEN_RET_DELIMS); ctrl->StartStyling(startPos, 0x1f); // text styling int bytes_left = 0; bool inMatchLine = false; int offset = 0; for(size_t i = 0; i < lines.GetCount(); ++i) { wxString curline = lines.Item(i); bytes_left = curline.length(); offset = 0; if(curline.StartsWith("/")) { ctrl->SetStyling(curline.Length(), LEX_FIF_MATCH_COMMENT); bytes_left = 0; } else if(curline.StartsWith(wxT(" "))) { ctrl->SetStyling(6, LEX_FIF_LINE_NUMBER); // first 6 chars are the line number bytes_left -= 6; inMatchLine = true; offset = 6; } else if(curline.StartsWith("=")) { ctrl->SetFoldLevel(ctrl->LineFromPosition(startPos) + i, 1 | wxSTC_FOLDLEVELHEADERFLAG); ctrl->SetStyling(curline.Length(), LEX_FIF_HEADER); // first 6 chars are the line number bytes_left = 0; } else if(curline == "\n") { // empty line ctrl->SetStyling(1, LEX_FIF_LINE_NUMBER); // first 6 chars are the line number inMatchLine = true; bytes_left = 0; } else { // File name ctrl->SetFoldLevel(ctrl->LineFromPosition(startPos) + i, 2 | wxSTC_FOLDLEVELHEADERFLAG); ctrl->SetStyling(curline.Length(), LEX_FIF_FILE); // first 6 chars are the line number bytes_left = 0; } // Check for scope static wxRegEx reScopeName(" \\[[\\<\\>a-z0-9_:~ ]+\\] ", wxRE_DEFAULT | wxRE_ICASE); size_t scopeStart = wxString::npos, scopeLen = 0; if(offset == 6 && reScopeName.Matches(curline)) { reScopeName.GetMatch(&scopeStart, &scopeLen); if(scopeStart == 6) { ctrl->SetStyling(scopeLen, LEX_FIF_SCOPE); bytes_left -= scopeLen; } } if(inMatchLine && bytes_left > 0) { // The remainder of this line should be a hyper link ctrl->SetStyling(bytes_left, LEX_FIF_MATCH); } else if(bytes_left > 0) { ctrl->SetStyling(bytes_left, LEX_FIF_DEFAULT); } } }
bool ParseCDBWatchValue(cb::shared_ptr<GDBWatch> watch, wxString const &value) { wxArrayString lines = GetArrayFromString(value, wxT('\n')); watch->SetDebugValue(value); watch->MarkChildsAsRemoved(); if (lines.GetCount() == 0) return false; static wxRegEx unexpected_error(wxT("^Unexpected token '.+'$")); static wxRegEx resolve_error(wxT("^Couldn't resolve error at '.+'$")); // search for errors for (unsigned ii = 0; ii < lines.GetCount(); ++ii) { if (unexpected_error.Matches(lines[ii]) || resolve_error.Matches(lines[ii]) || lines[ii] == wxT("No pointer for operator* '<EOL>'")) { watch->SetValue(lines[ii]); return true; } } if (lines.GetCount() == 1) { wxArrayString tokens = GetArrayFromString(lines[0], wxT(' ')); if (tokens.GetCount() < 2) return false; int type_token = 0; if (tokens[0] == wxT("class") || tokens[0] == wxT("struct")) type_token = 1; if (static_cast<int>(tokens.GetCount()) < type_token + 2) return false; int value_start = type_token + 1; if (tokens[type_token + 1] == wxT('*')) { watch->SetType(tokens[type_token] + tokens[type_token + 1]); value_start++; } else watch->SetType(tokens[type_token]); if(value_start >= static_cast<int>(tokens.GetCount())) return false; watch->SetValue(tokens[value_start]); watch->RemoveMarkedChildren(); return true; } else { wxArrayString tokens = GetArrayFromString(lines[0], wxT(' ')); if (tokens.GetCount() < 2) return false; bool set_type = true; if (tokens.GetCount() > 2) { if (tokens[0] == wxT("struct") || tokens[0] == wxT("class")) { if (tokens[2] == wxT('*') || tokens[2].StartsWith(wxT("["))) { watch->SetType(tokens[1] + tokens[2]); set_type = false; } } else { if (tokens[1] == wxT('*') || tokens[1].StartsWith(wxT("["))) { watch->SetType(tokens[0] + tokens[1]); watch->SetValue(lines[1]); return true; } } } if (set_type) watch->SetType(tokens[1]); static wxRegEx class_line(wxT("[ \\t]*\\+(0x[0-9a-f]+)[ \\t]([a-zA-Z0-9_]+)[ \\t]+:[ \\t]+(.+)")); if (!class_line.IsValid()) { int *p = NULL; *p = 0; } else { if (!class_line.Matches(wxT(" +0x000 a : 10"))) { int *p = NULL; *p = 0; } } for (unsigned ii = 1; ii < lines.GetCount(); ++ii) { if (class_line.Matches(lines[ii])) { cb::shared_ptr<GDBWatch> w = AddChild(watch, class_line.GetMatch(lines[ii], 2)); w->SetValue(class_line.GetMatch(lines[ii], 3)); w->SetDebugValue(lines[ii]); } } watch->RemoveMarkedChildren(); return true; } return false; }
//this allows copy/paste from Vixen grid: void RgbEffects::LoadPixelsFromTextFile(wxFile& debug, const wxString& filename) { imageCount = 0; imageIndex = 0; if (image.GetWidth() && image.GetHeight()) image.Clear(); //CAUTION: image must be non-empty to clear it (memory error otherwise) if (!PictureName.CmpNoCase(filename)) { wrdebug("no change: " + filename); return; } if (!wxFileExists(filename)) { wrdebug("not found: " + filename); return; } wxTextFile f; PixelsByFrame.clear(); if (!f.Open(filename.c_str())) { wrdebug("can't open: " + filename); return; } //read channel values from Vixen grid or routine: // std::vector<std::vector<std::pair<int, byte>>> ChannelsByFrame; //list of channel#s by frame and their associated value int numch = 0, chbase = 0, nodesize = 1; for (wxString linebuf = f.GetFirstLine(); !f.Eof(); linebuf = f.GetNextLine()) { std::string::size_type ofs; if ((ofs = linebuf.find("#")) != std::string::npos) linebuf.erase(ofs); //remove comments while (!linebuf.empty() && isspace(linebuf.Last())) linebuf.RemoveLast(); //trim trailing spaces if (linebuf.empty()) continue; //skip blank lines wrdebug(wxString::Format("read line '%s'", (const char*)linebuf.c_str())); static wxRegEx chbase_re("^\\s*ChannelBase\\s*=\\s*(-?[0-9]+)\\s*$", wxRE_ICASE); if (!PixelsByFrame.size() && chbase_re.Matches(linebuf)) //allow channels to be shifted { chbase = wxAtoi(chbase_re.GetMatch(linebuf, 1)); wrdebug(wxString::Format("got ch base %d", chbase)); continue; } static wxRegEx nodesize_re("^\\s*ChannelsPerNode\\s*=\\s*([13])\\s*$", wxRE_ICASE); if (!PixelsByFrame.size() && nodesize_re.Matches(linebuf)) //allow channels to be shifted { nodesize = wxAtoi(nodesize_re.GetMatch(linebuf, 1)); wrdebug(wxString::Format("got node size %d", nodesize)); continue; } PixelVector frame; wrdebug(wxString::Format("load channels for frame %d (%.3f sec): '" + linebuf + "'", PixelsByFrame.size(), PixelsByFrame.size() * 50/1000.)); wxStringTokenizer tkz(linebuf, " "); for (int chnum = 0; tkz.HasMoreTokens(); ++chnum) { wxByte chval = wxAtoi(tkz.GetNextToken()); wrdebug(wxString::Format("got chval %d for ch %d, frame %d", (int)chval, chnum, PixelsByFrame.size())); if (!chval) continue; //only need to remember channels that are on (assume most channels are off) std::pair<wxPoint, wxColor> new_pixel; static wxByte rgb[3]; switch (nodesize) { case 1: //map each Vixen channel to a monochrome pixel new_pixel.second.Set(chval, chval, chval); //grayscale break; case 3: //map Vixen triplets to an RGB pixel switch (chnum % 3) { case 0: rgb[0] = chval; continue; case 1: rgb[1] = chval; continue; case 2: rgb[2] = chval; break; } } new_pixel.second.Set(rgb[0], rgb[1], rgb[2]); // for (each wxPoint where chnum + chbase occurs in current model) frame.push_back(new_pixel); //build list of pixels that must be set if (chnum + 1 > numch) numch = chnum + 1; //vix grid or routine should be rectangular, but in case it isn't, pad out the shorter rows } PixelsByFrame.push_back(frame); //add new frame, MSVC 2010 doesn't support emplace_back } //now create an image to look like it was loaded like the other picture functions: // image.Create(maxcol + 1, pixels.size()); // for (int y = 0; y < pixels.size(); ++y) // for (int x = 0; x < pixels[y].size(); x += 3) // image.SetRGB(x, y, pixels[y][x + 0], pixels[y][x + 1], pixels[y][x + 2]); wrdebug(wxString::Format("read %d channels (relative to %d) x %d frames from Vixen, channels/node: %d", numch, chbase, PixelsByFrame.size(), nodesize)); // imageCount = 1; //TODO: allow multiple? // imageIndex = 0; PictureName = filename; }
void CDB_driver::ParseOutput(const wxString& output) { m_Cursor.changed = false; static wxString buffer; buffer << output << _T('\n'); m_pDBG->DebugLog(output); if (rePrompt.Matches(buffer)) { int idx = buffer.First(rePrompt.GetMatch(buffer)); cbAssert(idx != wxNOT_FOUND); m_ProgramIsStopped = true; m_QueueBusy = false; DebuggerCmd* cmd = CurrentCommand(); if (cmd) { RemoveTopCommand(false); buffer.Remove(idx); if (buffer[buffer.Length() - 1] == _T('\n')) buffer.Remove(buffer.Length() - 1); cmd->ParseOutput(buffer.Left(idx)); delete cmd; RunQueue(); } } else return; // come back later bool notifyChange = false; // non-command messages (e.g. breakpoint hits) // break them up in lines wxArrayString lines = GetArrayFromString(buffer, _T('\n')); for (unsigned int i = 0; i < lines.GetCount(); ++i) { // Log(_T("DEBUG: ") + lines[i]); // write it in the full debugger log if (lines[i].StartsWith(_T("Cannot execute "))) { Log(lines[i]); } else if (lines[i].Contains(_T("Access violation"))) { m_ProgramIsStopped = true; Log(lines[i]); m_pDBG->BringCBToFront(); Manager::Get()->GetDebuggerManager()->ShowBacktraceDialog(); DoBacktrace(true); InfoWindow::Display(_("Access violation"), lines[i]); break; } else if (notifyChange) continue; // Breakpoint 0 hit // > 38: if (!RegisterClassEx (&wincl)) else if (reBP.Matches(lines[i])) { m_ProgramIsStopped = true; Log(lines[i]); // Code breakpoint / assert m_pDBG->BringCBToFront(); Manager::Get()->GetDebuggerManager()->ShowBacktraceDialog(); DoBacktrace(true); break; } else if (lines[i].Contains(_T("Break instruction exception")) && !m_pDBG->IsTemporaryBreak()) { m_ProgramIsStopped = true; // Code breakpoint / assert m_pDBG->BringCBToFront(); Manager::Get()->GetDebuggerManager()->ShowBacktraceDialog(); DoBacktrace(true); break; } } if (notifyChange) NotifyCursorChanged(); buffer.Clear(); }
void NETLIST_OBJECT::ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItems ) { wxCHECK_RET( IsBusLabel( m_Label ), wxT( "<" ) + m_Label + wxT( "> is not a valid bus label." ) ); if( m_Type == NET_HIERLABEL ) m_Type = NET_HIERBUSLABELMEMBER; else if( m_Type == NET_GLOBLABEL ) m_Type = NET_GLOBBUSLABELMEMBER; else if( m_Type == NET_SHEETLABEL ) m_Type = NET_SHEETBUSLABELMEMBER; else if( m_Type == NET_LABEL ) m_Type = NET_BUSLABELMEMBER; else wxCHECK_RET( false, wxT( "Net list object type is not valid." ) ); unsigned i; wxString tmp, busName, busNumber; long begin, end, member; busName = busLabelRe.GetMatch( m_Label, 1 ); busNumber = busLabelRe.GetMatch( m_Label, 2 ); /* Search for '[' because a bus label is like "busname[nn..mm]" */ i = busNumber.Find( '[' ); i++; while( i < busNumber.Len() && busNumber[i] != '.' ) { tmp.Append( busNumber[i] ); i++; } tmp.ToLong( &begin ); while( i < busNumber.Len() && busNumber[i] == '.' ) i++; tmp.Empty(); while( i < busNumber.Len() && busNumber[i] != ']' ) { tmp.Append( busNumber[i] ); i++; } tmp.ToLong( &end ); if( begin < 0 ) begin = 0; if( end < 0 ) end = 0; if( begin > end ) std::swap( begin, end ); member = begin; tmp = busName; tmp << member; m_Label = tmp; m_Member = member; for( member++; member <= end; member++ ) { NETLIST_OBJECT* item = new NETLIST_OBJECT( *this ); // Conversion of bus label to the root name + the current member id. tmp = busName; tmp << member; item->m_Label = tmp; item->m_Member = member; aNetListItems.push_back( item ); } }
bool wxExFindOtherFileName( const wxFileName& filename, wxFileName* lastfile) { /* Add the base version if present. E.g. fullpath: F:\CCIS\v990308\com\atis\atis-ctrl\atis-ctrl.cc base: F:\CCIS\ append: \com\atis\atis-ctrl\atis-ctrl.cc */ const wxString fullpath = filename.GetFullPath(); const wxRegEx reg("[/|\\][a-z-]*[0-9]+\\.?[0-9]*\\.?[0-9]*\\.?[0-9]*"); if (!reg.Matches(fullpath.Lower())) { wxLogStatus(_("No version information found")); return false; } size_t start, len; if (!reg.GetMatch(&start, &len)) { wxFAIL; return false; } wxString base = fullpath.substr(0, start); if (!wxEndsWithPathSeparator(base)) { base += wxFileName::GetPathSeparator(); } wxDir dir(base); if (!dir.IsOpened()) { wxFAIL; return false; } wxString filename_string; bool cont = dir.GetFirst(&filename_string, wxEmptyString, wxDIR_DIRS); // only get dirs wxDateTime lastmodtime((time_t)0); const wxString append = fullpath.substr(start + len); bool found = false; // Readme: Maybe use a thread for this. while (cont) { wxFileName fn(base + filename_string + append); if (fn.FileExists() && fn.GetPath().CmpNoCase(filename.GetPath()) != 0 && fn.GetModificationTime() != filename.GetModificationTime()) { found = true; if (fn.GetModificationTime() > lastmodtime) { lastmodtime = fn.GetModificationTime(); *lastfile = fn; } } cont = dir.GetNext(&filename_string); if (wxTheApp != NULL) { wxTheApp->Yield(); } } if (!found) { wxLogStatus(_("No files found")); } return found; }
void EnvVarsTableDlg::OnExport(wxCommandEvent& event) { int selection = m_notebook1->GetSelection(); if(selection == wxNOT_FOUND) return; #ifdef __WXMSW__ bool isWindows = true; #else bool isWindows = false; #endif wxString text; if(selection == 0) { text = m_textCtrlDefault->GetText(); } else { EnvVarSetPage* page = dynamic_cast<EnvVarSetPage*>(m_notebook1->GetPage((size_t)selection)); if(page) { text = page->m_textCtrl->GetText(); } } if(text.IsEmpty()) return; wxArrayString lines = wxStringTokenize(text, wxT("\r\n"), wxTOKEN_STRTOK); wxString envfile; if(isWindows) { envfile << wxT("environment.bat"); } else { envfile << wxT("environment"); } wxFileName fn(wxGetCwd(), envfile); wxFFile fp(fn.GetFullPath(), wxT("w+b")); if(fp.IsOpened() == false) { wxMessageBox(wxString::Format(_("Failed to open file: '%s' for write"), fn.GetFullPath().c_str()), wxT("CodeLite"), wxOK | wxCENTER | wxICON_WARNING); return; } for(size_t i = 0; i < lines.GetCount(); i++) { wxString sLine = lines.Item(i).Trim().Trim(false); if(sLine.IsEmpty()) continue; static wxRegEx reVarPattern(wxT("\\$\\(( *)([a-zA-Z0-9_]+)( *)\\)")); if(isWindows) { while(reVarPattern.Matches(sLine)) { wxString varName = reVarPattern.GetMatch(sLine, 2); wxString text = reVarPattern.GetMatch(sLine); sLine.Replace(text, wxString::Format(wxT("%%%s%%"), varName.c_str())); } sLine.Prepend(wxT("set ")); sLine.Append(wxT("\r\n")); } else { while(reVarPattern.Matches(sLine)) { wxString varName = reVarPattern.GetMatch(sLine, 2); wxString text = reVarPattern.GetMatch(sLine); sLine.Replace(text, wxString::Format(wxT("$%s"), varName.c_str())); } sLine.Prepend(wxT("export ")); sLine.Append(wxT("\n")); } fp.Write(sLine); } wxMessageBox(wxString::Format(_("Environment exported to: '%s' successfully"), fn.GetFullPath().c_str()), wxT("CodeLite")); }
void DbgGdb::Poke() { static wxRegEx reCommand(wxT("^([0-9]{8})")); //poll the debugger output wxString line; if ( !m_gdbProcess || m_gdbOutputArr.IsEmpty() ) { return; } if (m_debuggeePid == wxNOT_FOUND) { if (GetIsRemoteDebugging()) { m_debuggeePid = m_gdbProcess->GetPid(); } else { std::vector<long> children; ProcUtils::GetChildren(m_gdbProcess->GetPid(), children); std::sort(children.begin(), children.end()); if (children.empty() == false) { m_debuggeePid = children.at(0); } if (m_debuggeePid != wxNOT_FOUND) { wxString msg; msg << wxT("Debuggee process ID: ") << m_debuggeePid; m_observer->UpdateAddLine(msg); } } } while ( DoGetNextLine( line ) ) { // For string manipulations without damaging the original line read wxString tmpline ( line ); StripString( tmpline ); tmpline.Trim().Trim(false); if (m_info.enableDebugLog) { //Is logging enabled? if (line.IsEmpty() == false && !tmpline.StartsWith(wxT(">")) ) { wxString strdebug(wxT("DEBUG>>")); strdebug << line; m_observer->UpdateAddLine(strdebug); } } if (reConnectionRefused.Matches(line)) { StripString(line); #ifdef __WXGTK__ m_consoleFinder.FreeConsole(); #endif m_observer->UpdateAddLine(line); m_observer->UpdateGotControl(DBG_EXITED_NORMALLY); return; } if( tmpline.StartsWith(wxT(">")) ) { // Shell line, probably user command line continue; } if (line.StartsWith(wxT("~")) || line.StartsWith(wxT("&"))) { // lines starting with ~ are considered "console stream" message // and are important to the CLI handler bool consoleStream(false); if ( line.StartsWith(wxT("~")) ) { consoleStream = true; } // Filter out some gdb error lines... if (FilterMessage(line)) { continue; } StripString( line ); // If we got a valid "CLI Handler" instead of writing the output to // the output view, concatenate it into the handler buffer if ( GetCliHandler() && consoleStream ) { GetCliHandler()->Append( line ); } else if ( consoleStream ) { // log message m_observer->UpdateAddLine( line ); } } else if (reCommand.Matches(line)) { //not a gdb message, get the command associated with the message wxString id = reCommand.GetMatch(line, 1); if ( GetCliHandler() && GetCliHandler()->GetCommandId() == id ) { // probably the "^done" message of the CLI command GetCliHandler()->ProcessOutput( line ); SetCliHandler( NULL ); // we are done processing the CLI } else { //strip the id from the line line = line.Mid(8); DoProcessAsyncCommand(line, id); } } else if (line.StartsWith(wxT("^done")) || line.StartsWith(wxT("*stopped"))) { //Unregistered command, use the default AsyncCommand handler to process the line DbgCmdHandlerAsyncCmd cmd(m_observer); cmd.ProcessOutput(line); } else { //Unknow format, just log it if( m_info.enableDebugLog && !FilterMessage(line)) { m_observer->UpdateAddLine(line); } } } }