From patchwork Wed May 13 21:12:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 6719 Received: (qmail 52243 invoked by alias); 13 May 2015 21:12:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 52220 invoked by uid 89); 13 May 2015 21:12:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qc0-f175.google.com Received: from mail-qc0-f175.google.com (HELO mail-qc0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 13 May 2015 21:12:45 +0000 Received: by qcvo8 with SMTP id o8so29798415qcv.0 for ; Wed, 13 May 2015 14:12:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=H9Khmjs1QrFUIJY/KQY6dtBddm3BncwvjvhvJ9a5NF8=; b=ZSphoYBi44tF1HkSibfFBFlQveiormyDY2qW5EFmTfPotG9nE/LVtqKFsmdj//PqfS 71zyGcz2umLwYNPoi3mwGFXWLUOKzZ/xRsDy11w7zpalHFRW2WMHCjDX0dQNfK7c6QEf UESmbDRCGa58ZAnjNfvTCVvIUyh8FQRx+HWSk7OL8tluT1OtDhLNXMrghdWwGXh8KUt8 3/HotI7NA0FsOInqTXPrmRa34vUieipt54gWe4YPRlKGdNT5IB+FOW+jjomL3ZJ64Uql cCHbQAiaTbMT0WTzegDZROsnW31xrfhlFAk+Tv9nzTElkq4eVIbQcbgnRDViu8SIi0UO CjCw== X-Gm-Message-State: ALoCoQncEqemwnCLUMYt3qOacJtooLxgWgqKqn87Z35xwJIhi/HLeX7mjLeHPqQxBl6pvuEKgg97 X-Received: by 10.55.20.215 with SMTP id 84mr1954676qku.51.1431551563680; Wed, 13 May 2015 14:12:43 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by mx.google.com with ESMTPSA id h14sm16388297qhc.46.2015.05.13.14.12.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 May 2015 14:12:43 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Remove buggy xterm workaround in tui_dispatch_ctrl_char() Date: Wed, 13 May 2015 17:12:38 -0400 Message-Id: <1431551558-7144-1-git-send-email-patrick@parcs.ath.cx> The function tui_dispatch_ctrl_char() has an old workaround (from 1999) for buggy terminals and/or ncurses library that don't return page up/down keys as single characters. Because the workaround is so old, I think the bug it is targetting is no longer relevant anymore. But more importantly, the workaround is itself buggy: it 1) performs a blocking call to wgetch() and 2) if the key returned by wgetch() does not make up a relevant key sequence it throws away the input instead of pushing it back via ungetch(). And indeed the workaround breaks Alt-key sequences under TERM=xterm because of bug #2. So this patch removes the buggy workaround and tidies up the function accordingly. I personally tested this change on a recent xterm (with TERM=xterm) in Fedora 20 and had no problems with having ncurses properly interpret page up/down keys. And Alt-key sequences now work when TERM=xterm too. gdb/ChangeLog: * tui/tui-command.c: Remove include of . (tui_dispatch_ctrl_char): Remove workaround for xterm terminals. --- gdb/tui/tui-command.c | 105 +++++++++++++++----------------------------------- 1 file changed, 32 insertions(+), 73 deletions(-) diff --git a/gdb/tui/tui-command.c b/gdb/tui/tui-command.c index 3551063..03ec076 100644 --- a/gdb/tui/tui-command.c +++ b/gdb/tui/tui-command.c @@ -20,7 +20,6 @@ along with this program. If not, see . */ #include "defs.h" -#include #include "tui/tui.h" #include "tui/tui-data.h" #include "tui/tui-win.h" @@ -54,80 +53,40 @@ tui_dispatch_ctrl_char (unsigned int ch) on through and do nothing here. */ if (win_info == NULL || win_info == TUI_CMD_WIN) return ch; - else + + switch (ch) { - unsigned int c = 0, ch_copy = ch; - int i; - char *term; - - /* If this is an xterm, page next/prev keys aren't returned by - keypad as a single char, so we must handle them here. Seems - like a bug in the curses library? */ - term = (char *) getenv ("TERM"); - if (term) - { - for (i = 0; term[i]; i++) - term[i] = toupper (term[i]); - if ((strcmp (term, "XTERM") == 0) - && key_is_start_sequence (ch)) - { - unsigned int page_ch = 0; - unsigned int tmp_char; - WINDOW *w = TUI_CMD_WIN->generic.handle; - - tmp_char = 0; - while (!key_is_end_sequence (tmp_char)) - { - tmp_char = (int) wgetch (w); - if (tmp_char == ERR) - { - return ch; - } - if (!tmp_char) - break; - if (tmp_char == 53) - page_ch = KEY_PPAGE; - else if (tmp_char == 54) - page_ch = KEY_NPAGE; - else - { - return 0; - } - } - ch_copy = page_ch; - } - } - - switch (ch_copy) - { - case KEY_NPAGE: - tui_scroll_forward (win_info, 0); - break; - case KEY_PPAGE: - tui_scroll_backward (win_info, 0); - break; - case KEY_DOWN: - case KEY_SF: - tui_scroll_forward (win_info, 1); - break; - case KEY_UP: - case KEY_SR: - tui_scroll_backward (win_info, 1); - break; - case KEY_RIGHT: - tui_scroll_left (win_info, 1); - break; - case KEY_LEFT: - tui_scroll_right (win_info, 1); - break; - case '\f': - break; - default: - c = ch_copy; - break; - } - return c; + case KEY_NPAGE: + tui_scroll_forward (win_info, 0); + break; + case KEY_PPAGE: + tui_scroll_backward (win_info, 0); + break; + case KEY_DOWN: + case KEY_SF: + tui_scroll_forward (win_info, 1); + break; + case KEY_UP: + case KEY_SR: + tui_scroll_backward (win_info, 1); + break; + case KEY_RIGHT: + tui_scroll_left (win_info, 1); + break; + case KEY_LEFT: + tui_scroll_right (win_info, 1); + break; + case '\f': + break; + default: + /* We didn't recognize the character as a control character, so pass it + through. */ + return ch; } + + /* We intercepted the control character, so return 0 (which readline + will interpret as a no-op). */ + return 0; } /* See tui-command.h. */