* h8300s now new target, not alias of h8300h
[deliverable/binutils-gdb.git] / gdb / tui / tuiLayout.c
CommitLineData
f377b406 1/* TUI layout window management.
f33c6cbf
AC
2
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
4 Inc.
5
f377b406 6 Contributed by Hewlett-Packard Company.
c906108c 7
f377b406
SC
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. */
c906108c 24
f33c6cbf
AC
25/* FIXME: cagney/2002-02-28: The GDB coding standard indicates that
26 "defs.h" should be included first. Unfortunatly some systems
27 (currently Debian GNU/Linux) include the <stdbool.h> via <curses.h>
28 and they clash with "bfd.h"'s definiton of true/false. The correct
29 fix is to remove true/false from "bfd.h", however, until that
30 happens, hack around it by including "config.h" and <curses.h>
31 first. */
32
4e8f7a8b
DJ
33#include "config.h"
34#ifdef HAVE_NCURSES_H
35#include <ncurses.h>
36#else
37#ifdef HAVE_CURSES_H
38#include <curses.h>
39#endif
40#endif
41
c906108c
SS
42#include "defs.h"
43#include "command.h"
44#include "symtab.h"
45#include "frame.h"
84b1e7c7 46#include <ctype.h>
c906108c
SS
47
48#include "tui.h"
49#include "tuiData.h"
84b1e7c7 50#include "tuiDataWin.h"
c906108c
SS
51#include "tuiGeneralWin.h"
52#include "tuiStack.h"
53#include "tuiRegs.h"
84b1e7c7
SC
54#include "tuiWin.h"
55#include "tuiSourceWin.h"
c906108c
SS
56#include "tuiDisassem.h"
57
58/*******************************
59** Static Local Decls
60********************************/
61
f6dd1e70
KB
62static void _initGenWinInfo (TuiGenWinInfoPtr, TuiWinType, int, int, int, int);
63static void _initAndMakeWin (Opaque *, TuiWinType, int, int, int, int, int);
64static void _showSourceOrDisassemAndCommand (TuiLayoutType);
65static void _makeSourceOrDisassemWindow (TuiWinInfoPtr *, TuiWinType, int, int);
a14ed312
KB
66static void _makeCommandWindow (TuiWinInfoPtr *, int, int);
67static void _makeSourceWindow (TuiWinInfoPtr *, int, int);
f6dd1e70 68static void _makeDisassemWindow (TuiWinInfoPtr *, int, int);
a14ed312
KB
69static void _makeDataWindow (TuiWinInfoPtr *, int, int);
70static void _showSourceCommand (void);
71static void _showDisassemCommand (void);
72static void _showSourceDisassemCommand (void);
73static void _showData (TuiLayoutType);
74static TuiLayoutType _nextLayout (void);
75static TuiLayoutType _prevLayout (void);
76static void _tuiLayout_command (char *, int);
77static void _tuiToggleLayout_command (char *, int);
a14ed312 78static void _tuiToggleSplitLayout_command (char *, int);
c774cec6 79static CORE_ADDR _extractDisplayStartAddr (void);
a14ed312 80static void _tuiHandleXDBLayout (TuiLayoutDefPtr);
c906108c
SS
81
82
83/***************************************
84** DEFINITIONS
85***************************************/
86
87#define LAYOUT_USAGE "Usage: layout prev | next | <layout_name> \n"
88
89/***************************************
90** Static Local Data
91***************************************/
92static TuiLayoutType lastLayout = UNDEFINED_LAYOUT;
93
94/***************************************
95** PUBLIC FUNCTIONS
96***************************************/
97
98/*
c5aa993b
JM
99 ** showLayout().
100 ** Show the screen layout defined
101 */
c906108c 102void
eca6576c 103showLayout (TuiLayoutType layout)
c906108c
SS
104{
105 TuiLayoutType curLayout = currentLayout ();
106
107 if (layout != curLayout)
108 {
109 /*
c5aa993b
JM
110 ** Since the new layout may cause changes in window size, we
111 ** should free the content and reallocate on next display of
112 ** source/asm
113 */
c906108c
SS
114 tuiClearAllSourceWinsContent (NO_EMPTY_SOURCE_PROMPT);
115 freeAllSourceWinsContent ();
116 clearSourceWindows ();
117 if (layout == SRC_DATA_COMMAND || layout == DISASSEM_DATA_COMMAND)
118 {
119 _showData (layout);
120 refreshAll (winList);
121 }
122 else
123 {
124 /* First make the current layout be invisible */
125 m_allBeInvisible ();
126 m_beInvisible (locatorWinInfoPtr ());
127
128 switch (layout)
129 {
130 /* Now show the new layout */
131 case SRC_COMMAND:
132 _showSourceCommand ();
133 addToSourceWindows (srcWin);
134 break;
135 case DISASSEM_COMMAND:
136 _showDisassemCommand ();
137 addToSourceWindows (disassemWin);
138 break;
139 case SRC_DISASSEM_COMMAND:
140 _showSourceDisassemCommand ();
141 addToSourceWindows (srcWin);
142 addToSourceWindows (disassemWin);
143 break;
144 default:
145 break;
146 }
147 }
148 }
149
150 return;
151} /* showLayout */
152
153
154/*
c5aa993b
JM
155 ** tuiSetLayout()
156 ** Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND,
157 ** SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND.
158 ** If the layout is SRC_DATA_COMMAND, DISASSEM_DATA_COMMAND, or
159 ** UNDEFINED_LAYOUT, then the data window is populated according
160 ** to regsDisplayType.
161 */
c906108c 162TuiStatus
eca6576c
SC
163tuiSetLayout (TuiLayoutType layoutType,
164 TuiRegisterDisplayType regsDisplayType)
c906108c
SS
165{
166 TuiStatus status = TUI_SUCCESS;
167
168 if (layoutType != UNDEFINED_LAYOUT || regsDisplayType != TUI_UNDEFINED_REGS)
169 {
170 TuiLayoutType curLayout = currentLayout (), newLayout = UNDEFINED_LAYOUT;
171 int regsPopulate = FALSE;
c774cec6 172 CORE_ADDR addr = _extractDisplayStartAddr ();
c906108c
SS
173 TuiWinInfoPtr newWinWithFocus = (TuiWinInfoPtr) NULL, winWithFocus = tuiWinWithFocus ();
174 TuiLayoutDefPtr layoutDef = tuiLayoutDef ();
175
176
177 if (layoutType == UNDEFINED_LAYOUT &&
178 regsDisplayType != TUI_UNDEFINED_REGS)
179 {
180 if (curLayout == SRC_DISASSEM_COMMAND)
181 newLayout = DISASSEM_DATA_COMMAND;
182 else if (curLayout == SRC_COMMAND || curLayout == SRC_DATA_COMMAND)
183 newLayout = SRC_DATA_COMMAND;
184 else if (curLayout == DISASSEM_COMMAND ||
185 curLayout == DISASSEM_DATA_COMMAND)
186 newLayout = DISASSEM_DATA_COMMAND;
187 }
188 else
189 newLayout = layoutType;
190
191 regsPopulate = (newLayout == SRC_DATA_COMMAND ||
192 newLayout == DISASSEM_DATA_COMMAND ||
193 regsDisplayType != TUI_UNDEFINED_REGS);
194 if (newLayout != curLayout || regsDisplayType != TUI_UNDEFINED_REGS)
195 {
196 if (newLayout != curLayout)
197 {
198 if (winWithFocus != cmdWin)
199 tuiClearWinFocus ();
200 showLayout (newLayout);
201 /*
c5aa993b
JM
202 ** Now determine where focus should be
203 */
c906108c
SS
204 if (winWithFocus != cmdWin)
205 {
206 switch (newLayout)
207 {
208 case SRC_COMMAND:
209 tuiSetWinFocusTo (srcWin);
210 layoutDef->displayMode = SRC_WIN;
211 layoutDef->split = FALSE;
212 break;
213 case DISASSEM_COMMAND:
214 /* the previous layout was not showing
c5aa993b
JM
215 ** code. this can happen if there is no
216 ** source available:
217 ** 1. if the source file is in another dir OR
218 ** 2. if target was compiled without -g
219 ** We still want to show the assembly though!
220 */
e8b915dc 221 addr = tuiGetBeginAsmAddress ();
c906108c
SS
222 tuiSetWinFocusTo (disassemWin);
223 layoutDef->displayMode = DISASSEM_WIN;
224 layoutDef->split = FALSE;
225 break;
226 case SRC_DISASSEM_COMMAND:
227 /* the previous layout was not showing
c5aa993b
JM
228 ** code. this can happen if there is no
229 ** source available:
230 ** 1. if the source file is in another dir OR
231 ** 2. if target was compiled without -g
232 ** We still want to show the assembly though!
233 */
e8b915dc 234 addr = tuiGetBeginAsmAddress ();
c906108c
SS
235 if (winWithFocus == srcWin)
236 tuiSetWinFocusTo (srcWin);
237 else
238 tuiSetWinFocusTo (disassemWin);
239 layoutDef->split = TRUE;
240 break;
241 case SRC_DATA_COMMAND:
242 if (winWithFocus != dataWin)
243 tuiSetWinFocusTo (srcWin);
244 else
245 tuiSetWinFocusTo (dataWin);
246 layoutDef->displayMode = SRC_WIN;
247 layoutDef->split = FALSE;
248 break;
249 case DISASSEM_DATA_COMMAND:
250 /* the previous layout was not showing
c5aa993b
JM
251 ** code. this can happen if there is no
252 ** source available:
253 ** 1. if the source file is in another dir OR
254 ** 2. if target was compiled without -g
255 ** We still want to show the assembly though!
256 */
e8b915dc 257 addr = tuiGetBeginAsmAddress ();
c906108c
SS
258 if (winWithFocus != dataWin)
259 tuiSetWinFocusTo (disassemWin);
260 else
261 tuiSetWinFocusTo (dataWin);
262 layoutDef->displayMode = DISASSEM_WIN;
263 layoutDef->split = FALSE;
264 break;
265 default:
266 break;
267 }
268 }
269 if (newWinWithFocus != (TuiWinInfoPtr) NULL)
270 tuiSetWinFocusTo (newWinWithFocus);
271 /*
c5aa993b
JM
272 ** Now update the window content
273 */
c906108c
SS
274 if (!regsPopulate &&
275 (newLayout == SRC_DATA_COMMAND ||
276 newLayout == DISASSEM_DATA_COMMAND))
277 tuiDisplayAllData ();
278
279 tuiUpdateSourceWindowsWithAddr (addr);
280 }
281 if (regsPopulate)
282 {
283 layoutDef->regsDisplayType =
284 (regsDisplayType == TUI_UNDEFINED_REGS ?
285 TUI_GENERAL_REGS : regsDisplayType);
286 tuiShowRegisters (layoutDef->regsDisplayType);
287 }
288 }
289 }
290 else
291 status = TUI_FAILURE;
292
293 return status;
294} /* tuiSetLayout */
295
c906108c 296/*
c5aa993b
JM
297 ** tuiAddWinToLayout().
298 ** Add the specified window to the layout in a logical way.
299 ** This means setting up the most logical layout given the
300 ** window to be added.
301 */
c906108c 302void
eca6576c 303tuiAddWinToLayout (TuiWinType type)
c906108c
SS
304{
305 TuiLayoutType curLayout = currentLayout ();
306
307 switch (type)
308 {
309 case SRC_WIN:
310 if (curLayout != SRC_COMMAND &&
311 curLayout != SRC_DISASSEM_COMMAND &&
312 curLayout != SRC_DATA_COMMAND)
313 {
314 clearSourceWindowsDetail ();
315 if (curLayout == DISASSEM_DATA_COMMAND)
316 showLayout (SRC_DATA_COMMAND);
317 else
318 showLayout (SRC_COMMAND);
319 }
320 break;
321 case DISASSEM_WIN:
322 if (curLayout != DISASSEM_COMMAND &&
323 curLayout != SRC_DISASSEM_COMMAND &&
324 curLayout != DISASSEM_DATA_COMMAND)
325 {
326 clearSourceWindowsDetail ();
327 if (curLayout == SRC_DATA_COMMAND)
328 showLayout (DISASSEM_DATA_COMMAND);
329 else
330 showLayout (DISASSEM_COMMAND);
331 }
332 break;
333 case DATA_WIN:
334 if (curLayout != SRC_DATA_COMMAND &&
335 curLayout != DISASSEM_DATA_COMMAND)
336 {
337 if (curLayout == DISASSEM_COMMAND)
338 showLayout (DISASSEM_DATA_COMMAND);
339 else
340 showLayout (SRC_DATA_COMMAND);
341 }
342 break;
343 default:
344 break;
345 }
346
347 return;
348} /* tuiAddWinToLayout */
349
350
c906108c 351/*
c5aa993b
JM
352 ** tuiDefaultWinHeight().
353 ** Answer the height of a window. If it hasn't been created yet,
354 ** answer what the height of a window would be based upon its
355 ** type and the layout.
356 */
c906108c 357int
eca6576c 358tuiDefaultWinHeight (TuiWinType type, TuiLayoutType layout)
c906108c
SS
359{
360 int h;
361
362 if (winList[type] != (TuiWinInfoPtr) NULL)
363 h = winList[type]->generic.height;
364 else
365 {
366 switch (layout)
367 {
368 case SRC_COMMAND:
369 case DISASSEM_COMMAND:
370 if (m_winPtrIsNull (cmdWin))
371 h = termHeight () / 2;
372 else
373 h = termHeight () - cmdWin->generic.height;
374 break;
375 case SRC_DISASSEM_COMMAND:
376 case SRC_DATA_COMMAND:
377 case DISASSEM_DATA_COMMAND:
378 if (m_winPtrIsNull (cmdWin))
379 h = termHeight () / 3;
380 else
381 h = (termHeight () - cmdWin->generic.height) / 2;
382 break;
383 default:
384 h = 0;
385 break;
386 }
387 }
388
389 return h;
390} /* tuiDefaultWinHeight */
391
392
393/*
c5aa993b
JM
394 ** tuiDefaultWinViewportHeight().
395 ** Answer the height of a window. If it hasn't been created yet,
396 ** answer what the height of a window would be based upon its
397 ** type and the layout.
398 */
c906108c 399int
eca6576c 400tuiDefaultWinViewportHeight (TuiWinType type, TuiLayoutType layout)
c906108c
SS
401{
402 int h;
403
404 h = tuiDefaultWinHeight (type, layout);
405
406 if (winList[type] == cmdWin)
407 h -= 1;
408 else
409 h -= 2;
410
411 return h;
412} /* tuiDefaultWinViewportHeight */
413
414
415/*
c5aa993b
JM
416 ** _initialize_tuiLayout().
417 ** Function to initialize gdb commands, for tui window layout
418 ** manipulation.
419 */
c906108c 420void
fba45db2 421_initialize_tuiLayout (void)
c906108c 422{
41783295
SC
423 add_com ("layout", class_tui, _tuiLayout_command,
424 "Change the layout of windows.\n\
c906108c
SS
425Usage: layout prev | next | <layout_name> \n\
426Layout names are:\n\
427 src : Displays source and command windows.\n\
428 asm : Displays disassembly and command windows.\n\
429 split : Displays source, disassembly and command windows.\n\
430 regs : Displays register window. If existing layout\n\
431 is source/command or assembly/command, the \n\
432 register window is displayed. If the\n\
433 source/assembly/command (split) is displayed, \n\
434 the register window is displayed with \n\
435 the window that has current logical focus.\n");
41783295
SC
436 if (xdb_commands)
437 {
438 add_com ("td", class_tui, _tuiToggleLayout_command,
439 "Toggle between Source/Command and Disassembly/Command layouts.\n");
440 add_com ("ts", class_tui, _tuiToggleSplitLayout_command,
441 "Toggle between Source/Command or Disassembly/Command and \n\
c906108c 442Source/Disassembly/Command layouts.\n");
c906108c 443 }
41783295 444}
c906108c
SS
445
446
447/*************************
448** STATIC LOCAL FUNCTIONS
449**************************/
450
451
452/*
c5aa993b
JM
453 ** _tuiSetLayoutTo()
454 ** Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, REGS,
455 ** $REGS, $GREGS, $FREGS, $SREGS.
456 */
e8b915dc
SC
457TuiStatus
458tui_set_layout (const char *layoutName)
c906108c
SS
459{
460 TuiStatus status = TUI_SUCCESS;
461
462 if (layoutName != (char *) NULL)
463 {
464 register int i;
465 register char *bufPtr;
466 TuiLayoutType newLayout = UNDEFINED_LAYOUT;
467 TuiRegisterDisplayType dpyType = TUI_UNDEFINED_REGS;
468 TuiLayoutType curLayout = currentLayout ();
469
19eb139b 470 bufPtr = (char *) xstrdup (layoutName);
c906108c
SS
471 for (i = 0; (i < strlen (layoutName)); i++)
472 bufPtr[i] = toupper (bufPtr[i]);
473
474 /* First check for ambiguous input */
475 if (strlen (bufPtr) <= 1 && (*bufPtr == 'S' || *bufPtr == '$'))
476 {
477 warning ("Ambiguous command input.\n");
478 status = TUI_FAILURE;
479 }
480 else
481 {
0963fc96 482 if (subset_compare (bufPtr, "SRC"))
c906108c 483 newLayout = SRC_COMMAND;
0963fc96 484 else if (subset_compare (bufPtr, "ASM"))
c906108c 485 newLayout = DISASSEM_COMMAND;
0963fc96 486 else if (subset_compare (bufPtr, "SPLIT"))
c906108c 487 newLayout = SRC_DISASSEM_COMMAND;
0963fc96
SC
488 else if (subset_compare (bufPtr, "REGS") ||
489 subset_compare (bufPtr, TUI_GENERAL_SPECIAL_REGS_NAME) ||
490 subset_compare (bufPtr, TUI_GENERAL_REGS_NAME) ||
491 subset_compare (bufPtr, TUI_FLOAT_REGS_NAME) ||
492 subset_compare (bufPtr, TUI_SPECIAL_REGS_NAME))
c906108c
SS
493 {
494 if (curLayout == SRC_COMMAND || curLayout == SRC_DATA_COMMAND)
495 newLayout = SRC_DATA_COMMAND;
496 else
497 newLayout = DISASSEM_DATA_COMMAND;
498
499/* could ifdef out the following code. when compile with -z, there are null
500 pointer references that cause a core dump if 'layout regs' is the first
501 layout command issued by the user. HP has asked us to hook up this code
502 - edie epstein
503 */
0963fc96 504 if (subset_compare (bufPtr, TUI_FLOAT_REGS_NAME))
c906108c
SS
505 {
506 if (dataWin->detail.dataDisplayInfo.regsDisplayType !=
507 TUI_SFLOAT_REGS &&
508 dataWin->detail.dataDisplayInfo.regsDisplayType !=
509 TUI_DFLOAT_REGS)
510 dpyType = TUI_SFLOAT_REGS;
511 else
512 dpyType =
513 dataWin->detail.dataDisplayInfo.regsDisplayType;
514 }
0963fc96 515 else if (subset_compare (bufPtr,
c906108c
SS
516 TUI_GENERAL_SPECIAL_REGS_NAME))
517 dpyType = TUI_GENERAL_AND_SPECIAL_REGS;
0963fc96 518 else if (subset_compare (bufPtr, TUI_GENERAL_REGS_NAME))
c906108c 519 dpyType = TUI_GENERAL_REGS;
0963fc96 520 else if (subset_compare (bufPtr, TUI_SPECIAL_REGS_NAME))
c906108c 521 dpyType = TUI_SPECIAL_REGS;
84b1e7c7 522 else if (dataWin)
c906108c
SS
523 {
524 if (dataWin->detail.dataDisplayInfo.regsDisplayType !=
525 TUI_UNDEFINED_REGS)
526 dpyType =
527 dataWin->detail.dataDisplayInfo.regsDisplayType;
528 else
529 dpyType = TUI_GENERAL_REGS;
530 }
531
532/* end of potential ifdef
533 */
534
535/* if ifdefed out code above, then assume that the user wishes to display the
536 general purpose registers
537 */
538
539/* dpyType = TUI_GENERAL_REGS;
540 */
541 }
0963fc96 542 else if (subset_compare (bufPtr, "NEXT"))
c906108c 543 newLayout = _nextLayout ();
0963fc96 544 else if (subset_compare (bufPtr, "PREV"))
c906108c
SS
545 newLayout = _prevLayout ();
546 else
547 status = TUI_FAILURE;
b8c9b27d 548 xfree (bufPtr);
c906108c
SS
549
550 tuiSetLayout (newLayout, dpyType);
551 }
552 }
553 else
554 status = TUI_FAILURE;
555
556 return status;
e8b915dc 557}
c906108c
SS
558
559
c774cec6 560static CORE_ADDR
c906108c 561_extractDisplayStartAddr (void)
c906108c
SS
562{
563 TuiLayoutType curLayout = currentLayout ();
c774cec6 564 CORE_ADDR addr;
84b1e7c7 565 CORE_ADDR pc;
c906108c
SS
566
567 switch (curLayout)
568 {
569 case SRC_COMMAND:
570 case SRC_DATA_COMMAND:
84b1e7c7
SC
571 find_line_pc (current_source_symtab,
572 srcWin->detail.sourceInfo.startLineOrAddr.lineNo,
573 &pc);
c774cec6 574 addr = pc;
c906108c
SS
575 break;
576 case DISASSEM_COMMAND:
577 case SRC_DISASSEM_COMMAND:
578 case DISASSEM_DATA_COMMAND:
579 addr = disassemWin->detail.sourceInfo.startLineOrAddr.addr;
580 break;
581 default:
c774cec6 582 addr = 0;
c906108c
SS
583 break;
584 }
585
586 return addr;
587} /* _extractDisplayStartAddr */
588
589
590static void
eca6576c 591_tuiHandleXDBLayout (TuiLayoutDefPtr layoutDef)
c906108c
SS
592{
593 if (layoutDef->split)
594 {
595 tuiSetLayout (SRC_DISASSEM_COMMAND, TUI_UNDEFINED_REGS);
596 tuiSetWinFocusTo (winList[layoutDef->displayMode]);
597 }
598 else
599 {
600 if (layoutDef->displayMode == SRC_WIN)
601 tuiSetLayout (SRC_COMMAND, TUI_UNDEFINED_REGS);
602 else
603 tuiSetLayout (DISASSEM_DATA_COMMAND, layoutDef->regsDisplayType);
604 }
605
606
607 return;
608} /* _tuiHandleXDBLayout */
609
610
611static void
eca6576c 612_tuiToggleLayout_command (char *arg, int fromTTY)
c906108c
SS
613{
614 TuiLayoutDefPtr layoutDef = tuiLayoutDef ();
615
19eb139b
SC
616 /* Make sure the curses mode is enabled. */
617 tui_enable ();
c906108c
SS
618 if (layoutDef->displayMode == SRC_WIN)
619 layoutDef->displayMode = DISASSEM_WIN;
620 else
621 layoutDef->displayMode = SRC_WIN;
622
623 if (!layoutDef->split)
624 _tuiHandleXDBLayout (layoutDef);
625
e8b915dc 626}
c906108c
SS
627
628
629static void
eca6576c 630_tuiToggleSplitLayout_command (char *arg, int fromTTY)
c906108c
SS
631{
632 TuiLayoutDefPtr layoutDef = tuiLayoutDef ();
633
19eb139b
SC
634 /* Make sure the curses mode is enabled. */
635 tui_enable ();
c906108c
SS
636 layoutDef->split = (!layoutDef->split);
637 _tuiHandleXDBLayout (layoutDef);
638
e8b915dc 639}
c906108c
SS
640
641
642static void
eca6576c 643_tuiLayout_command (char *arg, int fromTTY)
c906108c 644{
19eb139b
SC
645 /* Make sure the curses mode is enabled. */
646 tui_enable ();
647
648 /* Switch to the selected layout. */
e8b915dc 649 if (tui_set_layout (arg) != TUI_SUCCESS)
84b1e7c7 650 warning ("Invalid layout specified.\n%s", LAYOUT_USAGE);
c906108c 651
e8b915dc 652}
c906108c
SS
653
654/*
c5aa993b
JM
655 ** _nextLayout().
656 ** Answer the previous layout to cycle to.
657 */
c906108c 658static TuiLayoutType
c906108c 659_nextLayout (void)
c906108c
SS
660{
661 TuiLayoutType newLayout;
662
663 newLayout = currentLayout ();
664 if (newLayout == UNDEFINED_LAYOUT)
665 newLayout = SRC_COMMAND;
666 else
667 {
668 newLayout++;
669 if (newLayout == UNDEFINED_LAYOUT)
670 newLayout = SRC_COMMAND;
671 }
672
673 return newLayout;
674} /* _nextLayout */
675
676
677/*
c5aa993b
JM
678 ** _prevLayout().
679 ** Answer the next layout to cycle to.
680 */
c906108c 681static TuiLayoutType
c906108c 682_prevLayout (void)
c906108c
SS
683{
684 TuiLayoutType newLayout;
685
686 newLayout = currentLayout ();
687 if (newLayout == SRC_COMMAND)
688 newLayout = DISASSEM_DATA_COMMAND;
689 else
690 {
691 newLayout--;
692 if (newLayout == UNDEFINED_LAYOUT)
693 newLayout = DISASSEM_DATA_COMMAND;
694 }
695
696 return newLayout;
697} /* _prevLayout */
698
699
700
701/*
c5aa993b
JM
702 ** _makeCommandWindow().
703 */
c906108c 704static void
eca6576c 705_makeCommandWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
c906108c
SS
706{
707 _initAndMakeWin ((Opaque *) winInfoPtr,
708 CMD_WIN,
709 height,
710 termWidth (),
711 0,
712 originY,
713 DONT_BOX_WINDOW);
714
715 (*winInfoPtr)->canHighlight = FALSE;
716
717 return;
718} /* _makeCommandWindow */
719
720
721/*
c5aa993b
JM
722 ** _makeSourceWindow().
723 */
c906108c 724static void
eca6576c 725_makeSourceWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
c906108c
SS
726{
727 _makeSourceOrDisassemWindow (winInfoPtr, SRC_WIN, height, originY);
728
729 return;
730} /* _makeSourceWindow */
731
732
733/*
c5aa993b
JM
734 ** _makeDisassemWindow().
735 */
c906108c 736static void
eca6576c 737_makeDisassemWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
c906108c
SS
738{
739 _makeSourceOrDisassemWindow (winInfoPtr, DISASSEM_WIN, height, originY);
740
741 return;
742} /* _makeDisassemWindow */
743
744
745/*
c5aa993b
JM
746 ** _makeDataWindow().
747 */
c906108c 748static void
eca6576c 749_makeDataWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
c906108c
SS
750{
751 _initAndMakeWin ((Opaque *) winInfoPtr,
752 DATA_WIN,
753 height,
754 termWidth (),
755 0,
756 originY,
757 BOX_WINDOW);
758
759 return;
760} /* _makeDataWindow */
761
762
763
764/*
c5aa993b
JM
765 ** _showSourceCommand().
766 ** Show the Source/Command layout
767 */
c906108c 768static void
c906108c 769_showSourceCommand (void)
c906108c
SS
770{
771 _showSourceOrDisassemAndCommand (SRC_COMMAND);
772
773 return;
774} /* _showSourceCommand */
775
776
777/*
c5aa993b
JM
778 ** _showDisassemCommand().
779 ** Show the Dissassem/Command layout
780 */
c906108c 781static void
c906108c 782_showDisassemCommand (void)
c906108c
SS
783{
784 _showSourceOrDisassemAndCommand (DISASSEM_COMMAND);
785
786 return;
787} /* _showDisassemCommand */
788
789
790/*
c5aa993b
JM
791 ** _showSourceDisassemCommand().
792 ** Show the Source/Disassem/Command layout
793 */
c906108c 794static void
c906108c 795_showSourceDisassemCommand (void)
c906108c
SS
796{
797 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
798
799 if (currentLayout () != SRC_DISASSEM_COMMAND)
800 {
801 int cmdHeight, srcHeight, asmHeight;
802
803 if (m_winPtrNotNull (cmdWin))
804 cmdHeight = cmdWin->generic.height;
805 else
806 cmdHeight = termHeight () / 3;
807
808 srcHeight = (termHeight () - cmdHeight) / 2;
809 asmHeight = termHeight () - (srcHeight + cmdHeight);
810
811 if (m_winPtrIsNull (srcWin))
812 _makeSourceWindow (&srcWin, srcHeight, 0);
813 else
814 {
815 _initGenWinInfo (&srcWin->generic,
816 srcWin->generic.type,
817 srcHeight,
818 srcWin->generic.width,
819 srcWin->detail.sourceInfo.executionInfo->width,
820 0);
821 srcWin->canHighlight = TRUE;
822 _initGenWinInfo (srcWin->detail.sourceInfo.executionInfo,
823 EXEC_INFO_WIN,
824 srcHeight,
825 3,
826 0,
827 0);
828 m_beVisible (srcWin);
829 m_beVisible (srcWin->detail.sourceInfo.executionInfo);
830 srcWin->detail.sourceInfo.hasLocator = FALSE;;
831 }
832 if (m_winPtrNotNull (srcWin))
833 {
834 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
835
836 tuiShowSourceContent (srcWin);
837 if (m_winPtrIsNull (disassemWin))
838 {
839 _makeDisassemWindow (&disassemWin, asmHeight, srcHeight - 1);
840 _initAndMakeWin ((Opaque *) & locator,
841 LOCATOR_WIN,
842 2 /* 1 */ ,
843 termWidth (),
844 0,
845 (srcHeight + asmHeight) - 1,
846 DONT_BOX_WINDOW);
847 }
848 else
849 {
850 _initGenWinInfo (locator,
851 LOCATOR_WIN,
852 2 /* 1 */ ,
853 termWidth (),
854 0,
855 (srcHeight + asmHeight) - 1);
856 disassemWin->detail.sourceInfo.hasLocator = TRUE;
857 _initGenWinInfo (
858 &disassemWin->generic,
859 disassemWin->generic.type,
860 asmHeight,
861 disassemWin->generic.width,
862 disassemWin->detail.sourceInfo.executionInfo->width,
863 srcHeight - 1);
864 _initGenWinInfo (disassemWin->detail.sourceInfo.executionInfo,
865 EXEC_INFO_WIN,
866 asmHeight,
867 3,
868 0,
869 srcHeight - 1);
870 disassemWin->canHighlight = TRUE;
871 m_beVisible (disassemWin);
872 m_beVisible (disassemWin->detail.sourceInfo.executionInfo);
873 }
874 if (m_winPtrNotNull (disassemWin))
875 {
876 srcWin->detail.sourceInfo.hasLocator = FALSE;
877 disassemWin->detail.sourceInfo.hasLocator = TRUE;
878 m_beVisible (locator);
879 tuiShowLocatorContent ();
880 tuiShowSourceContent (disassemWin);
881
882 if (m_winPtrIsNull (cmdWin))
883 _makeCommandWindow (&cmdWin,
884 cmdHeight,
885 termHeight () - cmdHeight);
886 else
887 {
888 _initGenWinInfo (&cmdWin->generic,
889 cmdWin->generic.type,
890 cmdWin->generic.height,
891 cmdWin->generic.width,
892 0,
893 cmdWin->generic.origin.y);
894 cmdWin->canHighlight = FALSE;
895 m_beVisible (cmdWin);
896 }
897 if (m_winPtrNotNull (cmdWin))
898 tuiRefreshWin (&cmdWin->generic);
899 }
900 }
901 setCurrentLayoutTo (SRC_DISASSEM_COMMAND);
902 }
903
904 return;
905} /* _showSourceDisassemCommand */
906
907
908/*
c5aa993b
JM
909 ** _showData().
910 ** Show the Source/Data/Command or the Dissassembly/Data/Command layout
911 */
c906108c 912static void
eca6576c 913_showData (TuiLayoutType newLayout)
c906108c
SS
914{
915 int totalHeight = (termHeight () - cmdWin->generic.height);
916 int srcHeight, dataHeight;
917 TuiWinType winType;
918 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
919
920
921 dataHeight = totalHeight / 2;
922 srcHeight = totalHeight - dataHeight;
923 m_allBeInvisible ();
924 m_beInvisible (locator);
925 _makeDataWindow (&dataWin, dataHeight, 0);
926 dataWin->canHighlight = TRUE;
927 if (newLayout == SRC_DATA_COMMAND)
928 winType = SRC_WIN;
929 else
930 winType = DISASSEM_WIN;
931 if (m_winPtrIsNull (winList[winType]))
932 {
933 if (winType == SRC_WIN)
934 _makeSourceWindow (&winList[winType], srcHeight, dataHeight - 1);
935 else
936 _makeDisassemWindow (&winList[winType], srcHeight, dataHeight - 1);
937 _initAndMakeWin ((Opaque *) & locator,
938 LOCATOR_WIN,
939 2 /* 1 */ ,
940 termWidth (),
941 0,
942 totalHeight - 1,
943 DONT_BOX_WINDOW);
944 }
945 else
946 {
947 _initGenWinInfo (&winList[winType]->generic,
948 winList[winType]->generic.type,
949 srcHeight,
950 winList[winType]->generic.width,
951 winList[winType]->detail.sourceInfo.executionInfo->width,
952 dataHeight - 1);
953 _initGenWinInfo (winList[winType]->detail.sourceInfo.executionInfo,
954 EXEC_INFO_WIN,
955 srcHeight,
956 3,
957 0,
958 dataHeight - 1);
959 m_beVisible (winList[winType]);
960 m_beVisible (winList[winType]->detail.sourceInfo.executionInfo);
961 _initGenWinInfo (locator,
962 LOCATOR_WIN,
963 2 /* 1 */ ,
964 termWidth (),
965 0,
966 totalHeight - 1);
967 }
968 winList[winType]->detail.sourceInfo.hasLocator = TRUE;
969 m_beVisible (locator);
970 tuiShowLocatorContent ();
971 addToSourceWindows (winList[winType]);
972 setCurrentLayoutTo (newLayout);
973
974 return;
975} /* _showData */
976
977/*
c5aa993b
JM
978 ** _initGenWinInfo().
979 */
c906108c 980static void
eca6576c
SC
981_initGenWinInfo (TuiGenWinInfoPtr winInfo, TuiWinType type,
982 int height, int width, int originX, int originY)
c906108c
SS
983{
984 int h = height;
985
986 winInfo->type = type;
987 winInfo->width = width;
988 winInfo->height = h;
989 if (h > 1)
990 {
991 winInfo->viewportHeight = h - 1;
992 if (winInfo->type != CMD_WIN)
993 winInfo->viewportHeight--;
994 }
995 else
996 winInfo->viewportHeight = 1;
997 winInfo->origin.x = originX;
998 winInfo->origin.y = originY;
999
1000 return;
1001} /* _initGenWinInfo */
1002
1003/*
c5aa993b
JM
1004 ** _initAndMakeWin().
1005 */
c906108c 1006static void
eca6576c
SC
1007_initAndMakeWin (Opaque * winInfoPtr, TuiWinType winType,
1008 int height, int width, int originX, int originY, int boxIt)
c906108c
SS
1009{
1010 Opaque opaqueWinInfo = *winInfoPtr;
1011 TuiGenWinInfoPtr generic;
1012
1013 if (opaqueWinInfo == (Opaque) NULL)
1014 {
1015 if (m_winIsAuxillary (winType))
1016 opaqueWinInfo = (Opaque) allocGenericWinInfo ();
1017 else
1018 opaqueWinInfo = (Opaque) allocWinInfo (winType);
1019 }
1020 if (m_winIsAuxillary (winType))
1021 generic = (TuiGenWinInfoPtr) opaqueWinInfo;
1022 else
1023 generic = &((TuiWinInfoPtr) opaqueWinInfo)->generic;
1024
1025 if (opaqueWinInfo != (Opaque) NULL)
1026 {
1027 _initGenWinInfo (generic, winType, height, width, originX, originY);
1028 if (!m_winIsAuxillary (winType))
1029 {
1030 if (generic->type == CMD_WIN)
1031 ((TuiWinInfoPtr) opaqueWinInfo)->canHighlight = FALSE;
1032 else
1033 ((TuiWinInfoPtr) opaqueWinInfo)->canHighlight = TRUE;
1034 }
1035 makeWindow (generic, boxIt);
1036 if (winType == LOCATOR_WIN)
1037 tuiClearLocatorDisplay ();
c906108c
SS
1038 }
1039 *winInfoPtr = opaqueWinInfo;
1040
1041 return;
1042} /* _initAndMakeWin */
1043
1044
1045/*
c5aa993b
JM
1046 ** _makeSourceOrDisassemWindow().
1047 */
c906108c 1048static void
eca6576c
SC
1049_makeSourceOrDisassemWindow (TuiWinInfoPtr * winInfoPtr, TuiWinType type,
1050 int height, int originY)
c906108c
SS
1051{
1052 TuiGenWinInfoPtr executionInfo = (TuiGenWinInfoPtr) NULL;
1053
1054 /*
c5aa993b
JM
1055 ** Create the exeuction info window.
1056 */
c906108c
SS
1057 if (type == SRC_WIN)
1058 executionInfo = sourceExecInfoWinPtr ();
1059 else
1060 executionInfo = disassemExecInfoWinPtr ();
1061 _initAndMakeWin ((Opaque *) & executionInfo,
1062 EXEC_INFO_WIN,
1063 height,
1064 3,
1065 0,
1066 originY,
1067 DONT_BOX_WINDOW);
1068 /*
c5aa993b
JM
1069 ** Now create the source window.
1070 */
c906108c
SS
1071 _initAndMakeWin ((Opaque *) winInfoPtr,
1072 type,
1073 height,
1074 termWidth () - executionInfo->width,
1075 executionInfo->width,
1076 originY,
1077 BOX_WINDOW);
1078
1079 (*winInfoPtr)->detail.sourceInfo.executionInfo = executionInfo;
1080
1081 return;
1082} /* _makeSourceOrDisassemWindow */
1083
1084
1085/*
c5aa993b
JM
1086 ** _showSourceOrDisassemAndCommand().
1087 ** Show the Source/Command or the Disassem layout
1088 */
c906108c 1089static void
eca6576c 1090_showSourceOrDisassemAndCommand (TuiLayoutType layoutType)
c906108c
SS
1091{
1092 if (currentLayout () != layoutType)
1093 {
1094 TuiWinInfoPtr *winInfoPtr;
1095 int areaLeft;
1096 int srcHeight, cmdHeight;
1097 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
1098
1099 if (m_winPtrNotNull (cmdWin))
1100 cmdHeight = cmdWin->generic.height;
1101 else
1102 cmdHeight = termHeight () / 3;
1103 srcHeight = termHeight () - cmdHeight;
1104
1105
1106 if (layoutType == SRC_COMMAND)
1107 winInfoPtr = &srcWin;
1108 else
1109 winInfoPtr = &disassemWin;
1110
1111 if (m_winPtrIsNull (*winInfoPtr))
1112 {
1113 if (layoutType == SRC_COMMAND)
1114 _makeSourceWindow (winInfoPtr, srcHeight - 1, 0);
1115 else
1116 _makeDisassemWindow (winInfoPtr, srcHeight - 1, 0);
1117 _initAndMakeWin ((Opaque *) & locator,
1118 LOCATOR_WIN,
1119 2 /* 1 */ ,
1120 termWidth (),
1121 0,
1122 srcHeight - 1,
1123 DONT_BOX_WINDOW);
1124 }
1125 else
1126 {
1127 _initGenWinInfo (locator,
1128 LOCATOR_WIN,
1129 2 /* 1 */ ,
1130 termWidth (),
1131 0,
1132 srcHeight - 1);
1133 (*winInfoPtr)->detail.sourceInfo.hasLocator = TRUE;
1134 _initGenWinInfo (
1135 &(*winInfoPtr)->generic,
1136 (*winInfoPtr)->generic.type,
1137 srcHeight - 1,
1138 (*winInfoPtr)->generic.width,
1139 (*winInfoPtr)->detail.sourceInfo.executionInfo->width,
1140 0);
1141 _initGenWinInfo ((*winInfoPtr)->detail.sourceInfo.executionInfo,
1142 EXEC_INFO_WIN,
1143 srcHeight - 1,
1144 3,
1145 0,
1146 0);
1147 (*winInfoPtr)->canHighlight = TRUE;
1148 m_beVisible (*winInfoPtr);
1149 m_beVisible ((*winInfoPtr)->detail.sourceInfo.executionInfo);
1150 }
1151 if (m_winPtrNotNull (*winInfoPtr))
1152 {
1153 (*winInfoPtr)->detail.sourceInfo.hasLocator = TRUE;
1154 m_beVisible (locator);
1155 tuiShowLocatorContent ();
1156 tuiShowSourceContent (*winInfoPtr);
1157
1158 if (m_winPtrIsNull (cmdWin))
1159 {
1160 _makeCommandWindow (&cmdWin, cmdHeight, srcHeight);
1161 tuiRefreshWin (&cmdWin->generic);
1162 }
1163 else
1164 {
1165 _initGenWinInfo (&cmdWin->generic,
1166 cmdWin->generic.type,
1167 cmdWin->generic.height,
1168 cmdWin->generic.width,
1169 cmdWin->generic.origin.x,
1170 cmdWin->generic.origin.y);
1171 cmdWin->canHighlight = FALSE;
1172 m_beVisible (cmdWin);
1173 }
1174 }
1175 setCurrentLayoutTo (layoutType);
1176 }
1177
1178 return;
1179} /* _showSourceOrDisassemAndCommand */
This page took 0.261389 seconds and 4 git commands to generate.