pictlist.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * pictlist.c
  3. * Copyright (C) 2000-2004 A.J. van Os; Released under GNU GPL
  4. *
  5. * Description:
  6. * Build, read and destroy a list of Word picture information
  7. */
  8. #include <stdlib.h>
  9. #include "antiword.h"
  10. /*
  11. * Private structure to hide the way the information
  12. * is stored from the rest of the program
  13. */
  14. typedef struct picture_mem_tag {
  15. picture_block_type tInfo;
  16. struct picture_mem_tag *pNext;
  17. } picture_mem_type;
  18. /* Variables needed to write the Picture Information List */
  19. static picture_mem_type *pAnchor = NULL;
  20. static picture_mem_type *pPictureLast = NULL;
  21. /*
  22. * vDestroyPictInfoList - destroy the Picture Information List
  23. */
  24. void
  25. vDestroyPictInfoList(void)
  26. {
  27. picture_mem_type *pCurr, *pNext;
  28. DBG_MSG("vDestroyPictInfoList");
  29. /* Free the Picture Information List */
  30. pCurr = pAnchor;
  31. while (pCurr != NULL) {
  32. pNext = pCurr->pNext;
  33. pCurr = xfree(pCurr);
  34. pCurr = pNext;
  35. }
  36. pAnchor = NULL;
  37. /* Reset all control variables */
  38. pPictureLast = NULL;
  39. } /* end of vDestroyPictInfoList */
  40. /*
  41. * vAdd2PictInfoList - Add an element to the Picture Information List
  42. */
  43. void
  44. vAdd2PictInfoList(const picture_block_type *pPictureBlock)
  45. {
  46. picture_mem_type *pListMember;
  47. fail(pPictureBlock == NULL);
  48. NO_DBG_MSG("bAdd2PictInfoList");
  49. if (pPictureBlock->ulFileOffset == FC_INVALID) {
  50. /*
  51. * This offset is really past the end of the file,
  52. * so don't waste any memory by storing it.
  53. */
  54. return;
  55. }
  56. if (pPictureBlock->ulFileOffsetPicture == FC_INVALID) {
  57. /*
  58. * The place where this picture is supposed to be stored
  59. * doesn't exist.
  60. */
  61. return;
  62. }
  63. NO_DBG_HEX(pPictureBlock->ulFileOffset);
  64. NO_DBG_HEX(pPictureBlock->ulFileOffsetPicture);
  65. NO_DBG_HEX(pPictureBlock->ulPictureOffset);
  66. /* Create list member */
  67. pListMember = xmalloc(sizeof(picture_mem_type));
  68. /* Fill the list member */
  69. pListMember->tInfo = *pPictureBlock;
  70. pListMember->pNext = NULL;
  71. /* Add the new member to the list */
  72. if (pAnchor == NULL) {
  73. pAnchor = pListMember;
  74. } else {
  75. fail(pPictureLast == NULL);
  76. pPictureLast->pNext = pListMember;
  77. }
  78. pPictureLast = pListMember;
  79. } /* end of vAdd2PictInfoList */
  80. /*
  81. * Get the info with the given file offset from the Picture Information List
  82. */
  83. ULONG
  84. ulGetPictInfoListItem(ULONG ulFileOffset)
  85. {
  86. picture_mem_type *pCurr;
  87. for (pCurr = pAnchor; pCurr != NULL; pCurr = pCurr->pNext) {
  88. if (pCurr->tInfo.ulFileOffset == ulFileOffset) {
  89. return pCurr->tInfo.ulFileOffsetPicture;
  90. }
  91. }
  92. return FC_INVALID;
  93. } /* end of ulGetPictInfoListItem */