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