Imported from antiword-0.30.tar.gz.
[antiword.git] / rowlist.c
blobcce3d7a355599f8c4569d7593c8c87d236d7c794
1 /*
2 * rowlist.c
3 * Copyright (C) 1998,1999 A.J. van Os
5 * Description:
6 * Build, read and destroy a list of Word table-row information
7 */
9 #include <stdlib.h>
10 #include <string.h>
11 #include "antiword.h"
14 * Privat structures to hide the way the information
15 * is stored from the rest of the program
17 typedef struct row_unique_tag {
18 int iOffsetStart;
19 int iOffsetEnd;
20 } row_unique_type;
21 typedef struct row_common_tag {
22 int iColumnWidthSum; /* In twips */
23 short asColumnWidth[TABLE_COLUMN_MAX+1]; /* In twips */
24 unsigned char ucNumberOfColumns;
25 } row_common_type;
26 typedef struct row_desc_tag {
27 row_unique_type tUnique;
28 row_common_type *pCommon;
29 struct row_desc_tag *pNext;
30 } row_desc_type;
32 /* Variables needed to write the Row Information List */
33 static row_desc_type *pAnchor = NULL;
34 static row_desc_type *pRowLast = NULL;
35 /* Variable needed to read the Row Information List */
36 static row_desc_type *pRowCurrent = NULL;
40 * vDestroyRowInfoList - destroy the Row Information List
42 void
43 vDestroyRowInfoList(void)
45 row_desc_type *pCurr, *pNext;
47 DBG_MSG("vDestroyRowInfoList");
49 /* Free the Row Information List */
50 pCurr = pAnchor;
51 while (pCurr != NULL) {
52 pNext = pCurr->pNext;
53 pCurr->pCommon = xfree(pCurr->pCommon);
54 pCurr = xfree(pCurr);
55 pCurr = pNext;
57 pAnchor = NULL;
58 /* Reset all control variables */
59 pRowLast = NULL;
60 pRowCurrent = NULL;
61 } /* end of vDestroyRowInfoList */
64 * vAdd2RowInfoList - Add an element to the Row Information List
66 void
67 vAdd2RowInfoList(const row_block_type *pRowBlock)
69 row_desc_type *pNew;
70 short *psTmp;
71 int iIndex;
73 fail(pRowBlock == NULL);
75 NO_DBG_HEX(pRowBlock->iOffset);
76 NO_DBG_DEC(pRowBlock->iLength);
77 NO_DBG_DEC(pRowBlock->ucNumberOfColumns);
78 NO_DBG_DEC(pRowBlock->iColumnWidthSum);
80 /* Create the new list member */
81 pNew = xmalloc(sizeof(row_desc_type));
82 pNew->pCommon = xmalloc(sizeof(row_common_type));
83 /* Fill the new list member */
84 pNew->tUnique.iOffsetStart = pRowBlock->iOffsetStart;
85 pNew->tUnique.iOffsetEnd = pRowBlock->iOffsetEnd;
86 pNew->pCommon->iColumnWidthSum = pRowBlock->iColumnWidthSum;
87 (void)memcpy(pNew->pCommon->asColumnWidth,
88 pRowBlock->asColumnWidth,
89 sizeof(pNew->pCommon->asColumnWidth));
90 pNew->pCommon->ucNumberOfColumns = pRowBlock->ucNumberOfColumns;
91 pNew->pNext = NULL;
92 /* Correct the values where needed */
93 for (iIndex = 0, psTmp = pNew->pCommon->asColumnWidth;
94 iIndex < (int)pNew->pCommon->ucNumberOfColumns;
95 iIndex++, psTmp++) {
96 if (*psTmp < 0) {
97 *psTmp = 0;
98 DBG_MSG("The column width was negative");
101 /* Add the new member to the list */
102 if (pAnchor == NULL) {
103 pAnchor = pNew;
104 pRowCurrent = pNew;
105 } else {
106 fail(pRowLast == NULL);
107 pRowLast->pNext = pNew;
109 pRowLast = pNew;
110 } /* end of vAdd2RowInfoList */
113 * Get the next item in the Row Information List
115 BOOL
116 bGetNextRowInfoListItem(row_block_type *pItem)
118 fail(pItem == NULL);
120 if (pItem == NULL || pRowCurrent == NULL) {
121 return FALSE;
123 /* Get the information */
124 pItem->iOffsetStart = pRowCurrent->tUnique.iOffsetStart;
125 pItem->iOffsetEnd = pRowCurrent->tUnique.iOffsetEnd;
126 pItem->iColumnWidthSum = pRowCurrent->pCommon->iColumnWidthSum;
127 (void)memcpy(pItem->asColumnWidth,
128 pRowCurrent->pCommon->asColumnWidth,
129 sizeof(pItem->asColumnWidth));
130 pItem->ucNumberOfColumns = pRowCurrent->pCommon->ucNumberOfColumns;
131 /* Stand by for the next item in the list */
132 pRowCurrent = pRowCurrent->pNext;
133 return TRUE;
134 } /* end of bGetNextRowInfoListItem */