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