|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * depot.c 00003 * Copyright (C) 1998-2002 A.J. van Os; Released under GPL 00004 * 00005 * Description: 00006 * Functions to compute the depot offset 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 * vDestroySmallBlockList - destroy the small block list 00019 */ 00020 void 00021 vDestroySmallBlockList(void) 00022 { 00023 DBG_MSG("vDestroySmallBlockList"); 00024 00025 aulSmallBlockList = xfree(aulSmallBlockList); 00026 tSmallBlockListLen = 0; 00027 } /* end of vDestroySmalBlockList */ 00028 00029 /* 00030 * vCreateSmallBlockList - create the small block list 00031 * 00032 * returns: TRUE when successful, otherwise FALSE 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 /* Find the length of the small block list */ 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 /* There is no small block list */ 00061 fail(ulStartblock != END_OF_CHAIN); 00062 aulSmallBlockList = NULL; 00063 return TRUE; 00064 } 00065 00066 /* Create the small block list */ 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 } /* end of bCreateSmallBlockList */ 00082 00083 /* 00084 * ulDepotOffset - get the depot offset the block list 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 } /* end of ulDepotOffset */
|
© Nokia 2009 |