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