home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / anwor032.zip / antiword.0.32 / pictlist.c < prev    next >
C/C++ Source or Header  |  2000-11-23  |  2KB  |  103 lines

  1. /*
  2.  * pictlist.c
  3.  * Copyright (C) 2000 A.J. van Os; Released under 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. /* Variables needed to write the Picture Information List */
  14. static picture_desc_type    *pAnchor = NULL;
  15. static picture_desc_type    *pPictureLast = NULL;
  16.  
  17.  
  18. /*
  19.  * vDestroyPicInfoList - destroy the Picture Information List
  20.  */
  21. void
  22. vDestroyPicInfoList(void)
  23. {
  24.     picture_desc_type    *pCurr, *pNext;
  25.  
  26.     DBG_MSG("vDestroyPicInfoList");
  27.  
  28.     /* Free the Picture Information List */
  29.     pCurr = pAnchor;
  30.     while (pCurr != NULL) {
  31.         pNext = pCurr->pNext;
  32.         pCurr = xfree(pCurr);
  33.         pCurr = pNext;
  34.     }
  35.     pAnchor = NULL;
  36.     /* Reset all control variables */
  37.     pPictureLast = NULL;
  38. } /* end of vDestroyPicInfoList */
  39.  
  40. /*
  41.  * vAdd2PicInfoList - Add an element to the Picture Information List
  42.  */
  43. void
  44. vAdd2PicInfoList(const picture_block_type *pPictureBlock)
  45. {
  46.     picture_desc_type    *pListMember;
  47.  
  48.     fail(pPictureBlock == NULL);
  49.     fail(pPictureBlock->lFileOffset < -1);
  50.     fail(pPictureBlock->lFileOffsetPicture < -1);
  51.  
  52.     NO_DBG_MSG("bAdd2PicInfoList");
  53.  
  54.     if (pPictureBlock->lFileOffset < 0) {
  55.         /*
  56.          * This offset is really past the end of the file,
  57.          * so don't waste any memory by storing it.
  58.          */
  59.         return;
  60.     }
  61.     if (pPictureBlock->lFileOffsetPicture < 0) {
  62.         /*
  63.          * The place where this picture is supposed to be stored
  64.          * doesn't exist.
  65.          */
  66.         return;
  67.     }
  68.  
  69.     NO_DBG_HEX(pPictureBlock->lFileOffset);
  70.     NO_DBG_HEX(pPictureBlock->lFileOffsetPicture);
  71.     NO_DBG_HEX(pPictureBlock->lPictureOffset);
  72.  
  73.     /* Create list member */
  74.     pListMember = xmalloc(sizeof(picture_desc_type));
  75.     /* Fill the list member */
  76.     pListMember->tInfo = *pPictureBlock;
  77.     pListMember->pNext = NULL;
  78.     /* Add the new member to the list */
  79.     if (pAnchor == NULL) {
  80.         pAnchor = pListMember;
  81.     } else {
  82.         fail(pPictureLast == NULL);
  83.         pPictureLast->pNext = pListMember;
  84.     }
  85.     pPictureLast = pListMember;
  86. } /* end of vAdd2PicInfoList */
  87.  
  88. /*
  89.  * Get the info with the given file offset from the Picture Information List
  90.  */
  91. long
  92. lGetPicInfoListItem(long lFileOffset)
  93. {
  94.     picture_desc_type    *pCurr;
  95.  
  96.     for (pCurr = pAnchor; pCurr != NULL; pCurr = pCurr->pNext) {
  97.         if (pCurr->tInfo.lFileOffset == lFileOffset) {
  98.             return pCurr->tInfo.lFileOffsetPicture;
  99.         }
  100.     }
  101.     return -1;
  102. } /* end of lGetPicInfoListItem */
  103.