#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <fcntl.h>
#include <ctype.h>
#include "CompressMan.hpp"
#include "VPathExprMan.hpp"
#include "Input.hpp"
#include "CurPath.hpp"
Go to the source code of this file.
Defines | |
#define | MAGIC_KEY 0x5e3d29e |
Functions | |
MemStreamer | tmpmem (5) |
MemStreamer | mainmem (1000) |
MemStreamer | blockmem (1000) |
void | PrintUsage (char showmoreoptions) |
int | HandleAllOptions (char **argv, int argc) |
char | AskOverwriteFile (char *file) |
void | HandleSingleFile (char *file) |
void | HandleFileArg (char *filepattern) |
int | main (int argc, char **argv) |
Variables | |
CurPath | curpath |
LabelDict | globallabeldict |
VPathExprMan | pathexprman |
char | usestdout |
char | no_output |
char | globalfullwhitespacescompress |
char | verbose |
char | output_initialized |
char | delete_inputfiles |
unsigned long | memory_cutoff |
char | overwrite_files |
char | skip_all_files |
|
|
|
Definition at line 178 of file Main.cpp. 00183 { 00184 int c; 00185 00186 if((!FileExists(file))||(overwrite_files)) 00187 // If the file doesn't exist or we automatically overwrite it, 00188 // then we can simply return true 00189 return 1; 00190 00191 printf("Overwrite file %s ? (Y(es) | N(o) | A(ll) | Q(uit)) ",file); 00192 00193 // We wait until the user presses 'y', 'n', 'q', or 'a' 00194 do 00195 { 00196 #ifdef WIN32 00197 c=_getch(); 00198 printf("\n"); 00199 #else 00200 c=getchar(); 00201 #endif 00202 switch(toupper(c)) 00203 { 00204 case 'Y': return 1; 00205 case 'N': return 0; 00206 case 'Q': skip_all_files=1;return 0; 00207 case 'A': overwrite_files=1;return 1; 00208 } 00209 } 00210 while(1); 00211 } |
|
Definition at line 452 of file Options.cpp. 00456 { 00457 char *option; 00458 int len; 00459 00460 InitArguments(argv,argc); 00461 00462 while((option=GetNextArgument(&len))!=NULL) 00463 { 00464 if(*option!='-') 00465 break; 00466 00467 SkipArgumentString(1); 00468 option++; 00469 00470 InterpretOptionString(option); 00471 } 00472 00473 return curargidx; 00474 } |
|
Definition at line 307 of file Main.cpp. 00312 { 00313 char fullpath[400]; 00314 #ifdef WIN32 00315 _finddata_t finddata; 00316 long handle; 00317 char *ptr; 00318 int fullpathlen; 00319 00320 // Let's check if we have any meta characters '*' or '?' ? 00321 // We don't have them, we go directly to 'HandleSingleFile' 00322 00323 ptr=filepattern; 00324 while(*ptr!=0) 00325 { 00326 if((*ptr=='*')||(*ptr=='?')) 00327 break; 00328 ptr++; 00329 } 00330 00331 if(*ptr==0) // We didn't find any metacharacter? 00332 // The file name gets directly forwarded to HandleSingleFile 00333 { 00334 strcpy(fullpath,filepattern); 00335 HandleSingleFile(fullpath); 00336 return; 00337 } 00338 // Otherwise, we apply functions '_findfirst' and '_findnext' 00339 00340 // We scan from the back of the file name and look 00341 // for a separator 00342 ptr=filepattern+strlen(filepattern)-1; 00343 00344 while(ptr>=filepattern) 00345 { 00346 if((*ptr=='\\')||(*ptr=='/')) 00347 break; 00348 ptr--; 00349 } 00350 00351 if(ptr<filepattern) // We didn't find a separator ? 00352 { 00353 // The file path is empty 00354 *fullpath=0; 00355 fullpathlen=0; 00356 } 00357 else 00358 { 00359 // We the path part from the file pattern including 00360 // the separator that we found 00361 memcpy(fullpath,filepattern,ptr-filepattern+1); 00362 fullpath[ptr-filepattern+1]=0; 00363 fullpathlen=ptr-filepattern+1; 00364 } 00365 00366 // Let's now look for the file 00367 handle=_findfirst(filepattern,&finddata); 00368 if(handle==-1) 00369 { 00370 printf("Could not find %s!\n",filepattern); 00371 return; 00372 } 00373 00374 do 00375 { 00376 // We concatenate the file name to the path 00377 strcpy(fullpath+fullpathlen,finddata.name); 00378 00379 HandleSingleFile(fullpath); 00380 if(skip_all_files) 00381 break; 00382 00383 if(_findnext(handle,&finddata)!=0) 00384 break; 00385 } 00386 while(1); 00387 00388 _findclose(handle); 00389 #else 00390 00391 // In UNIX, the file name expansion is done by the shell 00392 // ==> We only need to look at the specific file 00393 strcpy(fullpath,filepattern); 00394 HandleSingleFile(fullpath); 00395 #endif 00396 } |
|
Definition at line 213 of file Main.cpp. 00217 { 00218 int len=strlen(file); 00219 char *outfilename=file+len+5; 00220 // We use the space after the input file 00221 // and leave a little bit of space for possible extension '.xmi' or '.xm' 00222 00223 strcpy(outfilename,file); 00224 00225 try{ 00226 00227 #ifdef XMILL 00228 // For the compressor, we replace ending '.xml' with '.xmi' 00229 // Or, if there is no ending '.xml', we replace by '.xm' 00230 00231 if((len>=4)&&(strcmp(file+len-4,".xml")==0)) 00232 strcpy(outfilename+len-4,".xmi"); 00233 else 00234 strcat(outfilename,".xm"); 00235 00236 Compress(file,usestdout ? NULL : outfilename); 00237 00238 #ifdef PROFILE 00239 if(verbose) 00240 globallabeldict.PrintProfile(); 00241 #endif 00242 00243 #endif 00244 00245 #ifdef XDEMILL 00246 // For decompression, we omit ending '.xm' or replace 00247 // ending '.xmi' with '.xml' 00248 if((len>=3)&&(strcmp(file+len-3,".xm")==0)) 00249 // Do we have ending '.xm' ? 00250 { 00251 outfilename[len-3]=0; // We eliminate the ending in the out file name 00252 Uncompress(file,usestdout ? NULL : outfilename); 00253 } 00254 else 00255 { 00256 // We replace '.xmi' by '.xml' 00257 if((len>=4)&&(strcmp(file+len-4,".xmi")==0)) 00258 { 00259 strcpy(outfilename+len-4,".xml"); 00260 Uncompress(file,usestdout ? NULL : outfilename); 00261 } 00262 else 00263 { 00264 // Otherwise, we assume the user specified the *uncompressed* 00265 // file and we try to either replace '.xml' by '.xmi' 00266 // or append '.xm'. 00267 00268 if((len>=4)&&(strcmp(file+len-4,".xml")==0)) 00269 { 00270 strcpy(file+len-4,".xmi"); 00271 if(FileExists(file)) 00272 { 00273 Uncompress(file,usestdout ? NULL : outfilename); 00274 return; 00275 } 00276 strcpy(file+len-4,".xml"); 00277 } 00278 00279 // Let's try to append '.xm' 00280 strcpy(file+len,".xm"); 00281 00282 if(FileExists(file)==0) 00283 { 00284 strcpy(file+len,""); 00285 Error("Could not find file '"); 00286 ErrorCont(file); 00287 ErrorCont("' with extension '.xm'!"); 00288 PrintErrorMsg(); 00289 return; 00290 } 00291 Uncompress(file,usestdout ? NULL : outfilename); 00292 return; 00293 } 00294 } 00295 #endif 00296 } 00297 catch(XMillException *) 00298 // An error occurred 00299 { 00300 Error("Error in file '"); 00301 ErrorCont(file); 00302 ErrorCont("':"); 00303 PrintErrorMsg(); 00304 } 00305 } |
|
Definition at line 479 of file Options.cpp. 00480 { 00481 printf("XMill 0.7 (30 Nov 99) - a compressor for XML\n"); 00482 printf("Copyright (C) 1999 AT&T Labs Research\n"); 00483 00484 #ifdef XMILL 00485 00486 if(showmoreoptions==0) 00487 printf("\nUsage:\n\n xmill [-i file] [-v] [-p path] [-m num] [-1..9] [-c] [-d] [-r] [-w] [-h] file ...\n\n"); 00488 else 00489 { 00490 printf("\nUsage:\n\n xmill [-i file] [-v] [-p path] [-m num] [-1..9] [-c] [-d] [-r] [-w] [-h]\n"); 00491 printf(" [-w(i|g|t)] [-l(i|g|t)] [-r(i|g|t)] [-a(i|g)] [-n(c|t|p|d)] file ...\n\n"); 00492 } 00493 00494 printf(" -i file - include options from file\n"); 00495 printf(" -v - verbose mode\n"); 00496 printf(" -p path - define path expression\n"); 00497 printf(" -m num - set memory limit\n"); 00498 printf(" -1..9 - set the compression factor of zlib (default=6)\n"); 00499 // printf(" -t - test mode (no output)\n"); 00500 printf(" -c - write on standard output\n"); 00501 // printf(" -k - keep original files unchanged (default)\n"); 00502 printf(" -d - delete input files\n"); 00503 printf(" -f - force overwrite of output files\n"); 00504 printf(" -w - preserve white spaces\n"); 00505 printf(" -h - show extended white space options and user compressors\n"); 00506 00507 if(showmoreoptions) 00508 { 00509 printf("\n Extended options:\n\n"); 00510 printf(" -wi - ignore complete white spaces (default)\n"); 00511 printf(" -wg - store complete white spaces in global container\n"); 00512 printf(" -wt - store complete white spaces as normal text\n"); 00513 printf(" -li - ignore left white spaces (default)\n"); 00514 printf(" -lg - store left white spaces in global container\n"); 00515 printf(" -lt - store left white spaces as normal text\n"); 00516 printf(" -ri - ignore right white spaces (default)\n"); 00517 printf(" -rg - store right white spaces in global container\n"); 00518 printf(" -rt - store right white spaces as normal text\n"); 00519 printf(" -ai - ignore attribute white spaces (default)\n"); 00520 printf(" -ag - store attribute white spaces in global container\n"); 00521 printf("\n"); 00522 printf(" -nc - ignore comments\n"); 00523 printf(" -nt - ignore DOCTYPE sections\n"); 00524 printf(" -np - ignore PI sections\n"); 00525 printf(" -nd - ignore CDATA sections\n"); 00526 printf("\n"); 00527 printf("\n User compressors:\n\n"); 00528 compressman.PrintCompressorInfo(); 00529 } 00530 #endif 00531 00532 #ifdef XDEMILL 00533 printf("Usage:\n\n\t xdemill [-i file] [-v] [-c] [-d] [-r] [-os num] [-ot] [-oz] [-od] [-ou] file ...\n\n"); 00534 printf(" -i file - include options from file\n"); 00535 printf(" -v - verbose mode\n"); 00536 printf(" -c - write on standard output\n"); 00537 // printf(" -k - keep original files unchanged\n"); 00538 printf(" -d - delete input files\n"); 00539 printf(" -f - force overwrite of output files\n"); 00540 // printf(" -t - test mode (no output)\n"); 00541 printf(" -os num - output formatted XML with space intentation\n"); 00542 printf(" -ot - output formatted XML with tabular intentation\n"); 00543 printf(" -oz - output unformatted XML (without white spaces)\n"); 00544 #ifdef WIN32 00545 printf(" -od - uses DOS newline convention (default)\n"); 00546 printf(" -ou - uses UNIX newline convention\n"); 00547 #else 00548 printf(" -od - uses DOS newline convention\n"); 00549 printf(" -ou - uses UNIX newline convention (default)\n"); 00550 #endif 00551 // printf(" -ow num - wrap XML output after specified number of characters\n"); 00552 #endif 00553 } |
|
|
|
Definition at line 407 of file Main.cpp. 00410 { 00411 int fileidx; 00412 00413 // We set the default file mode to 'binary' 00414 #ifdef WIN32 00415 _fmode=_O_BINARY; 00416 #endif 00417 00418 00419 //////////////////////////////////////////////// 00420 // Jason Kim added for Binary format as input 00421 //////////////////////////////////////////////// 00422 InitGlobalTokenTable(); 00423 //////////////////////////////////////////////// 00424 // Jason Kim added for Binary format as input 00425 //////////////////////////////////////////////// 00426 00427 00428 if(argc==1) // No arguments for the program? 00429 { 00430 PrintUsage(0); 00431 return 0; 00432 } 00433 00434 #ifdef XMILL 00435 else 00436 { 00437 if((argc==2)&&(strcmp(argv[1],"-h")==0)) 00438 // Is there is exactly on argument '-h' ? 00439 { 00440 PrintUsage(1); 00441 return 0; 00442 } 00443 } 00444 #endif 00445 00446 // Now we start the heavy work! 00447 00448 try{ 00449 00450 globallabeldict.Init(); // Initialized the label dictionary 00451 00452 #ifdef XMILL 00453 // Initializes the FSM structures. 00454 // It creates two labels '#' and '@#' 00455 FSMInit(); 00456 00457 #ifdef USE_FORWARD_DATAGUIDE 00458 extern void InitForwardDataGuide(); 00459 00460 InitForwardDataGuide(); 00461 #endif 00462 00463 #endif 00464 00465 // Parse options 00466 fileidx=HandleAllOptions(argv+1,argc-1)+1; 00467 00468 #ifdef XMILL 00469 // In the compressor, we append two default paths: '//#' and '/' 00470 // to take care of all paths 00471 char *pathptr="//#"; 00472 pathexprman.AddNewVPathExpr(pathptr,pathptr+strlen(pathptr)); 00473 pathptr="/"; 00474 pathexprman.AddNewVPathExpr(pathptr,pathptr+strlen(pathptr)); 00475 00476 globallabeldict.FinishedPredefinedLabels(); 00477 // We remember which labels are predefined (i.e. labels defined through FSMs) 00478 // All labels that are inserted later will be eliminated 00479 // between two parses of two input files. 00480 00481 pathexprman.InitWhitespaceHandling(); 00482 // If the default white space handling for the path expression 00483 // is the global setting, then we replace that reference 00484 // by the global default value. 00485 // This is done after all options are parsed, 00486 // since the global white space options could come *after* 00487 // the path expressions have been inserted. 00488 #endif 00489 00490 00491 00492 // Are there no arguments except options? 00493 if(fileidx>=argc) 00494 { 00495 if(usestdout) // Did the user specify '-c' for using 'stdout'? 00496 { 00497 00498 #ifdef XMILL 00499 Compress(NULL,NULL); 00500 #endif 00501 00502 #ifdef XDEMILL 00503 Uncompress(NULL,NULL); 00504 #endif 00505 00506 return 0; 00507 } 00508 else 00509 { 00510 Error("No input file specified! Specify '-c' to use stdin/stdout"); 00511 Exit(); 00512 } 00513 } 00514 00515 } 00516 catch(XMillException *) 00517 // An error occurred 00518 { 00519 return -1; 00520 } 00521 00522 // Let's look at all files 00523 do 00524 { 00525 HandleFileArg(argv[fileidx]); 00526 if(skip_all_files) 00527 break; 00528 fileidx++; 00529 } 00530 while(fileidx<argc); 00531 00532 00533 //////////////////////////////////////////////// 00534 // Jason Kim added for Binary format as input 00535 //////////////////////////////////////////////// 00536 CleanupGlobalTokenTable(); 00537 //////////////////////////////////////////////// 00538 // Jason Kim added for Binary format as input 00539 //////////////////////////////////////////////// 00540 00541 00542 return 0; 00543 } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|