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