15796c8dcSSimon Schubert /* Specific command window processing.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1998-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert Contributed by Hewlett-Packard Company.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This file is part of GDB.
85796c8dcSSimon Schubert
95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
125796c8dcSSimon Schubert (at your option) any later version.
135796c8dcSSimon Schubert
145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
175796c8dcSSimon Schubert GNU General Public License for more details.
185796c8dcSSimon Schubert
195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
215796c8dcSSimon Schubert
225796c8dcSSimon Schubert #include "defs.h"
235796c8dcSSimon Schubert #include <ctype.h>
245796c8dcSSimon Schubert #include "tui/tui.h"
255796c8dcSSimon Schubert #include "tui/tui-data.h"
265796c8dcSSimon Schubert #include "tui/tui-win.h"
275796c8dcSSimon Schubert #include "tui/tui-io.h"
285796c8dcSSimon Schubert #include "tui/tui-command.h"
295796c8dcSSimon Schubert
305796c8dcSSimon Schubert #include "gdb_curses.h"
315796c8dcSSimon Schubert #include "gdb_string.h"
325796c8dcSSimon Schubert
335796c8dcSSimon Schubert
345796c8dcSSimon Schubert /*****************************************
355796c8dcSSimon Schubert ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
365796c8dcSSimon Schubert ******************************************/
375796c8dcSSimon Schubert
385796c8dcSSimon Schubert
395796c8dcSSimon Schubert
405796c8dcSSimon Schubert /*****************************************
415796c8dcSSimon Schubert ** PUBLIC FUNCTIONS **
425796c8dcSSimon Schubert ******************************************/
435796c8dcSSimon Schubert
445796c8dcSSimon Schubert /* Dispatch the correct tui function based upon the control
455796c8dcSSimon Schubert character. */
465796c8dcSSimon Schubert unsigned int
tui_dispatch_ctrl_char(unsigned int ch)475796c8dcSSimon Schubert tui_dispatch_ctrl_char (unsigned int ch)
485796c8dcSSimon Schubert {
495796c8dcSSimon Schubert struct tui_win_info *win_info = tui_win_with_focus ();
505796c8dcSSimon Schubert
515796c8dcSSimon Schubert /* Handle the CTRL-L refresh for each window. */
525796c8dcSSimon Schubert if (ch == '\f')
535796c8dcSSimon Schubert tui_refresh_all_win ();
545796c8dcSSimon Schubert
555796c8dcSSimon Schubert /* If the command window has the logical focus, or no-one does
565796c8dcSSimon Schubert assume it is the command window; in this case, pass the character
575796c8dcSSimon Schubert on through and do nothing here. */
585796c8dcSSimon Schubert if (win_info == NULL || win_info == TUI_CMD_WIN)
595796c8dcSSimon Schubert return ch;
605796c8dcSSimon Schubert else
615796c8dcSSimon Schubert {
625796c8dcSSimon Schubert unsigned int c = 0, ch_copy = ch;
635796c8dcSSimon Schubert int i;
645796c8dcSSimon Schubert char *term;
655796c8dcSSimon Schubert
665796c8dcSSimon Schubert /* If this is an xterm, page next/prev keys aren't returned by
675796c8dcSSimon Schubert keypad as a single char, so we must handle them here. Seems
685796c8dcSSimon Schubert like a bug in the curses library? */
695796c8dcSSimon Schubert term = (char *) getenv ("TERM");
705796c8dcSSimon Schubert if (term)
715796c8dcSSimon Schubert {
725796c8dcSSimon Schubert for (i = 0; term[i]; i++)
735796c8dcSSimon Schubert term[i] = toupper (term[i]);
745796c8dcSSimon Schubert if ((strcmp (term, "XTERM") == 0)
755796c8dcSSimon Schubert && key_is_start_sequence (ch))
765796c8dcSSimon Schubert {
775796c8dcSSimon Schubert unsigned int page_ch = 0;
785796c8dcSSimon Schubert unsigned int tmp_char;
795796c8dcSSimon Schubert WINDOW *w = TUI_CMD_WIN->generic.handle;
805796c8dcSSimon Schubert
815796c8dcSSimon Schubert tmp_char = 0;
825796c8dcSSimon Schubert while (!key_is_end_sequence (tmp_char))
835796c8dcSSimon Schubert {
845796c8dcSSimon Schubert tmp_char = (int) wgetch (w);
855796c8dcSSimon Schubert if (tmp_char == ERR)
865796c8dcSSimon Schubert {
875796c8dcSSimon Schubert return ch;
885796c8dcSSimon Schubert }
895796c8dcSSimon Schubert if (!tmp_char)
905796c8dcSSimon Schubert break;
915796c8dcSSimon Schubert if (tmp_char == 53)
925796c8dcSSimon Schubert page_ch = KEY_PPAGE;
935796c8dcSSimon Schubert else if (tmp_char == 54)
945796c8dcSSimon Schubert page_ch = KEY_NPAGE;
955796c8dcSSimon Schubert else
965796c8dcSSimon Schubert {
975796c8dcSSimon Schubert return 0;
985796c8dcSSimon Schubert }
995796c8dcSSimon Schubert }
1005796c8dcSSimon Schubert ch_copy = page_ch;
1015796c8dcSSimon Schubert }
1025796c8dcSSimon Schubert }
1035796c8dcSSimon Schubert
1045796c8dcSSimon Schubert switch (ch_copy)
1055796c8dcSSimon Schubert {
1065796c8dcSSimon Schubert case KEY_NPAGE:
1075796c8dcSSimon Schubert tui_scroll_forward (win_info, 0);
1085796c8dcSSimon Schubert break;
1095796c8dcSSimon Schubert case KEY_PPAGE:
1105796c8dcSSimon Schubert tui_scroll_backward (win_info, 0);
1115796c8dcSSimon Schubert break;
1125796c8dcSSimon Schubert case KEY_DOWN:
1135796c8dcSSimon Schubert case KEY_SF:
1145796c8dcSSimon Schubert tui_scroll_forward (win_info, 1);
1155796c8dcSSimon Schubert break;
1165796c8dcSSimon Schubert case KEY_UP:
1175796c8dcSSimon Schubert case KEY_SR:
1185796c8dcSSimon Schubert tui_scroll_backward (win_info, 1);
1195796c8dcSSimon Schubert break;
1205796c8dcSSimon Schubert case KEY_RIGHT:
1215796c8dcSSimon Schubert tui_scroll_left (win_info, 1);
1225796c8dcSSimon Schubert break;
1235796c8dcSSimon Schubert case KEY_LEFT:
1245796c8dcSSimon Schubert tui_scroll_right (win_info, 1);
1255796c8dcSSimon Schubert break;
1265796c8dcSSimon Schubert case '\f':
1275796c8dcSSimon Schubert break;
1285796c8dcSSimon Schubert default:
1295796c8dcSSimon Schubert c = ch_copy;
1305796c8dcSSimon Schubert break;
1315796c8dcSSimon Schubert }
1325796c8dcSSimon Schubert return c;
1335796c8dcSSimon Schubert }
1345796c8dcSSimon Schubert }
135