CleanUp.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: CleanUp.c /main/10 1996/01/29 12:19:40 cde-hp $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: CleanUp.c
  28. **
  29. ** Project: Cde DtHelp
  30. **
  31. ** Description:
  32. **
  33. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  34. **
  35. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  36. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  37. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  38. ** (c) Copyright 1993, 1994 Novell, Inc.
  39. **
  40. **
  41. ****************************************************************************
  42. ************************************<+>*************************************/
  43. /*
  44. * system includes
  45. */
  46. #include <stdlib.h>
  47. #include <X11/Intrinsic.h>
  48. /*
  49. * Canvas Engine includes
  50. */
  51. #include "CanvasP.h"
  52. #include "CanvasSegP.h"
  53. #include "LinkMgrP.h"
  54. /*
  55. * private includes
  56. */
  57. #include "bufioI.h"
  58. #include "CleanUpI.h"
  59. #include "FontAttrI.h"
  60. #include "FormatUtilI.h"
  61. #include "RegionI.h"
  62. #include "StringFuncsI.h"
  63. #include "XInterfaceI.h"
  64. #ifdef NLS16
  65. #endif
  66. /******** Private Function Declarations ********/
  67. /******** End Private Function Declarations ********/
  68. /*****************************************************************************
  69. * Private Defines
  70. *****************************************************************************/
  71. /*****************************************************************************
  72. * Private Macros
  73. *****************************************************************************/
  74. #define AbbrevStr(x) (FrmtPrivInfoPtr(x)->abbrev)
  75. #define DupFlag(x) (FrmtPrivInfoPtr(x)->dup_flag)
  76. #define MatchInfo(x) (FrmtPrivInfoPtr(x)->match_info)
  77. #define TopFlag(x) (FrmtPrivInfoPtr(x)->top_block)
  78. /*****************************************************************************
  79. * Private Functions
  80. *****************************************************************************/
  81. static void
  82. CheckFreePrivInfo(_DtCvSegment *seg)
  83. {
  84. /*
  85. * free the match information
  86. */
  87. if (NULL != MatchInfo(seg))
  88. {
  89. SdlMatchData *m = (SdlMatchData *)(MatchInfo(seg));
  90. if (NULL != m->ssi)
  91. free(m->ssi);
  92. free(m);
  93. }
  94. /*
  95. * free any abbreviation
  96. */
  97. if (NULL != AbbrevStr(seg))
  98. free(AbbrevStr(seg));
  99. }
  100. static void
  101. FreePrivateAndSeg(_DtCvSegment *seg)
  102. {
  103. if (NULL != seg)
  104. {
  105. /*
  106. * free the private information block
  107. */
  108. if (NULL != FrmtPrivInfoPtr(seg))
  109. free(FrmtPrivInfoPtr(seg));
  110. /*
  111. * free the segment block
  112. */
  113. free(seg);
  114. }
  115. }
  116. /*****************************************************************************
  117. * Semi-Private Variables
  118. *****************************************************************************/
  119. /*****************************************************************************
  120. * Semi-Public Functions
  121. *****************************************************************************/
  122. /*****************************************************************************
  123. * Function: void _DtHelpFreeSegments (_DtCvSegment *seg_list)
  124. *
  125. * Parameters:
  126. * seg_list Specifies the Canvas Engine segment list.
  127. *
  128. * Returns: Nothing
  129. *
  130. * Purpose: Free all memory associated with an SDL list.
  131. *****************************************************************************/
  132. void
  133. _DtHelpFreeSegments (
  134. _DtCvSegment *seg_list,
  135. _DtCvStatus unresolved,
  136. void (*destroy_region)(),
  137. _DtCvPointer client_data)
  138. {
  139. int i;
  140. char dupFlag;
  141. char **strs;
  142. _DtCvSegment *nextSeg;
  143. _DtCvSegment *topSeg = NULL;
  144. _DtCvSegment *topTab = NULL;
  145. _DtCvSegment **tableSeg;
  146. while (seg_list != NULL)
  147. {
  148. dupFlag = DupFlag(seg_list);
  149. nextSeg = seg_list->next_seg;
  150. switch (_DtCvPrimaryTypeOfSeg(seg_list))
  151. {
  152. case _DtCvCONTAINER:
  153. /*
  154. * free the id block.
  155. */
  156. if (False == dupFlag &&
  157. NULL != _DtCvContainerIdOfSeg(seg_list))
  158. free(_DtCvContainerIdOfSeg(seg_list));
  159. /*
  160. * free the contents of the block
  161. */
  162. _DtHelpFreeSegments(_DtCvContainerListOfSeg(seg_list),
  163. unresolved,
  164. destroy_region,
  165. client_data);
  166. break;
  167. case _DtCvMARKER:
  168. if (False == dupFlag)
  169. free(_DtCvIdOfMarkerSeg(seg_list));
  170. break;
  171. case _DtCvREGION:
  172. if (False == dupFlag && NULL != destroy_region)
  173. (destroy_region)(client_data,
  174. _DtCvInfoOfRegionSeg(seg_list));
  175. break;
  176. case _DtCvSTRING:
  177. if (False == dupFlag)
  178. {
  179. free(_DtCvStringOfStringSeg(seg_list));
  180. if (True == unresolved &&
  181. NULL != _DtCvFontOfStringSeg(seg_list))
  182. free(_DtCvFontOfStringSeg(seg_list));
  183. }
  184. break;
  185. case _DtCvTABLE:
  186. if (True == dupFlag)
  187. break;
  188. /*
  189. * free the blocks
  190. */
  191. tableSeg = _DtCvCellsOfTableSeg(seg_list);
  192. while (NULL != tableSeg && NULL != *tableSeg)
  193. {
  194. /*
  195. * free the id block.
  196. */
  197. if (False == DupFlag(*tableSeg)
  198. && NULL != _DtCvContainerIdOfSeg(*tableSeg))
  199. free(_DtCvContainerIdOfSeg(*tableSeg));
  200. /*
  201. * free the contents of the block
  202. */
  203. _DtHelpFreeSegments(
  204. _DtCvContainerListOfSeg(*tableSeg),
  205. unresolved,
  206. destroy_region,
  207. client_data);
  208. tableSeg++;
  209. }
  210. /*
  211. * free each of the table cells
  212. */
  213. tableSeg = _DtCvCellsOfTableSeg(seg_list);
  214. while (NULL != tableSeg && NULL != *tableSeg)
  215. {
  216. if (True == TopFlag(*tableSeg))
  217. {
  218. FreePrivateAndSeg(topTab);
  219. topTab = *tableSeg;
  220. }
  221. CheckFreePrivInfo(*tableSeg);
  222. tableSeg++;
  223. }
  224. FreePrivateAndSeg(topTab);
  225. topTab = NULL;
  226. /*
  227. * free the list of cells
  228. */
  229. tableSeg = _DtCvCellsOfTableSeg(seg_list);
  230. free (tableSeg);
  231. /*
  232. * free the row ids.
  233. */
  234. _DtHelpCeFreeStringArray(
  235. _DtCvCellIdsOfTableSeg(seg_list));
  236. /*
  237. * free the column justification and width.
  238. */
  239. free((void *) _DtCvColJustifyOfTableSeg(seg_list));
  240. strs = _DtCvColWOfTableSeg(seg_list);
  241. for (i = 0;
  242. NULL != strs && i < _DtCvNumColsOfTableSeg(seg_list);
  243. i++, strs++)
  244. free((void *) *strs);
  245. if (NULL != _DtCvColWOfTableSeg(seg_list))
  246. free((void *) _DtCvColWOfTableSeg(seg_list));
  247. break;
  248. }
  249. CheckFreePrivInfo(seg_list);
  250. if (True == TopFlag(seg_list))
  251. {
  252. FreePrivateAndSeg(topSeg);
  253. topSeg = seg_list;
  254. }
  255. seg_list = nextSeg;
  256. }
  257. FreePrivateAndSeg(topSeg);
  258. } /* End _DtHelpFreeSegments */
  259. /*****************************************************************************
  260. * Function: void _DtHelpDestroyTopicData (
  261. * _DtCvSegment *seg_list)
  262. *
  263. * Parameters:
  264. * seg_list Specifies the SDL segment list.
  265. *
  266. * Returns: Nothing
  267. *
  268. * Purpose: Free all memory associated with an SDL list.
  269. *****************************************************************************/
  270. void
  271. _DtHelpDestroyTopicData (
  272. _DtCvTopicInfo *topic,
  273. void (*destroy_region)(),
  274. _DtCvPointer client_data)
  275. {
  276. if (NULL != topic)
  277. {
  278. /*
  279. * free the segment list
  280. */
  281. _DtHelpFreeSegments(topic->seg_list, _DtCvFALSE,
  282. destroy_region, client_data);
  283. /*
  284. * free the id string
  285. */
  286. if (NULL != topic->id_str)
  287. free(topic->id_str);
  288. /*
  289. * free the database
  290. */
  291. _DtLinkDbDestroy(topic->link_data);
  292. /*
  293. * free the structure
  294. */
  295. free(topic);
  296. }
  297. } /* End _DtHelpDestroyTopicData */