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