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