PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Info.c

#
C | 125 lines | 75 code | 6 blank | 44 comment | 13 complexity | 5ebdcfe04894430bdea0b08521ea6db7 MD5 | raw file
  1. /*
  2. * Copyright (C) 1989-95 GROUPE BULL
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to
  6. * deal in the Software without restriction, including without limitation the
  7. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. * sell copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  18. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. *
  21. * Except as contained in this notice, the name of GROUPE BULL shall not be
  22. * used in advertising or otherwise to promote the sale, use or other dealings
  23. * in this Software without prior written authorization from GROUPE BULL.
  24. */
  25. /*****************************************************************************\
  26. * Info.c: *
  27. * *
  28. * XPM library *
  29. * Functions related to the XpmInfo structure. *
  30. * *
  31. * Developed by Arnaud Le Hors *
  32. \*****************************************************************************/
  33. #ifdef HAVE_CONFIG_H
  34. #include <config.h>
  35. #endif
  36. #include "XpmI.h"
  37. /*
  38. * Init returned data to free safely later on
  39. */
  40. void
  41. xpmInitXpmInfo(XpmInfo *info)
  42. {
  43. if (info) {
  44. info->hints_cmt = NULL;
  45. info->colors_cmt = NULL;
  46. info->pixels_cmt = NULL;
  47. info->extensions = NULL;
  48. info->nextensions = 0;
  49. }
  50. }
  51. /*
  52. * Free the XpmInfo data which have been allocated
  53. */
  54. void
  55. XpmFreeXpmInfo(XpmInfo *info)
  56. {
  57. if (info) {
  58. if (info->valuemask & XpmComments) {
  59. if (info->hints_cmt) {
  60. XpmFree(info->hints_cmt);
  61. info->hints_cmt = NULL;
  62. }
  63. if (info->colors_cmt) {
  64. XpmFree(info->colors_cmt);
  65. info->colors_cmt = NULL;
  66. }
  67. if (info->pixels_cmt) {
  68. XpmFree(info->pixels_cmt);
  69. info->pixels_cmt = NULL;
  70. }
  71. }
  72. if (info->valuemask & XpmReturnExtensions && info->nextensions) {
  73. XpmFreeExtensions(info->extensions, info->nextensions);
  74. info->extensions = NULL;
  75. info->nextensions = 0;
  76. }
  77. info->valuemask = 0;
  78. }
  79. }
  80. /*
  81. * Set the XpmInfo valuemask to retrieve required info
  82. */
  83. void
  84. xpmSetInfoMask(
  85. XpmInfo *info,
  86. XpmAttributes *attributes)
  87. {
  88. info->valuemask = 0;
  89. if (attributes->valuemask & XpmReturnInfos)
  90. info->valuemask |= XpmReturnComments;
  91. if (attributes->valuemask & XpmReturnExtensions)
  92. info->valuemask |= XpmReturnExtensions;
  93. }
  94. /*
  95. * Fill in the XpmInfo with the XpmAttributes
  96. */
  97. void
  98. xpmSetInfo(
  99. XpmInfo *info,
  100. XpmAttributes *attributes)
  101. {
  102. info->valuemask = 0;
  103. if (attributes->valuemask & XpmInfos) {
  104. info->valuemask |= XpmComments | XpmColorTable;
  105. info->hints_cmt = attributes->hints_cmt;
  106. info->colors_cmt = attributes->colors_cmt;
  107. info->pixels_cmt = attributes->pixels_cmt;
  108. }
  109. if (attributes->valuemask & XpmExtensions) {
  110. info->valuemask |= XpmExtensions;
  111. info->extensions = attributes->extensions;
  112. info->nextensions = attributes->nextensions;
  113. }
  114. if (attributes->valuemask & XpmHotspot) {
  115. info->valuemask |= XpmHotspot;
  116. info->x_hotspot = attributes->x_hotspot;
  117. info->y_hotspot = attributes->y_hotspot;
  118. }
  119. }