-
Notifications
You must be signed in to change notification settings - Fork 5
/
sectlist.c
165 lines (144 loc) · 3.7 KB
/
sectlist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* sectlist.c
* Copyright (C) 2001-2004 A.J. van Os; Released under GNU GPL
*
* Description:
* Build, read and destroy list(s) of Word section information
*/
#include <stddef.h>
#include <string.h>
#include "antiword.h"
/*
* Private structure to hide the way the information
* is stored from the rest of the program
*/
typedef struct section_mem_tag {
section_block_type tInfo;
ULONG ulCharPos;
struct section_mem_tag *pNext;
} section_mem_type;
/* Variables needed to write the Section Information List */
static section_mem_type *pAnchor = NULL;
static section_mem_type *pSectionLast = NULL;
/*
* vDestroySectionInfoList - destroy the Section Information List
*/
void
vDestroySectionInfoList(void)
{
section_mem_type *pCurr, *pNext;
DBG_MSG("vDestroySectionInfoList");
/* Free the Section Information List */
pCurr = pAnchor;
while (pCurr != NULL) {
pNext = pCurr->pNext;
pCurr = xfree(pCurr);
pCurr = pNext;
}
pAnchor = NULL;
/* Reset all control variables */
pSectionLast = NULL;
} /* end of vDestroySectionInfoList */
/*
* vAdd2SectionInfoList - Add an element to the Section Information List
*/
void
vAdd2SectionInfoList(const section_block_type *pSection, ULONG ulCharPos)
{
section_mem_type *pListMember;
fail(pSection == NULL);
/* Create list member */
pListMember = xmalloc(sizeof(section_mem_type));
/* Fill the list member */
pListMember->tInfo = *pSection;
pListMember->ulCharPos = ulCharPos;
pListMember->pNext = NULL;
/* Add the new member to the list */
if (pAnchor == NULL) {
pAnchor = pListMember;
} else {
fail(pSectionLast == NULL);
pSectionLast->pNext = pListMember;
}
pSectionLast = pListMember;
} /* vAdd2SectionInfoList */
/*
* vGetDefaultSection - fill the section struct with default values
*/
void
vGetDefaultSection(section_block_type *pSection)
{
(void)memset(pSection, 0, sizeof(*pSection));
pSection->bNewPage = TRUE;
} /* end of vGetDefaultSection */
/*
* vDefault2SectionInfoList - Add a default to the Section Information List
*/
void
vDefault2SectionInfoList(ULONG ulCharPos)
{
section_block_type tSection;
vGetDefaultSection(&tSection);
vAdd2SectionInfoList(&tSection, ulCharPos);
} /* end of vDefault2SectionInfoList */
/*
* pGetSectionInfo - get the section information
*/
const section_block_type *
pGetSectionInfo(const section_block_type *pOld, ULONG ulCharPos)
{
const section_mem_type *pCurr;
if (pOld == NULL || ulCharPos == 0) {
if (pAnchor == NULL) {
/* There are no records, make one */
vDefault2SectionInfoList(0);
fail(pAnchor == NULL);
}
/* The first record */
NO_DBG_MSG("First record");
return &pAnchor->tInfo;
}
NO_DBG_HEX(ulCharPos);
for (pCurr = pAnchor; pCurr != NULL; pCurr = pCurr->pNext) {
NO_DBG_HEX(pCurr->ulCharPos);
if (ulCharPos == pCurr->ulCharPos ||
ulCharPos + 1 == pCurr->ulCharPos) {
NO_DBG_HEX(pCurr->ulCharPos);
return &pCurr->tInfo;
}
}
return pOld;
} /* end of pGetSectionInfo */
/*
* tGetNumberOfSections - get the number of sections
*/
size_t
tGetNumberOfSections(void)
{
const section_mem_type *pCurr;
size_t tCounter;
for (tCounter = 0, pCurr = pAnchor;
pCurr != NULL;
tCounter++, pCurr = pCurr->pNext)
; /* Empty */
return tCounter;
} /* end of tGetNumberOfSections */
/*
* ucGetSepHdrFtrSpecification - get the Heder/footer specification
*/
UCHAR
ucGetSepHdrFtrSpecification(size_t tSectionNumber)
{
const section_mem_type *pCurr;
size_t tIndex;
for (tIndex = 0, pCurr = pAnchor;
tIndex < tSectionNumber && pCurr != NULL;
tIndex++, pCurr = pCurr->pNext)
; /* Empty */
if (pCurr == NULL) {
DBG_DEC(tSectionNumber);
DBG_FIXME();
return 0x00;
}
return pCurr->tInfo.ucHdrFtrSpecification;
} /* end of ucGetSepHdrFtrSpecification */