00001 /* 00002 This product contains certain software code or other information 00003 ("AT&T Software") proprietary to AT&T Corp. ("AT&T"). The AT&T 00004 Software is provided to you "AS IS". YOU ASSUME TOTAL RESPONSIBILITY 00005 AND RISK FOR USE OF THE AT&T SOFTWARE. AT&T DOES NOT MAKE, AND 00006 EXPRESSLY DISCLAIMS, ANY EXPRESS OR IMPLIED WARRANTIES OF ANY KIND 00007 WHATSOEVER, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 00008 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WARRANTIES OF 00009 TITLE OR NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS, ANY 00010 WARRANTIES ARISING BY USAGE OF TRADE, COURSE OF DEALING OR COURSE OF 00011 PERFORMANCE, OR ANY WARRANTY THAT THE AT&T SOFTWARE IS "ERROR FREE" OR 00012 WILL MEET YOUR REQUIREMENTS. 00013 00014 Unless you accept a license to use the AT&T Software, you shall not 00015 reverse compile, disassemble or otherwise reverse engineer this 00016 product to ascertain the source code for any AT&T Software. 00017 00018 (c) AT&T Corp. All rights reserved. AT&T is a registered trademark of AT&T Corp. 00019 00020 *********************************************************************** 00021 00022 History: 00023 00024 24/11/99 - initial release by Hartmut Liefke, liefke@seas.upenn.edu 00025 Dan Suciu, suciu@research.att.com 00026 */ 00027 00028 //************************************************************************** 00029 //************************************************************************** 00030 00031 // This module contains the container manager for the decompressor 00032 00033 #include "UnCompCont.hpp" 00034 #include "VPathExprMan.hpp" 00035 #include "Types.hpp" 00036 #include "SmallUncompress.hpp" 00037 00038 extern VPathExprMan pathexprman; 00039 00040 UncompressContainerMan uncomprcont; 00041 00042 inline void UncompressContainer::AllocateContMem(unsigned long mincontsize) 00043 // Allocates the memory - but only if the size is larger than 'mincontsize' 00044 // This will allows us to allocate memory starting with the largest 00045 // containers. Then, smaller containers can be allocated. 00046 { 00047 if((dataptr!=NULL)||(size<mincontsize)) 00048 return; 00049 00050 curptr=dataptr=AllocateMemBlock(size); 00051 } 00052 00053 inline void UncompressContainerBlock::Load(SmallBlockUncompressor *uncompressor) 00054 // Loads the container block information (number+size of containers) 00055 // from the small decompressor object 00056 { 00057 // Let's load the index of the path expression 00058 unsigned long pathidx=uncompressor->LoadUInt32(); 00059 if(pathidx!=0) 00060 pathexpr=pathexprman.GetPathExpr(pathidx-1); 00061 else 00062 pathexpr=NULL; 00063 00064 // Let's load the number of containers 00065 contnum=uncompressor->LoadUInt32(); 00066 00067 if((pathexpr!=NULL)&&(pathexpr->GetUserContNum()!=contnum)) 00068 { 00069 Error("Corrupt compressed file !"); 00070 Exit(); 00071 } 00072 00073 // Let's allocate some memory for the container structures 00074 // and the necessary state space 00075 contarray=(UncompressContainer *)blockmem.GetByteBlock( 00076 sizeof(UncompressContainer)*contnum+ 00077 ((pathexpr!=NULL) ? pathexpr->GetUserDataSize() : 0)); 00078 00079 // let's load the size of each single container 00080 for(unsigned i=0;i<contnum;i++) 00081 contarray[i].SetSize(uncompressor->LoadUInt32()); 00082 }; 00083 00084 inline void UncompressContainerBlock::AllocateContMem(unsigned long mincontsize) 00085 // Allocates the memory for those containers with size>mincontsize 00086 { 00087 for(unsigned i=0;i<contnum;i++) 00088 contarray[i].AllocateContMem(mincontsize); 00089 }; 00090 00091 //**************************************************************************** 00092 //**************************************************************************** 00093 00094 void UncompressContainerMan::Load(SmallBlockUncompressor *uncompressor) 00095 // Loads the structural information from the small block decompressor 00096 { 00097 // The number of container blocks 00098 blocknum=uncompressor->LoadUInt32(); 00099 00100 // Let's allocate the container block array 00101 blockarray=(UncompressContainerBlock *)blockmem.GetByteBlock(sizeof(UncompressContainerBlock)*blocknum); 00102 00103 // Let's load the structural information for all container blocks 00104 for(unsigned i=0;i<blocknum;i++) 00105 blockarray[i].Load(uncompressor); 00106 } 00107 00108 00109 void UncompressContainerMan::AllocateContMem() 00110 // Allocates the memory for the container sequentially. 00111 // Loads the container block information (number+size+structure of container blocks) 00112 // from the small decompressor object 00113 // This function starts with large containers and then allocates 00114 // memory for smaller containers 00115 { 00116 unsigned i; 00117 00118 // We do the container allocation in 5 steps 00119 00120 for(i=0;i<blocknum;i++) 00121 blockarray[i].AllocateContMem(1000000L); 00122 00123 for(i=0;i<blocknum;i++) 00124 blockarray[i].AllocateContMem(200000L); 00125 00126 for(i=0;i<blocknum;i++) 00127 blockarray[i].AllocateContMem(40000L); 00128 00129 for(i=0;i<blocknum;i++) 00130 blockarray[i].AllocateContMem(8000L); 00131 00132 for(i=0;i<blocknum;i++) 00133 blockarray[i].AllocateContMem(0L); 00134 } 00135 00136 //**************************************************************************** 00137 //**************************************************************************** 00138 00139 void UncompressContainer::UncompressSmallContainer(SmallBlockUncompressor *uncompressor) 00140 // Decompresses the small container data and stores 00141 // it in the data buffer 00142 { 00143 unsigned char *srcptr=uncompressor->LoadData(size); 00144 memcpy(dataptr,srcptr,size); 00145 } 00146 00147 void UncompressContainer::UncompressLargeContainer(Input *input) 00148 // Decompresses the large container data and stores 00149 // it in the data buffer 00150 { 00151 Uncompressor uncompress; 00152 unsigned long uncompsize=size; 00153 00154 uncompress.Uncompress(input,dataptr,&uncompsize); 00155 if(uncompsize!=size) 00156 { 00157 Error("Corrupt file!"); 00158 Exit(); 00159 } 00160 } 00161 00162 //**************************************************************************** 00163 00164 void UncompressContainerBlock::UncompressSmallContainers(SmallBlockUncompressor *uncompressor) 00165 // Decompresses the data of small containers and stores 00166 // it in the data buffers 00167 { 00168 unsigned long i; 00169 00170 for(i=0;i<contnum;i++) 00171 { 00172 if(contarray[i].GetSize()<SMALLCONT_THRESHOLD) 00173 contarray[i].UncompressSmallContainer(uncompressor); 00174 } 00175 } 00176 00177 void UncompressContainerBlock::UncompressLargeContainers(Input *input) 00178 // Decompresses the data of large containers and stores 00179 // it in the data buffers 00180 { 00181 for(unsigned long i=0;i<contnum;i++) 00182 { 00183 if(contarray[i].GetSize()>=SMALLCONT_THRESHOLD) 00184 contarray[i].UncompressLargeContainer(input); 00185 } 00186 } 00187 00188 //**************************************************************************** 00189 //**************************************************************************** 00190 00191 void UncompressContainerMan::UncompressSmallContainers(SmallBlockUncompressor *uncompressor) 00192 // Decompresses the data of small containers and stores 00193 // it in the data buffers 00194 { 00195 for(unsigned long i=0;i<blocknum;i++) 00196 blockarray[i].UncompressSmallContainers(uncompressor); 00197 } 00198 00199 void UncompressContainerMan::UncompressLargeContainers(Input *input) 00200 // Decompresses the data of large containers and stores 00201 // it in the data buffers 00202 { 00203 for(unsigned long i=0;i<blocknum;i++) 00204 blockarray[i].UncompressLargeContainers(input); 00205 } 00206 00207 //**************************************************************************** 00208 00209 void UncompressContainerMan::Init() 00210 // Initializes the state data for the user compressors 00211 // of all container blocks 00212 { 00213 for(unsigned long i=0;i<blocknum;i++) 00214 blockarray[i].Init(); 00215 } 00216 00217 00218 //**************************************************************************** 00219 //**************************************************************************** 00220 00221 // All functions for release the memory of the containers 00222 00223 inline void UncompressContainer::ReleaseContMem() 00224 { 00225 FreeMemBlock(dataptr,size); 00226 } 00227 00228 inline void UncompressContainerBlock::ReleaseContMem() 00229 { 00230 for(unsigned long i=0;i<contnum;i++) 00231 contarray[i].ReleaseContMem(); 00232 } 00233 00234 void UncompressContainerMan::ReleaseContMem() 00235 { 00236 for(unsigned long i=0;i<blocknum;i++) 00237 blockarray[i].ReleaseContMem(); 00238 } 00239 00240 void UncompressContainerMan::FinishUncompress() 00241 { 00242 for(unsigned long i=0;i<blocknum;i++) 00243 blockarray[i].FinishUncompress(); 00244 }