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