Imported from antiword-0.37.tar.gz.
[antiword.git] / pictlist.c
blobdd9e4bfc0809670fd83c0b64f0998a164af9e099
1 /*
2 * pictlist.c
3 * Copyright (C) 2000-2004 A.J. van Os; Released under GNU GPL
5 * Description:
6 * Build, read and destroy a list of Word picture information
7 */
9 #include <stdlib.h>
10 #include "antiword.h"
14 * Private structure to hide the way the information
15 * is stored from the rest of the program
17 typedef struct picture_mem_tag {
18 picture_block_type tInfo;
19 struct picture_mem_tag *pNext;
20 } picture_mem_type;
22 /* Variables needed to write the Picture Information List */
23 static picture_mem_type *pAnchor = NULL;
24 static picture_mem_type *pPictureLast = NULL;
28 * vDestroyPictInfoList - destroy the Picture Information List
30 void
31 vDestroyPictInfoList(void)
33 picture_mem_type *pCurr, *pNext;
35 DBG_MSG("vDestroyPictInfoList");
37 /* Free the Picture Information List */
38 pCurr = pAnchor;
39 while (pCurr != NULL) {
40 pNext = pCurr->pNext;
41 pCurr = xfree(pCurr);
42 pCurr = pNext;
44 pAnchor = NULL;
45 /* Reset all control variables */
46 pPictureLast = NULL;
47 } /* end of vDestroyPictInfoList */
50 * vAdd2PictInfoList - Add an element to the Picture Information List
52 void
53 vAdd2PictInfoList(const picture_block_type *pPictureBlock)
55 picture_mem_type *pListMember;
57 fail(pPictureBlock == NULL);
59 NO_DBG_MSG("bAdd2PictInfoList");
61 if (pPictureBlock->ulFileOffset == FC_INVALID) {
63 * This offset is really past the end of the file,
64 * so don't waste any memory by storing it.
66 return;
68 if (pPictureBlock->ulFileOffsetPicture == FC_INVALID) {
70 * The place where this picture is supposed to be stored
71 * doesn't exist.
73 return;
76 NO_DBG_HEX(pPictureBlock->ulFileOffset);
77 NO_DBG_HEX(pPictureBlock->ulFileOffsetPicture);
78 NO_DBG_HEX(pPictureBlock->ulPictureOffset);
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;
92 pPictureLast = pListMember;
93 } /* end of vAdd2PictInfoList */
96 * Get the info with the given file offset from the Picture Information List
98 ULONG
99 ulGetPictInfoListItem(ULONG ulFileOffset)
101 picture_mem_type *pCurr;
103 for (pCurr = pAnchor; pCurr != NULL; pCurr = pCurr->pNext) {
104 if (pCurr->tInfo.ulFileOffset == ulFileOffset) {
105 return pCurr->tInfo.ulFileOffsetPicture;
108 return FC_INVALID;
109 } /* end of ulGetPictInfoListItem */