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