3 * Copyright (C) 2001,2002 A.J. van Os; Released under 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 ulTextOffset
)
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
->ulTextOffset
= ulTextOffset
;
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 ulTextOffset
)
93 section_block_type tSection
;
95 vGetDefaultSection(&tSection
);
96 vAdd2SectionInfoList(&tSection
, ulTextOffset
);
97 } /* end of vDefault2SectionInfoList */
100 * pGetSectionInfo - get the section information
102 const section_block_type
*
103 pGetSectionInfo(const section_block_type
*pOld
, ULONG ulTextOffset
)
105 const section_mem_type
*pCurr
;
107 if (pOld
== NULL
|| ulTextOffset
== 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
;
117 for (pCurr
= pAnchor
; pCurr
!= NULL
; pCurr
= pCurr
->pNext
) {
118 if (ulTextOffset
== pCurr
->ulTextOffset
||
119 ulTextOffset
+ 1 == pCurr
->ulTextOffset
) {
120 NO_DBG_HEX(pCurr
->ulTextOffset
);
121 return &pCurr
->tInfo
;
125 } /* end of pGetSectionInfo */