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