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