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