3 * Copyright (C) 2001-2004 A.J. van Os; Released under GNU GPL
6 * Build, read and destroy list(s) of Word section information
15 * Private structure to hide the way the information
16 * is stored from the rest of the program
18 typedef struct section_mem_tag
{
19 section_block_type tInfo
;
21 struct section_mem_tag
*pNext
;
24 /* Variables needed to write the Section Information List */
25 static section_mem_type
*pAnchor
= NULL
;
26 static section_mem_type
*pSectionLast
= NULL
;
30 * vDestroySectionInfoList - destroy the Section Information List
33 vDestroySectionInfoList(void)
35 section_mem_type
*pCurr
, *pNext
;
37 DBG_MSG("vDestroySectionInfoList");
39 /* Free the Section Information List */
41 while (pCurr
!= NULL
) {
47 /* Reset all control variables */
49 } /* end of vDestroySectionInfoList */
52 * vAdd2SectionInfoList - Add an element to the Section Information List
55 vAdd2SectionInfoList(const section_block_type
*pSection
, ULONG ulCharPos
)
57 section_mem_type
*pListMember
;
59 fail(pSection
== NULL
);
61 /* Create list member */
62 pListMember
= xmalloc(sizeof(section_mem_type
));
63 /* Fill the list member */
64 pListMember
->tInfo
= *pSection
;
65 pListMember
->ulCharPos
= ulCharPos
;
66 pListMember
->pNext
= NULL
;
67 /* Add the new member to the list */
68 if (pAnchor
== NULL
) {
69 pAnchor
= pListMember
;
71 fail(pSectionLast
== NULL
);
72 pSectionLast
->pNext
= pListMember
;
74 pSectionLast
= pListMember
;
75 } /* vAdd2SectionInfoList */
78 * vGetDefaultSection - fill the section struct with default values
81 vGetDefaultSection(section_block_type
*pSection
)
83 (void)memset(pSection
, 0, sizeof(*pSection
));
84 pSection
->bNewPage
= TRUE
;
85 } /* end of vGetDefaultSection */
88 * vDefault2SectionInfoList - Add a default to the Section Information List
91 vDefault2SectionInfoList(ULONG ulCharPos
)
93 section_block_type tSection
;
95 vGetDefaultSection(&tSection
);
96 vAdd2SectionInfoList(&tSection
, ulCharPos
);
97 } /* end of vDefault2SectionInfoList */
100 * pGetSectionInfo - get the section information
102 const section_block_type
*
103 pGetSectionInfo(const section_block_type
*pOld
, ULONG ulCharPos
)
105 const section_mem_type
*pCurr
;
107 if (pOld
== NULL
|| ulCharPos
== 0) {
108 if (pAnchor
== NULL
) {
109 /* There are no records, make one */
110 vDefault2SectionInfoList(0);
111 fail(pAnchor
== NULL
);
113 /* The first record */
114 NO_DBG_MSG("First record");
115 return &pAnchor
->tInfo
;
118 NO_DBG_HEX(ulCharPos
);
119 for (pCurr
= pAnchor
; pCurr
!= NULL
; pCurr
= pCurr
->pNext
) {
120 NO_DBG_HEX(pCurr
->ulCharPos
);
121 if (ulCharPos
== pCurr
->ulCharPos
||
122 ulCharPos
+ 1 == pCurr
->ulCharPos
) {
123 NO_DBG_HEX(pCurr
->ulCharPos
);
124 return &pCurr
->tInfo
;
128 } /* end of pGetSectionInfo */
131 * tGetNumberOfSections - get the number of sections
134 tGetNumberOfSections(void)
136 const section_mem_type
*pCurr
;
139 for (tCounter
= 0, pCurr
= pAnchor
;
141 tCounter
++, pCurr
= pCurr
->pNext
)
144 } /* end of tGetNumberOfSections */
147 * ucGetSepHdrFtrSpecification - get the Heder/footer specification
150 ucGetSepHdrFtrSpecification(size_t tSectionNumber
)
152 const section_mem_type
*pCurr
;
155 for (tIndex
= 0, pCurr
= pAnchor
;
156 tIndex
< tSectionNumber
&& pCurr
!= NULL
;
157 tIndex
++, pCurr
= pCurr
->pNext
)
160 DBG_DEC(tSectionNumber
);
164 return pCurr
->tInfo
.ucHdrFtrSpecification
;
165 } /* end of ucGetSepHdrFtrSpecification */