Imported from antiword-0.36.tar.gz.
[antiword.git] / pictlist.c
blob994020942feaa4d8e900d8c32c79f1dba5087415
1 /*
2 * pictlist.c
3 * Copyright (C) 2000,2001 A.J. van Os; Released under GPL
5 * Description:
6 * Build, read and destroy a list of Word picture information
7 */
9 #include <stdlib.h>
10 #include "antiword.h"
13 /* Variables needed to write the Picture Information List */
14 static picture_desc_type *pAnchor = NULL;
15 static picture_desc_type *pPictureLast = NULL;
19 * vDestroyPictInfoList - destroy the Picture Information List
21 void
22 vDestroyPictInfoList(void)
24 picture_desc_type *pCurr, *pNext;
26 DBG_MSG("vDestroyPictInfoList");
28 /* Free the Picture Information List */
29 pCurr = pAnchor;
30 while (pCurr != NULL) {
31 pNext = pCurr->pNext;
32 pCurr = xfree(pCurr);
33 pCurr = pNext;
35 pAnchor = NULL;
36 /* Reset all control variables */
37 pPictureLast = NULL;
38 } /* end of vDestroyPictInfoList */
41 * vAdd2PictInfoList - Add an element to the Picture Information List
43 void
44 vAdd2PictInfoList(const picture_block_type *pPictureBlock)
46 picture_desc_type *pListMember;
48 fail(pPictureBlock == NULL);
50 NO_DBG_MSG("bAdd2PictInfoList");
52 if (pPictureBlock->ulFileOffset == FC_INVALID) {
54 * This offset is really past the end of the file,
55 * so don't waste any memory by storing it.
57 return;
59 if (pPictureBlock->ulFileOffsetPicture == FC_INVALID) {
61 * The place where this picture is supposed to be stored
62 * doesn't exist.
64 return;
67 NO_DBG_HEX(pPictureBlock->ulFileOffset);
68 NO_DBG_HEX(pPictureBlock->ulFileOffsetPicture);
69 NO_DBG_HEX(pPictureBlock->ulPictureOffset);
71 /* Create list member */
72 pListMember = xmalloc(sizeof(picture_desc_type));
73 /* Fill the list member */
74 pListMember->tInfo = *pPictureBlock;
75 pListMember->pNext = NULL;
76 /* Add the new member to the list */
77 if (pAnchor == NULL) {
78 pAnchor = pListMember;
79 } else {
80 fail(pPictureLast == NULL);
81 pPictureLast->pNext = pListMember;
83 pPictureLast = pListMember;
84 } /* end of vAdd2PictInfoList */
87 * Get the info with the given file offset from the Picture Information List
89 ULONG
90 ulGetPictInfoListItem(ULONG ulFileOffset)
92 picture_desc_type *pCurr;
94 for (pCurr = pAnchor; pCurr != NULL; pCurr = pCurr->pNext) {
95 if (pCurr->tInfo.ulFileOffset == ulFileOffset) {
96 return pCurr->tInfo.ulFileOffsetPicture;
99 return FC_INVALID;
100 } /* end of ulGetPictInfoListItem */