00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <stddef.h>
00010 #include <string.h>
00011 #include "antiword.h"
00012
00013
00014
00015
00016
00017
00018 typedef struct section_mem_tag {
00019 section_block_type tInfo;
00020 ULONG ulCharPos;
00021 struct section_mem_tag *pNext;
00022 } section_mem_type;
00023
00024
00025 static section_mem_type *pAnchor = NULL;
00026 static section_mem_type *pSectionLast = NULL;
00027
00028
00029
00030
00031
00032 void
00033 vDestroySectionInfoList(void)
00034 {
00035 section_mem_type *pCurr, *pNext;
00036
00037 DBG_MSG("vDestroySectionInfoList");
00038
00039
00040 pCurr = pAnchor;
00041 while (pCurr != NULL) {
00042 pNext = pCurr->pNext;
00043 pCurr = xfree(pCurr);
00044 pCurr = pNext;
00045 }
00046 pAnchor = NULL;
00047
00048 pSectionLast = NULL;
00049 }
00050
00051
00052
00053
00054 void
00055 vAdd2SectionInfoList(const section_block_type *pSection, ULONG ulCharPos)
00056 {
00057 section_mem_type *pListMember;
00058
00059 fail(pSection == NULL);
00060
00061
00062 pListMember = xmalloc(sizeof(section_mem_type));
00063
00064 pListMember->tInfo = *pSection;
00065 pListMember->ulCharPos = ulCharPos;
00066 pListMember->pNext = NULL;
00067
00068 if (pAnchor == NULL) {
00069 pAnchor = pListMember;
00070 } else {
00071 fail(pSectionLast == NULL);
00072 pSectionLast->pNext = pListMember;
00073 }
00074 pSectionLast = pListMember;
00075 }
00076
00077
00078
00079
00080 void
00081 vGetDefaultSection(section_block_type *pSection)
00082 {
00083 (void)memset(pSection, 0, sizeof(*pSection));
00084 pSection->bNewPage = TRUE;
00085 }
00086
00087
00088
00089
00090 void
00091 vDefault2SectionInfoList(ULONG ulCharPos)
00092 {
00093 section_block_type tSection;
00094
00095 vGetDefaultSection(&tSection);
00096 vAdd2SectionInfoList(&tSection, ulCharPos);
00097 }
00098
00099
00100
00101
00102 const section_block_type *
00103 pGetSectionInfo(const section_block_type *pOld, ULONG ulCharPos)
00104 {
00105 const section_mem_type *pCurr;
00106
00107 if (pOld == NULL || ulCharPos == 0) {
00108 if (pAnchor == NULL) {
00109
00110 vDefault2SectionInfoList(0);
00111 fail(pAnchor == NULL);
00112 }
00113
00114 NO_DBG_MSG("First record");
00115 return &pAnchor->tInfo;
00116 }
00117
00118 NO_DBG_HEX(ulCharPos);
00119 for (pCurr = pAnchor; pCurr != NULL; pCurr = pCurr->pNext) {
00120 NO_DBG_HEX(pCurr->ulCharPos);
00121 if (ulCharPos == pCurr->ulCharPos ||
00122 ulCharPos + 1 == pCurr->ulCharPos) {
00123 NO_DBG_HEX(pCurr->ulCharPos);
00124 return &pCurr->tInfo;
00125 }
00126 }
00127 return pOld;
00128 }
00129
00130
00131
00132
00133 size_t
00134 tGetNumberOfSections(void)
00135 {
00136 const section_mem_type *pCurr;
00137 size_t tCounter;
00138
00139 for (tCounter = 0, pCurr = pAnchor;
00140 pCurr != NULL;
00141 tCounter++, pCurr = pCurr->pNext)
00142 ;
00143 return tCounter;
00144 }
00145
00146
00147
00148
00149 UCHAR
00150 ucGetSepHdrFtrSpecification(size_t tSectionNumber)
00151 {
00152 const section_mem_type *pCurr;
00153 size_t tIndex;
00154
00155 for (tIndex = 0, pCurr = pAnchor;
00156 tIndex < tSectionNumber && pCurr != NULL;
00157 tIndex++, pCurr = pCurr->pNext)
00158 ;
00159 if (pCurr == NULL) {
00160 DBG_DEC(tSectionNumber);
00161 DBG_FIXME();
00162 return 0x00;
00163 }
00164 return pCurr->tInfo.ucHdrFtrSpecification;
00165 }