xref: /dragonfly/contrib/gdb-7/gdb/tui/tui-command.c (revision c1543a89)
1 /* Specific command window processing.
2 
3    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
4    2009 Free Software Foundation, Inc.
5 
6    Contributed by Hewlett-Packard Company.
7 
8    This file is part of GDB.
9 
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22 
23 #include "defs.h"
24 #include <ctype.h>
25 #include "tui/tui.h"
26 #include "tui/tui-data.h"
27 #include "tui/tui-win.h"
28 #include "tui/tui-io.h"
29 #include "tui/tui-command.h"
30 
31 #include "gdb_curses.h"
32 #include "gdb_string.h"
33 
34 
35 /*****************************************
36 ** STATIC LOCAL FUNCTIONS FORWARD DECLS    **
37 ******************************************/
38 
39 
40 
41 /*****************************************
42 ** PUBLIC FUNCTIONS                        **
43 ******************************************/
44 
45 /* Dispatch the correct tui function based upon the control
46    character.  */
47 unsigned int
48 tui_dispatch_ctrl_char (unsigned int ch)
49 {
50   struct tui_win_info *win_info = tui_win_with_focus ();
51 
52   /* Handle the CTRL-L refresh for each window.  */
53   if (ch == '\f')
54     tui_refresh_all_win ();
55 
56   /* If the command window has the logical focus, or no-one does
57      assume it is the command window; in this case, pass the character
58      on through and do nothing here.  */
59   if (win_info == NULL || win_info == TUI_CMD_WIN)
60     return ch;
61   else
62     {
63       unsigned int c = 0, ch_copy = ch;
64       int i;
65       char *term;
66 
67       /* If this is an xterm, page next/prev keys aren't returned by
68          keypad as a single char, so we must handle them here.  Seems
69          like a bug in the curses library?  */
70       term = (char *) getenv ("TERM");
71       if (term)
72 	{
73 	  for (i = 0; term[i]; i++)
74 	    term[i] = toupper (term[i]);
75 	  if ((strcmp (term, "XTERM") == 0)
76 	      && key_is_start_sequence (ch))
77 	    {
78 	      unsigned int page_ch = 0;
79 	      unsigned int tmp_char;
80               WINDOW *w = TUI_CMD_WIN->generic.handle;
81 
82 	      tmp_char = 0;
83 	      while (!key_is_end_sequence (tmp_char))
84 		{
85 		  tmp_char = (int) wgetch (w);
86 		  if (tmp_char == ERR)
87 		    {
88 		      return ch;
89 		    }
90 		  if (!tmp_char)
91 		    break;
92 		  if (tmp_char == 53)
93 		    page_ch = KEY_PPAGE;
94 		  else if (tmp_char == 54)
95 		    page_ch = KEY_NPAGE;
96 		  else
97 		    {
98 		      return 0;
99 		    }
100 		}
101 	      ch_copy = page_ch;
102 	    }
103 	}
104 
105       switch (ch_copy)
106 	{
107 	case KEY_NPAGE:
108 	  tui_scroll_forward (win_info, 0);
109 	  break;
110 	case KEY_PPAGE:
111 	  tui_scroll_backward (win_info, 0);
112 	  break;
113 	case KEY_DOWN:
114 	case KEY_SF:
115 	  tui_scroll_forward (win_info, 1);
116 	  break;
117 	case KEY_UP:
118 	case KEY_SR:
119 	  tui_scroll_backward (win_info, 1);
120 	  break;
121 	case KEY_RIGHT:
122 	  tui_scroll_left (win_info, 1);
123 	  break;
124 	case KEY_LEFT:
125 	  tui_scroll_right (win_info, 1);
126 	  break;
127 	case '\f':
128           break;
129 	default:
130 	  c = ch_copy;
131 	  break;
132 	}
133       return c;
134     }
135 }
136