00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "CompressMan.hpp"
00036
00037
00038
00039 CompressMan compressman;
00040
00041
00042
00043
00044 inline void CompressMan::AddCompressFactory(UserCompressorFactory *compressor)
00045
00046 {
00047
00048
00049
00050
00051
00052 if(lastref==NULL)
00053 lastref=&compressorlist;
00054
00055 *lastref=compressor;
00056 lastref=&(compressor->next);
00057 *lastref=NULL;
00058 }
00059
00060 UserCompressorFactory::UserCompressorFactory()
00061
00062 {
00063 compressman.AddCompressFactory(this);
00064 }
00065
00066
00067
00068
00069 char *FindEndOfParamString(char *str,char *endptr)
00070
00071
00072
00073 {
00074 int parenthesiscount=0;
00075 char *startptr=str;
00076 char *saveptr;
00077
00078 while(str<endptr)
00079 {
00080 switch(*str)
00081 {
00082 case '"':
00083 saveptr=str;
00084 str++;
00085 while(str<endptr)
00086 {
00087 if(*str=='\\')
00088 {
00089 str++;
00090 continue;
00091 }
00092 if(*str=='"')
00093 break;
00094 str++;
00095 }
00096 if(str==endptr)
00097 {
00098 Error("Could not find closing '\"' in string '");
00099 ErrorCont(saveptr,endptr-saveptr);
00100 ErrorCont("'");
00101 Exit();
00102 }
00103 break;
00104
00105 case '(':
00106 parenthesiscount++;
00107 break;
00108
00109 case ')':
00110 if(parenthesiscount==0)
00111 return str;
00112 parenthesiscount--;
00113 break;
00114 }
00115 str++;
00116 }
00117 Error("Could not find closing parenthesis for parameter '");
00118 ErrorCont(startptr,endptr-startptr);
00119 ErrorCont("'");
00120 Exit();
00121 return NULL;
00122 }
00123
00124
00125
00126 extern UserCompressorFactory *constantcompressfactoryptr;
00127
00128
00129
00130 #ifdef XMILL
00131
00132 UserCompressor *CompressMan::CreateCompressorInstance(char * &compressorname,char *endptr)
00133
00134
00135
00136
00137
00138 {
00139 char *ptr1=compressorname,
00140 *ptr2;
00141
00142 if(*compressorname=='"')
00143
00144 {
00145 ptr2=ParseString(ptr1,endptr);
00146
00147 compressorname=ptr2+1;
00148
00149 return constantcompressfactoryptr->InstantiateCompressor(ptr1,ptr2-ptr1+1);
00150 }
00151
00152
00153 while(ptr1<endptr)
00154 {
00155 if((*ptr1=='(')||(*ptr1==')')||(*ptr1==',')||
00156 (*ptr1==' ')||(*ptr1=='\n')||(*ptr1=='\r')||(*ptr1=='\t'))
00157 break;
00158 ptr1++;
00159 }
00160
00161 UserCompressorFactory *compressor=FindCompressorFactory(compressorname,ptr1-compressorname);
00162
00163 if(compressor==NULL)
00164 {
00165 Error("Compressor '");
00166 ErrorCont(compressorname,ptr1-compressorname);
00167 ErrorCont("' is not defined");
00168 Exit();
00169 }
00170
00171
00172 if(*ptr1=='(')
00173 {
00174
00175 ptr2=FindEndOfParamString(ptr1+1,endptr);
00176
00177 compressorname=ptr2+1;
00178
00179 return compressor->InstantiateCompressor(ptr1+1,ptr2-1-ptr1);
00180 }
00181 else
00182 {
00183 compressorname=ptr1;
00184 return compressor->InstantiateCompressor(NULL,0);
00185 }
00186 }
00187 #endif
00188
00189
00190
00191 #ifdef XDEMILL
00192 UserUncompressor *CompressMan::CreateUncompressorInstance(char * &compressorname,char *endptr)
00193
00194
00195
00196
00197
00198 {
00199 char *ptr1=compressorname,
00200 *ptr2;
00201
00202 if(*compressorname=='"')
00203
00204 {
00205
00206 ptr2=ParseString(ptr1,endptr);
00207
00208 compressorname=ptr2+1;
00209
00210 return constantcompressfactoryptr->InstantiateUncompressor(ptr1,ptr2-ptr1+1);
00211 }
00212
00213
00214 while(ptr1<endptr)
00215 {
00216 if((*ptr1=='(')||(*ptr1==')')||(*ptr1==',')||
00217 (*ptr1==' ')||(*ptr1=='\n')||(*ptr1=='\r')||(*ptr1=='\t'))
00218 break;
00219 ptr1++;
00220 }
00221
00222
00223 UserCompressorFactory *compressor=FindCompressorFactory(compressorname,ptr1-compressorname);
00224
00225 if(compressor==NULL)
00226 {
00227 Error("Compressor '");
00228 ErrorCont(compressorname,ptr1-compressorname);
00229 ErrorCont("' is not defined");
00230 Exit();
00231 }
00232
00233
00234 if(*ptr1=='(')
00235 {
00236 ptr2=FindEndOfParamString(ptr1+1,endptr);
00237
00238 compressorname=ptr2+1;
00239
00240 return compressor->InstantiateUncompressor(ptr1+1,ptr2-1-ptr1);
00241 }
00242 else
00243 {
00244 compressorname=ptr1;
00245 return compressor->InstantiateUncompressor(NULL,0);
00246 }
00247 }
00248 #endif
00249
00250 UserCompressorFactory *CompressMan::FindCompressorFactory(char *name,int len)
00251
00252
00253 {
00254 UserCompressorFactory *compressor=compressorlist;
00255 int namelen;
00256
00257 while(compressor!=NULL)
00258 {
00259 namelen=strlen(compressor->GetName());
00260 if((namelen==len)&&
00261 (memcmp(compressor->GetName(),name,len)==0))
00262 return compressor;
00263 compressor=compressor->next;
00264 }
00265 Error("Could not find compressor '");
00266 ErrorCont(name,len);
00267 ErrorCont("'!");
00268 Exit();
00269 return NULL;
00270 }
00271
00272
00273
00274 #ifdef XMILL
00275
00276 void CompressMan::PrintCompressorInfo()
00277
00278 {
00279 UserCompressorFactory *compressor=compressorlist;
00280 int maxnamelen=0,namelen;
00281
00282
00283 while(compressor!=NULL)
00284 {
00285 namelen=strlen(compressor->GetName());
00286 if(maxnamelen<namelen)
00287 maxnamelen=namelen;
00288
00289 compressor=compressor->next;
00290 }
00291
00292
00293
00294 compressor=compressorlist;
00295
00296 while(compressor!=NULL)
00297 {
00298 printf(" ");
00299 printf(compressor->GetName());
00300 namelen=strlen(compressor->GetName());
00301
00302 while(namelen<maxnamelen)
00303 {
00304 printf(" ");
00305 namelen++;
00306 }
00307 printf(" - ");
00308 printf(compressor->GetDescription());
00309 printf("\n");
00310
00311 compressor=compressor->next;
00312 }
00313 }
00314
00315
00316
00317
00318 unsigned long CompressMan::GetDataSize()
00319
00320
00321 {
00322 UserCompressorFactory *compressor=compressorlist;
00323 unsigned long size=0;
00324
00325 while(compressor!=NULL)
00326 {
00327 size+=compressor->GetGlobalDataSize();
00328 compressor=compressor->next;
00329 }
00330 return size;
00331 }
00332
00333 void CompressMan::CompressSmallGlobalData(Compressor *compress)
00334
00335
00336 {
00337 UserCompressorFactory *compressor=compressorlist;
00338
00339 while(compressor!=NULL)
00340 {
00341 compressor->CompressSmallGlobalData(compress);
00342 compressor=compressor->next;
00343 }
00344 }
00345
00346 void CompressMan::CompressLargeGlobalData(Output *output)
00347
00348
00349 {
00350 UserCompressorFactory *compressor=compressorlist;
00351
00352 while(compressor!=NULL)
00353 {
00354 compressor->CompressLargeGlobalData(output);
00355 compressor=compressor->next;
00356 }
00357 }
00358
00359 #endif
00360
00361
00362
00363 #ifdef XDEMILL
00364
00365 void CompressMan::UncompressSmallGlobalData(SmallBlockUncompressor *uncompressor)
00366
00367
00368 {
00369 UserCompressorFactory *compressor=compressorlist;
00370
00371
00372
00373 while(compressor!=NULL)
00374 {
00375 compressor->UncompressSmallGlobalData(uncompressor);
00376 compressor=compressor->next;
00377 }
00378 }
00379
00380 void CompressMan::UncompressLargeGlobalData(Input *input)
00381
00382
00383 {
00384 UserCompressorFactory *compressor=compressorlist;
00385
00386
00387
00388
00389 while(compressor!=NULL)
00390 {
00391 compressor->UncompressLargeGlobalData(input);
00392 compressor=compressor->next;
00393 }
00394 }
00395
00396 void CompressMan::FinishUncompress()
00397
00398 {
00399 UserCompressorFactory *compressor=compressorlist;
00400
00401
00402
00403 while(compressor!=NULL)
00404 {
00405 compressor->FinishUncompress();
00406 compressor=compressor->next;
00407 }
00408 }
00409
00410 void CompressMan::DebugPrint()
00411 {
00412 UserCompressorFactory *compressor=compressorlist;
00413 while(compressor!=NULL)
00414 {
00415 printf("%lu =>",compressor);
00416 printf("%s\n",compressor->GetName());
00417 compressor=compressor->next;
00418 }
00419 }
00420
00421 #endif