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