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