examples/PIPS/antiword/src/pictlist.c

00001 /*
00002  * pictlist.c
00003  * Copyright (C) 2000-2004 A.J. van Os; Released under GNU GPL
00004  *
00005  * Description:
00006  * Build, read and destroy a list of Word picture information
00007  */
00008 
00009 #include <stdlib.h>
00010 #include "antiword.h"
00011 
00012 
00013 /*
00014  * Private structure to hide the way the information
00015  * is stored from the rest of the program
00016  */
00017 typedef struct picture_mem_tag {
00018         picture_block_type      tInfo;
00019         struct picture_mem_tag *pNext;
00020 } picture_mem_type;
00021 
00022 /* Variables needed to write the Picture Information List */
00023 static picture_mem_type *pAnchor = NULL;
00024 static picture_mem_type *pPictureLast = NULL;
00025 
00026 
00027 /*
00028  * vDestroyPictInfoList - destroy the Picture Information List
00029  */
00030 void
00031 vDestroyPictInfoList(void)
00032 {
00033         picture_mem_type        *pCurr, *pNext;
00034 
00035         DBG_MSG("vDestroyPictInfoList");
00036 
00037         /* Free the Picture Information List */
00038         pCurr = pAnchor;
00039         while (pCurr != NULL) {
00040                 pNext = pCurr->pNext;
00041                 pCurr = xfree(pCurr);
00042                 pCurr = pNext;
00043         }
00044         pAnchor = NULL;
00045         /* Reset all control variables */
00046         pPictureLast = NULL;
00047 } /* end of vDestroyPictInfoList */
00048 
00049 /*
00050  * vAdd2PictInfoList - Add an element to the Picture Information List
00051  */
00052 void
00053 vAdd2PictInfoList(const picture_block_type *pPictureBlock)
00054 {
00055         picture_mem_type        *pListMember;
00056 
00057         fail(pPictureBlock == NULL);
00058 
00059         NO_DBG_MSG("bAdd2PictInfoList");
00060 
00061         if (pPictureBlock->ulFileOffset == FC_INVALID) {
00062                 /*
00063                  * This offset is really past the end of the file,
00064                  * so don't waste any memory by storing it.
00065                  */
00066                 return;
00067         }
00068         if (pPictureBlock->ulFileOffsetPicture == FC_INVALID) {
00069                 /*
00070                  * The place where this picture is supposed to be stored
00071                  * doesn't exist.
00072                  */
00073                 return;
00074         }
00075 
00076         NO_DBG_HEX(pPictureBlock->ulFileOffset);
00077         NO_DBG_HEX(pPictureBlock->ulFileOffsetPicture);
00078         NO_DBG_HEX(pPictureBlock->ulPictureOffset);
00079 
00080         /* Create list member */
00081         pListMember = xmalloc(sizeof(picture_mem_type));
00082         /* Fill the list member */
00083         pListMember->tInfo = *pPictureBlock;
00084         pListMember->pNext = NULL;
00085         /* Add the new member to the list */
00086         if (pAnchor == NULL) {
00087                 pAnchor = pListMember;
00088         } else {
00089                 fail(pPictureLast == NULL);
00090                 pPictureLast->pNext = pListMember;
00091         }
00092         pPictureLast = pListMember;
00093 } /* end of vAdd2PictInfoList */
00094 
00095 /*
00096  * Get the info with the given file offset from the Picture Information List
00097  */
00098 ULONG
00099 ulGetPictInfoListItem(ULONG ulFileOffset)
00100 {
00101         picture_mem_type        *pCurr;
00102 
00103         for (pCurr = pAnchor; pCurr != NULL; pCurr = pCurr->pNext) {
00104                 if (pCurr->tInfo.ulFileOffset == ulFileOffset) {
00105                         return pCurr->tInfo.ulFileOffsetPicture;
00106                 }
00107         }
00108         return FC_INVALID;
00109 } /* end of ulGetPictInfoListItem */

Generated by  doxygen 1.6.2