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