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