Catch GOT offsets for a symbol which have no associated GOT subsection.
[deliverable/binutils-gdb.git] / gdb / tui / tui-win.c
1 /* TUI window generic functions.
2
3 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
4 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 2 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, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
24
25 /* This module contains procedures for handling tui window functions
26 like resize, scrolling, scrolling, changing focus, etc.
27
28 Author: Susan B. Macchia */
29
30 #include "defs.h"
31 #include "command.h"
32 #include "symtab.h"
33 #include "breakpoint.h"
34 #include "frame.h"
35 #include "cli/cli-cmds.h"
36 #include "top.h"
37 #include "source.h"
38
39 #include "tui/tui.h"
40 #include "tui/tui-data.h"
41 #include "tui/tui-wingeneral.h"
42 #include "tui/tui-stack.h"
43 #include "tui/tui-regs.h"
44 #include "tui/tui-disasm.h"
45 #include "tui/tui-source.h"
46 #include "tui/tui-winsource.h"
47 #include "tui/tui-windata.h"
48
49 #ifdef HAVE_NCURSES_H
50 #include <ncurses.h>
51 #else
52 #ifdef HAVE_CURSES_H
53 #include <curses.h>
54 #endif
55 #endif
56
57 #include "gdb_string.h"
58 #include <ctype.h>
59 #include <readline/readline.h>
60
61 /*******************************
62 ** Static Local Decls
63 ********************************/
64 static void make_visible_with_new_height (struct tui_win_info *);
65 static void make_invisible_and_set_new_height (struct tui_win_info *, int);
66 static enum tui_status tui_adjust_win_heights (struct tui_win_info *, int);
67 static int new_height_ok (struct tui_win_info *, int);
68 static void tui_set_tab_width_command (char *, int);
69 static void tui_refresh_all_command (char *, int);
70 static void tui_set_win_height_command (char *, int);
71 static void tui_xdb_set_win_height_command (char *, int);
72 static void tui_all_windows_info (char *, int);
73 static void tui_set_focus_command (char *, int);
74 static void tui_scroll_forward_command (char *, int);
75 static void tui_scroll_backward_command (char *, int);
76 static void tui_scroll_left_command (char *, int);
77 static void tui_scroll_right_command (char *, int);
78 static void parse_scrolling_args (char *, struct tui_win_info * *, int *);
79
80
81 /***************************************
82 ** DEFINITIONS
83 ***************************************/
84 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
85 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
86 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
87
88 /***************************************
89 ** PUBLIC FUNCTIONS
90 ***************************************/
91
92 #ifndef ACS_LRCORNER
93 # define ACS_LRCORNER '+'
94 #endif
95 #ifndef ACS_LLCORNER
96 # define ACS_LLCORNER '+'
97 #endif
98 #ifndef ACS_ULCORNER
99 # define ACS_ULCORNER '+'
100 #endif
101 #ifndef ACS_URCORNER
102 # define ACS_URCORNER '+'
103 #endif
104 #ifndef ACS_HLINE
105 # define ACS_HLINE '-'
106 #endif
107 #ifndef ACS_VLINE
108 # define ACS_VLINE '|'
109 #endif
110
111 /* Possible values for tui-border-kind variable. */
112 static const char *tui_border_kind_enums[] = {
113 "space",
114 "ascii",
115 "acs",
116 NULL
117 };
118
119 /* Possible values for tui-border-mode and tui-active-border-mode. */
120 static const char *tui_border_mode_enums[] = {
121 "normal",
122 "standout",
123 "reverse",
124 "half",
125 "half-standout",
126 "bold",
127 "bold-standout",
128 NULL
129 };
130
131 struct tui_translate
132 {
133 const char *name;
134 int value;
135 };
136
137 /* Translation table for border-mode variables.
138 The list of values must be terminated by a NULL.
139 After the NULL value, an entry defines the default. */
140 struct tui_translate tui_border_mode_translate[] = {
141 { "normal", A_NORMAL },
142 { "standout", A_STANDOUT },
143 { "reverse", A_REVERSE },
144 { "half", A_DIM },
145 { "half-standout", A_DIM | A_STANDOUT },
146 { "bold", A_BOLD },
147 { "bold-standout", A_BOLD | A_STANDOUT },
148 { 0, 0 },
149 { "normal", A_NORMAL }
150 };
151
152 /* Translation tables for border-kind, one for each border
153 character (see wborder, border curses operations).
154 -1 is used to indicate the ACS because ACS characters
155 are determined at run time by curses (depends on terminal). */
156 struct tui_translate tui_border_kind_translate_vline[] = {
157 { "space", ' ' },
158 { "ascii", '|' },
159 { "acs", -1 },
160 { 0, 0 },
161 { "ascii", '|' }
162 };
163
164 struct tui_translate tui_border_kind_translate_hline[] = {
165 { "space", ' ' },
166 { "ascii", '-' },
167 { "acs", -1 },
168 { 0, 0 },
169 { "ascii", '-' }
170 };
171
172 struct tui_translate tui_border_kind_translate_ulcorner[] = {
173 { "space", ' ' },
174 { "ascii", '+' },
175 { "acs", -1 },
176 { 0, 0 },
177 { "ascii", '+' }
178 };
179
180 struct tui_translate tui_border_kind_translate_urcorner[] = {
181 { "space", ' ' },
182 { "ascii", '+' },
183 { "acs", -1 },
184 { 0, 0 },
185 { "ascii", '+' }
186 };
187
188 struct tui_translate tui_border_kind_translate_llcorner[] = {
189 { "space", ' ' },
190 { "ascii", '+' },
191 { "acs", -1 },
192 { 0, 0 },
193 { "ascii", '+' }
194 };
195
196 struct tui_translate tui_border_kind_translate_lrcorner[] = {
197 { "space", ' ' },
198 { "ascii", '+' },
199 { "acs", -1 },
200 { 0, 0 },
201 { "ascii", '+' }
202 };
203
204
205 /* Tui configuration variables controlled with set/show command. */
206 const char *tui_active_border_mode = "bold-standout";
207 const char *tui_border_mode = "normal";
208 const char *tui_border_kind = "acs";
209
210 /* Tui internal configuration variables. These variables are
211 updated by tui_update_variables to reflect the tui configuration
212 variables. */
213 chtype tui_border_vline;
214 chtype tui_border_hline;
215 chtype tui_border_ulcorner;
216 chtype tui_border_urcorner;
217 chtype tui_border_llcorner;
218 chtype tui_border_lrcorner;
219
220 int tui_border_attrs;
221 int tui_active_border_attrs;
222
223 /* Identify the item in the translation table.
224 When the item is not recognized, use the default entry. */
225 static struct tui_translate *
226 translate (const char *name, struct tui_translate *table)
227 {
228 while (table->name)
229 {
230 if (name && strcmp (table->name, name) == 0)
231 return table;
232 table++;
233 }
234
235 /* Not found, return default entry. */
236 table++;
237 return table;
238 }
239
240 /* Update the tui internal configuration according to gdb settings.
241 Returns 1 if the configuration has changed and the screen should
242 be redrawn. */
243 int
244 tui_update_variables (void)
245 {
246 int need_redraw = 0;
247 struct tui_translate *entry;
248
249 entry = translate (tui_border_mode, tui_border_mode_translate);
250 if (tui_border_attrs != entry->value)
251 {
252 tui_border_attrs = entry->value;
253 need_redraw = 1;
254 }
255 entry = translate (tui_active_border_mode, tui_border_mode_translate);
256 if (tui_active_border_attrs != entry->value)
257 {
258 tui_active_border_attrs = entry->value;
259 need_redraw = 1;
260 }
261
262 /* If one corner changes, all characters are changed.
263 Only check the first one. The ACS characters are determined at
264 run time by curses terminal management. */
265 entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
266 if (tui_border_lrcorner != (chtype) entry->value)
267 {
268 tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
269 need_redraw = 1;
270 }
271 entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
272 tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
273
274 entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
275 tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
276
277 entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
278 tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
279
280 entry = translate (tui_border_kind, tui_border_kind_translate_hline);
281 tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
282
283 entry = translate (tui_border_kind, tui_border_kind_translate_vline);
284 tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
285
286 return need_redraw;
287 }
288
289 static void
290 set_tui_cmd (char *args, int from_tty)
291 {
292 }
293
294 static void
295 show_tui_cmd (char *args, int from_tty)
296 {
297 }
298
299 /* Function to initialize gdb commands, for tui window manipulation. */
300 void
301 _initialize_tui_win (void)
302 {
303 struct cmd_list_element *c;
304 static struct cmd_list_element *tui_setlist;
305 static struct cmd_list_element *tui_showlist;
306
307 /* Define the classes of commands.
308 They will appear in the help list in the reverse of this order. */
309 add_cmd ("tui", class_tui, NULL,
310 "Text User Interface commands.",
311 &cmdlist);
312
313 add_prefix_cmd ("tui", class_tui, set_tui_cmd,
314 "TUI configuration variables",
315 &tui_setlist, "set tui ",
316 0/*allow-unknown*/, &setlist);
317 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
318 "TUI configuration variables",
319 &tui_showlist, "show tui ",
320 0/*allow-unknown*/, &showlist);
321
322 add_com ("refresh", class_tui, tui_refresh_all_command,
323 "Refresh the terminal display.\n");
324 if (xdb_commands)
325 add_com_alias ("U", "refresh", class_tui, 0);
326 add_com ("tabset", class_tui, tui_set_tab_width_command,
327 "Set the width (in characters) of tab stops.\n\
328 Usage: tabset <n>\n");
329 add_com ("winheight", class_tui, tui_set_win_height_command,
330 "Set the height of a specified window.\n\
331 Usage: winheight <win_name> [+ | -] <#lines>\n\
332 Window names are:\n\
333 src : the source window\n\
334 cmd : the command window\n\
335 asm : the disassembly window\n\
336 regs : the register display\n");
337 add_com_alias ("wh", "winheight", class_tui, 0);
338 add_info ("win", tui_all_windows_info,
339 "List of all displayed windows.\n");
340 add_com ("focus", class_tui, tui_set_focus_command,
341 "Set focus to named window or next/prev window.\n\
342 Usage: focus {<win> | next | prev}\n\
343 Valid Window names are:\n\
344 src : the source window\n\
345 asm : the disassembly window\n\
346 regs : the register display\n\
347 cmd : the command window\n");
348 add_com_alias ("fs", "focus", class_tui, 0);
349 add_com ("+", class_tui, tui_scroll_forward_command,
350 "Scroll window forward.\nUsage: + [win] [n]\n");
351 add_com ("-", class_tui, tui_scroll_backward_command,
352 "Scroll window backward.\nUsage: - [win] [n]\n");
353 add_com ("<", class_tui, tui_scroll_left_command,
354 "Scroll window forward.\nUsage: < [win] [n]\n");
355 add_com (">", class_tui, tui_scroll_right_command,
356 "Scroll window backward.\nUsage: > [win] [n]\n");
357 if (xdb_commands)
358 add_com ("w", class_xdb, tui_xdb_set_win_height_command,
359 "XDB compatibility command for setting the height of a command window.\n\
360 Usage: w <#lines>\n");
361
362 /* Define the tui control variables. */
363 c = add_set_enum_cmd
364 ("border-kind", no_class,
365 tui_border_kind_enums, &tui_border_kind,
366 "Set the kind of border for TUI windows.\n"
367 "This variable controls the border of TUI windows:\n"
368 "space use a white space\n"
369 "ascii use ascii characters + - | for the border\n"
370 "acs use the Alternate Character Set\n",
371 &tui_setlist);
372 add_show_from_set (c, &tui_showlist);
373
374 c = add_set_enum_cmd
375 ("border-mode", no_class,
376 tui_border_mode_enums, &tui_border_mode,
377 "Set the attribute mode to use for the TUI window borders.\n"
378 "This variable controls the attributes to use for the window borders:\n"
379 "normal normal display\n"
380 "standout use highlight mode of terminal\n"
381 "reverse use reverse video mode\n"
382 "half use half bright\n"
383 "half-standout use half bright and standout mode\n"
384 "bold use extra bright or bold\n"
385 "bold-standout use extra bright or bold with standout mode\n",
386 &tui_setlist);
387 add_show_from_set (c, &tui_showlist);
388
389 c = add_set_enum_cmd
390 ("active-border-mode", no_class,
391 tui_border_mode_enums, &tui_active_border_mode,
392 "Set the attribute mode to use for the active TUI window border.\n"
393 "This variable controls the attributes to use for the active window border:\n"
394 "normal normal display\n"
395 "standout use highlight mode of terminal\n"
396 "reverse use reverse video mode\n"
397 "half use half bright\n"
398 "half-standout use half bright and standout mode\n"
399 "bold use extra bright or bold\n"
400 "bold-standout use extra bright or bold with standout mode\n",
401 &tui_setlist);
402 add_show_from_set (c, &tui_showlist);
403 }
404
405 /* Update gdb's knowledge of the terminal size. */
406 void
407 tui_update_gdb_sizes (void)
408 {
409 char cmd[50];
410 int screenheight, screenwidth;
411
412 rl_get_screen_size (&screenheight, &screenwidth);
413 /* Set to TUI command window dimension or use readline values. */
414 sprintf (cmd, "set width %d",
415 tui_active ? TUI_CMD_WIN->generic.width : screenwidth);
416 execute_command (cmd, 0);
417 sprintf (cmd, "set height %d",
418 tui_active ? TUI_CMD_WIN->generic.height : screenheight);
419 execute_command (cmd, 0);
420 }
421
422
423 /* Set the logical focus to win_info. */
424 void
425 tui_set_win_focus_to (struct tui_win_info * win_info)
426 {
427 if (win_info != NULL)
428 {
429 struct tui_win_info * win_with_focus = tui_win_with_focus ();
430
431 if (win_with_focus != NULL
432 && win_with_focus->generic.type != CMD_WIN)
433 tui_unhighlight_win (win_with_focus);
434 tui_set_win_with_focus (win_info);
435 if (win_info->generic.type != CMD_WIN)
436 tui_highlight_win (win_info);
437 }
438 }
439
440
441 void
442 tui_scroll_forward (struct tui_win_info * win_to_scroll, int num_to_scroll)
443 {
444 if (win_to_scroll != TUI_CMD_WIN)
445 {
446 int _num_to_scroll = num_to_scroll;
447
448 if (num_to_scroll == 0)
449 _num_to_scroll = win_to_scroll->generic.height - 3;
450 /*
451 ** If we are scrolling the source or disassembly window, do a
452 ** "psuedo" scroll since not all of the source is in memory,
453 ** only what is in the viewport. If win_to_scroll is the
454 ** command window do nothing since the term should handle it.
455 */
456 if (win_to_scroll == TUI_SRC_WIN)
457 tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll);
458 else if (win_to_scroll == TUI_DISASM_WIN)
459 tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll);
460 else if (win_to_scroll == TUI_DATA_WIN)
461 tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll);
462 }
463 }
464
465 void
466 tui_scroll_backward (struct tui_win_info * win_to_scroll, int num_to_scroll)
467 {
468 if (win_to_scroll != TUI_CMD_WIN)
469 {
470 int _num_to_scroll = num_to_scroll;
471
472 if (num_to_scroll == 0)
473 _num_to_scroll = win_to_scroll->generic.height - 3;
474 /*
475 ** If we are scrolling the source or disassembly window, do a
476 ** "psuedo" scroll since not all of the source is in memory,
477 ** only what is in the viewport. If win_to_scroll is the
478 ** command window do nothing since the term should handle it.
479 */
480 if (win_to_scroll == TUI_SRC_WIN)
481 tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll);
482 else if (win_to_scroll == TUI_DISASM_WIN)
483 tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll);
484 else if (win_to_scroll == TUI_DATA_WIN)
485 tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll);
486 }
487 }
488
489
490 void
491 tui_scroll_left (struct tui_win_info * win_to_scroll, int num_to_scroll)
492 {
493 if (win_to_scroll != TUI_CMD_WIN)
494 {
495 int _num_to_scroll = num_to_scroll;
496
497 if (_num_to_scroll == 0)
498 _num_to_scroll = 1;
499 /*
500 ** If we are scrolling the source or disassembly window, do a
501 ** "psuedo" scroll since not all of the source is in memory,
502 ** only what is in the viewport. If win_to_scroll is the
503 ** command window do nothing since the term should handle it.
504 */
505 if (win_to_scroll == TUI_SRC_WIN || win_to_scroll == TUI_DISASM_WIN)
506 tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL, _num_to_scroll);
507 }
508 }
509
510
511 void
512 tui_scroll_right (struct tui_win_info * win_to_scroll, int num_to_scroll)
513 {
514 if (win_to_scroll != TUI_CMD_WIN)
515 {
516 int _num_to_scroll = num_to_scroll;
517
518 if (_num_to_scroll == 0)
519 _num_to_scroll = 1;
520 /*
521 ** If we are scrolling the source or disassembly window, do a
522 ** "psuedo" scroll since not all of the source is in memory,
523 ** only what is in the viewport. If win_to_scroll is the
524 ** command window do nothing since the term should handle it.
525 */
526 if (win_to_scroll == TUI_SRC_WIN || win_to_scroll == TUI_DISASM_WIN)
527 tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL, _num_to_scroll);
528 }
529 }
530
531
532 /* Scroll a window. Arguments are passed through a va_list. */
533 void
534 tui_scroll (enum tui_scroll_direction direction,
535 struct tui_win_info * win_to_scroll,
536 int num_to_scroll)
537 {
538 switch (direction)
539 {
540 case FORWARD_SCROLL:
541 tui_scroll_forward (win_to_scroll, num_to_scroll);
542 break;
543 case BACKWARD_SCROLL:
544 tui_scroll_backward (win_to_scroll, num_to_scroll);
545 break;
546 case LEFT_SCROLL:
547 tui_scroll_left (win_to_scroll, num_to_scroll);
548 break;
549 case RIGHT_SCROLL:
550 tui_scroll_right (win_to_scroll, num_to_scroll);
551 break;
552 default:
553 break;
554 }
555 }
556
557
558 void
559 tui_refresh_all_win (void)
560 {
561 enum tui_win_type type;
562
563 clearok (curscr, TRUE);
564 tui_refresh_all (tui_win_list);
565 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
566 {
567 if (tui_win_list[type] && tui_win_list[type]->generic.is_visible)
568 {
569 switch (type)
570 {
571 case SRC_WIN:
572 case DISASSEM_WIN:
573 tui_show_source_content (tui_win_list[type]);
574 tui_check_and_display_highlight_if_needed (tui_win_list[type]);
575 tui_erase_exec_info_content (tui_win_list[type]);
576 tui_update_exec_info (tui_win_list[type]);
577 break;
578 case DATA_WIN:
579 tui_refresh_data_win ();
580 break;
581 default:
582 break;
583 }
584 }
585 }
586 tui_show_locator_content ();
587 }
588
589
590 /* Resize all the windows based on the the terminal size. This
591 function gets called from within the readline sinwinch handler. */
592 void
593 tui_resize_all (void)
594 {
595 int height_diff, width_diff;
596 int screenheight, screenwidth;
597
598 rl_get_screen_size (&screenheight, &screenwidth);
599 width_diff = screenwidth - tui_term_width ();
600 height_diff = screenheight - tui_term_height ();
601 if (height_diff || width_diff)
602 {
603 enum tui_layout_type cur_layout = tui_current_layout ();
604 struct tui_win_info * win_with_focus = tui_win_with_focus ();
605 struct tui_win_info *first_win;
606 struct tui_win_info *second_win;
607 struct tui_gen_win_info * locator = tui_locator_win_info_ptr ();
608 enum tui_win_type win_type;
609 int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
610
611 /* turn keypad off while we resize */
612 if (win_with_focus != TUI_CMD_WIN)
613 keypad (TUI_CMD_WIN->generic.handle, FALSE);
614 tui_update_gdb_sizes ();
615 tui_set_term_height_to (screenheight);
616 tui_set_term_width_to (screenwidth);
617 if (cur_layout == SRC_DISASSEM_COMMAND ||
618 cur_layout == SRC_DATA_COMMAND || cur_layout == DISASSEM_DATA_COMMAND)
619 num_wins_displayed++;
620 split_diff = height_diff / num_wins_displayed;
621 cmd_split_diff = split_diff;
622 if (height_diff % num_wins_displayed)
623 {
624 if (height_diff < 0)
625 cmd_split_diff--;
626 else
627 cmd_split_diff++;
628 }
629 /* now adjust each window */
630 clear ();
631 refresh ();
632 switch (cur_layout)
633 {
634 case SRC_COMMAND:
635 case DISASSEM_COMMAND:
636 first_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
637 first_win->generic.width += width_diff;
638 locator->width += width_diff;
639 /* check for invalid heights */
640 if (height_diff == 0)
641 new_height = first_win->generic.height;
642 else if ((first_win->generic.height + split_diff) >=
643 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
644 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
645 else if ((first_win->generic.height + split_diff) <= 0)
646 new_height = MIN_WIN_HEIGHT;
647 else
648 new_height = first_win->generic.height + split_diff;
649
650 make_invisible_and_set_new_height (first_win, new_height);
651 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
652 TUI_CMD_WIN->generic.width += width_diff;
653 new_height = screenheight - TUI_CMD_WIN->generic.origin.y;
654 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
655 make_visible_with_new_height (first_win);
656 make_visible_with_new_height (TUI_CMD_WIN);
657 if (first_win->generic.content_size <= 0)
658 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
659 break;
660 default:
661 if (cur_layout == SRC_DISASSEM_COMMAND)
662 {
663 first_win = TUI_SRC_WIN;
664 first_win->generic.width += width_diff;
665 second_win = TUI_DISASM_WIN;
666 second_win->generic.width += width_diff;
667 }
668 else
669 {
670 first_win = TUI_DATA_WIN;
671 first_win->generic.width += width_diff;
672 second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
673 second_win->generic.width += width_diff;
674 }
675 /* Change the first window's height/width */
676 /* check for invalid heights */
677 if (height_diff == 0)
678 new_height = first_win->generic.height;
679 else if ((first_win->generic.height +
680 second_win->generic.height + (split_diff * 2)) >=
681 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
682 new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
683 else if ((first_win->generic.height + split_diff) <= 0)
684 new_height = MIN_WIN_HEIGHT;
685 else
686 new_height = first_win->generic.height + split_diff;
687 make_invisible_and_set_new_height (first_win, new_height);
688
689 if (first_win == TUI_DATA_WIN && width_diff != 0)
690 first_win->detail.data_display_info.regs_column_count =
691 tui_calculate_regs_column_count (
692 first_win->detail.data_display_info.regs_display_type);
693 locator->width += width_diff;
694
695 /* Change the second window's height/width */
696 /* check for invalid heights */
697 if (height_diff == 0)
698 new_height = second_win->generic.height;
699 else if ((first_win->generic.height +
700 second_win->generic.height + (split_diff * 2)) >=
701 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
702 {
703 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
704 if (new_height % 2)
705 new_height = (new_height / 2) + 1;
706 else
707 new_height /= 2;
708 }
709 else if ((second_win->generic.height + split_diff) <= 0)
710 new_height = MIN_WIN_HEIGHT;
711 else
712 new_height = second_win->generic.height + split_diff;
713 second_win->generic.origin.y = first_win->generic.height - 1;
714 make_invisible_and_set_new_height (second_win, new_height);
715
716 /* Change the command window's height/width */
717 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
718 make_invisible_and_set_new_height (
719 TUI_CMD_WIN, TUI_CMD_WIN->generic.height + cmd_split_diff);
720 make_visible_with_new_height (first_win);
721 make_visible_with_new_height (second_win);
722 make_visible_with_new_height (TUI_CMD_WIN);
723 if (first_win->generic.content_size <= 0)
724 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
725 if (second_win->generic.content_size <= 0)
726 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
727 break;
728 }
729 /*
730 ** Now remove all invisible windows, and their content so that they get
731 ** created again when called for with the new size
732 */
733 for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
734 {
735 if (win_type != CMD_WIN && (tui_win_list[win_type] != NULL)
736 && !tui_win_list[win_type]->generic.is_visible)
737 {
738 tui_free_window (tui_win_list[win_type]);
739 tui_win_list[win_type] = (struct tui_win_info *) NULL;
740 }
741 }
742 tui_set_win_resized_to (TRUE);
743 /* turn keypad back on, unless focus is in the command window */
744 if (win_with_focus != TUI_CMD_WIN)
745 keypad (TUI_CMD_WIN->generic.handle, TRUE);
746 }
747 }
748
749
750 /* SIGWINCH signal handler for the tui. This signal handler is always
751 called, even when the readline package clears signals because it is
752 set as the old_sigwinch() (TUI only). */
753 void
754 tui_sigwinch_handler (int signal)
755 {
756 /*
757 ** Say that a resize was done so that the readline can do it
758 ** later when appropriate.
759 */
760 tui_set_win_resized_to (TRUE);
761 }
762
763
764
765 /*************************
766 ** STATIC LOCAL FUNCTIONS
767 **************************/
768
769
770 static void
771 tui_scroll_forward_command (char *arg, int from_tty)
772 {
773 int num_to_scroll = 1;
774 struct tui_win_info * win_to_scroll;
775
776 /* Make sure the curses mode is enabled. */
777 tui_enable ();
778 if (arg == (char *) NULL)
779 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
780 else
781 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
782 tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll);
783 }
784
785
786 static void
787 tui_scroll_backward_command (char *arg, int from_tty)
788 {
789 int num_to_scroll = 1;
790 struct tui_win_info * win_to_scroll;
791
792 /* Make sure the curses mode is enabled. */
793 tui_enable ();
794 if (arg == (char *) NULL)
795 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
796 else
797 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
798 tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll);
799 }
800
801
802 static void
803 tui_scroll_left_command (char *arg, int from_tty)
804 {
805 int num_to_scroll;
806 struct tui_win_info * win_to_scroll;
807
808 /* Make sure the curses mode is enabled. */
809 tui_enable ();
810 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
811 tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll);
812 }
813
814
815 static void
816 tui_scroll_right_command (char *arg, int from_tty)
817 {
818 int num_to_scroll;
819 struct tui_win_info * win_to_scroll;
820
821 /* Make sure the curses mode is enabled. */
822 tui_enable ();
823 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
824 tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll);
825 }
826
827
828 /* Set focus to the window named by 'arg'. */
829 static void
830 tui_set_focus (char *arg, int from_tty)
831 {
832 if (arg != (char *) NULL)
833 {
834 char *buf_ptr = (char *) xstrdup (arg);
835 int i;
836 struct tui_win_info * win_info = (struct tui_win_info *) NULL;
837
838 for (i = 0; (i < strlen (buf_ptr)); i++)
839 buf_ptr[i] = toupper (arg[i]);
840
841 if (subset_compare (buf_ptr, "NEXT"))
842 win_info = tui_next_win (tui_win_with_focus ());
843 else if (subset_compare (buf_ptr, "PREV"))
844 win_info = tui_prev_win (tui_win_with_focus ());
845 else
846 win_info = tui_partial_win_by_name (buf_ptr);
847
848 if (win_info == (struct tui_win_info *) NULL || !win_info->generic.is_visible)
849 warning ("Invalid window specified. \n\
850 The window name specified must be valid and visible.\n");
851 else
852 {
853 tui_set_win_focus_to (win_info);
854 keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
855 }
856
857 if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
858 tui_refresh_data_win ();
859 xfree (buf_ptr);
860 printf_filtered ("Focus set to %s window.\n",
861 tui_win_name ((struct tui_gen_win_info *) tui_win_with_focus ()));
862 }
863 else
864 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE);
865 }
866
867 static void
868 tui_set_focus_command (char *arg, int from_tty)
869 {
870 /* Make sure the curses mode is enabled. */
871 tui_enable ();
872 tui_set_focus (arg, from_tty);
873 }
874
875
876 static void
877 tui_all_windows_info (char *arg, int from_tty)
878 {
879 enum tui_win_type type;
880 struct tui_win_info * win_with_focus = tui_win_with_focus ();
881
882 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
883 if (tui_win_list[type] && tui_win_list[type]->generic.is_visible)
884 {
885 if (win_with_focus == tui_win_list[type])
886 printf_filtered (" %s\t(%d lines) <has focus>\n",
887 tui_win_name (&tui_win_list[type]->generic),
888 tui_win_list[type]->generic.height);
889 else
890 printf_filtered (" %s\t(%d lines)\n",
891 tui_win_name (&tui_win_list[type]->generic),
892 tui_win_list[type]->generic.height);
893 }
894 }
895
896
897 static void
898 tui_refresh_all_command (char *arg, int from_tty)
899 {
900 /* Make sure the curses mode is enabled. */
901 tui_enable ();
902
903 tui_refresh_all_win ();
904 }
905
906
907 /* Set the height of the specified window. */
908 static void
909 tui_set_tab_width_command (char *arg, int from_tty)
910 {
911 /* Make sure the curses mode is enabled. */
912 tui_enable ();
913 if (arg != (char *) NULL)
914 {
915 int ts;
916
917 ts = atoi (arg);
918 if (ts > 0)
919 tui_set_default_tab_len (ts);
920 else
921 warning ("Tab widths greater than 0 must be specified.\n");
922 }
923 }
924
925
926 /* Set the height of the specified window. */
927 static void
928 tui_set_win_height (char *arg, int from_tty)
929 {
930 /* Make sure the curses mode is enabled. */
931 tui_enable ();
932 if (arg != (char *) NULL)
933 {
934 char *buf = xstrdup (arg);
935 char *buf_ptr = buf;
936 char *wname = (char *) NULL;
937 int new_height, i;
938 struct tui_win_info * win_info;
939
940 wname = buf_ptr;
941 buf_ptr = strchr (buf_ptr, ' ');
942 if (buf_ptr != (char *) NULL)
943 {
944 *buf_ptr = (char) 0;
945
946 /*
947 ** Validate the window name
948 */
949 for (i = 0; i < strlen (wname); i++)
950 wname[i] = toupper (wname[i]);
951 win_info = tui_partial_win_by_name (wname);
952
953 if (win_info == (struct tui_win_info *) NULL || !win_info->generic.is_visible)
954 warning ("Invalid window specified. \n\
955 The window name specified must be valid and visible.\n");
956 else
957 {
958 /* Process the size */
959 while (*(++buf_ptr) == ' ')
960 ;
961
962 if (*buf_ptr != (char) 0)
963 {
964 int negate = FALSE;
965 int fixed_size = TRUE;
966 int input_no;;
967
968 if (*buf_ptr == '+' || *buf_ptr == '-')
969 {
970 if (*buf_ptr == '-')
971 negate = TRUE;
972 fixed_size = FALSE;
973 buf_ptr++;
974 }
975 input_no = atoi (buf_ptr);
976 if (input_no > 0)
977 {
978 if (negate)
979 input_no *= (-1);
980 if (fixed_size)
981 new_height = input_no;
982 else
983 new_height = win_info->generic.height + input_no;
984 /*
985 ** Now change the window's height, and adjust all
986 ** other windows around it
987 */
988 if (tui_adjust_win_heights (win_info,
989 new_height) == TUI_FAILURE)
990 warning ("Invalid window height specified.\n%s",
991 WIN_HEIGHT_USAGE);
992 else
993 tui_update_gdb_sizes ();
994 }
995 else
996 warning ("Invalid window height specified.\n%s",
997 WIN_HEIGHT_USAGE);
998 }
999 }
1000 }
1001 else
1002 printf_filtered (WIN_HEIGHT_USAGE);
1003
1004 if (buf != (char *) NULL)
1005 xfree (buf);
1006 }
1007 else
1008 printf_filtered (WIN_HEIGHT_USAGE);
1009 }
1010
1011 /* Set the height of the specified window, with va_list. */
1012 static void
1013 tui_set_win_height_command (char *arg, int from_tty)
1014 {
1015 /* Make sure the curses mode is enabled. */
1016 tui_enable ();
1017 tui_set_win_height (arg, from_tty);
1018 }
1019
1020
1021 /* XDB Compatibility command for setting the window height. This will
1022 increase or decrease the command window by the specified amount. */
1023 static void
1024 tui_xdb_set_win_height (char *arg, int from_tty)
1025 {
1026 /* Make sure the curses mode is enabled. */
1027 tui_enable ();
1028 if (arg != (char *) NULL)
1029 {
1030 int input_no = atoi (arg);
1031
1032 if (input_no > 0)
1033 { /* Add 1 for the locator */
1034 int new_height = tui_term_height () - (input_no + 1);
1035
1036 if (!new_height_ok (tui_win_list[CMD_WIN], new_height) ||
1037 tui_adjust_win_heights (tui_win_list[CMD_WIN],
1038 new_height) == TUI_FAILURE)
1039 warning ("Invalid window height specified.\n%s",
1040 XDBWIN_HEIGHT_USAGE);
1041 }
1042 else
1043 warning ("Invalid window height specified.\n%s",
1044 XDBWIN_HEIGHT_USAGE);
1045 }
1046 else
1047 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE);
1048 }
1049
1050 /* Set the height of the specified window, with va_list. */
1051 static void
1052 tui_xdb_set_win_height_command (char *arg, int from_tty)
1053 {
1054 tui_xdb_set_win_height (arg, from_tty);
1055 }
1056
1057
1058 /* Function to adjust all window heights around the primary. */
1059 static enum tui_status
1060 tui_adjust_win_heights (struct tui_win_info * primary_win_info, int new_height)
1061 {
1062 enum tui_status status = TUI_FAILURE;
1063
1064 if (new_height_ok (primary_win_info, new_height))
1065 {
1066 status = TUI_SUCCESS;
1067 if (new_height != primary_win_info->generic.height)
1068 {
1069 int diff;
1070 struct tui_win_info * win_info;
1071 struct tui_gen_win_info * locator = tui_locator_win_info_ptr ();
1072 enum tui_layout_type cur_layout = tui_current_layout ();
1073
1074 diff = (new_height - primary_win_info->generic.height) * (-1);
1075 if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
1076 {
1077 struct tui_win_info * src_win_info;
1078
1079 make_invisible_and_set_new_height (primary_win_info, new_height);
1080 if (primary_win_info->generic.type == CMD_WIN)
1081 {
1082 win_info = (struct tui_win_info *) (tui_source_windows ())->list[0];
1083 src_win_info = win_info;
1084 }
1085 else
1086 {
1087 win_info = tui_win_list[CMD_WIN];
1088 src_win_info = primary_win_info;
1089 }
1090 make_invisible_and_set_new_height (win_info,
1091 win_info->generic.height + diff);
1092 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1093 make_visible_with_new_height (win_info);
1094 make_visible_with_new_height (primary_win_info);
1095 if (src_win_info->generic.content_size <= 0)
1096 tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);
1097 }
1098 else
1099 {
1100 struct tui_win_info *first_win;
1101 struct tui_win_info *second_win;
1102
1103 if (cur_layout == SRC_DISASSEM_COMMAND)
1104 {
1105 first_win = TUI_SRC_WIN;
1106 second_win = TUI_DISASM_WIN;
1107 }
1108 else
1109 {
1110 first_win = TUI_DATA_WIN;
1111 second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
1112 }
1113 if (primary_win_info == TUI_CMD_WIN)
1114 { /*
1115 ** Split the change in height accross the 1st & 2nd windows
1116 ** adjusting them as well.
1117 */
1118 int first_split_diff = diff / 2; /* subtract the locator */
1119 int second_split_diff = first_split_diff;
1120
1121 if (diff % 2)
1122 {
1123 if (first_win->generic.height >
1124 second_win->generic.height)
1125 if (diff < 0)
1126 first_split_diff--;
1127 else
1128 first_split_diff++;
1129 else
1130 {
1131 if (diff < 0)
1132 second_split_diff--;
1133 else
1134 second_split_diff++;
1135 }
1136 }
1137 /* make sure that the minimum hieghts are honored */
1138 while ((first_win->generic.height + first_split_diff) < 3)
1139 {
1140 first_split_diff++;
1141 second_split_diff--;
1142 }
1143 while ((second_win->generic.height + second_split_diff) < 3)
1144 {
1145 second_split_diff++;
1146 first_split_diff--;
1147 }
1148 make_invisible_and_set_new_height (
1149 first_win,
1150 first_win->generic.height + first_split_diff);
1151 second_win->generic.origin.y = first_win->generic.height - 1;
1152 make_invisible_and_set_new_height (
1153 second_win, second_win->generic.height + second_split_diff);
1154 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1155 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
1156 }
1157 else
1158 {
1159 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1160 { /*
1161 ** If there is no way to increase the command window
1162 ** take real estate from the 1st or 2nd window.
1163 */
1164 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1165 {
1166 int i;
1167 for (i = TUI_CMD_WIN->generic.height + diff;
1168 (i < 1); i++)
1169 if (primary_win_info == first_win)
1170 second_win->generic.height--;
1171 else
1172 first_win->generic.height--;
1173 }
1174 }
1175 if (primary_win_info == first_win)
1176 make_invisible_and_set_new_height (first_win, new_height);
1177 else
1178 make_invisible_and_set_new_height (
1179 first_win,
1180 first_win->generic.height);
1181 second_win->generic.origin.y = first_win->generic.height - 1;
1182 if (primary_win_info == second_win)
1183 make_invisible_and_set_new_height (second_win, new_height);
1184 else
1185 make_invisible_and_set_new_height (
1186 second_win, second_win->generic.height);
1187 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1188 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1189 make_invisible_and_set_new_height (TUI_CMD_WIN, 1);
1190 else
1191 make_invisible_and_set_new_height (
1192 TUI_CMD_WIN, TUI_CMD_WIN->generic.height + diff);
1193 }
1194 make_visible_with_new_height (TUI_CMD_WIN);
1195 make_visible_with_new_height (second_win);
1196 make_visible_with_new_height (first_win);
1197 if (first_win->generic.content_size <= 0)
1198 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
1199 if (second_win->generic.content_size <= 0)
1200 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
1201 }
1202 }
1203 }
1204
1205 return status;
1206 }
1207
1208
1209 /* Function make the target window (and auxillary windows associated
1210 with the targer) invisible, and set the new height and location. */
1211 static void
1212 make_invisible_and_set_new_height (struct tui_win_info * win_info, int height)
1213 {
1214 int i;
1215 struct tui_gen_win_info * gen_win_info;
1216
1217 tui_make_invisible (&win_info->generic);
1218 win_info->generic.height = height;
1219 if (height > 1)
1220 win_info->generic.viewport_height = height - 1;
1221 else
1222 win_info->generic.viewport_height = height;
1223 if (win_info != TUI_CMD_WIN)
1224 win_info->generic.viewport_height--;
1225
1226 /* Now deal with the auxillary windows associated with win_info */
1227 switch (win_info->generic.type)
1228 {
1229 case SRC_WIN:
1230 case DISASSEM_WIN:
1231 gen_win_info = win_info->detail.source_info.execution_info;
1232 tui_make_invisible (gen_win_info);
1233 gen_win_info->height = height;
1234 gen_win_info->origin.y = win_info->generic.origin.y;
1235 if (height > 1)
1236 gen_win_info->viewport_height = height - 1;
1237 else
1238 gen_win_info->viewport_height = height;
1239 if (win_info != TUI_CMD_WIN)
1240 gen_win_info->viewport_height--;
1241
1242 if (tui_win_has_locator (win_info))
1243 {
1244 gen_win_info = tui_locator_win_info_ptr ();
1245 tui_make_invisible (gen_win_info);
1246 gen_win_info->origin.y = win_info->generic.origin.y + height;
1247 }
1248 break;
1249 case DATA_WIN:
1250 /* delete all data item windows */
1251 for (i = 0; i < win_info->generic.content_size; i++)
1252 {
1253 gen_win_info = (struct tui_gen_win_info *) & ((struct tui_win_element *)
1254 win_info->generic.content[i])->which_element.data_window;
1255 tui_delete_win (gen_win_info->handle);
1256 gen_win_info->handle = (WINDOW *) NULL;
1257 }
1258 break;
1259 default:
1260 break;
1261 }
1262 }
1263
1264
1265 /* Function to make the windows with new heights visible. This means
1266 re-creating the windows' content since the window had to be
1267 destroyed to be made invisible. */
1268 static void
1269 make_visible_with_new_height (struct tui_win_info * win_info)
1270 {
1271 struct symtab *s;
1272
1273 tui_make_visible (&win_info->generic);
1274 tui_check_and_display_highlight_if_needed (win_info);
1275 switch (win_info->generic.type)
1276 {
1277 case SRC_WIN:
1278 case DISASSEM_WIN:
1279 tui_free_win_content (win_info->detail.source_info.execution_info);
1280 tui_make_visible (win_info->detail.source_info.execution_info);
1281 if (win_info->generic.content != NULL)
1282 {
1283 union tui_line_or_address line_or_addr;
1284 struct symtab_and_line cursal
1285 = get_current_source_symtab_and_line ();
1286
1287 if (win_info->generic.type == SRC_WIN)
1288 line_or_addr.line_no =
1289 win_info->detail.source_info.start_line_or_addr.line_no;
1290 else
1291 line_or_addr.addr =
1292 win_info->detail.source_info.start_line_or_addr.addr;
1293 tui_free_win_content (&win_info->generic);
1294 tui_update_source_window (win_info, cursal.symtab, line_or_addr, TRUE);
1295 }
1296 else if (deprecated_selected_frame != (struct frame_info *) NULL)
1297 {
1298 union tui_line_or_address line;
1299 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
1300
1301
1302 s = find_pc_symtab (get_frame_pc (deprecated_selected_frame));
1303 if (win_info->generic.type == SRC_WIN)
1304 line.line_no = cursal.line;
1305 else
1306 {
1307 find_line_pc (s, cursal.line, &line.addr);
1308 }
1309 tui_update_source_window (win_info, s, line, TRUE);
1310 }
1311 if (tui_win_has_locator (win_info))
1312 {
1313 tui_make_visible (tui_locator_win_info_ptr ());
1314 tui_show_locator_content ();
1315 }
1316 break;
1317 case DATA_WIN:
1318 tui_display_all_data ();
1319 break;
1320 case CMD_WIN:
1321 win_info->detail.command_info.cur_line = 0;
1322 win_info->detail.command_info.curch = 0;
1323 wmove (win_info->generic.handle,
1324 win_info->detail.command_info.cur_line,
1325 win_info->detail.command_info.curch);
1326 break;
1327 default:
1328 break;
1329 }
1330 }
1331
1332
1333 static int
1334 new_height_ok (struct tui_win_info * primary_win_info, int new_height)
1335 {
1336 int ok = (new_height < tui_term_height ());
1337
1338 if (ok)
1339 {
1340 int diff;
1341 enum tui_layout_type cur_layout = tui_current_layout ();
1342
1343 diff = (new_height - primary_win_info->generic.height) * (-1);
1344 if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
1345 {
1346 ok = ((primary_win_info->generic.type == CMD_WIN &&
1347 new_height <= (tui_term_height () - 4) &&
1348 new_height >= MIN_CMD_WIN_HEIGHT) ||
1349 (primary_win_info->generic.type != CMD_WIN &&
1350 new_height <= (tui_term_height () - 2) &&
1351 new_height >= MIN_WIN_HEIGHT));
1352 if (ok)
1353 { /* check the total height */
1354 struct tui_win_info * win_info;
1355
1356 if (primary_win_info == TUI_CMD_WIN)
1357 win_info = (struct tui_win_info *) (tui_source_windows ())->list[0];
1358 else
1359 win_info = TUI_CMD_WIN;
1360 ok = ((new_height +
1361 (win_info->generic.height + diff)) <= tui_term_height ());
1362 }
1363 }
1364 else
1365 {
1366 int cur_total_height, total_height, min_height = 0;
1367 struct tui_win_info *first_win;
1368 struct tui_win_info *second_win;
1369
1370 if (cur_layout == SRC_DISASSEM_COMMAND)
1371 {
1372 first_win = TUI_SRC_WIN;
1373 second_win = TUI_DISASM_WIN;
1374 }
1375 else
1376 {
1377 first_win = TUI_DATA_WIN;
1378 second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
1379 }
1380 /*
1381 ** We could simply add all the heights to obtain the same result
1382 ** but below is more explicit since we subtract 1 for the
1383 ** line that the first and second windows share, and add one
1384 ** for the locator.
1385 */
1386 total_height = cur_total_height =
1387 (first_win->generic.height + second_win->generic.height - 1)
1388 + TUI_CMD_WIN->generic.height + 1 /*locator */ ;
1389 if (primary_win_info == TUI_CMD_WIN)
1390 {
1391 /* locator included since first & second win share a line */
1392 ok = ((first_win->generic.height +
1393 second_win->generic.height + diff) >=
1394 (MIN_WIN_HEIGHT * 2) &&
1395 new_height >= MIN_CMD_WIN_HEIGHT);
1396 if (ok)
1397 {
1398 total_height = new_height + (first_win->generic.height +
1399 second_win->generic.height + diff);
1400 min_height = MIN_CMD_WIN_HEIGHT;
1401 }
1402 }
1403 else
1404 {
1405 min_height = MIN_WIN_HEIGHT;
1406 /*
1407 ** First see if we can increase/decrease the command
1408 ** window. And make sure that the command window is
1409 ** at least 1 line
1410 */
1411 ok = ((TUI_CMD_WIN->generic.height + diff) > 0);
1412 if (!ok)
1413 { /*
1414 ** Looks like we have to increase/decrease one of
1415 ** the other windows
1416 */
1417 if (primary_win_info == first_win)
1418 ok = (second_win->generic.height + diff) >= min_height;
1419 else
1420 ok = (first_win->generic.height + diff) >= min_height;
1421 }
1422 if (ok)
1423 {
1424 if (primary_win_info == first_win)
1425 total_height = new_height +
1426 second_win->generic.height +
1427 TUI_CMD_WIN->generic.height + diff;
1428 else
1429 total_height = new_height +
1430 first_win->generic.height +
1431 TUI_CMD_WIN->generic.height + diff;
1432 }
1433 }
1434 /*
1435 ** Now make sure that the proposed total height doesn't exceed
1436 ** the old total height.
1437 */
1438 if (ok)
1439 ok = (new_height >= min_height && total_height <= cur_total_height);
1440 }
1441 }
1442
1443 return ok;
1444 }
1445
1446
1447 static void
1448 parse_scrolling_args (char *arg, struct tui_win_info * * win_to_scroll,
1449 int *num_to_scroll)
1450 {
1451 if (num_to_scroll)
1452 *num_to_scroll = 0;
1453 *win_to_scroll = tui_win_with_focus ();
1454
1455 /*
1456 ** First set up the default window to scroll, in case there is no
1457 ** window name arg
1458 */
1459 if (arg != (char *) NULL)
1460 {
1461 char *buf, *buf_ptr;
1462
1463 /* process the number of lines to scroll */
1464 buf = buf_ptr = xstrdup (arg);
1465 if (isdigit (*buf_ptr))
1466 {
1467 char *num_str;
1468
1469 num_str = buf_ptr;
1470 buf_ptr = strchr (buf_ptr, ' ');
1471 if (buf_ptr != (char *) NULL)
1472 {
1473 *buf_ptr = (char) 0;
1474 if (num_to_scroll)
1475 *num_to_scroll = atoi (num_str);
1476 buf_ptr++;
1477 }
1478 else if (num_to_scroll)
1479 *num_to_scroll = atoi (num_str);
1480 }
1481
1482 /* process the window name if one is specified */
1483 if (buf_ptr != (char *) NULL)
1484 {
1485 char *wname;
1486 int i;
1487
1488 if (*buf_ptr == ' ')
1489 while (*(++buf_ptr) == ' ')
1490 ;
1491
1492 if (*buf_ptr != (char) 0)
1493 wname = buf_ptr;
1494 else
1495 wname = "?";
1496
1497 /* Validate the window name */
1498 for (i = 0; i < strlen (wname); i++)
1499 wname[i] = toupper (wname[i]);
1500 *win_to_scroll = tui_partial_win_by_name (wname);
1501
1502 if (*win_to_scroll == (struct tui_win_info *) NULL ||
1503 !(*win_to_scroll)->generic.is_visible)
1504 warning ("Invalid window specified. \n\
1505 The window name specified must be valid and visible.\n");
1506 else if (*win_to_scroll == TUI_CMD_WIN)
1507 *win_to_scroll = (struct tui_win_info *) (tui_source_windows ())->list[0];
1508 }
1509 xfree (buf);
1510 }
1511 }
This page took 0.059292 seconds and 4 git commands to generate.