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