summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/common/Terminal.cpp
diff options
context:
space:
mode:
authorKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
committerKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
commitb9c1b51e45b845debb76d8658edabca70ca56079 (patch)
treedfcb5a13ef2b014202340f47036da383eaee74aa /lldb/source/Host/common/Terminal.cpp
parentd5aa73376966339caad04013510626ec2e42c760 (diff)
downloadbcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz
bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
Diffstat (limited to 'lldb/source/Host/common/Terminal.cpp')
-rw-r--r--lldb/source/Host/common/Terminal.cpp332
1 files changed, 135 insertions, 197 deletions
diff --git a/lldb/source/Host/common/Terminal.cpp b/lldb/source/Host/common/Terminal.cpp
index c59766a7edb..022b3fa50a8 100644
--- a/lldb/source/Host/common/Terminal.cpp
+++ b/lldb/source/Host/common/Terminal.cpp
@@ -19,120 +19,91 @@
#include <termios.h>
#endif
-
using namespace lldb_private;
-bool
-Terminal::IsATerminal () const
-{
-
- return m_fd >= 0 && ::isatty (m_fd);
-}
-
+bool Terminal::IsATerminal() const { return m_fd >= 0 && ::isatty(m_fd); }
-bool
-Terminal::SetEcho (bool enabled)
-{
- if (FileDescriptorIsValid())
- {
+bool Terminal::SetEcho(bool enabled) {
+ if (FileDescriptorIsValid()) {
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
- if (IsATerminal ())
- {
- struct termios fd_termios;
- if (::tcgetattr(m_fd, &fd_termios) == 0)
- {
- bool set_corectly = false;
- if (enabled)
- {
- if (fd_termios.c_lflag & ECHO)
- set_corectly = true;
- else
- fd_termios.c_lflag |= ECHO;
- }
- else
- {
- if (fd_termios.c_lflag & ECHO)
- fd_termios.c_lflag &= ~ECHO;
- else
- set_corectly = true;
- }
-
- if (set_corectly)
- return true;
- return ::tcsetattr (m_fd, TCSANOW, &fd_termios) == 0;
- }
+ if (IsATerminal()) {
+ struct termios fd_termios;
+ if (::tcgetattr(m_fd, &fd_termios) == 0) {
+ bool set_corectly = false;
+ if (enabled) {
+ if (fd_termios.c_lflag & ECHO)
+ set_corectly = true;
+ else
+ fd_termios.c_lflag |= ECHO;
+ } else {
+ if (fd_termios.c_lflag & ECHO)
+ fd_termios.c_lflag &= ~ECHO;
+ else
+ set_corectly = true;
}
-#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
+
+ if (set_corectly)
+ return true;
+ return ::tcsetattr(m_fd, TCSANOW, &fd_termios) == 0;
+ }
}
- return false;
+#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
+ }
+ return false;
}
-bool
-Terminal::SetCanonical (bool enabled)
-{
- if (FileDescriptorIsValid())
- {
+bool Terminal::SetCanonical(bool enabled) {
+ if (FileDescriptorIsValid()) {
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
- if (IsATerminal ())
- {
- struct termios fd_termios;
- if (::tcgetattr(m_fd, &fd_termios) == 0)
- {
- bool set_corectly = false;
- if (enabled)
- {
- if (fd_termios.c_lflag & ICANON)
- set_corectly = true;
- else
- fd_termios.c_lflag |= ICANON;
- }
- else
- {
- if (fd_termios.c_lflag & ICANON)
- fd_termios.c_lflag &= ~ICANON;
- else
- set_corectly = true;
- }
-
- if (set_corectly)
- return true;
- return ::tcsetattr (m_fd, TCSANOW, &fd_termios) == 0;
- }
+ if (IsATerminal()) {
+ struct termios fd_termios;
+ if (::tcgetattr(m_fd, &fd_termios) == 0) {
+ bool set_corectly = false;
+ if (enabled) {
+ if (fd_termios.c_lflag & ICANON)
+ set_corectly = true;
+ else
+ fd_termios.c_lflag |= ICANON;
+ } else {
+ if (fd_termios.c_lflag & ICANON)
+ fd_termios.c_lflag &= ~ICANON;
+ else
+ set_corectly = true;
}
-#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
+
+ if (set_corectly)
+ return true;
+ return ::tcsetattr(m_fd, TCSANOW, &fd_termios) == 0;
+ }
}
- return false;
+#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
+ }
+ return false;
}
//----------------------------------------------------------------------
// Default constructor
//----------------------------------------------------------------------
-TerminalState::TerminalState() :
- m_tty(),
- m_tflags(-1),
+TerminalState::TerminalState()
+ : m_tty(), m_tflags(-1),
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
- m_termios_ap(),
+ m_termios_ap(),
#endif
- m_process_group(-1)
-{
+ m_process_group(-1) {
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
-TerminalState::~TerminalState()
-{
-}
+TerminalState::~TerminalState() {}
-void
-TerminalState::Clear ()
-{
- m_tty.Clear();
- m_tflags = -1;
+void TerminalState::Clear() {
+ m_tty.Clear();
+ m_tflags = -1;
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
- m_termios_ap.reset();
+ m_termios_ap.reset();
#endif
- m_process_group = -1;
+ m_process_group = -1;
}
//----------------------------------------------------------------------
@@ -140,142 +111,114 @@ TerminalState::Clear ()
// and if "save_process_group" is true, attempt to save the process
// group info for the TTY.
//----------------------------------------------------------------------
-bool
-TerminalState::Save (int fd, bool save_process_group)
-{
- m_tty.SetFileDescriptor(fd);
- if (m_tty.IsATerminal())
- {
+bool TerminalState::Save(int fd, bool save_process_group) {
+ m_tty.SetFileDescriptor(fd);
+ if (m_tty.IsATerminal()) {
#ifndef LLDB_DISABLE_POSIX
- m_tflags = ::fcntl (fd, F_GETFL, 0);
+ m_tflags = ::fcntl(fd, F_GETFL, 0);
#endif
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
- if (m_termios_ap.get() == NULL)
- m_termios_ap.reset (new struct termios);
- int err = ::tcgetattr (fd, m_termios_ap.get());
- if (err != 0)
- m_termios_ap.reset();
+ if (m_termios_ap.get() == NULL)
+ m_termios_ap.reset(new struct termios);
+ int err = ::tcgetattr(fd, m_termios_ap.get());
+ if (err != 0)
+ m_termios_ap.reset();
#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
#ifndef LLDB_DISABLE_POSIX
- if (save_process_group)
- m_process_group = ::tcgetpgrp (0);
- else
- m_process_group = -1;
-#endif
- }
+ if (save_process_group)
+ m_process_group = ::tcgetpgrp(0);
else
- {
- m_tty.Clear();
- m_tflags = -1;
+ m_process_group = -1;
+#endif
+ } else {
+ m_tty.Clear();
+ m_tflags = -1;
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
- m_termios_ap.reset();
+ m_termios_ap.reset();
#endif
- m_process_group = -1;
- }
- return IsValid();
+ m_process_group = -1;
+ }
+ return IsValid();
}
//----------------------------------------------------------------------
// Restore the state of the TTY using the cached values from a
// previous call to Save().
//----------------------------------------------------------------------
-bool
-TerminalState::Restore () const
-{
+bool TerminalState::Restore() const {
#ifndef LLDB_DISABLE_POSIX
- if (IsValid())
- {
- const int fd = m_tty.GetFileDescriptor();
- if (TFlagsIsValid())
- fcntl (fd, F_SETFL, m_tflags);
+ if (IsValid()) {
+ const int fd = m_tty.GetFileDescriptor();
+ if (TFlagsIsValid())
+ fcntl(fd, F_SETFL, m_tflags);
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
- if (TTYStateIsValid())
- tcsetattr (fd, TCSANOW, m_termios_ap.get());
+ if (TTYStateIsValid())
+ tcsetattr(fd, TCSANOW, m_termios_ap.get());
#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
- if (ProcessGroupIsValid())
- {
- // Save the original signal handler.
- void (*saved_sigttou_callback) (int) = NULL;
- saved_sigttou_callback = (void (*)(int)) signal (SIGTTOU, SIG_IGN);
- // Set the process group
- tcsetpgrp (fd, m_process_group);
- // Restore the original signal handler.
- signal (SIGTTOU, saved_sigttou_callback);
- }
- return true;
+ if (ProcessGroupIsValid()) {
+ // Save the original signal handler.
+ void (*saved_sigttou_callback)(int) = NULL;
+ saved_sigttou_callback = (void (*)(int))signal(SIGTTOU, SIG_IGN);
+ // Set the process group
+ tcsetpgrp(fd, m_process_group);
+ // Restore the original signal handler.
+ signal(SIGTTOU, saved_sigttou_callback);
}
+ return true;
+ }
#endif
- return false;
+ return false;
}
-
-
-
//----------------------------------------------------------------------
// Returns true if this object has valid saved TTY state settings
// that can be used to restore a previous state.
//----------------------------------------------------------------------
-bool
-TerminalState::IsValid() const
-{
- return m_tty.FileDescriptorIsValid () && (TFlagsIsValid() || TTYStateIsValid());
+bool TerminalState::IsValid() const {
+ return m_tty.FileDescriptorIsValid() &&
+ (TFlagsIsValid() || TTYStateIsValid());
}
//----------------------------------------------------------------------
// Returns true if m_tflags is valid
//----------------------------------------------------------------------
-bool
-TerminalState::TFlagsIsValid() const
-{
- return m_tflags != -1;
-}
+bool TerminalState::TFlagsIsValid() const { return m_tflags != -1; }
//----------------------------------------------------------------------
// Returns true if m_ttystate is valid
//----------------------------------------------------------------------
-bool
-TerminalState::TTYStateIsValid() const
-{
+bool TerminalState::TTYStateIsValid() const {
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
- return m_termios_ap.get() != 0;
+ return m_termios_ap.get() != 0;
#else
- return false;
+ return false;
#endif
}
//----------------------------------------------------------------------
// Returns true if m_process_group is valid
//----------------------------------------------------------------------
-bool
-TerminalState::ProcessGroupIsValid() const
-{
- return static_cast<int32_t>(m_process_group) != -1;
+bool TerminalState::ProcessGroupIsValid() const {
+ return static_cast<int32_t>(m_process_group) != -1;
}
//------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------
-TerminalStateSwitcher::TerminalStateSwitcher () :
- m_currentState(UINT32_MAX)
-{
-}
+TerminalStateSwitcher::TerminalStateSwitcher() : m_currentState(UINT32_MAX) {}
//------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------
-TerminalStateSwitcher::~TerminalStateSwitcher ()
-{
-}
+TerminalStateSwitcher::~TerminalStateSwitcher() {}
//------------------------------------------------------------------
// Returns the number of states that this switcher contains
//------------------------------------------------------------------
-uint32_t
-TerminalStateSwitcher::GetNumberOfStates() const
-{
- return llvm::array_lengthof(m_ttystates);
+uint32_t TerminalStateSwitcher::GetNumberOfStates() const {
+ return llvm::array_lengthof(m_ttystates);
}
//------------------------------------------------------------------
@@ -283,28 +226,26 @@ TerminalStateSwitcher::GetNumberOfStates() const
//
// Returns true if the restore was successful, false otherwise.
//------------------------------------------------------------------
-bool
-TerminalStateSwitcher::Restore (uint32_t idx) const
-{
- const uint32_t num_states = GetNumberOfStates();
- if (idx >= num_states)
- return false;
-
- // See if we already are in this state?
- if (m_currentState < num_states && (idx == m_currentState) && m_ttystates[idx].IsValid())
- return true;
-
- // Set the state to match the index passed in and only update the
- // current state if there are no errors.
- if (m_ttystates[idx].Restore())
- {
- m_currentState = idx;
- return true;
- }
-
- // We failed to set the state. The tty state was invalid or not
- // initialized.
+bool TerminalStateSwitcher::Restore(uint32_t idx) const {
+ const uint32_t num_states = GetNumberOfStates();
+ if (idx >= num_states)
return false;
+
+ // See if we already are in this state?
+ if (m_currentState < num_states && (idx == m_currentState) &&
+ m_ttystates[idx].IsValid())
+ return true;
+
+ // Set the state to match the index passed in and only update the
+ // current state if there are no errors.
+ if (m_ttystates[idx].Restore()) {
+ m_currentState = idx;
+ return true;
+ }
+
+ // We failed to set the state. The tty state was invalid or not
+ // initialized.
+ return false;
}
//------------------------------------------------------------------
@@ -313,13 +254,10 @@ TerminalStateSwitcher::Restore (uint32_t idx) const
//
// Returns true if the restore was successful, false otherwise.
//------------------------------------------------------------------
-bool
-TerminalStateSwitcher::Save (uint32_t idx, int fd, bool save_process_group)
-{
- const uint32_t num_states = GetNumberOfStates();
- if (idx < num_states)
- return m_ttystates[idx].Save(fd, save_process_group);
- return false;
+bool TerminalStateSwitcher::Save(uint32_t idx, int fd,
+ bool save_process_group) {
+ const uint32_t num_states = GetNumberOfStates();
+ if (idx < num_states)
+ return m_ttystates[idx].Save(fd, save_process_group);
+ return false;
}
-
-
OpenPOWER on IntegriCloud