]>
Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI data manipulation routines. |
f33c6cbf | 2 | |
6aba47ca | 3 | Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007 |
48426bc2 | 4 | Free Software Foundation, Inc. |
f33c6cbf | 5 | |
f377b406 SC |
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 | |
88d83552 EZ |
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | Boston, MA 02110-1301, USA. */ | |
c906108c | 24 | |
96ec9981 DJ |
25 | #include "defs.h" |
26 | #include "symtab.h" | |
d7b2e967 AC |
27 | #include "tui/tui.h" |
28 | #include "tui/tui-data.h" | |
29 | #include "tui/tui-wingeneral.h" | |
f33c6cbf | 30 | |
6d012f14 | 31 | #include "gdb_string.h" |
6a83354a | 32 | #include "gdb_curses.h" |
4e8f7a8b | 33 | |
c906108c SS |
34 | /**************************** |
35 | ** GLOBAL DECLARATIONS | |
36 | ****************************/ | |
6d012f14 | 37 | struct tui_win_info *(tui_win_list[MAX_MAJOR_WINDOWS]); |
c906108c | 38 | |
c906108c SS |
39 | /*************************** |
40 | ** Private data | |
41 | ****************************/ | |
6ba8e26f AC |
42 | static enum tui_layout_type current_layout = UNDEFINED_LAYOUT; |
43 | static int term_height, term_width; | |
2a8854a7 | 44 | static struct tui_gen_win_info _locator; |
6ba8e26f AC |
45 | static struct tui_gen_win_info exec_info[2]; |
46 | static struct tui_win_info * src_win_list[2]; | |
96c1eda2 | 47 | static struct tui_list source_windows = {src_win_list, 0}; |
6ba8e26f AC |
48 | static int default_tab_len = DEFAULT_TAB_LEN; |
49 | static struct tui_win_info * win_with_focus = (struct tui_win_info *) NULL; | |
50 | static struct tui_layout_def layout_def = | |
51 | {SRC_WIN, /* DISPLAY_MODE */ | |
52 | FALSE, /* SPLIT */ | |
53 | TUI_UNDEFINED_REGS, /* REGS_DISPLAY_TYPE */ | |
54 | TUI_SFLOAT_REGS}; /* FLOAT_REGS_DISPLAY_TYPE */ | |
55 | static int win_resized = FALSE; | |
c906108c SS |
56 | |
57 | ||
58 | /********************************* | |
59 | ** Static function forward decls | |
60 | **********************************/ | |
6ba8e26f AC |
61 | static void free_content (tui_win_content, int, enum tui_win_type); |
62 | static void free_content_elements (tui_win_content, int, enum tui_win_type); | |
c906108c SS |
63 | |
64 | ||
65 | ||
66 | /********************************* | |
67 | ** PUBLIC FUNCTIONS | |
68 | **********************************/ | |
69 | ||
6d012f14 AC |
70 | int |
71 | tui_win_is_source_type (enum tui_win_type win_type) | |
72 | { | |
73 | return (win_type == SRC_WIN || win_type == DISASSEM_WIN); | |
74 | } | |
75 | ||
76 | int | |
77 | tui_win_is_auxillary (enum tui_win_type win_type) | |
78 | { | |
79 | return (win_type > MAX_MAJOR_WINDOWS); | |
80 | } | |
81 | ||
82 | int | |
83 | tui_win_has_locator (struct tui_win_info *win_info) | |
84 | { | |
85 | return (win_info != NULL \ | |
86 | && win_info->detail.source_info.has_locator); | |
87 | } | |
88 | ||
89 | void | |
90 | tui_set_win_highlight (struct tui_win_info *win_info, int highlight) | |
91 | { | |
92 | if (win_info != NULL) | |
93 | win_info->is_highlighted = highlight; | |
94 | } | |
95 | ||
c906108c SS |
96 | /****************************************** |
97 | ** ACCESSORS & MUTATORS FOR PRIVATE DATA | |
98 | ******************************************/ | |
99 | ||
dd1abb8c | 100 | /* Answer a whether the terminal window has been resized or not. */ |
c906108c | 101 | int |
dd1abb8c | 102 | tui_win_resized (void) |
c906108c | 103 | { |
6ba8e26f | 104 | return win_resized; |
dd1abb8c | 105 | } |
c906108c SS |
106 | |
107 | ||
dd1abb8c | 108 | /* Set a whether the terminal window has been resized or not. */ |
c906108c | 109 | void |
dd1abb8c | 110 | tui_set_win_resized_to (int resized) |
c906108c | 111 | { |
6ba8e26f | 112 | win_resized = resized; |
dd1abb8c | 113 | } |
c906108c SS |
114 | |
115 | ||
dd1abb8c | 116 | /* Answer a pointer to the current layout definition. */ |
2a8854a7 | 117 | struct tui_layout_def * |
dd1abb8c | 118 | tui_layout_def (void) |
c906108c | 119 | { |
6ba8e26f | 120 | return &layout_def; |
dd1abb8c | 121 | } |
c906108c SS |
122 | |
123 | ||
dd1abb8c | 124 | /* Answer the window with the logical focus. */ |
2a8854a7 | 125 | struct tui_win_info * |
dd1abb8c | 126 | tui_win_with_focus (void) |
c906108c | 127 | { |
6ba8e26f | 128 | return win_with_focus; |
dd1abb8c | 129 | } |
c906108c SS |
130 | |
131 | ||
dd1abb8c | 132 | /* Set the window that has the logical focus. */ |
c906108c | 133 | void |
6d012f14 | 134 | tui_set_win_with_focus (struct tui_win_info * win_info) |
c906108c | 135 | { |
6ba8e26f | 136 | win_with_focus = win_info; |
dd1abb8c | 137 | } |
c906108c SS |
138 | |
139 | ||
dd1abb8c | 140 | /* Answer the length in chars, of tabs. */ |
c906108c | 141 | int |
dd1abb8c | 142 | tui_default_tab_len (void) |
c906108c | 143 | { |
6ba8e26f | 144 | return default_tab_len; |
dd1abb8c | 145 | } |
c906108c SS |
146 | |
147 | ||
dd1abb8c | 148 | /* Set the length in chars, of tabs. */ |
c906108c | 149 | void |
dd1abb8c | 150 | tui_set_default_tab_len (int len) |
c906108c | 151 | { |
6ba8e26f | 152 | default_tab_len = len; |
dd1abb8c | 153 | } |
c906108c SS |
154 | |
155 | ||
6ba8e26f AC |
156 | /* Accessor for the current source window. Usually there is only one |
157 | source window (either source or disassembly), but both can be | |
158 | displayed at the same time. */ | |
2a8854a7 | 159 | struct tui_list * |
dd1abb8c | 160 | tui_source_windows (void) |
c906108c | 161 | { |
6ba8e26f | 162 | return &source_windows; |
dd1abb8c | 163 | } |
c906108c SS |
164 | |
165 | ||
dd1abb8c AC |
166 | /* Clear the list of source windows. Usually there is only one source |
167 | window (either source or disassembly), but both can be displayed at | |
168 | the same time. */ | |
c906108c | 169 | void |
dd1abb8c | 170 | tui_clear_source_windows (void) |
c906108c | 171 | { |
6ba8e26f AC |
172 | source_windows.list[0] = NULL; |
173 | source_windows.list[1] = NULL; | |
174 | source_windows.count = 0; | |
dd1abb8c | 175 | } |
c906108c SS |
176 | |
177 | ||
dd1abb8c | 178 | /* Clear the pertinant detail in the source windows. */ |
c906108c | 179 | void |
dd1abb8c | 180 | tui_clear_source_windows_detail (void) |
c906108c SS |
181 | { |
182 | int i; | |
183 | ||
dd1abb8c | 184 | for (i = 0; i < (tui_source_windows ())->count; i++) |
96c1eda2 | 185 | tui_clear_win_detail ((tui_source_windows ())->list[i]); |
dd1abb8c | 186 | } |
c906108c SS |
187 | |
188 | ||
dd1abb8c AC |
189 | /* Add a window to the list of source windows. Usually there is only |
190 | one source window (either source or disassembly), but both can be | |
191 | displayed at the same time. */ | |
c906108c | 192 | void |
6d012f14 | 193 | tui_add_to_source_windows (struct tui_win_info * win_info) |
c906108c | 194 | { |
6ba8e26f AC |
195 | if (source_windows.count < 2) |
196 | source_windows.list[source_windows.count++] = (void *) win_info; | |
dd1abb8c | 197 | } |
c906108c SS |
198 | |
199 | ||
dd1abb8c | 200 | /* Clear the pertinant detail in the windows. */ |
c906108c | 201 | void |
6d012f14 | 202 | tui_clear_win_detail (struct tui_win_info * win_info) |
c906108c | 203 | { |
6d012f14 | 204 | if (win_info != NULL) |
c906108c | 205 | { |
6d012f14 | 206 | switch (win_info->generic.type) |
c906108c SS |
207 | { |
208 | case SRC_WIN: | |
209 | case DISASSEM_WIN: | |
362c05fe AS |
210 | win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; |
211 | win_info->detail.source_info.start_line_or_addr.u.addr = 0; | |
6d012f14 | 212 | win_info->detail.source_info.horizontal_offset = 0; |
c906108c SS |
213 | break; |
214 | case CMD_WIN: | |
6d012f14 AC |
215 | win_info->detail.command_info.cur_line = |
216 | win_info->detail.command_info.curch = 0; | |
c906108c SS |
217 | break; |
218 | case DATA_WIN: | |
6d012f14 | 219 | win_info->detail.data_display_info.data_content = |
2a8854a7 | 220 | (tui_win_content) NULL; |
6d012f14 AC |
221 | win_info->detail.data_display_info.data_content_count = 0; |
222 | win_info->detail.data_display_info.regs_content = | |
2a8854a7 | 223 | (tui_win_content) NULL; |
6d012f14 AC |
224 | win_info->detail.data_display_info.regs_content_count = 0; |
225 | win_info->detail.data_display_info.regs_display_type = | |
c906108c | 226 | TUI_UNDEFINED_REGS; |
6d012f14 AC |
227 | win_info->detail.data_display_info.regs_column_count = 1; |
228 | win_info->detail.data_display_info.display_regs = FALSE; | |
c906108c SS |
229 | break; |
230 | default: | |
231 | break; | |
232 | } | |
233 | } | |
6ba8e26f | 234 | } |
c906108c SS |
235 | |
236 | ||
6ba8e26f | 237 | /* Accessor for the source execution info ptr. */ |
2a8854a7 | 238 | struct tui_gen_win_info * |
dd1abb8c | 239 | tui_source_exec_info_win_ptr (void) |
c906108c | 240 | { |
6ba8e26f AC |
241 | return &exec_info[0]; |
242 | } | |
c906108c SS |
243 | |
244 | ||
6ba8e26f | 245 | /* Accessor for the disassem execution info ptr. */ |
2a8854a7 | 246 | struct tui_gen_win_info * |
dd1abb8c | 247 | tui_disassem_exec_info_win_ptr (void) |
c906108c | 248 | { |
6ba8e26f AC |
249 | return &exec_info[1]; |
250 | } | |
c906108c SS |
251 | |
252 | ||
dd1abb8c AC |
253 | /* Accessor for the locator win info. Answers a pointer to the static |
254 | locator win info struct. */ | |
2a8854a7 | 255 | struct tui_gen_win_info * |
dd1abb8c | 256 | tui_locator_win_info_ptr (void) |
c906108c SS |
257 | { |
258 | return &_locator; | |
2a8854a7 | 259 | } |
c906108c SS |
260 | |
261 | ||
6ba8e26f | 262 | /* Accessor for the term_height. */ |
c906108c | 263 | int |
dd1abb8c | 264 | tui_term_height (void) |
c906108c | 265 | { |
6ba8e26f | 266 | return term_height; |
dd1abb8c | 267 | } |
c906108c SS |
268 | |
269 | ||
dd1abb8c | 270 | /* Mutator for the term height. */ |
c906108c | 271 | void |
dd1abb8c | 272 | tui_set_term_height_to (int h) |
c906108c | 273 | { |
6ba8e26f | 274 | term_height = h; |
dd1abb8c | 275 | } |
c906108c SS |
276 | |
277 | ||
6ba8e26f | 278 | /* Accessor for the term_width. */ |
c906108c | 279 | int |
dd1abb8c | 280 | tui_term_width (void) |
c906108c | 281 | { |
6ba8e26f | 282 | return term_width; |
dd1abb8c | 283 | } |
c906108c SS |
284 | |
285 | ||
6ba8e26f | 286 | /* Mutator for the term_width. */ |
c906108c | 287 | void |
dd1abb8c | 288 | tui_set_term_width_to (int w) |
c906108c | 289 | { |
6ba8e26f | 290 | term_width = w; |
dd1abb8c | 291 | } |
c906108c SS |
292 | |
293 | ||
dd1abb8c | 294 | /* Accessor for the current layout. */ |
2a8854a7 | 295 | enum tui_layout_type |
dd1abb8c | 296 | tui_current_layout (void) |
c906108c | 297 | { |
6ba8e26f | 298 | return current_layout; |
dd1abb8c | 299 | } |
c906108c SS |
300 | |
301 | ||
dd1abb8c | 302 | /* Mutator for the current layout. */ |
c906108c | 303 | void |
6ba8e26f | 304 | tui_set_current_layout_to (enum tui_layout_type new_layout) |
c906108c | 305 | { |
6ba8e26f | 306 | current_layout = new_layout; |
dd1abb8c | 307 | } |
c906108c SS |
308 | |
309 | ||
6ba8e26f | 310 | /* Set the origin of the window. */ |
c906108c | 311 | void |
6ba8e26f | 312 | set_gen_win_origin (struct tui_gen_win_info * win_info, int x, int y) |
c906108c | 313 | { |
6d012f14 AC |
314 | win_info->origin.x = x; |
315 | win_info->origin.y = y; | |
6ba8e26f | 316 | } |
c906108c SS |
317 | |
318 | ||
319 | /***************************** | |
320 | ** OTHER PUBLIC FUNCTIONS | |
321 | *****************************/ | |
322 | ||
323 | ||
dd1abb8c AC |
324 | /* Answer the next window in the list, cycling back to the top if |
325 | necessary. */ | |
2a8854a7 | 326 | struct tui_win_info * |
6ba8e26f | 327 | tui_next_win (struct tui_win_info * cur_win) |
c906108c | 328 | { |
6ba8e26f AC |
329 | enum tui_win_type type = cur_win->generic.type; |
330 | struct tui_win_info * next_win = (struct tui_win_info *) NULL; | |
c906108c | 331 | |
6ba8e26f | 332 | if (cur_win->generic.type == CMD_WIN) |
c906108c SS |
333 | type = SRC_WIN; |
334 | else | |
6ba8e26f AC |
335 | type = cur_win->generic.type + 1; |
336 | while (type != cur_win->generic.type && (next_win == NULL)) | |
c906108c | 337 | { |
6d012f14 | 338 | if (tui_win_list[type] && tui_win_list[type]->generic.is_visible) |
6ba8e26f | 339 | next_win = tui_win_list[type]; |
c906108c SS |
340 | else |
341 | { | |
342 | if (type == CMD_WIN) | |
343 | type = SRC_WIN; | |
344 | else | |
345 | type++; | |
346 | } | |
347 | } | |
348 | ||
6ba8e26f AC |
349 | return next_win; |
350 | } | |
c906108c SS |
351 | |
352 | ||
dd1abb8c AC |
353 | /* Answer the prev window in the list, cycling back to the bottom if |
354 | necessary. */ | |
2a8854a7 | 355 | struct tui_win_info * |
6ba8e26f | 356 | tui_prev_win (struct tui_win_info * cur_win) |
c906108c | 357 | { |
6ba8e26f | 358 | enum tui_win_type type = cur_win->generic.type; |
2a8854a7 | 359 | struct tui_win_info * prev = (struct tui_win_info *) NULL; |
c906108c | 360 | |
6ba8e26f | 361 | if (cur_win->generic.type == SRC_WIN) |
c906108c SS |
362 | type = CMD_WIN; |
363 | else | |
6ba8e26f AC |
364 | type = cur_win->generic.type - 1; |
365 | while (type != cur_win->generic.type && (prev == NULL)) | |
c906108c | 366 | { |
6d012f14 AC |
367 | if (tui_win_list[type]->generic.is_visible) |
368 | prev = tui_win_list[type]; | |
c906108c SS |
369 | else |
370 | { | |
371 | if (type == SRC_WIN) | |
372 | type = CMD_WIN; | |
373 | else | |
374 | type--; | |
375 | } | |
376 | } | |
377 | ||
378 | return prev; | |
cb50eddd | 379 | } |
c906108c SS |
380 | |
381 | ||
dd1abb8c | 382 | /* Answer the window represented by name. */ |
2a8854a7 | 383 | struct tui_win_info * |
dd1abb8c | 384 | tui_partial_win_by_name (char *name) |
c906108c | 385 | { |
6d012f14 | 386 | struct tui_win_info * win_info = (struct tui_win_info *) NULL; |
c906108c SS |
387 | |
388 | if (name != (char *) NULL) | |
389 | { | |
390 | int i = 0; | |
391 | ||
6d012f14 | 392 | while (i < MAX_MAJOR_WINDOWS && win_info == NULL) |
c906108c | 393 | { |
6d012f14 | 394 | if (tui_win_list[i] != 0) |
a4b99e53 | 395 | { |
6ba8e26f AC |
396 | char *cur_name = tui_win_name (&tui_win_list[i]->generic); |
397 | if (strlen (name) <= strlen (cur_name) && | |
398 | strncmp (name, cur_name, strlen (name)) == 0) | |
6d012f14 | 399 | win_info = tui_win_list[i]; |
a4b99e53 | 400 | } |
c906108c SS |
401 | i++; |
402 | } | |
403 | } | |
404 | ||
6d012f14 | 405 | return win_info; |
6ba8e26f | 406 | } |
c906108c SS |
407 | |
408 | ||
6ba8e26f | 409 | /* Answer the name of the window. */ |
c906108c | 410 | char * |
6d012f14 | 411 | tui_win_name (struct tui_gen_win_info * win_info) |
c906108c SS |
412 | { |
413 | char *name = (char *) NULL; | |
414 | ||
6d012f14 | 415 | switch (win_info->type) |
c906108c SS |
416 | { |
417 | case SRC_WIN: | |
418 | name = SRC_NAME; | |
419 | break; | |
420 | case CMD_WIN: | |
421 | name = CMD_NAME; | |
422 | break; | |
423 | case DISASSEM_WIN: | |
424 | name = DISASSEM_NAME; | |
425 | break; | |
426 | case DATA_WIN: | |
427 | name = DATA_NAME; | |
428 | break; | |
429 | default: | |
430 | name = ""; | |
431 | break; | |
432 | } | |
433 | ||
434 | return name; | |
6ba8e26f | 435 | } |
c906108c SS |
436 | |
437 | ||
c906108c | 438 | void |
dd1abb8c | 439 | tui_initialize_static_data (void) |
c906108c | 440 | { |
dd1abb8c AC |
441 | tui_init_generic_part (tui_source_exec_info_win_ptr ()); |
442 | tui_init_generic_part (tui_disassem_exec_info_win_ptr ()); | |
443 | tui_init_generic_part (tui_locator_win_info_ptr ()); | |
444 | } | |
c906108c SS |
445 | |
446 | ||
2a8854a7 | 447 | struct tui_gen_win_info * |
dd1abb8c | 448 | tui_alloc_generic_win_info (void) |
c906108c | 449 | { |
2a8854a7 | 450 | struct tui_gen_win_info * win; |
c906108c | 451 | |
c0645fb5 | 452 | if ((win = XMALLOC (struct tui_gen_win_info)) != NULL) |
dd1abb8c | 453 | tui_init_generic_part (win); |
c906108c SS |
454 | |
455 | return win; | |
6ba8e26f | 456 | } |
c906108c SS |
457 | |
458 | ||
c906108c | 459 | void |
2a8854a7 | 460 | tui_init_generic_part (struct tui_gen_win_info * win) |
c906108c SS |
461 | { |
462 | win->width = | |
463 | win->height = | |
464 | win->origin.x = | |
465 | win->origin.y = | |
6d012f14 AC |
466 | win->viewport_height = |
467 | win->content_size = | |
468 | win->last_visible_line = 0; | |
c906108c | 469 | win->handle = (WINDOW *) NULL; |
22940a24 | 470 | win->content = NULL; |
6d012f14 AC |
471 | win->content_in_use = |
472 | win->is_visible = FALSE; | |
bc6b7f04 SC |
473 | win->title = 0; |
474 | } | |
c906108c SS |
475 | |
476 | ||
477 | /* | |
6ba8e26f | 478 | ** init_content_element(). |
c5aa993b | 479 | */ |
c906108c | 480 | void |
6ba8e26f | 481 | init_content_element (struct tui_win_element * element, enum tui_win_type type) |
c906108c SS |
482 | { |
483 | element->highlight = FALSE; | |
484 | switch (type) | |
485 | { | |
486 | case SRC_WIN: | |
487 | case DISASSEM_WIN: | |
6d012f14 | 488 | element->which_element.source.line = (char *) NULL; |
362c05fe AS |
489 | element->which_element.source.line_or_addr.loa = LOA_LINE; |
490 | element->which_element.source.line_or_addr.u.line_no = 0; | |
6d012f14 AC |
491 | element->which_element.source.is_exec_point = FALSE; |
492 | element->which_element.source.has_break = FALSE; | |
c906108c SS |
493 | break; |
494 | case DATA_WIN: | |
6d012f14 AC |
495 | tui_init_generic_part (&element->which_element.data_window); |
496 | element->which_element.data_window.type = DATA_ITEM_WIN; | |
497 | ((struct tui_gen_win_info *) & element->which_element.data_window)->content = | |
22940a24 | 498 | (void **) tui_alloc_content (1, DATA_ITEM_WIN); |
2a8854a7 | 499 | ((struct tui_gen_win_info *) |
6d012f14 | 500 | & element->which_element.data_window)->content_size = 1; |
c906108c SS |
501 | break; |
502 | case CMD_WIN: | |
6d012f14 | 503 | element->which_element.command.line = (char *) NULL; |
c906108c SS |
504 | break; |
505 | case DATA_ITEM_WIN: | |
6d012f14 AC |
506 | element->which_element.data.name = (char *) NULL; |
507 | element->which_element.data.type = TUI_REGISTER; | |
508 | element->which_element.data.item_no = UNDEFINED_ITEM; | |
509 | element->which_element.data.value = NULL; | |
510 | element->which_element.data.highlight = FALSE; | |
10f59415 | 511 | element->which_element.data.content = (char*) NULL; |
c906108c SS |
512 | break; |
513 | case LOCATOR_WIN: | |
6d012f14 AC |
514 | element->which_element.locator.file_name[0] = |
515 | element->which_element.locator.proc_name[0] = (char) 0; | |
516 | element->which_element.locator.line_no = 0; | |
517 | element->which_element.locator.addr = 0; | |
c906108c SS |
518 | break; |
519 | case EXEC_INFO_WIN: | |
6d012f14 AC |
520 | memset(element->which_element.simple_string, ' ', |
521 | sizeof(element->which_element.simple_string)); | |
c906108c SS |
522 | break; |
523 | default: | |
524 | break; | |
525 | } | |
6ba8e26f | 526 | } |
c906108c | 527 | |
c906108c | 528 | void |
6ba8e26f | 529 | init_win_info (struct tui_win_info * win_info) |
c906108c | 530 | { |
6d012f14 AC |
531 | tui_init_generic_part (&win_info->generic); |
532 | win_info->can_highlight = | |
533 | win_info->is_highlighted = FALSE; | |
534 | switch (win_info->generic.type) | |
c906108c SS |
535 | { |
536 | case SRC_WIN: | |
537 | case DISASSEM_WIN: | |
6d012f14 AC |
538 | win_info->detail.source_info.execution_info = (struct tui_gen_win_info *) NULL; |
539 | win_info->detail.source_info.has_locator = FALSE; | |
540 | win_info->detail.source_info.horizontal_offset = 0; | |
362c05fe AS |
541 | win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; |
542 | win_info->detail.source_info.start_line_or_addr.u.addr = 0; | |
6d012f14 | 543 | win_info->detail.source_info.filename = 0; |
c906108c SS |
544 | break; |
545 | case DATA_WIN: | |
6d012f14 AC |
546 | win_info->detail.data_display_info.data_content = (tui_win_content) NULL; |
547 | win_info->detail.data_display_info.data_content_count = 0; | |
548 | win_info->detail.data_display_info.regs_content = (tui_win_content) NULL; | |
549 | win_info->detail.data_display_info.regs_content_count = 0; | |
550 | win_info->detail.data_display_info.regs_display_type = | |
c906108c | 551 | TUI_UNDEFINED_REGS; |
6d012f14 AC |
552 | win_info->detail.data_display_info.regs_column_count = 1; |
553 | win_info->detail.data_display_info.display_regs = FALSE; | |
10f59415 | 554 | win_info->detail.data_display_info.current_group = 0; |
c906108c SS |
555 | break; |
556 | case CMD_WIN: | |
6d012f14 AC |
557 | win_info->detail.command_info.cur_line = 0; |
558 | win_info->detail.command_info.curch = 0; | |
c906108c SS |
559 | break; |
560 | default: | |
6d012f14 | 561 | win_info->detail.opaque = NULL; |
c906108c SS |
562 | break; |
563 | } | |
6ba8e26f | 564 | } |
c906108c SS |
565 | |
566 | ||
2a8854a7 | 567 | struct tui_win_info * |
22940a24 | 568 | tui_alloc_win_info (enum tui_win_type type) |
c906108c | 569 | { |
c0645fb5 | 570 | struct tui_win_info * win_info; |
c906108c | 571 | |
c0645fb5 MS |
572 | win_info = XMALLOC (struct tui_win_info); |
573 | if (win_info != NULL) | |
c906108c | 574 | { |
6d012f14 | 575 | win_info->generic.type = type; |
6ba8e26f | 576 | init_win_info (win_info); |
c906108c SS |
577 | } |
578 | ||
6d012f14 | 579 | return win_info; |
6ba8e26f | 580 | } |
c906108c SS |
581 | |
582 | ||
6ba8e26f | 583 | /* Allocates the content and elements in a block. */ |
2a8854a7 | 584 | tui_win_content |
6ba8e26f | 585 | tui_alloc_content (int num_elements, enum tui_win_type type) |
c906108c | 586 | { |
c0645fb5 MS |
587 | tui_win_content content; |
588 | char *element_block_ptr; | |
c906108c SS |
589 | int i; |
590 | ||
c0645fb5 MS |
591 | content = xmalloc (sizeof (struct tui_win_element *) * num_elements); |
592 | if (content != NULL) | |
593 | { | |
594 | /* | |
595 | * All windows, except the data window, can allocate the | |
596 | * elements in a chunk. The data window cannot because items | |
597 | * can be added/removed from the data display by the user at any | |
598 | * time. | |
599 | */ | |
c906108c SS |
600 | if (type != DATA_WIN) |
601 | { | |
c0645fb5 MS |
602 | element_block_ptr = |
603 | xmalloc (sizeof (struct tui_win_element) * num_elements); | |
604 | if (element_block_ptr != NULL) | |
c906108c | 605 | { |
6ba8e26f | 606 | for (i = 0; i < num_elements; i++) |
c906108c | 607 | { |
6ba8e26f AC |
608 | content[i] = (struct tui_win_element *) element_block_ptr; |
609 | init_content_element (content[i], type); | |
610 | element_block_ptr += sizeof (struct tui_win_element); | |
c906108c SS |
611 | } |
612 | } | |
613 | else | |
614 | { | |
22940a24 | 615 | xfree (content); |
2a8854a7 | 616 | content = (tui_win_content) NULL; |
c906108c SS |
617 | } |
618 | } | |
619 | } | |
620 | ||
621 | return content; | |
6ba8e26f | 622 | } |
c906108c SS |
623 | |
624 | ||
dd1abb8c | 625 | /* Adds the input number of elements to the windows's content. If no |
6ba8e26f | 626 | content has been allocated yet, alloc_content() is called to do |
dd1abb8c AC |
627 | this. The index of the first element added is returned, unless |
628 | there is a memory allocation error, in which case, (-1) is | |
629 | returned. */ | |
c906108c | 630 | int |
6ba8e26f | 631 | tui_add_content_elements (struct tui_gen_win_info * win_info, int num_elements) |
c906108c | 632 | { |
6ba8e26f AC |
633 | struct tui_win_element * element_ptr; |
634 | int i, index_start; | |
c906108c | 635 | |
6d012f14 | 636 | if (win_info->content == NULL) |
c906108c | 637 | { |
6ba8e26f AC |
638 | win_info->content = (void **) tui_alloc_content (num_elements, win_info->type); |
639 | index_start = 0; | |
c906108c SS |
640 | } |
641 | else | |
6ba8e26f | 642 | index_start = win_info->content_size; |
6d012f14 | 643 | if (win_info->content != NULL) |
c906108c | 644 | { |
6ba8e26f | 645 | for (i = index_start; (i < num_elements + index_start); i++) |
c906108c | 646 | { |
c0645fb5 | 647 | if ((element_ptr = XMALLOC (struct tui_win_element)) != NULL) |
c906108c | 648 | { |
6ba8e26f AC |
649 | win_info->content[i] = (void *) element_ptr; |
650 | init_content_element (element_ptr, win_info->type); | |
6d012f14 | 651 | win_info->content_size++; |
c906108c | 652 | } |
c0645fb5 | 653 | else /* Things must be really hosed now! We ran out of memory!? */ |
c906108c SS |
654 | return (-1); |
655 | } | |
656 | } | |
657 | ||
6ba8e26f AC |
658 | return index_start; |
659 | } | |
c906108c SS |
660 | |
661 | ||
6d012f14 | 662 | /* Delete all curses windows associated with win_info, leaving everything |
bc6b7f04 | 663 | else intact. */ |
c906108c | 664 | void |
6ba8e26f | 665 | tui_del_window (struct tui_win_info * win_info) |
c906108c | 666 | { |
6ba8e26f | 667 | struct tui_gen_win_info * generic_win; |
c906108c | 668 | |
6d012f14 | 669 | switch (win_info->generic.type) |
c906108c SS |
670 | { |
671 | case SRC_WIN: | |
672 | case DISASSEM_WIN: | |
6ba8e26f AC |
673 | generic_win = tui_locator_win_info_ptr (); |
674 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 675 | { |
6ba8e26f AC |
676 | tui_delete_win (generic_win->handle); |
677 | generic_win->handle = (WINDOW *) NULL; | |
678 | generic_win->is_visible = FALSE; | |
c906108c | 679 | } |
6d012f14 | 680 | if (win_info->detail.source_info.filename) |
bc6b7f04 | 681 | { |
6d012f14 AC |
682 | xfree (win_info->detail.source_info.filename); |
683 | win_info->detail.source_info.filename = 0; | |
bc6b7f04 | 684 | } |
6ba8e26f AC |
685 | generic_win = win_info->detail.source_info.execution_info; |
686 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 687 | { |
6ba8e26f AC |
688 | tui_delete_win (generic_win->handle); |
689 | generic_win->handle = (WINDOW *) NULL; | |
690 | generic_win->is_visible = FALSE; | |
c906108c SS |
691 | } |
692 | break; | |
693 | case DATA_WIN: | |
6d012f14 | 694 | if (win_info->generic.content != NULL) |
c906108c | 695 | { |
6d012f14 AC |
696 | tui_del_data_windows (win_info->detail.data_display_info.regs_content, |
697 | win_info->detail.data_display_info.regs_content_count); | |
698 | tui_del_data_windows (win_info->detail.data_display_info.data_content, | |
699 | win_info->detail.data_display_info.data_content_count); | |
c906108c SS |
700 | } |
701 | break; | |
702 | default: | |
703 | break; | |
704 | } | |
6d012f14 | 705 | if (win_info->generic.handle != (WINDOW *) NULL) |
c906108c | 706 | { |
6d012f14 AC |
707 | tui_delete_win (win_info->generic.handle); |
708 | win_info->generic.handle = (WINDOW *) NULL; | |
709 | win_info->generic.is_visible = FALSE; | |
c906108c | 710 | } |
bc6b7f04 | 711 | } |
c906108c SS |
712 | |
713 | ||
c906108c | 714 | void |
6d012f14 | 715 | tui_free_window (struct tui_win_info * win_info) |
c906108c | 716 | { |
6ba8e26f | 717 | struct tui_gen_win_info * generic_win; |
c906108c | 718 | |
6d012f14 | 719 | switch (win_info->generic.type) |
c906108c SS |
720 | { |
721 | case SRC_WIN: | |
722 | case DISASSEM_WIN: | |
6ba8e26f AC |
723 | generic_win = tui_locator_win_info_ptr (); |
724 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 725 | { |
6ba8e26f AC |
726 | tui_delete_win (generic_win->handle); |
727 | generic_win->handle = (WINDOW *) NULL; | |
c906108c | 728 | } |
6ba8e26f | 729 | tui_free_win_content (generic_win); |
6d012f14 | 730 | if (win_info->detail.source_info.filename) |
bc6b7f04 | 731 | { |
6d012f14 AC |
732 | xfree (win_info->detail.source_info.filename); |
733 | win_info->detail.source_info.filename = 0; | |
bc6b7f04 | 734 | } |
6ba8e26f AC |
735 | generic_win = win_info->detail.source_info.execution_info; |
736 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 737 | { |
6ba8e26f AC |
738 | tui_delete_win (generic_win->handle); |
739 | generic_win->handle = (WINDOW *) NULL; | |
740 | tui_free_win_content (generic_win); | |
c906108c SS |
741 | } |
742 | break; | |
743 | case DATA_WIN: | |
6d012f14 | 744 | if (win_info->generic.content != NULL) |
c906108c | 745 | { |
6d012f14 AC |
746 | tui_free_data_content (win_info->detail.data_display_info.regs_content, |
747 | win_info->detail.data_display_info.regs_content_count); | |
748 | win_info->detail.data_display_info.regs_content = | |
2a8854a7 | 749 | (tui_win_content) NULL; |
6d012f14 AC |
750 | win_info->detail.data_display_info.regs_content_count = 0; |
751 | tui_free_data_content (win_info->detail.data_display_info.data_content, | |
752 | win_info->detail.data_display_info.data_content_count); | |
753 | win_info->detail.data_display_info.data_content = | |
2a8854a7 | 754 | (tui_win_content) NULL; |
6d012f14 AC |
755 | win_info->detail.data_display_info.data_content_count = 0; |
756 | win_info->detail.data_display_info.regs_display_type = | |
c906108c | 757 | TUI_UNDEFINED_REGS; |
6d012f14 AC |
758 | win_info->detail.data_display_info.regs_column_count = 1; |
759 | win_info->detail.data_display_info.display_regs = FALSE; | |
760 | win_info->generic.content = NULL; | |
761 | win_info->generic.content_size = 0; | |
c906108c SS |
762 | } |
763 | break; | |
764 | default: | |
765 | break; | |
766 | } | |
6d012f14 | 767 | if (win_info->generic.handle != (WINDOW *) NULL) |
c906108c | 768 | { |
6d012f14 AC |
769 | tui_delete_win (win_info->generic.handle); |
770 | win_info->generic.handle = (WINDOW *) NULL; | |
771 | tui_free_win_content (&win_info->generic); | |
c906108c | 772 | } |
6d012f14 AC |
773 | if (win_info->generic.title) |
774 | xfree (win_info->generic.title); | |
775 | xfree (win_info); | |
bc6b7f04 | 776 | } |
c906108c SS |
777 | |
778 | ||
c906108c | 779 | void |
dd1abb8c | 780 | tui_free_all_source_wins_content (void) |
c906108c SS |
781 | { |
782 | int i; | |
783 | ||
dd1abb8c | 784 | for (i = 0; i < (tui_source_windows ())->count; i++) |
c906108c | 785 | { |
96c1eda2 | 786 | struct tui_win_info * win_info = (tui_source_windows ())->list[i]; |
c906108c | 787 | |
6d012f14 | 788 | if (win_info != NULL) |
c906108c | 789 | { |
6d012f14 AC |
790 | tui_free_win_content (&(win_info->generic)); |
791 | tui_free_win_content (win_info->detail.source_info.execution_info); | |
c906108c SS |
792 | } |
793 | } | |
dd1abb8c | 794 | } |
c906108c SS |
795 | |
796 | ||
c906108c | 797 | void |
6d012f14 | 798 | tui_free_win_content (struct tui_gen_win_info * win_info) |
c906108c | 799 | { |
6d012f14 | 800 | if (win_info->content != NULL) |
c906108c | 801 | { |
6ba8e26f | 802 | free_content ((tui_win_content) win_info->content, |
6d012f14 AC |
803 | win_info->content_size, |
804 | win_info->type); | |
805 | win_info->content = NULL; | |
c906108c | 806 | } |
6d012f14 | 807 | win_info->content_size = 0; |
6ba8e26f | 808 | } |
c906108c SS |
809 | |
810 | ||
c906108c | 811 | void |
6ba8e26f | 812 | tui_del_data_windows (tui_win_content content, int content_size) |
c906108c SS |
813 | { |
814 | int i; | |
815 | ||
816 | /* | |
2a8854a7 | 817 | ** Remember that data window content elements are of type struct tui_gen_win_info *, |
c5aa993b JM |
818 | ** each of which whose single element is a data element. |
819 | */ | |
6ba8e26f | 820 | for (i = 0; i < content_size; i++) |
c906108c | 821 | { |
6ba8e26f | 822 | struct tui_gen_win_info * generic_win = &content[i]->which_element.data_window; |
c906108c | 823 | |
6ba8e26f | 824 | if (generic_win != (struct tui_gen_win_info *) NULL) |
c906108c | 825 | { |
6ba8e26f AC |
826 | tui_delete_win (generic_win->handle); |
827 | generic_win->handle = (WINDOW *) NULL; | |
828 | generic_win->is_visible = FALSE; | |
c906108c SS |
829 | } |
830 | } | |
dd1abb8c | 831 | } |
c906108c SS |
832 | |
833 | ||
834 | void | |
6ba8e26f | 835 | tui_free_data_content (tui_win_content content, int content_size) |
c906108c SS |
836 | { |
837 | int i; | |
838 | ||
839 | /* | |
2a8854a7 | 840 | ** Remember that data window content elements are of type struct tui_gen_win_info *, |
c5aa993b JM |
841 | ** each of which whose single element is a data element. |
842 | */ | |
6ba8e26f | 843 | for (i = 0; i < content_size; i++) |
c906108c | 844 | { |
6ba8e26f | 845 | struct tui_gen_win_info * generic_win = &content[i]->which_element.data_window; |
c906108c | 846 | |
6ba8e26f | 847 | if (generic_win != (struct tui_gen_win_info *) NULL) |
c906108c | 848 | { |
6ba8e26f AC |
849 | tui_delete_win (generic_win->handle); |
850 | generic_win->handle = (WINDOW *) NULL; | |
851 | tui_free_win_content (generic_win); | |
c906108c SS |
852 | } |
853 | } | |
6ba8e26f AC |
854 | free_content (content, |
855 | content_size, | |
c906108c | 856 | DATA_WIN); |
6ba8e26f | 857 | } |
c906108c SS |
858 | |
859 | ||
860 | /********************************** | |
861 | ** LOCAL STATIC FUNCTIONS ** | |
862 | **********************************/ | |
863 | ||
864 | ||
c906108c | 865 | static void |
6ba8e26f | 866 | free_content (tui_win_content content, int content_size, enum tui_win_type win_type) |
c906108c | 867 | { |
2a8854a7 | 868 | if (content != (tui_win_content) NULL) |
c906108c | 869 | { |
6ba8e26f | 870 | free_content_elements (content, content_size, win_type); |
22940a24 | 871 | xfree (content); |
c906108c | 872 | } |
6ba8e26f | 873 | } |
c906108c SS |
874 | |
875 | ||
876 | /* | |
6ba8e26f | 877 | ** free_content_elements(). |
c5aa993b | 878 | */ |
c906108c | 879 | static void |
6ba8e26f | 880 | free_content_elements (tui_win_content content, int content_size, enum tui_win_type type) |
c906108c | 881 | { |
2a8854a7 | 882 | if (content != (tui_win_content) NULL) |
c906108c SS |
883 | { |
884 | int i; | |
885 | ||
886 | if (type == SRC_WIN || type == DISASSEM_WIN) | |
887 | { | |
888 | /* free whole source block */ | |
6d012f14 | 889 | xfree (content[0]->which_element.source.line); |
c906108c SS |
890 | } |
891 | else | |
892 | { | |
6ba8e26f | 893 | for (i = 0; i < content_size; i++) |
c906108c | 894 | { |
2a8854a7 | 895 | struct tui_win_element * element; |
c906108c SS |
896 | |
897 | element = content[i]; | |
2a8854a7 | 898 | if (element != (struct tui_win_element *) NULL) |
c906108c SS |
899 | { |
900 | switch (type) | |
901 | { | |
902 | case DATA_WIN: | |
22940a24 | 903 | xfree (element); |
c906108c SS |
904 | break; |
905 | case DATA_ITEM_WIN: | |
906 | /* | |
c5aa993b JM |
907 | ** Note that data elements are not allocated |
908 | ** in a single block, but individually, as needed. | |
909 | */ | |
6d012f14 AC |
910 | if (element->which_element.data.type != TUI_REGISTER) |
911 | xfree ((void *)element->which_element.data.name); | |
912 | xfree (element->which_element.data.value); | |
10f59415 | 913 | xfree (element->which_element.data.content); |
22940a24 | 914 | xfree (element); |
c906108c SS |
915 | break; |
916 | case CMD_WIN: | |
6d012f14 | 917 | xfree (element->which_element.command.line); |
c906108c SS |
918 | break; |
919 | default: | |
920 | break; | |
921 | } | |
922 | } | |
923 | } | |
924 | } | |
925 | if (type != DATA_WIN && type != DATA_ITEM_WIN) | |
22940a24 | 926 | xfree (content[0]); /* free the element block */ |
c906108c | 927 | } |
6ba8e26f | 928 | } |