home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / anwor032.zip / antiword.0.32 / rowlist.c < prev    next >
C/C++ Source or Header  |  2001-05-10  |  3KB  |  119 lines

  1. /*
  2.  * rowlist.c
  3.  * Copyright (C) 1998-2001 A.J. van Os; Released under GPL
  4.  *
  5.  * Description:
  6.  * Build, read and destroy a list of Word table-row information
  7.  */
  8.  
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include "antiword.h"
  12.  
  13. /*
  14.  * Private structure to hide the way the information
  15.  * is stored from the rest of the program
  16.  */
  17. typedef struct row_desc_tag {
  18.     row_block_type        tInfo;
  19.     struct row_desc_tag    *pNext;
  20. } row_desc_type;
  21.  
  22. /* Variables needed to write the Row Information List */
  23. static row_desc_type    *pAnchor = NULL;
  24. static row_desc_type    *pRowLast = NULL;
  25. /* Variable needed to read the Row Information List */
  26. static row_desc_type    *pRowCurrent = NULL;
  27.  
  28.  
  29. /*
  30.  * vDestroyRowInfoList - destroy the Row Information List
  31.  */
  32. void
  33. vDestroyRowInfoList(void)
  34. {
  35.     row_desc_type    *pCurr, *pNext;
  36.  
  37.     DBG_MSG("vDestroyRowInfoList");
  38.  
  39.     /* Free the Row Information List */
  40.     pCurr = pAnchor;
  41.     while (pCurr != NULL) {
  42.         pNext = pCurr->pNext;
  43.         pCurr = xfree(pCurr);
  44.         pCurr = pNext;
  45.     }
  46.     pAnchor = NULL;
  47.     /* Reset all control variables */
  48.     pRowLast = NULL;
  49.     pRowCurrent = NULL;
  50. } /* end of vDestroyRowInfoList */
  51.  
  52. /*
  53.  * vAdd2RowInfoList - Add an element to the Row Information List
  54.  */
  55. void
  56. vAdd2RowInfoList(const row_block_type *pRowBlock)
  57. {
  58.     row_desc_type    *pNew;
  59.     short        *psTmp;
  60.     int        iIndex;
  61.  
  62.     fail(pRowBlock == NULL);
  63.  
  64.     if (pRowBlock->lFileOffsetStart < 0 ||
  65.         pRowBlock->lFileOffsetEnd < 0 ||
  66.         pRowBlock->lFileOffsetStart == pRowBlock->lFileOffsetEnd) {
  67.         DBG_HEX_C(pRowBlock->lFileOffsetStart >= 0,
  68.             pRowBlock->lFileOffsetStart);
  69.         DBG_HEX_C(pRowBlock->lFileOffsetEnd >= 0,
  70.             pRowBlock->lFileOffsetEnd);
  71.         return;
  72.     }
  73.  
  74.     NO_DBG_HEX(pRowBlock->lFileOffsetStart);
  75.     NO_DBG_HEX(pRowBlock->lFileOffsetEnd);
  76.     NO_DBG_DEC(pRowBlock->ucNumberOfColumns);
  77.     NO_DBG_DEC(pRowBlock->iColumnWidthSum);
  78.  
  79.     /* Create the new list member */
  80.     pNew = xmalloc(sizeof(row_desc_type));
  81.     /* Fill the new list member */
  82.     pNew->tInfo = *pRowBlock;
  83.     pNew->pNext = NULL;
  84.     /* Correct the values where needed */
  85.     for (iIndex = 0, psTmp = pNew->tInfo.asColumnWidth;
  86.          iIndex < (int)pNew->tInfo.ucNumberOfColumns;
  87.          iIndex++, psTmp++) {
  88.         if (*psTmp < 0) {
  89.             *psTmp = 0;
  90.             DBG_MSG("The column width was negative");
  91.         }
  92.     }
  93.     /* Add the new member to the list */
  94.     if (pAnchor == NULL) {
  95.         pAnchor = pNew;
  96.         pRowCurrent = pNew;
  97.     } else {
  98.         fail(pRowLast == NULL);
  99.         pRowLast->pNext = pNew;
  100.     }
  101.     pRowLast = pNew;
  102. } /* end of vAdd2RowInfoList */
  103.  
  104. /*
  105.  * Get the next item in the Row Information List
  106.  */
  107. const row_block_type *
  108. pGetNextRowInfoListItem(void)
  109. {
  110.     const row_block_type    *pItem;
  111.  
  112.     if (pRowCurrent == NULL) {
  113.         return NULL;
  114.     }
  115.     pItem = &pRowCurrent->tInfo;
  116.     pRowCurrent = pRowCurrent->pNext;
  117.     return pItem;
  118. } /* end of pGetNextRowInfoListItem */
  119.