diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:51:52 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:51:52 +0000 |
commit | 5f29bb8a675e8f96452b632e7129113f7dec850e (patch) | |
tree | 3d3f2a0d3ad10872a4dcaba8ec8d1d20c87ab147 /source/Host/common/Terminal.cpp | |
parent | 88c643b6fec27eec436c8d138fee6346e92337d6 (diff) |
Notes
Diffstat (limited to 'source/Host/common/Terminal.cpp')
-rw-r--r-- | source/Host/common/Terminal.cpp | 53 |
1 files changed, 13 insertions, 40 deletions
diff --git a/source/Host/common/Terminal.cpp b/source/Host/common/Terminal.cpp index be912fbe6155..4b536b03d852 100644 --- a/source/Host/common/Terminal.cpp +++ b/source/Host/common/Terminal.cpp @@ -1,9 +1,8 @@ //===-- Terminal.cpp --------------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -82,36 +81,30 @@ bool Terminal::SetCanonical(bool enabled) { return false; } -//---------------------------------------------------------------------- // Default constructor -//---------------------------------------------------------------------- TerminalState::TerminalState() : m_tty(), m_tflags(-1), #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED - m_termios_ap(), + m_termios_up(), #endif m_process_group(-1) { } -//---------------------------------------------------------------------- // Destructor -//---------------------------------------------------------------------- TerminalState::~TerminalState() {} void TerminalState::Clear() { m_tty.Clear(); m_tflags = -1; #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED - m_termios_ap.reset(); + m_termios_up.reset(); #endif m_process_group = -1; } -//---------------------------------------------------------------------- // Save the current state of the TTY for the file descriptor "fd" 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()) { @@ -119,11 +112,11 @@ bool TerminalState::Save(int fd, bool save_process_group) { 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 (m_termios_up == nullptr) + m_termios_up.reset(new struct termios); + int err = ::tcgetattr(fd, m_termios_up.get()); if (err != 0) - m_termios_ap.reset(); + m_termios_up.reset(); #endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED #ifndef LLDB_DISABLE_POSIX if (save_process_group) @@ -135,17 +128,15 @@ bool TerminalState::Save(int fd, bool save_process_group) { m_tty.Clear(); m_tflags = -1; #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED - m_termios_ap.reset(); + m_termios_up.reset(); #endif 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 { #ifndef LLDB_DISABLE_POSIX if (IsValid()) { @@ -155,12 +146,12 @@ bool TerminalState::Restore() const { #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED if (TTYStateIsValid()) - tcsetattr(fd, TCSANOW, m_termios_ap.get()); + tcsetattr(fd, TCSANOW, m_termios_up.get()); #endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED if (ProcessGroupIsValid()) { // Save the original signal handler. - void (*saved_sigttou_callback)(int) = NULL; + void (*saved_sigttou_callback)(int) = nullptr; saved_sigttou_callback = (void (*)(int))signal(SIGTTOU, SIG_IGN); // Set the process group tcsetpgrp(fd, m_process_group); @@ -173,60 +164,44 @@ bool TerminalState::Restore() const { 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()); } -//---------------------------------------------------------------------- // Returns true if m_tflags is valid -//---------------------------------------------------------------------- bool TerminalState::TFlagsIsValid() const { return m_tflags != -1; } -//---------------------------------------------------------------------- // Returns true if m_ttystate is valid -//---------------------------------------------------------------------- bool TerminalState::TTYStateIsValid() const { #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED - return m_termios_ap.get() != 0; + return m_termios_up != nullptr; #else return false; #endif } -//---------------------------------------------------------------------- // Returns true if m_process_group is valid -//---------------------------------------------------------------------- bool TerminalState::ProcessGroupIsValid() const { return static_cast<int32_t>(m_process_group) != -1; } -//------------------------------------------------------------------ // Constructor -//------------------------------------------------------------------ TerminalStateSwitcher::TerminalStateSwitcher() : m_currentState(UINT32_MAX) {} -//------------------------------------------------------------------ // Destructor -//------------------------------------------------------------------ TerminalStateSwitcher::~TerminalStateSwitcher() {} -//------------------------------------------------------------------ // Returns the number of states that this switcher contains -//------------------------------------------------------------------ uint32_t TerminalStateSwitcher::GetNumberOfStates() const { return llvm::array_lengthof(m_ttystates); } -//------------------------------------------------------------------ // Restore the state at index "idx". // // 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) @@ -248,12 +223,10 @@ bool TerminalStateSwitcher::Restore(uint32_t idx) const { return false; } -//------------------------------------------------------------------ // Save the state at index "idx" for file descriptor "fd" and save the process // group if requested. // // 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(); |