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