00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "antiword.h"
00010
00011 #define SIZE_RATIO (BIG_BLOCK_SIZE/SMALL_BLOCK_SIZE)
00012
00013 static ULONG *aulSmallBlockList = NULL;
00014 static size_t tSmallBlockListLen = 0;
00015
00016
00017
00018
00019
00020 void
00021 vDestroySmallBlockList(void)
00022 {
00023 DBG_MSG("vDestroySmallBlockList");
00024
00025 aulSmallBlockList = xfree(aulSmallBlockList);
00026 tSmallBlockListLen = 0;
00027 }
00028
00029
00030
00031
00032
00033
00034 BOOL
00035 bCreateSmallBlockList(ULONG ulStartblock, const ULONG *aulBBD, size_t tBBDLen)
00036 {
00037 ULONG ulTmp;
00038 size_t tSize;
00039 int iIndex;
00040
00041 fail(aulSmallBlockList != NULL);
00042 fail(tSmallBlockListLen != 0);
00043 fail(ulStartblock > MAX_BLOCKNUMBER && ulStartblock != END_OF_CHAIN);
00044 fail(aulBBD == NULL);
00045 fail(tBBDLen == 0);
00046
00047
00048 for (tSmallBlockListLen = 0, ulTmp = ulStartblock;
00049 tSmallBlockListLen < tBBDLen && ulTmp != END_OF_CHAIN;
00050 tSmallBlockListLen++, ulTmp = aulBBD[ulTmp]) {
00051 if (ulTmp >= (ULONG)tBBDLen) {
00052 DBG_DEC(ulTmp);
00053 DBG_DEC(tBBDLen);
00054 werr(1, "The Big Block Depot is damaged");
00055 }
00056 }
00057 DBG_DEC(tSmallBlockListLen);
00058
00059 if (tSmallBlockListLen == 0) {
00060
00061 fail(ulStartblock != END_OF_CHAIN);
00062 aulSmallBlockList = NULL;
00063 return TRUE;
00064 }
00065
00066
00067 tSize = tSmallBlockListLen * sizeof(ULONG);
00068 aulSmallBlockList = xmalloc(tSize);
00069 for (iIndex = 0, ulTmp = ulStartblock;
00070 iIndex < (int)tBBDLen && ulTmp != END_OF_CHAIN;
00071 iIndex++, ulTmp = aulBBD[ulTmp]) {
00072 if (ulTmp >= (ULONG)tBBDLen) {
00073 DBG_DEC(ulTmp);
00074 DBG_DEC(tBBDLen);
00075 werr(1, "The Big Block Depot is damaged");
00076 }
00077 aulSmallBlockList[iIndex] = ulTmp;
00078 NO_DBG_DEC(aulSmallBlockList[iIndex]);
00079 }
00080 return TRUE;
00081 }
00082
00083
00084
00085
00086 ULONG
00087 ulDepotOffset(ULONG ulIndex, size_t tBlockSize)
00088 {
00089 ULONG ulTmp;
00090 size_t tTmp;
00091
00092 fail(ulIndex >= ULONG_MAX / BIG_BLOCK_SIZE);
00093
00094 switch (tBlockSize) {
00095 case BIG_BLOCK_SIZE:
00096 return (ulIndex + 1) * BIG_BLOCK_SIZE;
00097 case SMALL_BLOCK_SIZE:
00098 tTmp = (size_t)(ulIndex / SIZE_RATIO);
00099 ulTmp = ulIndex % SIZE_RATIO;
00100 if (aulSmallBlockList == NULL ||
00101 tTmp >= tSmallBlockListLen) {
00102 DBG_HEX(aulSmallBlockList);
00103 DBG_DEC(tSmallBlockListLen);
00104 DBG_DEC(tTmp);
00105 return 0;
00106 }
00107 return ((aulSmallBlockList[tTmp] + 1) * SIZE_RATIO +
00108 ulTmp) * SMALL_BLOCK_SIZE;
00109 default:
00110 DBG_DEC(tBlockSize);
00111 DBG_FIXME();
00112 return 0;
00113 }
00114 }