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