examples/PIPS/antiword/src/rowlist.c

00001 /*
00002  * rowlist.c
00003  * Copyright (C) 1998-2004 A.J. van Os; Released under GPL
00004  *
00005  * Description:
00006  * Build, read and destroy a list of Word table-row information
00007  */
00008 
00009 #include <stdlib.h>
00010 #include <string.h>
00011 #include "antiword.h"
00012 
00013 /*
00014  * Private structure to hide the way the information
00015  * is stored from the rest of the program
00016  */
00017 typedef struct row_desc_tag {
00018         row_block_type          tInfo;
00019         struct row_desc_tag     *pNext;
00020 } row_desc_type;
00021 
00022 /* Variables needed to write the Row Information List */
00023 static row_desc_type    *pAnchor = NULL;
00024 static row_desc_type    *pRowLast = NULL;
00025 /* Variable needed to read the Row Information List */
00026 static row_desc_type    *pRowCurrent = NULL;
00027 
00028 
00029 /*
00030  * vDestroyRowInfoList - destroy the Row Information List
00031  */
00032 void
00033 vDestroyRowInfoList(void)
00034 {
00035         row_desc_type   *pCurr, *pNext;
00036 
00037         DBG_MSG("vDestroyRowInfoList");
00038 
00039         /* Free the Row Information List */
00040         pCurr = pAnchor;
00041         while (pCurr != NULL) {
00042                 pNext = pCurr->pNext;
00043                 pCurr = xfree(pCurr);
00044                 pCurr = pNext;
00045         }
00046         pAnchor = NULL;
00047         /* Reset all control variables */
00048         pRowLast = NULL;
00049         pRowCurrent = NULL;
00050 } /* end of vDestroyRowInfoList */
00051 
00052 /*
00053  * vAdd2RowInfoList - Add an element to the Row Information List
00054  */
00055 void
00056 vAdd2RowInfoList(const row_block_type *pRowBlock)
00057 {
00058         row_desc_type   *pListMember;
00059         short           *psTmp;
00060         int             iIndex;
00061 
00062         fail(pRowBlock == NULL);
00063 
00064         if (pRowBlock->ulFileOffsetStart == FC_INVALID ||
00065             pRowBlock->ulFileOffsetEnd == FC_INVALID ||
00066             pRowBlock->ulFileOffsetStart == pRowBlock->ulFileOffsetEnd) {
00067                 DBG_HEX_C(pRowBlock->ulFileOffsetStart != FC_INVALID,
00068                         pRowBlock->ulFileOffsetStart);
00069                 DBG_HEX_C(pRowBlock->ulFileOffsetEnd != FC_INVALID,
00070                         pRowBlock->ulFileOffsetEnd);
00071                 return;
00072         }
00073 
00074         NO_DBG_HEX(pRowBlock->ulFileOffsetStart);
00075         NO_DBG_HEX(pRowBlock->ulFileOffsetEnd);
00076         NO_DBG_DEC(pRowBlock->ucNumberOfColumns);
00077 
00078         /* Create the new list member */
00079         pListMember = xmalloc(sizeof(row_desc_type));
00080         /* Fill the new list member */
00081         pListMember->tInfo = *pRowBlock;
00082         pListMember->pNext = NULL;
00083         /* Correct the values where needed */
00084         for (iIndex = 0, psTmp = pListMember->tInfo.asColumnWidth;
00085              iIndex < (int)pListMember->tInfo.ucNumberOfColumns;
00086              iIndex++, psTmp++) {
00087                 if (*psTmp < 0) {
00088                         *psTmp = 0;
00089                         DBG_MSG("The column width was negative");
00090                 }
00091         }
00092         /* Add the new member to the list */
00093         if (pAnchor == NULL) {
00094                 pAnchor = pListMember;
00095                 pRowCurrent = pListMember;
00096         } else {
00097                 fail(pRowLast == NULL);
00098                 pRowLast->pNext = pListMember;
00099         }
00100         pRowLast = pListMember;
00101 } /* end of vAdd2RowInfoList */
00102 
00103 /*
00104  * Get the next item in the Row Information List
00105  */
00106 const row_block_type *
00107 pGetNextRowInfoListItem(void)
00108 {
00109         const row_block_type    *pItem;
00110 
00111         if (pRowCurrent == NULL) {
00112                 return NULL;
00113         }
00114         pItem = &pRowCurrent->tInfo;
00115         pRowCurrent = pRowCurrent->pNext;
00116         return pItem;
00117 } /* end of pGetNextRowInfoListItem */

Generated by  doxygen 1.6.2