2007-08-14 Michael Snyder <msnyder@access-company.com>
[platform/upstream/binutils.git] / gdb / tui / tui-layout.c
1 /* TUI layout window management.
2
3    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007
4    Free Software 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., 51 Franklin Street, Fifth Floor,
23    Boston, MA 02110-1301, 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 #include "gdb_string.h"
43 #include "gdb_curses.h"
44
45 /*******************************
46 ** Static Local Decls
47 ********************************/
48 static void show_layout (enum tui_layout_type);
49 static void init_gen_win_info (struct tui_gen_win_info *, enum tui_win_type, int, int, int, int);
50 static void *init_and_make_win (void *, enum tui_win_type, int, int, int, int, int);
51 static void show_source_or_disasm_and_command (enum tui_layout_type);
52 static void make_source_or_disasm_window (struct tui_win_info **, enum tui_win_type, int, int);
53 static void make_command_window (struct tui_win_info **, int, int);
54 static void make_source_window (struct tui_win_info **, int, int);
55 static void make_disasm_window (struct tui_win_info **, int, int);
56 static void make_data_window (struct tui_win_info **, int, int);
57 static void show_source_command (void);
58 static void show_disasm_command (void);
59 static void show_source_disasm_command (void);
60 static void show_data (enum tui_layout_type);
61 static enum tui_layout_type next_layout (void);
62 static enum tui_layout_type prev_layout (void);
63 static void tui_layout_command (char *, int);
64 static void tui_toggle_layout_command (char *, int);
65 static void tui_toggle_split_layout_command (char *, int);
66 static CORE_ADDR extract_display_start_addr (void);
67 static void tui_handle_xdb_layout (struct tui_layout_def *);
68
69
70 /***************************************
71 ** DEFINITIONS
72 ***************************************/
73
74 #define LAYOUT_USAGE     "Usage: layout prev | next | <layout_name> \n"
75
76 /* Show the screen layout defined.  */
77 static void
78 show_layout (enum tui_layout_type layout)
79 {
80   enum tui_layout_type cur_layout = tui_current_layout ();
81
82   if (layout != cur_layout)
83     {
84       /*
85          ** Since the new layout may cause changes in window size, we
86          ** should free the content and reallocate on next display of
87          ** source/asm.
88        */
89       tui_free_all_source_wins_content ();
90       tui_clear_source_windows ();
91       if (layout == SRC_DATA_COMMAND || layout == DISASSEM_DATA_COMMAND)
92         {
93           show_data (layout);
94           tui_refresh_all (tui_win_list);
95         }
96       else
97         {
98           /* First make the current layout be invisible.  */
99           tui_make_all_invisible ();
100           tui_make_invisible (tui_locator_win_info_ptr ());
101
102           switch (layout)
103             {
104               /* Now show the new layout.  */
105             case SRC_COMMAND:
106               show_source_command ();
107               tui_add_to_source_windows (TUI_SRC_WIN);
108               break;
109             case DISASSEM_COMMAND:
110               show_disasm_command ();
111               tui_add_to_source_windows (TUI_DISASM_WIN);
112               break;
113             case SRC_DISASSEM_COMMAND:
114               show_source_disasm_command ();
115               tui_add_to_source_windows (TUI_SRC_WIN);
116               tui_add_to_source_windows (TUI_DISASM_WIN);
117               break;
118             default:
119               break;
120             }
121         }
122     }
123 }
124
125
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 to
130    regs_display_type.  */
131 enum tui_status
132 tui_set_layout (enum tui_layout_type layout_type,
133                 enum tui_register_display_type regs_display_type)
134 {
135   enum tui_status status = TUI_SUCCESS;
136
137   if (layout_type != UNDEFINED_LAYOUT || regs_display_type != TUI_UNDEFINED_REGS)
138     {
139       enum tui_layout_type cur_layout = tui_current_layout (), new_layout = UNDEFINED_LAYOUT;
140       int regs_populate = FALSE;
141       CORE_ADDR addr = extract_display_start_addr ();
142       struct tui_win_info *win_with_focus = tui_win_with_focus ();
143       struct tui_layout_def *layout_def = tui_layout_def ();
144
145
146       if (layout_type == UNDEFINED_LAYOUT &&
147           regs_display_type != TUI_UNDEFINED_REGS)
148         {
149           if (cur_layout == SRC_DISASSEM_COMMAND)
150             new_layout = DISASSEM_DATA_COMMAND;
151           else if (cur_layout == SRC_COMMAND || cur_layout == SRC_DATA_COMMAND)
152             new_layout = SRC_DATA_COMMAND;
153           else if (cur_layout == DISASSEM_COMMAND ||
154                    cur_layout == DISASSEM_DATA_COMMAND)
155             new_layout = DISASSEM_DATA_COMMAND;
156         }
157       else
158         new_layout = layout_type;
159
160       regs_populate = (new_layout == SRC_DATA_COMMAND ||
161                       new_layout == DISASSEM_DATA_COMMAND ||
162                       regs_display_type != TUI_UNDEFINED_REGS);
163       if (new_layout != cur_layout || regs_display_type != TUI_UNDEFINED_REGS)
164         {
165           if (new_layout != cur_layout)
166             {
167               show_layout (new_layout);
168               /*
169                  ** Now determine where focus should be.
170                */
171               if (win_with_focus != TUI_CMD_WIN)
172                 {
173                   switch (new_layout)
174                     {
175                     case SRC_COMMAND:
176                       tui_set_win_focus_to (TUI_SRC_WIN);
177                       layout_def->display_mode = SRC_WIN;
178                       layout_def->split = FALSE;
179                       break;
180                     case DISASSEM_COMMAND:
181                       /* The previous layout was not showing
182                          ** code. this can happen if there is no
183                          ** source available:
184                          ** 1. if the source file is in another dir OR
185                          ** 2. if target was compiled without -g
186                          ** We still want to show the assembly though!
187                        */
188                       addr = tui_get_begin_asm_address ();
189                       tui_set_win_focus_to (TUI_DISASM_WIN);
190                       layout_def->display_mode = DISASSEM_WIN;
191                       layout_def->split = FALSE;
192                       break;
193                     case SRC_DISASSEM_COMMAND:
194                       /* The previous layout was not showing
195                          ** code. this can happen if there is no
196                          ** source available:
197                          ** 1. if the source file is in another dir OR
198                          ** 2. if target was compiled without -g
199                          ** We still want to show the assembly though!
200                        */
201                       addr = tui_get_begin_asm_address ();
202                       if (win_with_focus == TUI_SRC_WIN)
203                         tui_set_win_focus_to (TUI_SRC_WIN);
204                       else
205                         tui_set_win_focus_to (TUI_DISASM_WIN);
206                       layout_def->split = TRUE;
207                       break;
208                     case SRC_DATA_COMMAND:
209                       if (win_with_focus != TUI_DATA_WIN)
210                         tui_set_win_focus_to (TUI_SRC_WIN);
211                       else
212                         tui_set_win_focus_to (TUI_DATA_WIN);
213                       layout_def->display_mode = SRC_WIN;
214                       layout_def->split = FALSE;
215                       break;
216                     case DISASSEM_DATA_COMMAND:
217                       /* The previous layout was not showing
218                          ** code. this can happen if there is no
219                          ** source available:
220                          ** 1. if the source file is in another dir OR
221                          ** 2. if target was compiled without -g
222                          ** We still want to show the assembly though!
223                        */
224                       addr = tui_get_begin_asm_address ();
225                       if (win_with_focus != TUI_DATA_WIN)
226                         tui_set_win_focus_to (TUI_DISASM_WIN);
227                       else
228                         tui_set_win_focus_to (TUI_DATA_WIN);
229                       layout_def->display_mode = DISASSEM_WIN;
230                       layout_def->split = FALSE;
231                       break;
232                     default:
233                       break;
234                     }
235                 }
236               /*
237                * Now update the window content.
238                */
239               if (!regs_populate &&
240                   (new_layout == SRC_DATA_COMMAND ||
241                    new_layout == DISASSEM_DATA_COMMAND))
242                 tui_display_all_data ();
243
244               tui_update_source_windows_with_addr (addr);
245             }
246           if (regs_populate)
247             {
248               tui_show_registers (TUI_DATA_WIN->detail.data_display_info.current_group);
249             }
250         }
251     }
252   else
253     status = TUI_FAILURE;
254
255   return status;
256 }
257
258 /* Add the specified window to the layout in a logical way.  This
259    means setting up the most logical layout given the window to be
260    added.  */
261 void
262 tui_add_win_to_layout (enum tui_win_type type)
263 {
264   enum tui_layout_type cur_layout = tui_current_layout ();
265
266   switch (type)
267     {
268     case SRC_WIN:
269       if (cur_layout != SRC_COMMAND &&
270           cur_layout != SRC_DISASSEM_COMMAND &&
271           cur_layout != SRC_DATA_COMMAND)
272         {
273           tui_clear_source_windows_detail ();
274           if (cur_layout == DISASSEM_DATA_COMMAND)
275             show_layout (SRC_DATA_COMMAND);
276           else
277             show_layout (SRC_COMMAND);
278         }
279       break;
280     case DISASSEM_WIN:
281       if (cur_layout != DISASSEM_COMMAND &&
282           cur_layout != SRC_DISASSEM_COMMAND &&
283           cur_layout != DISASSEM_DATA_COMMAND)
284         {
285           tui_clear_source_windows_detail ();
286           if (cur_layout == SRC_DATA_COMMAND)
287             show_layout (DISASSEM_DATA_COMMAND);
288           else
289             show_layout (DISASSEM_COMMAND);
290         }
291       break;
292     case DATA_WIN:
293       if (cur_layout != SRC_DATA_COMMAND &&
294           cur_layout != DISASSEM_DATA_COMMAND)
295         {
296           if (cur_layout == DISASSEM_COMMAND)
297             show_layout (DISASSEM_DATA_COMMAND);
298           else
299             show_layout (SRC_DATA_COMMAND);
300         }
301       break;
302     default:
303       break;
304     }
305 }
306
307
308 /* Answer the height of a window.  If it hasn't been created yet,
309    answer what the height of a window would be based upon its type and
310    the layout.  */
311 int
312 tui_default_win_height (enum tui_win_type type, enum tui_layout_type layout)
313 {
314   int h;
315
316   if (tui_win_list[type] != (struct tui_win_info *) NULL)
317     h = tui_win_list[type]->generic.height;
318   else
319     {
320       switch (layout)
321         {
322         case SRC_COMMAND:
323         case DISASSEM_COMMAND:
324           if (TUI_CMD_WIN == NULL)
325             h = tui_term_height () / 2;
326           else
327             h = tui_term_height () - TUI_CMD_WIN->generic.height;
328           break;
329         case SRC_DISASSEM_COMMAND:
330         case SRC_DATA_COMMAND:
331         case DISASSEM_DATA_COMMAND:
332           if (TUI_CMD_WIN == NULL)
333             h = tui_term_height () / 3;
334           else
335             h = (tui_term_height () - TUI_CMD_WIN->generic.height) / 2;
336           break;
337         default:
338           h = 0;
339           break;
340         }
341     }
342
343   return h;
344 }
345
346
347 /* Answer the height of a window.  If it hasn't been created yet,
348    answer what the height of a window would be based upon its type and
349    the layout.  */
350 int
351 tui_default_win_viewport_height (enum tui_win_type type,
352                                  enum tui_layout_type layout)
353 {
354   int h;
355
356   h = tui_default_win_height (type, layout);
357
358   if (tui_win_list[type] == TUI_CMD_WIN)
359     h -= 1;
360   else
361     h -= 2;
362
363   return h;
364 }
365
366
367 /* Function to initialize gdb commands, for tui window layout
368    manipulation.  */
369 void
370 _initialize_tui_layout (void)
371 {
372   add_com ("layout", class_tui, tui_layout_command, _("\
373 Change the layout of windows.\n\
374 Usage: layout prev | next | <layout_name> \n\
375 Layout names are:\n\
376    src   : Displays source and command windows.\n\
377    asm   : Displays disassembly and command windows.\n\
378    split : Displays source, disassembly and command windows.\n\
379    regs  : Displays register window. If existing layout\n\
380            is source/command or assembly/command, the \n\
381            register window is displayed. If the\n\
382            source/assembly/command (split) is displayed, \n\
383            the register window is displayed with \n\
384            the window that has current logical focus.\n"));
385   if (xdb_commands)
386     {
387       add_com ("td", class_tui, tui_toggle_layout_command, _("\
388 Toggle between Source/Command and Disassembly/Command layouts.\n"));
389       add_com ("ts", class_tui, tui_toggle_split_layout_command, _("\
390 Toggle between Source/Command or Disassembly/Command and \n\
391 Source/Disassembly/Command layouts.\n"));
392     }
393 }
394
395
396 /*************************
397 ** STATIC LOCAL FUNCTIONS
398 **************************/
399
400
401 /* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA,
402    REGS, $REGS, $GREGS, $FREGS, $SREGS.  */
403 enum tui_status
404 tui_set_layout_for_display_command (const char *layout_name)
405 {
406   enum tui_status status = TUI_SUCCESS;
407
408   if (layout_name != (char *) NULL)
409     {
410       int i;
411       char *buf_ptr;
412       enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
413       enum tui_register_display_type dpy_type = TUI_UNDEFINED_REGS;
414       enum tui_layout_type cur_layout = tui_current_layout ();
415
416       buf_ptr = (char *) xstrdup (layout_name);
417       for (i = 0; (i < strlen (layout_name)); i++)
418         buf_ptr[i] = toupper (buf_ptr[i]);
419
420       /* First check for ambiguous input.  */
421       if (strlen (buf_ptr) <= 1 && (*buf_ptr == 'S' || *buf_ptr == '$'))
422         {
423           warning (_("Ambiguous command input."));
424           status = TUI_FAILURE;
425         }
426       else
427         {
428           if (subset_compare (buf_ptr, "SRC"))
429             new_layout = SRC_COMMAND;
430           else if (subset_compare (buf_ptr, "ASM"))
431             new_layout = DISASSEM_COMMAND;
432           else if (subset_compare (buf_ptr, "SPLIT"))
433             new_layout = SRC_DISASSEM_COMMAND;
434           else if (subset_compare (buf_ptr, "REGS") ||
435                    subset_compare (buf_ptr, TUI_GENERAL_SPECIAL_REGS_NAME) ||
436                    subset_compare (buf_ptr, TUI_GENERAL_REGS_NAME) ||
437                    subset_compare (buf_ptr, TUI_FLOAT_REGS_NAME) ||
438                    subset_compare (buf_ptr, TUI_SPECIAL_REGS_NAME))
439             {
440               if (cur_layout == SRC_COMMAND || cur_layout == SRC_DATA_COMMAND)
441                 new_layout = SRC_DATA_COMMAND;
442               else
443                 new_layout = DISASSEM_DATA_COMMAND;
444
445               /* Could ifdef out the following code. when compile with
446                  -z, there are null pointer references that cause a
447                  core dump if 'layout regs' is the first layout
448                  command issued by the user. HP has asked us to hook
449                  up this code.  - edie epstein  */
450               if (subset_compare (buf_ptr, TUI_FLOAT_REGS_NAME))
451                 {
452                   if (TUI_DATA_WIN->detail.data_display_info.regs_display_type !=
453                       TUI_SFLOAT_REGS &&
454                       TUI_DATA_WIN->detail.data_display_info.regs_display_type !=
455                       TUI_DFLOAT_REGS)
456                     dpy_type = TUI_SFLOAT_REGS;
457                   else
458                     dpy_type =
459                       TUI_DATA_WIN->detail.data_display_info.regs_display_type;
460                 }
461               else if (subset_compare (buf_ptr,
462                                       TUI_GENERAL_SPECIAL_REGS_NAME))
463                 dpy_type = TUI_GENERAL_AND_SPECIAL_REGS;
464               else if (subset_compare (buf_ptr, TUI_GENERAL_REGS_NAME))
465                 dpy_type = TUI_GENERAL_REGS;
466               else if (subset_compare (buf_ptr, TUI_SPECIAL_REGS_NAME))
467                 dpy_type = TUI_SPECIAL_REGS;
468               else if (TUI_DATA_WIN)
469                 {
470                   if (TUI_DATA_WIN->detail.data_display_info.regs_display_type !=
471                       TUI_UNDEFINED_REGS)
472                     dpy_type =
473                       TUI_DATA_WIN->detail.data_display_info.regs_display_type;
474                   else
475                     dpy_type = TUI_GENERAL_REGS;
476                 }
477
478               /* End of potential ifdef.
479                */
480
481               /* If ifdefed out code above, then assume that the user
482                  wishes to display the general purpose registers .
483               */
484
485               /* dpy_type = TUI_GENERAL_REGS; */
486             }
487           else if (subset_compare (buf_ptr, "NEXT"))
488             new_layout = next_layout ();
489           else if (subset_compare (buf_ptr, "PREV"))
490             new_layout = prev_layout ();
491           else
492             status = TUI_FAILURE;
493
494           tui_set_layout (new_layout, dpy_type);
495         }
496       xfree (buf_ptr);
497     }
498   else
499     status = TUI_FAILURE;
500
501   return status;
502 }
503
504
505 static CORE_ADDR
506 extract_display_start_addr (void)
507 {
508   enum tui_layout_type cur_layout = tui_current_layout ();
509   CORE_ADDR addr;
510   CORE_ADDR pc;
511   struct symtab_and_line cursal = get_current_source_symtab_and_line ();
512
513   switch (cur_layout)
514     {
515     case SRC_COMMAND:
516     case SRC_DATA_COMMAND:
517       find_line_pc (cursal.symtab,
518                     TUI_SRC_WIN->detail.source_info.start_line_or_addr.u.line_no,
519                     &pc);
520       addr = pc;
521       break;
522     case DISASSEM_COMMAND:
523     case SRC_DISASSEM_COMMAND:
524     case DISASSEM_DATA_COMMAND:
525       addr = TUI_DISASM_WIN->detail.source_info.start_line_or_addr.u.addr;
526       break;
527     default:
528       addr = 0;
529       break;
530     }
531
532   return addr;
533 }
534
535
536 static void
537 tui_handle_xdb_layout (struct tui_layout_def *layout_def)
538 {
539   if (layout_def->split)
540     {
541       tui_set_layout (SRC_DISASSEM_COMMAND, TUI_UNDEFINED_REGS);
542       tui_set_win_focus_to (tui_win_list[layout_def->display_mode]);
543     }
544   else
545     {
546       if (layout_def->display_mode == SRC_WIN)
547         tui_set_layout (SRC_COMMAND, TUI_UNDEFINED_REGS);
548       else
549         tui_set_layout (DISASSEM_DATA_COMMAND, layout_def->regs_display_type);
550     }
551 }
552
553
554 static void
555 tui_toggle_layout_command (char *arg, int from_tty)
556 {
557   struct tui_layout_def *layout_def = tui_layout_def ();
558
559   /* Make sure the curses mode is enabled.  */
560   tui_enable ();
561   if (layout_def->display_mode == SRC_WIN)
562     layout_def->display_mode = DISASSEM_WIN;
563   else
564     layout_def->display_mode = SRC_WIN;
565
566   if (!layout_def->split)
567     tui_handle_xdb_layout (layout_def);
568 }
569
570
571 static void
572 tui_toggle_split_layout_command (char *arg, int from_tty)
573 {
574   struct tui_layout_def *layout_def = tui_layout_def ();
575
576   /* Make sure the curses mode is enabled.  */
577   tui_enable ();
578   layout_def->split = (!layout_def->split);
579   tui_handle_xdb_layout (layout_def);
580 }
581
582
583 static void
584 tui_layout_command (char *arg, int from_tty)
585 {
586   /* Make sure the curses mode is enabled.  */
587   tui_enable ();
588
589   /* Switch to the selected layout.  */
590   if (tui_set_layout_for_display_command (arg) != TUI_SUCCESS)
591     warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE);
592
593 }
594
595 /* Answer the previous layout to cycle to.  */
596 static enum tui_layout_type
597 next_layout (void)
598 {
599   enum tui_layout_type new_layout;
600
601   new_layout = tui_current_layout ();
602   if (new_layout == UNDEFINED_LAYOUT)
603     new_layout = SRC_COMMAND;
604   else
605     {
606       new_layout++;
607       if (new_layout == UNDEFINED_LAYOUT)
608         new_layout = SRC_COMMAND;
609     }
610
611   return new_layout;
612 }
613
614
615 /* Answer the next layout to cycle to.  */
616 static enum tui_layout_type
617 prev_layout (void)
618 {
619   enum tui_layout_type new_layout;
620
621   new_layout = tui_current_layout ();
622   if (new_layout == SRC_COMMAND)
623     new_layout = DISASSEM_DATA_COMMAND;
624   else
625     {
626       new_layout--;
627       if (new_layout == UNDEFINED_LAYOUT)
628         new_layout = DISASSEM_DATA_COMMAND;
629     }
630
631   return new_layout;
632 }
633
634
635
636 static void
637 make_command_window (struct tui_win_info **win_info_ptr, int height, int origin_y)
638 {
639   *win_info_ptr = init_and_make_win (*win_info_ptr,
640                                      CMD_WIN,
641                                      height,
642                                      tui_term_width (),
643                                      0,
644                                      origin_y,
645                                      DONT_BOX_WINDOW);
646
647   (*win_info_ptr)->can_highlight = FALSE;
648 }
649
650
651 /*
652    ** make_source_window().
653  */
654 static void
655 make_source_window (struct tui_win_info **win_info_ptr, int height, int origin_y)
656 {
657   make_source_or_disasm_window (win_info_ptr, SRC_WIN, height, origin_y);
658
659   return;
660 }                               /* make_source_window */
661
662
663 /*
664    ** make_disasm_window().
665  */
666 static void
667 make_disasm_window (struct tui_win_info **win_info_ptr, int height, int origin_y)
668 {
669   make_source_or_disasm_window (win_info_ptr, DISASSEM_WIN, height, origin_y);
670
671   return;
672 }                               /* make_disasm_window */
673
674
675 static void
676 make_data_window (struct tui_win_info **win_info_ptr, int height, int origin_y)
677 {
678   *win_info_ptr = init_and_make_win (*win_info_ptr,
679                                      DATA_WIN,
680                                      height,
681                                      tui_term_width (),
682                                      0,
683                                      origin_y,
684                                      BOX_WINDOW);
685 }
686
687
688
689 /* Show the Source/Command layout.  */
690 static void
691 show_source_command (void)
692 {
693   show_source_or_disasm_and_command (SRC_COMMAND);
694 }
695
696
697 /* Show the Dissassem/Command layout.  */
698 static void
699 show_disasm_command (void)
700 {
701   show_source_or_disasm_and_command (DISASSEM_COMMAND);
702 }
703
704
705 /* Show the Source/Disassem/Command layout.  */
706 static void
707 show_source_disasm_command (void)
708 {
709   if (tui_current_layout () != SRC_DISASSEM_COMMAND)
710     {
711       int cmd_height, src_height, asm_height;
712
713       if (TUI_CMD_WIN != NULL)
714         cmd_height = TUI_CMD_WIN->generic.height;
715       else
716         cmd_height = tui_term_height () / 3;
717
718       src_height = (tui_term_height () - cmd_height) / 2;
719       asm_height = tui_term_height () - (src_height + cmd_height);
720
721       if (TUI_SRC_WIN == NULL)
722         make_source_window (&TUI_SRC_WIN, src_height, 0);
723       else
724         {
725           init_gen_win_info (&TUI_SRC_WIN->generic,
726                            TUI_SRC_WIN->generic.type,
727                            src_height,
728                            TUI_SRC_WIN->generic.width,
729                            TUI_SRC_WIN->detail.source_info.execution_info->width,
730                            0);
731           TUI_SRC_WIN->can_highlight = TRUE;
732           init_gen_win_info (TUI_SRC_WIN->detail.source_info.execution_info,
733                            EXEC_INFO_WIN,
734                            src_height,
735                            3,
736                            0,
737                            0);
738           tui_make_visible (&TUI_SRC_WIN->generic);
739           tui_make_visible (TUI_SRC_WIN->detail.source_info.execution_info);
740           TUI_SRC_WIN->detail.source_info.has_locator = FALSE;;
741         }
742       if (TUI_SRC_WIN != NULL)
743         {
744           struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
745
746           tui_show_source_content (TUI_SRC_WIN);
747           if (TUI_DISASM_WIN == NULL)
748             {
749               make_disasm_window (&TUI_DISASM_WIN, asm_height, src_height - 1);
750               locator = init_and_make_win (locator,
751                                            LOCATOR_WIN,
752                                            2 /* 1 */ ,
753                                            tui_term_width (),
754                                            0,
755                                            (src_height + asm_height) - 1,
756                                            DONT_BOX_WINDOW);
757             }
758           else
759             {
760               init_gen_win_info (locator,
761                                LOCATOR_WIN,
762                                2 /* 1 */ ,
763                                tui_term_width (),
764                                0,
765                                (src_height + asm_height) - 1);
766               TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
767               init_gen_win_info (
768                                 &TUI_DISASM_WIN->generic,
769                                 TUI_DISASM_WIN->generic.type,
770                                 asm_height,
771                                 TUI_DISASM_WIN->generic.width,
772                         TUI_DISASM_WIN->detail.source_info.execution_info->width,
773                                 src_height - 1);
774               init_gen_win_info (TUI_DISASM_WIN->detail.source_info.execution_info,
775                                EXEC_INFO_WIN,
776                                asm_height,
777                                3,
778                                0,
779                                src_height - 1);
780               TUI_DISASM_WIN->can_highlight = TRUE;
781               tui_make_visible (&TUI_DISASM_WIN->generic);
782               tui_make_visible (TUI_DISASM_WIN->detail.source_info.execution_info);
783             }
784           if (TUI_DISASM_WIN != NULL)
785             {
786               TUI_SRC_WIN->detail.source_info.has_locator = FALSE;
787               TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
788               tui_make_visible (locator);
789               tui_show_locator_content ();
790               tui_show_source_content (TUI_DISASM_WIN);
791
792               if (TUI_CMD_WIN == NULL)
793                 make_command_window (&TUI_CMD_WIN,
794                                     cmd_height,
795                                     tui_term_height () - cmd_height);
796               else
797                 {
798                   init_gen_win_info (&TUI_CMD_WIN->generic,
799                                    TUI_CMD_WIN->generic.type,
800                                    TUI_CMD_WIN->generic.height,
801                                    TUI_CMD_WIN->generic.width,
802                                    0,
803                                    TUI_CMD_WIN->generic.origin.y);
804                   TUI_CMD_WIN->can_highlight = FALSE;
805                   tui_make_visible (&TUI_CMD_WIN->generic);
806                 }
807               if (TUI_CMD_WIN != NULL)
808                 tui_refresh_win (&TUI_CMD_WIN->generic);
809             }
810         }
811       tui_set_current_layout_to (SRC_DISASSEM_COMMAND);
812     }
813 }
814
815
816 /* Show the Source/Data/Command or the Dissassembly/Data/Command
817    layout.  */
818 static void
819 show_data (enum tui_layout_type new_layout)
820 {
821   int total_height = (tui_term_height () - TUI_CMD_WIN->generic.height);
822   int src_height, data_height;
823   enum tui_win_type win_type;
824   struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
825
826
827   data_height = total_height / 2;
828   src_height = total_height - data_height;
829   tui_make_all_invisible ();
830   tui_make_invisible (locator);
831   make_data_window (&TUI_DATA_WIN, data_height, 0);
832   TUI_DATA_WIN->can_highlight = TRUE;
833   if (new_layout == SRC_DATA_COMMAND)
834     win_type = SRC_WIN;
835   else
836     win_type = DISASSEM_WIN;
837   if (tui_win_list[win_type] == NULL)
838     {
839       if (win_type == SRC_WIN)
840         make_source_window (&tui_win_list[win_type], src_height, data_height - 1);
841       else
842         make_disasm_window (&tui_win_list[win_type], src_height, data_height - 1);
843       locator = init_and_make_win (locator,
844                                    LOCATOR_WIN,
845                                    2 /* 1 */ ,
846                                    tui_term_width (),
847                                    0,
848                                    total_height - 1,
849                                    DONT_BOX_WINDOW);
850     }
851   else
852     {
853       init_gen_win_info (&tui_win_list[win_type]->generic,
854                        tui_win_list[win_type]->generic.type,
855                        src_height,
856                        tui_win_list[win_type]->generic.width,
857                    tui_win_list[win_type]->detail.source_info.execution_info->width,
858                        data_height - 1);
859       init_gen_win_info (tui_win_list[win_type]->detail.source_info.execution_info,
860                        EXEC_INFO_WIN,
861                        src_height,
862                        3,
863                        0,
864                        data_height - 1);
865       tui_make_visible (&tui_win_list[win_type]->generic);
866       tui_make_visible (tui_win_list[win_type]->detail.source_info.execution_info);
867       init_gen_win_info (locator,
868                        LOCATOR_WIN,
869                        2 /* 1 */ ,
870                        tui_term_width (),
871                        0,
872                        total_height - 1);
873     }
874   tui_win_list[win_type]->detail.source_info.has_locator = TRUE;
875   tui_make_visible (locator);
876   tui_show_locator_content ();
877   tui_add_to_source_windows (tui_win_list[win_type]);
878   tui_set_current_layout_to (new_layout);
879 }
880
881 /*
882    ** init_gen_win_info().
883  */
884 static void
885 init_gen_win_info (struct tui_gen_win_info *win_info, enum tui_win_type type,
886                  int height, int width, int origin_x, int origin_y)
887 {
888   int h = height;
889
890   win_info->type = type;
891   win_info->width = width;
892   win_info->height = h;
893   if (h > 1)
894     {
895       win_info->viewport_height = h - 1;
896       if (win_info->type != CMD_WIN)
897         win_info->viewport_height--;
898     }
899   else
900     win_info->viewport_height = 1;
901   win_info->origin.x = origin_x;
902   win_info->origin.y = origin_y;
903
904   return;
905 }                               /* init_gen_win_info */
906
907 /*
908    ** init_and_make_win().
909  */
910 static void *
911 init_and_make_win (void *opaque_win_info, enum tui_win_type win_type,
912                    int height, int width, int origin_x, int origin_y,
913                    int box_it)
914 {
915   struct tui_gen_win_info *generic;
916
917   if (opaque_win_info == NULL)
918     {
919       if (tui_win_is_auxillary (win_type))
920         opaque_win_info = (void *) tui_alloc_generic_win_info ();
921       else
922         opaque_win_info = (void *) tui_alloc_win_info (win_type);
923     }
924   if (tui_win_is_auxillary (win_type))
925     generic = (struct tui_gen_win_info *) opaque_win_info;
926   else
927     generic = &((struct tui_win_info *) opaque_win_info)->generic;
928
929   if (opaque_win_info != NULL)
930     {
931       init_gen_win_info (generic, win_type, height, width, origin_x, origin_y);
932       if (!tui_win_is_auxillary (win_type))
933         {
934           if (generic->type == CMD_WIN)
935             ((struct tui_win_info *) opaque_win_info)->can_highlight = FALSE;
936           else
937             ((struct tui_win_info *) opaque_win_info)->can_highlight = TRUE;
938         }
939       tui_make_window (generic, box_it);
940     }
941   return opaque_win_info;
942 }
943
944
945 static void
946 make_source_or_disasm_window (struct tui_win_info **win_info_ptr, enum tui_win_type type,
947                              int height, int origin_y)
948 {
949   struct tui_gen_win_info *execution_info = (struct tui_gen_win_info *) NULL;
950
951   /*
952      ** Create the exeuction info window.
953    */
954   if (type == SRC_WIN)
955     execution_info = tui_source_exec_info_win_ptr ();
956   else
957     execution_info = tui_disassem_exec_info_win_ptr ();
958   execution_info = init_and_make_win (execution_info,
959                                       EXEC_INFO_WIN,
960                                       height,
961                                       3,
962                                       0,
963                                       origin_y,
964                                       DONT_BOX_WINDOW);
965   /*
966      ** Now create the source window.
967    */
968   *win_info_ptr = init_and_make_win (*win_info_ptr,
969                                      type,
970                                      height,
971                                      tui_term_width () - execution_info->width,
972                                      execution_info->width,
973                                      origin_y,
974                                      BOX_WINDOW);
975
976   (*win_info_ptr)->detail.source_info.execution_info = execution_info;
977 }
978
979
980 /* Show the Source/Command or the Disassem layout.  */
981 static void
982 show_source_or_disasm_and_command (enum tui_layout_type layout_type)
983 {
984   if (tui_current_layout () != layout_type)
985     {
986       struct tui_win_info **win_info_ptr;
987       int src_height, cmd_height;
988       struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
989
990       if (TUI_CMD_WIN != NULL)
991         cmd_height = TUI_CMD_WIN->generic.height;
992       else
993         cmd_height = tui_term_height () / 3;
994       src_height = tui_term_height () - cmd_height;
995
996
997       if (layout_type == SRC_COMMAND)
998         win_info_ptr = &TUI_SRC_WIN;
999       else
1000         win_info_ptr = &TUI_DISASM_WIN;
1001
1002       if ((*win_info_ptr) == NULL)
1003         {
1004           if (layout_type == SRC_COMMAND)
1005             make_source_window (win_info_ptr, src_height - 1, 0);
1006           else
1007             make_disasm_window (win_info_ptr, src_height - 1, 0);
1008           locator = init_and_make_win (locator,
1009                                        LOCATOR_WIN,
1010                                        2 /* 1 */ ,
1011                                        tui_term_width (),
1012                                        0,
1013                                        src_height - 1,
1014                                        DONT_BOX_WINDOW);
1015         }
1016       else
1017         {
1018           init_gen_win_info (locator,
1019                            LOCATOR_WIN,
1020                            2 /* 1 */ ,
1021                            tui_term_width (),
1022                            0,
1023                            src_height - 1);
1024           (*win_info_ptr)->detail.source_info.has_locator = TRUE;
1025           init_gen_win_info (
1026                             &(*win_info_ptr)->generic,
1027                             (*win_info_ptr)->generic.type,
1028                             src_height - 1,
1029                             (*win_info_ptr)->generic.width,
1030                       (*win_info_ptr)->detail.source_info.execution_info->width,
1031                             0);
1032           init_gen_win_info ((*win_info_ptr)->detail.source_info.execution_info,
1033                            EXEC_INFO_WIN,
1034                            src_height - 1,
1035                            3,
1036                            0,
1037                            0);
1038           (*win_info_ptr)->can_highlight = TRUE;
1039           tui_make_visible (&(*win_info_ptr)->generic);
1040           tui_make_visible ((*win_info_ptr)->detail.source_info.execution_info);
1041         }
1042       if ((*win_info_ptr) != NULL)
1043         {
1044           (*win_info_ptr)->detail.source_info.has_locator = TRUE;
1045           tui_make_visible (locator);
1046           tui_show_locator_content ();
1047           tui_show_source_content (*win_info_ptr);
1048
1049           if (TUI_CMD_WIN == NULL)
1050             {
1051               make_command_window (&TUI_CMD_WIN, cmd_height, src_height);
1052               tui_refresh_win (&TUI_CMD_WIN->generic);
1053             }
1054           else
1055             {
1056               init_gen_win_info (&TUI_CMD_WIN->generic,
1057                                TUI_CMD_WIN->generic.type,
1058                                TUI_CMD_WIN->generic.height,
1059                                TUI_CMD_WIN->generic.width,
1060                                TUI_CMD_WIN->generic.origin.x,
1061                                TUI_CMD_WIN->generic.origin.y);
1062               TUI_CMD_WIN->can_highlight = FALSE;
1063               tui_make_visible (&TUI_CMD_WIN->generic);
1064             }
1065         }
1066       tui_set_current_layout_to (layout_type);
1067     }
1068 }