Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ IncludeCategories:
- Regex: '^<wx/wxprec.h>'
Priority: -1
SortPriority: 0
- Regex: '^"precompiled_header.h"'
Priority: -1
SortPriority: 0
- Regex: '^".*"'
Priority: 1
SortPriority: 0
Expand Down Expand Up @@ -54,7 +57,7 @@ SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
Standard: C++11
Standard: c++20
TabWidth: 4
UseTab: Never
SortIncludes: true
Expand Down
12 changes: 6 additions & 6 deletions CodeLite/AsyncProcess/ChildProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
ChildProcess::~ChildProcess()
{
#if USE_IPROCESS
if(m_process) {
if (m_process) {
m_process->Detach();
}
#else
if(m_childProcess) {
if (m_childProcess) {
m_childProcess->Detach();
}
#endif
Expand All @@ -25,7 +25,7 @@ namespace
{
wxString& wrap_with_quotes(wxString& str)
{
if(!str.empty() && str.Contains(" ") && !str.StartsWith("\"") && !str.EndsWith("\"")) {
if (!str.empty() && str.Contains(" ") && !str.StartsWith("\"") && !str.EndsWith("\"")) {
str.Prepend("\"").Append("\"");
}
return str;
Expand All @@ -34,7 +34,7 @@ wxString& wrap_with_quotes(wxString& str)

void ChildProcess::Start(const wxArrayString& args)
{
if(args.IsEmpty()) {
if (args.IsEmpty()) {
return;
}
#if USE_IPROCESS
Expand All @@ -51,7 +51,7 @@ void ChildProcess::Start(const wxArrayString& args)

// Launch the process
m_process.reset(::CreateAsyncProcess(this, command, IProcessCreateDefault | IProcessStderrEvent));
if(!m_process) {
if (!m_process) {
throw clException(wxString() << "Failed to execute process: " << command);
};
#else
Expand All @@ -63,7 +63,7 @@ void ChildProcess::Write(const wxString& message) { Write(StringUtils::ToStdStri

void ChildProcess::Write(const std::string& message)
{
if(!IsOk()) {
if (!IsOk()) {
return;
}
#if USE_IPROCESS
Expand Down
39 changes: 25 additions & 14 deletions CodeLite/AsyncProcess/TerminalEmulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@ class MyProcess : public wxProcess
: wxProcess(parent)
, m_parent(parent)
{
if(m_parent) { m_parent->m_myProcesses.push_back(this); }
if (m_parent) {
m_parent->m_myProcesses.push_back(this);
}
}

virtual ~MyProcess() { m_parent = NULL; }
void OnTerminate(int pid, int status)
{
if(m_parent) {
if (m_parent) {
clCommandEvent terminateEvent(wxEVT_TERMINAL_COMMAND_EXIT);
m_parent->AddPendingEvent(terminateEvent);
m_parent->m_pid = wxNOT_FOUND;

std::list<wxProcess*>::iterator iter =
std::find_if(m_parent->m_myProcesses.begin(), m_parent->m_myProcesses.end(),
[&](wxProcess* proc) { return proc == this; });
if(iter != m_parent->m_myProcesses.end()) { m_parent->m_myProcesses.erase(iter); }
std::list<wxProcess*>::iterator iter = std::find_if(m_parent->m_myProcesses.begin(),
m_parent->m_myProcesses.end(),
[&](wxProcess* proc) { return proc == this; });
if (iter != m_parent->m_myProcesses.end()) {
m_parent->m_myProcesses.erase(iter);
}
delete this;
}
}
Expand All @@ -61,8 +65,11 @@ TerminalEmulator::~TerminalEmulator()
}
}

bool TerminalEmulator::ExecuteConsole(const wxString& command, bool waitOnExit, const wxString& command_args,
const wxString& workingDirectory, const wxString& title)
bool TerminalEmulator::ExecuteConsole(const wxString& command,
bool waitOnExit,
const wxString& command_args,
const wxString& workingDirectory,
const wxString& title)
{
wxUnusedVar(title);
clConsoleBase::Ptr_t console = clConsoleBase::GetTerminal();
Expand All @@ -72,7 +79,7 @@ bool TerminalEmulator::ExecuteConsole(const wxString& command, bool waitOnExit,
console->SetCallback(new MyProcess(this));

wxString strTitle = title;
if(strTitle.IsEmpty()) {
if (strTitle.IsEmpty()) {
strTitle << "'" << command << "'";
} else {
strTitle.Prepend("'").Append("'");
Expand All @@ -94,9 +101,11 @@ void TerminalEmulator::OnProcessTerminated(clProcessEvent& event)

void TerminalEmulator::Terminate()
{
if(IsRunning()) {
if(m_process) { m_process->Terminate(); }
if(m_pid != wxNOT_FOUND) {
if (IsRunning()) {
if (m_process) {
m_process->Terminate();
}
if (m_pid != wxNOT_FOUND) {
wxKill(m_pid, wxSIGKILL, NULL, wxKILL_CHILDREN);
m_pid = wxNOT_FOUND;
}
Expand All @@ -114,15 +123,17 @@ void TerminalEmulator::OnProcessOutput(clProcessEvent& event)

bool TerminalEmulator::ExecuteNoConsole(const wxString& commandToRun, const wxString& workingDirectory)
{
if(m_process) {
if (m_process) {
// another process is running
return false;
}

wxString command;
#ifdef __WXMSW__
wxString shell = wxGetenv("COMSPEC");
if(shell.IsEmpty()) { shell = "CMD"; }
if (shell.IsEmpty()) {
shell = "CMD";
}

command << shell << wxT(" /c \"");
command << commandToRun << wxT("\"");
Expand Down
7 changes: 5 additions & 2 deletions CodeLite/AsyncProcess/TerminalEmulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ class WXDLLIMPEXP_CL TerminalEmulator : public wxEvtHandler
* "Hit any key to continue"
* @param title set the terminal title. If an empty string is provided, use the command as the title
*/
bool ExecuteConsole(const wxString& command, bool waitOnExit = false, const wxString& command_args = "",
const wxString& workingDirectory = "", const wxString& title = "");
bool ExecuteConsole(const wxString& command,
bool waitOnExit = false,
const wxString& command_args = "",
const wxString& workingDirectory = "",
const wxString& title = "");
/**
* @brief execute a command without attaching console
*/
Expand Down
3 changes: 1 addition & 2 deletions CodeLite/AsyncProcess/TerminalEmulatorFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ TerminalEmulatorFrame::TerminalEmulatorFrame(wxWindow* parent)
: TerminalEmulatorFrameBase(parent)
{
m_terminal = new TerminalEmulatorUI(this);
GetSizer()->Add(m_terminal, 1, wxEXPAND|wxALL);

GetSizer()->Add(m_terminal, 1, wxEXPAND | wxALL);
}
#endif // LIBCODELITE_WITH_UI
3 changes: 2 additions & 1 deletion CodeLite/AsyncProcess/TerminalEmulatorFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
#ifndef TERMINALEMULATORFRAME_H
#define TERMINALEMULATORFRAME_H

#include "TerminalEmulatorUIBase.h"
#include "TerminalEmulatorUI.h"
#include "TerminalEmulatorUIBase.h"
#if wxUSE_GUI
class WXDLLIMPEXP_CL TerminalEmulatorFrame : public TerminalEmulatorFrameBase
{
TerminalEmulatorUI* m_terminal;

public:
TerminalEmulatorFrame(wxWindow* parent);
virtual ~TerminalEmulatorFrame() = default;
Expand Down
10 changes: 5 additions & 5 deletions CodeLite/AsyncProcess/TerminalEmulatorUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ void TerminalEmulatorUI::OnSendCommand(wxCommandEvent& event) {}

void TerminalEmulatorUI::SetTerminal(TerminalEmulator* terminal)
{
if(m_terminal) {
if (m_terminal) {
DoUnBindTerminal(m_terminal);
}
this->m_terminal = terminal;
if(m_terminal) {
if (m_terminal) {
DoBindTerminal(m_terminal);
}
}

void TerminalEmulatorUI::OnProcessExit(clCommandEvent& e)
{
e.Skip();
if(m_terminal) {
if (m_terminal) {
DoUnBindTerminal(m_terminal);
m_terminal = NULL;
}
Expand All @@ -43,15 +43,15 @@ void TerminalEmulatorUI::OnProcessOutput(clCommandEvent& e)

void TerminalEmulatorUI::DoBindTerminal(TerminalEmulator* terminal)
{
if(terminal) {
if (terminal) {
terminal->Bind(wxEVT_TERMINAL_COMMAND_EXIT, &TerminalEmulatorUI::OnProcessExit, this);
terminal->Bind(wxEVT_TERMINAL_COMMAND_OUTPUT, &TerminalEmulatorUI::OnProcessOutput, this);
}
}

void TerminalEmulatorUI::DoUnBindTerminal(TerminalEmulator* terminal)
{
if(terminal) {
if (terminal) {
terminal->Unbind(wxEVT_TERMINAL_COMMAND_EXIT, &TerminalEmulatorUI::OnProcessExit, this);
terminal->Unbind(wxEVT_TERMINAL_COMMAND_OUTPUT, &TerminalEmulatorUI::OnProcessOutput, this);
}
Expand Down
9 changes: 5 additions & 4 deletions CodeLite/AsyncProcess/TerminalEmulatorUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,26 @@
#include <wx/setup.h>

#if wxUSE_GUI
#include "TerminalEmulatorUIBase.h"
#include "TerminalEmulator.h"
#include "TerminalEmulatorUIBase.h"

class WXDLLIMPEXP_CL TerminalEmulatorUI : public TerminalEmulatorUIBase
{
TerminalEmulator* m_terminal;

private:
void DoBindTerminal(TerminalEmulator* terminal);
void DoUnBindTerminal(TerminalEmulator* terminal);

public:
TerminalEmulatorUI(wxWindow* parent);
virtual ~TerminalEmulatorUI() = default;

void Clear();
void SetTerminal(TerminalEmulator* terminal) ;
void SetTerminal(TerminalEmulator* terminal);
TerminalEmulator* GetTerminal() { return m_terminal; }
wxStyledTextCtrl* GetTerminalOutputWindow() { return m_stc; }

protected:
virtual void OnSendCommand(wxCommandEvent& event);
void OnProcessExit(clCommandEvent& e);
Expand Down
16 changes: 8 additions & 8 deletions CodeLite/AsyncProcess/UnixProcess.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#ifndef UNIX_PROCESS_H
#define UNIX_PROCESS_H
#if defined(__WXGTK__) || defined(__WXOSX__)
#include <atomic>
#include <exception>
#include <functional>
#include <iostream>
#include <memory>
#include <sys/wait.h>
#include <thread>
#include <unistd.h>
#include <wx/thread.h>
#include <wx/msgqueue.h>
#include <atomic>
#include <wx/event.h>
#include <wx/msgqueue.h>
#include <wx/thread.h>

// Wrapping pipe in a class makes sure they are closed when we leave scope
#define CLOSE_FD(fd) \
if(fd != wxNOT_FOUND) { \
::close(fd); \
fd = wxNOT_FOUND; \
#define CLOSE_FD(fd) \
if (fd != wxNOT_FOUND) { \
::close(fd); \
fd = wxNOT_FOUND; \
}

class CPipe
Expand All @@ -39,7 +39,7 @@ class CPipe
bool Open()
{
int fd[2];
if(pipe(fd) == 0) {
if (pipe(fd) == 0) {
m_readFd = fd[0];
m_writeFd = fd[1];
return true;
Expand Down
6 changes: 3 additions & 3 deletions CodeLite/AsyncProcess/ZombieReaperPOSIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ ZombieReaperPOSIX::ZombieReaperPOSIX()

void* ZombieReaperPOSIX::Entry()
{
while(!TestDestroy()) {
while (!TestDestroy()) {
int status(0);
pid_t pid = ::waitpid((pid_t)-1, &status, WNOHANG);
if(pid > 0) {
if (pid > 0) {
// Notify about this process termination
wxProcessEvent event(0, pid, status);
event.SetEventType(wxEVT_CL_PROCESS_TERMINATED);
Expand All @@ -61,7 +61,7 @@ void* ZombieReaperPOSIX::Entry()

void ZombieReaperPOSIX::Stop()
{
if(IsAlive()) {
if (IsAlive()) {
Delete(NULL, wxTHREAD_WAIT_BLOCK);
} else {
Wait(wxTHREAD_WAIT_BLOCK);
Expand Down
13 changes: 7 additions & 6 deletions CodeLite/AsyncProcess/ZombieReaperPOSIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@

#ifndef __WXMSW__

#include <wx/event.h>
#include <wx/thread.h>
#include "codelite_exports.h"

#include <wx/event.h>
#include <wx/process.h>
#include <wx/thread.h>

wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_CL_PROCESS_TERMINATED, wxProcessEvent);

Expand All @@ -42,13 +43,13 @@ class WXDLLIMPEXP_CL ZombieReaperPOSIX : public wxThread
ZombieReaperPOSIX();
virtual ~ZombieReaperPOSIX() = default;

void Start() {
void Start()
{
Create();
Run();
}

void Stop();
};
#endif
#endif
#endif // ZOMBIEREAPERPOSIX_H

Loading
Loading