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