gdb: Add completer for layout command.
[deliverable/binutils-gdb.git] / gdb / tui / tui-layout.c
1 /* TUI layout window management.
2
3 Copyright (C) 1998-2015 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 VEC (char_ptr) *
357 layout_completer (struct cmd_list_element *ignore,
358 const char *text, const char *word)
359 {
360 static const char *layout_names [] =
361 { "src", "asm", "split", "regs", "next", "prev", NULL };
362
363 return complete_on_enum (layout_names, text, word);
364 }
365
366 /* Function to initialize gdb commands, for tui window layout
367 manipulation. */
368
369 /* Provide a prototype to silence -Wmissing-prototypes. */
370 extern initialize_file_ftype _initialize_tui_layout;
371
372 void
373 _initialize_tui_layout (void)
374 {
375 struct cmd_list_element *cmd;
376
377 cmd = add_com ("layout", class_tui, tui_layout_command, _("\
378 Change the layout of windows.\n\
379 Usage: layout prev | next | <layout_name> \n\
380 Layout names are:\n\
381 src : Displays source and command windows.\n\
382 asm : Displays disassembly and command windows.\n\
383 split : Displays source, disassembly and command windows.\n\
384 regs : Displays register window. If existing layout\n\
385 is source/command or assembly/command, the \n\
386 register window is displayed. If the\n\
387 source/assembly/command (split) is displayed, \n\
388 the register window is displayed with \n\
389 the window that has current logical focus.\n"));
390 set_cmd_completer (cmd, layout_completer);
391 }
392
393
394 /*************************
395 ** STATIC LOCAL FUNCTIONS
396 **************************/
397
398
399 /* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or
400 REGS. */
401 enum tui_status
402 tui_set_layout_by_name (const char *layout_name)
403 {
404 enum tui_status status = TUI_SUCCESS;
405
406 if (layout_name != (char *) NULL)
407 {
408 int i;
409 char *buf_ptr;
410 enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
411 enum tui_layout_type cur_layout = tui_current_layout ();
412
413 buf_ptr = (char *) xstrdup (layout_name);
414 for (i = 0; (i < strlen (layout_name)); i++)
415 buf_ptr[i] = toupper (buf_ptr[i]);
416
417 /* First check for ambiguous input. */
418 if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
419 {
420 warning (_("Ambiguous command input."));
421 status = TUI_FAILURE;
422 }
423 else
424 {
425 if (subset_compare (buf_ptr, "SRC"))
426 new_layout = SRC_COMMAND;
427 else if (subset_compare (buf_ptr, "ASM"))
428 new_layout = DISASSEM_COMMAND;
429 else if (subset_compare (buf_ptr, "SPLIT"))
430 new_layout = SRC_DISASSEM_COMMAND;
431 else if (subset_compare (buf_ptr, "REGS"))
432 {
433 if (cur_layout == SRC_COMMAND
434 || cur_layout == SRC_DATA_COMMAND)
435 new_layout = SRC_DATA_COMMAND;
436 else
437 new_layout = DISASSEM_DATA_COMMAND;
438 }
439 else if (subset_compare (buf_ptr, "NEXT"))
440 new_layout = next_layout ();
441 else if (subset_compare (buf_ptr, "PREV"))
442 new_layout = prev_layout ();
443 else
444 status = TUI_FAILURE;
445
446 tui_set_layout (new_layout);
447 }
448 xfree (buf_ptr);
449 }
450 else
451 status = TUI_FAILURE;
452
453 return status;
454 }
455
456
457 static void
458 extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
459 {
460 enum tui_layout_type cur_layout = tui_current_layout ();
461 struct gdbarch *gdbarch = get_current_arch ();
462 CORE_ADDR addr;
463 CORE_ADDR pc;
464 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
465
466 switch (cur_layout)
467 {
468 case SRC_COMMAND:
469 case SRC_DATA_COMMAND:
470 gdbarch = TUI_SRC_WIN->detail.source_info.gdbarch;
471 find_line_pc (cursal.symtab,
472 TUI_SRC_WIN->detail.source_info.start_line_or_addr.u.line_no,
473 &pc);
474 addr = pc;
475 break;
476 case DISASSEM_COMMAND:
477 case SRC_DISASSEM_COMMAND:
478 case DISASSEM_DATA_COMMAND:
479 gdbarch = TUI_DISASM_WIN->detail.source_info.gdbarch;
480 addr = TUI_DISASM_WIN->detail.source_info.start_line_or_addr.u.addr;
481 break;
482 default:
483 addr = 0;
484 break;
485 }
486
487 *gdbarch_p = gdbarch;
488 *addr_p = addr;
489 }
490
491
492 static void
493 tui_layout_command (char *arg, int from_tty)
494 {
495 /* Make sure the curses mode is enabled. */
496 tui_enable ();
497
498 /* Switch to the selected layout. */
499 if (tui_set_layout_by_name (arg) != TUI_SUCCESS)
500 warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE);
501
502 }
503
504 /* Answer the previous layout to cycle to. */
505 static enum tui_layout_type
506 next_layout (void)
507 {
508 int new_layout;
509
510 new_layout = tui_current_layout ();
511 if (new_layout == UNDEFINED_LAYOUT)
512 new_layout = SRC_COMMAND;
513 else
514 {
515 new_layout++;
516 if (new_layout == UNDEFINED_LAYOUT)
517 new_layout = SRC_COMMAND;
518 }
519
520 return (enum tui_layout_type) new_layout;
521 }
522
523
524 /* Answer the next layout to cycle to. */
525 static enum tui_layout_type
526 prev_layout (void)
527 {
528 int new_layout;
529
530 new_layout = tui_current_layout ();
531 if (new_layout == SRC_COMMAND)
532 new_layout = DISASSEM_DATA_COMMAND;
533 else
534 {
535 new_layout--;
536 if (new_layout == UNDEFINED_LAYOUT)
537 new_layout = DISASSEM_DATA_COMMAND;
538 }
539
540 return (enum tui_layout_type) new_layout;
541 }
542
543
544
545 static void
546 make_command_window (struct tui_win_info **win_info_ptr,
547 int height, int origin_y)
548 {
549 *win_info_ptr = 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 = init_and_make_win (*win_info_ptr,
590 DATA_WIN,
591 height,
592 tui_term_width (),
593 0,
594 origin_y,
595 BOX_WINDOW);
596 }
597
598
599
600 /* Show the Source/Command layout. */
601 static void
602 show_source_command (void)
603 {
604 show_source_or_disasm_and_command (SRC_COMMAND);
605 }
606
607
608 /* Show the Dissassem/Command layout. */
609 static void
610 show_disasm_command (void)
611 {
612 show_source_or_disasm_and_command (DISASSEM_COMMAND);
613 }
614
615
616 /* Show the Source/Disassem/Command layout. */
617 static void
618 show_source_disasm_command (void)
619 {
620 if (tui_current_layout () != SRC_DISASSEM_COMMAND)
621 {
622 int cmd_height, src_height, asm_height;
623
624 if (TUI_CMD_WIN != NULL)
625 cmd_height = TUI_CMD_WIN->generic.height;
626 else
627 cmd_height = tui_term_height () / 3;
628
629 src_height = (tui_term_height () - cmd_height) / 2;
630 asm_height = tui_term_height () - (src_height + cmd_height);
631
632 if (TUI_SRC_WIN == NULL)
633 make_source_window (&TUI_SRC_WIN, src_height, 0);
634 else
635 {
636 init_gen_win_info (&TUI_SRC_WIN->generic,
637 TUI_SRC_WIN->generic.type,
638 src_height,
639 TUI_SRC_WIN->generic.width,
640 TUI_SRC_WIN->detail.source_info.execution_info->width,
641 0);
642 TUI_SRC_WIN->can_highlight = TRUE;
643 init_gen_win_info (TUI_SRC_WIN->detail.source_info.execution_info,
644 EXEC_INFO_WIN,
645 src_height,
646 3,
647 0,
648 0);
649 tui_make_visible (&TUI_SRC_WIN->generic);
650 tui_make_visible (TUI_SRC_WIN->detail.source_info.execution_info);
651 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;;
652 }
653 if (TUI_SRC_WIN != NULL)
654 {
655 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
656
657 tui_show_source_content (TUI_SRC_WIN);
658 if (TUI_DISASM_WIN == NULL)
659 {
660 make_disasm_window (&TUI_DISASM_WIN, asm_height, src_height - 1);
661 locator = init_and_make_win (locator,
662 LOCATOR_WIN,
663 2 /* 1 */ ,
664 tui_term_width (),
665 0,
666 (src_height + asm_height) - 1,
667 DONT_BOX_WINDOW);
668 }
669 else
670 {
671 init_gen_win_info (locator,
672 LOCATOR_WIN,
673 2 /* 1 */ ,
674 tui_term_width (),
675 0,
676 (src_height + asm_height) - 1);
677 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
678 init_gen_win_info (&TUI_DISASM_WIN->generic,
679 TUI_DISASM_WIN->generic.type,
680 asm_height,
681 TUI_DISASM_WIN->generic.width,
682 TUI_DISASM_WIN->detail.source_info.execution_info->width,
683 src_height - 1);
684 init_gen_win_info (TUI_DISASM_WIN->detail.source_info.execution_info,
685 EXEC_INFO_WIN,
686 asm_height,
687 3,
688 0,
689 src_height - 1);
690 TUI_DISASM_WIN->can_highlight = TRUE;
691 tui_make_visible (&TUI_DISASM_WIN->generic);
692 tui_make_visible (TUI_DISASM_WIN->detail.source_info.execution_info);
693 }
694 if (TUI_DISASM_WIN != NULL)
695 {
696 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;
697 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
698 tui_make_visible (locator);
699 tui_show_locator_content ();
700 tui_show_source_content (TUI_DISASM_WIN);
701
702 if (TUI_CMD_WIN == NULL)
703 make_command_window (&TUI_CMD_WIN,
704 cmd_height,
705 tui_term_height () - cmd_height);
706 else
707 {
708 init_gen_win_info (&TUI_CMD_WIN->generic,
709 TUI_CMD_WIN->generic.type,
710 TUI_CMD_WIN->generic.height,
711 TUI_CMD_WIN->generic.width,
712 0,
713 TUI_CMD_WIN->generic.origin.y);
714 TUI_CMD_WIN->can_highlight = FALSE;
715 tui_make_visible (&TUI_CMD_WIN->generic);
716 }
717 if (TUI_CMD_WIN != NULL)
718 tui_refresh_win (&TUI_CMD_WIN->generic);
719 }
720 }
721 tui_set_current_layout_to (SRC_DISASSEM_COMMAND);
722 }
723 }
724
725
726 /* Show the Source/Data/Command or the Dissassembly/Data/Command
727 layout. */
728 static void
729 show_data (enum tui_layout_type new_layout)
730 {
731 int total_height = (tui_term_height () - TUI_CMD_WIN->generic.height);
732 int src_height, data_height;
733 enum tui_win_type win_type;
734 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
735
736
737 data_height = total_height / 2;
738 src_height = total_height - data_height;
739 tui_make_all_invisible ();
740 tui_make_invisible (locator);
741 make_data_window (&TUI_DATA_WIN, data_height, 0);
742 TUI_DATA_WIN->can_highlight = TRUE;
743 if (new_layout == SRC_DATA_COMMAND)
744 win_type = SRC_WIN;
745 else
746 win_type = DISASSEM_WIN;
747 if (tui_win_list[win_type] == NULL)
748 {
749 if (win_type == SRC_WIN)
750 make_source_window (&tui_win_list[win_type], src_height, data_height - 1);
751 else
752 make_disasm_window (&tui_win_list[win_type], src_height, data_height - 1);
753 locator = init_and_make_win (locator,
754 LOCATOR_WIN,
755 2 /* 1 */ ,
756 tui_term_width (),
757 0,
758 total_height - 1,
759 DONT_BOX_WINDOW);
760 }
761 else
762 {
763 init_gen_win_info (&tui_win_list[win_type]->generic,
764 tui_win_list[win_type]->generic.type,
765 src_height,
766 tui_win_list[win_type]->generic.width,
767 tui_win_list[win_type]->detail.source_info.execution_info->width,
768 data_height - 1);
769 init_gen_win_info (tui_win_list[win_type]->detail.source_info.execution_info,
770 EXEC_INFO_WIN,
771 src_height,
772 3,
773 0,
774 data_height - 1);
775 tui_make_visible (&tui_win_list[win_type]->generic);
776 tui_make_visible (tui_win_list[win_type]->detail.source_info.execution_info);
777 init_gen_win_info (locator,
778 LOCATOR_WIN,
779 2 /* 1 */ ,
780 tui_term_width (),
781 0,
782 total_height - 1);
783 }
784 tui_win_list[win_type]->detail.source_info.has_locator = TRUE;
785 tui_make_visible (locator);
786 tui_show_locator_content ();
787 tui_add_to_source_windows (tui_win_list[win_type]);
788 tui_set_current_layout_to (new_layout);
789 }
790
791 /* init_gen_win_info().
792 */
793 static void
794 init_gen_win_info (struct tui_gen_win_info *win_info,
795 enum tui_win_type type,
796 int height, int width,
797 int origin_x, int origin_y)
798 {
799 int h = height;
800
801 win_info->type = type;
802 win_info->width = width;
803 win_info->height = h;
804 if (h > 1)
805 {
806 win_info->viewport_height = h - 1;
807 if (win_info->type != CMD_WIN)
808 win_info->viewport_height--;
809 }
810 else
811 win_info->viewport_height = 1;
812 win_info->origin.x = origin_x;
813 win_info->origin.y = origin_y;
814
815 return;
816 } /* init_gen_win_info */
817
818 /* init_and_make_win().
819 */
820 static void *
821 init_and_make_win (void *opaque_win_info,
822 enum tui_win_type win_type,
823 int height, int width,
824 int origin_x, int origin_y,
825 int box_it)
826 {
827 struct tui_gen_win_info *generic;
828
829 if (opaque_win_info == NULL)
830 {
831 if (tui_win_is_auxillary (win_type))
832 opaque_win_info = (void *) tui_alloc_generic_win_info ();
833 else
834 opaque_win_info = (void *) tui_alloc_win_info (win_type);
835 }
836 if (tui_win_is_auxillary (win_type))
837 generic = (struct tui_gen_win_info *) opaque_win_info;
838 else
839 generic = &((struct tui_win_info *) opaque_win_info)->generic;
840
841 if (opaque_win_info != NULL)
842 {
843 init_gen_win_info (generic, win_type, height, width, origin_x, origin_y);
844 if (!tui_win_is_auxillary (win_type))
845 {
846 if (generic->type == CMD_WIN)
847 ((struct tui_win_info *) opaque_win_info)->can_highlight = FALSE;
848 else
849 ((struct tui_win_info *) opaque_win_info)->can_highlight = TRUE;
850 }
851 tui_make_window (generic, box_it);
852 }
853 return opaque_win_info;
854 }
855
856
857 static void
858 make_source_or_disasm_window (struct tui_win_info **win_info_ptr,
859 enum tui_win_type type,
860 int height, int origin_y)
861 {
862 struct tui_gen_win_info *execution_info = (struct tui_gen_win_info *) NULL;
863
864 /* Create the exeuction info window. */
865 if (type == SRC_WIN)
866 execution_info = tui_source_exec_info_win_ptr ();
867 else
868 execution_info = tui_disassem_exec_info_win_ptr ();
869 execution_info = init_and_make_win (execution_info,
870 EXEC_INFO_WIN,
871 height,
872 3,
873 0,
874 origin_y,
875 DONT_BOX_WINDOW);
876
877 /* Now create the source window. */
878 *win_info_ptr = init_and_make_win (*win_info_ptr,
879 type,
880 height,
881 tui_term_width () - execution_info->width,
882 execution_info->width,
883 origin_y,
884 BOX_WINDOW);
885
886 (*win_info_ptr)->detail.source_info.execution_info = execution_info;
887 }
888
889
890 /* Show the Source/Command or the Disassem layout. */
891 static void
892 show_source_or_disasm_and_command (enum tui_layout_type layout_type)
893 {
894 if (tui_current_layout () != layout_type)
895 {
896 struct tui_win_info **win_info_ptr;
897 int src_height, cmd_height;
898 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
899
900 if (TUI_CMD_WIN != NULL)
901 cmd_height = TUI_CMD_WIN->generic.height;
902 else
903 cmd_height = tui_term_height () / 3;
904 src_height = tui_term_height () - cmd_height;
905
906 if (layout_type == SRC_COMMAND)
907 win_info_ptr = &TUI_SRC_WIN;
908 else
909 win_info_ptr = &TUI_DISASM_WIN;
910
911 if ((*win_info_ptr) == NULL)
912 {
913 if (layout_type == SRC_COMMAND)
914 make_source_window (win_info_ptr, src_height - 1, 0);
915 else
916 make_disasm_window (win_info_ptr, src_height - 1, 0);
917 locator = init_and_make_win (locator,
918 LOCATOR_WIN,
919 2 /* 1 */ ,
920 tui_term_width (),
921 0,
922 src_height - 1,
923 DONT_BOX_WINDOW);
924 }
925 else
926 {
927 init_gen_win_info (locator,
928 LOCATOR_WIN,
929 2 /* 1 */ ,
930 tui_term_width (),
931 0,
932 src_height - 1);
933 (*win_info_ptr)->detail.source_info.has_locator = TRUE;
934 init_gen_win_info (&(*win_info_ptr)->generic,
935 (*win_info_ptr)->generic.type,
936 src_height - 1,
937 (*win_info_ptr)->generic.width,
938 (*win_info_ptr)->detail.source_info.execution_info->width,
939 0);
940 init_gen_win_info ((*win_info_ptr)->detail.source_info.execution_info,
941 EXEC_INFO_WIN,
942 src_height - 1,
943 3,
944 0,
945 0);
946 (*win_info_ptr)->can_highlight = TRUE;
947 tui_make_visible (&(*win_info_ptr)->generic);
948 tui_make_visible ((*win_info_ptr)->detail.source_info.execution_info);
949 }
950 if ((*win_info_ptr) != NULL)
951 {
952 (*win_info_ptr)->detail.source_info.has_locator = TRUE;
953 tui_make_visible (locator);
954 tui_show_locator_content ();
955 tui_show_source_content (*win_info_ptr);
956
957 if (TUI_CMD_WIN == NULL)
958 {
959 make_command_window (&TUI_CMD_WIN, cmd_height, src_height);
960 tui_refresh_win (&TUI_CMD_WIN->generic);
961 }
962 else
963 {
964 init_gen_win_info (&TUI_CMD_WIN->generic,
965 TUI_CMD_WIN->generic.type,
966 TUI_CMD_WIN->generic.height,
967 TUI_CMD_WIN->generic.width,
968 TUI_CMD_WIN->generic.origin.x,
969 TUI_CMD_WIN->generic.origin.y);
970 TUI_CMD_WIN->can_highlight = FALSE;
971 tui_make_visible (&TUI_CMD_WIN->generic);
972 }
973 }
974 tui_set_current_layout_to (layout_type);
975 }
976 }
This page took 0.068894 seconds and 4 git commands to generate.