Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Options.cpp File Reference

#include <stdio.h>
#include <stdlib.h>
#include "Types.hpp"
#include "Input.hpp"
#include "VPathExprMan.hpp"

Go to the source code of this file.

Functions

void InitArguments (char **argv, int argc)
char * GetNextArgument (int *len)
void SkipArgumentString (int len)
void ParseOptionFile (char *filename)
void InterpretOptionString (char *option)
int HandleAllOptions (char **argv, int argc)
void PrintUsage (char showmoreoptions)

Variables

char usedosnewline = 0
char globalfullwhitespacescompress = WHITESPACE_IGNORE
VPathExprMan pathexprman
unsigned long memory_cutoff = 8L*1024L*1024L
char delete_inputfiles = 0
char overwrite_files = 0
char skip_all_files = 0
char no_output = 0
char usestdout = 0
char verbose = 0
char output_initialized = 0
char ** argstrings
int argnum
int curargidx
char * curargptr
char * optfiledata
char * curfileptr


Function Documentation

char* GetNextArgument int *    len [inline]
 

Definition at line 136 of file Options.cpp.

Referenced by InterpretOptionString().

00140 {
00141    do
00142    {
00143       // We don't have a file loaded
00144       if(curfileptr==NULL)
00145       {
00146          // Let's skip white spaces
00147          while((*curargptr==' ')||(*curargptr=='\t')||(*curargptr=='\n')||(*curargptr=='\r'))
00148             curargptr++;
00149 
00150          // If we have some actual option strings left, then scan up to the
00151          // next white space
00152          if(*curargptr!=0)
00153          {
00154             char *endptr=curargptr+1;
00155             while((*endptr!=0)&&
00156                   (*endptr!=' ')&&(*endptr!='\t')&&
00157                   (*endptr!='\n')&&(*endptr!='\r'))
00158                endptr++;
00159 
00160             *len=(endptr-curargptr);
00161             return curargptr;
00162          }
00163 
00164          // We didn't find an option string ==> Go to next string
00165          curargidx++;
00166          if(curargidx==argnum)   // No more string? => Exit
00167             return NULL;
00168 
00169          curargptr=argstrings[curargidx];
00170       }
00171       else  // If we have a file, then we do something very similar
00172       {
00173          // Let's skip white spaces
00174          while((*curfileptr==' ')||(*curfileptr=='\t')||(*curfileptr=='\n')||(*curfileptr=='\r'))
00175             curfileptr++;
00176 
00177          if(*curfileptr!=0)
00178             return curfileptr;
00179 
00180          // Let's get rid of the file data
00181 //         delete[] optfiledata;
00182          // We keep the file, since in VPathExprMan, the pathstrings
00183          // are direct pointers into the memory of the file data
00184          // This is a bad solution!
00185 
00186          curfileptr=NULL;
00187          curfileptr=NULL;
00188       }
00189    }
00190    while(1);
00191 }

int HandleAllOptions char **    argv,
int    argc
 

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 }

void InitArguments char **    argv,
int    argc
[inline]
 

Definition at line 123 of file Options.cpp.

00125 {
00126    argstrings=argv;
00127    argnum=argc;
00128 
00129    curargidx=0;
00130    curargptr=argstrings[curargidx];
00131 
00132    optfiledata=NULL;
00133    curfileptr=NULL;
00134 }

void InterpretOptionString char *    option
 

Definition at line 250 of file Options.cpp.

00252 {
00253    int   len;
00254 
00255    switch(*option)
00256    {
00257       // Includes an option file
00258    case 'i':SkipArgumentString(1);
00259             option=GetNextArgument(&len);
00260             if(option[len]!=0)   // white space in file name?
00261             {
00262                Error("Invalid filename for option '-f'");
00263                Exit();
00264             }
00265             SkipArgumentString(len);
00266             ParseOptionFile(option);
00267             return;
00268 
00269    case 'v':   verbose=1;SkipArgumentString(1);return;
00270    case 't':   no_output=1;SkipArgumentString(1);return;
00271 
00272 
00273 #ifdef XDEMILL
00274    case 'b':   g_bBinary=1;SkipArgumentString(1);return;
00275 #endif
00276 
00277    case 'c':   usestdout=1;SkipArgumentString(1);return;
00278 //   case 'k':   delete_inputfiles=0;SkipArgumentString(1);return;
00279    case 'd':   delete_inputfiles=1;SkipArgumentString(1);return;
00280    case 'f':   overwrite_files=1;SkipArgumentString(1);return;
00281 
00282 #ifdef TIMING
00283    case 'T':   timing=1;SkipArgumentString(1);return;
00284 #endif
00285 
00286 #ifdef XMILL
00287       // Sets the memory window size
00288    case 'm':SkipArgumentString(1);
00289             option=GetNextArgument(&len);
00290             SkipArgumentString(len);
00291             memory_cutoff=atoi(option);
00292             if(memory_cutoff<1)
00293             {
00294                Error("Option '-m' must be followed be a number >=1");
00295                Exit();
00296             }
00297             memory_cutoff*=1024L*1024L;
00298             return;
00299 
00300       // Reads a path expression
00301    case 'p':   SkipArgumentString(1);
00302                option=GetNextArgument(&len);
00303                {
00304                char *ptr=option;
00305                pathexprman.AddNewVPathExpr(ptr,option+strlen(option));
00306                   // 'ptr' is moved to the characters after the path expression
00307                SkipArgumentString(ptr-option);
00308                }
00309 
00310                return;
00311 
00312       // Sets the left white space handling
00313    case 'l':   option++;
00314                switch(*option)
00315                {
00316                case 'i':   globalleftwhitespacescompress=WHITESPACE_IGNORE;SkipArgumentString(2);return;
00317                case 'g':   globalleftwhitespacescompress=WHITESPACE_STOREGLOBAL;SkipArgumentString(2);return;
00318                case 't':   globalleftwhitespacescompress=WHITESPACE_STORETEXT;SkipArgumentString(2);return;
00319                }
00320                break;
00321 
00322       // Sets the right white space handling
00323    case 'r':   option++;
00324                switch(*option)
00325                {
00326                case 'i':   globalrightwhitespacescompress=WHITESPACE_IGNORE;SkipArgumentString(2);return;
00327                case 'g':   globalrightwhitespacescompress=WHITESPACE_STOREGLOBAL;SkipArgumentString(2);return;
00328                case 't':   globalrightwhitespacescompress=WHITESPACE_STORETEXT;SkipArgumentString(2);return;
00329                }
00330                break;
00331 
00332       // Sets the full white space handling
00333    case 'w':   option++;
00334                switch(*option)
00335                {
00336                case 'i':   globalfullwhitespacescompress=WHITESPACE_IGNORE;SkipArgumentString(2);return;
00337                case 'g':   globalfullwhitespacescompress=WHITESPACE_STOREGLOBAL;SkipArgumentString(2);return;
00338                case 't':   globalfullwhitespacescompress=WHITESPACE_STORETEXT;SkipArgumentString(2);return;
00339                default:
00340                            globalleftwhitespacescompress=WHITESPACE_STOREGLOBAL;
00341                            globalrightwhitespacescompress=WHITESPACE_STOREGLOBAL;
00342                            globalfullwhitespacescompress=WHITESPACE_STOREGLOBAL;
00343                            globalattribwhitespacescompress=WHITESPACE_STOREGLOBAL;
00344                            SkipArgumentString(1);return;
00345                }
00346                break;
00347 
00348       // Sets the attribute white space handling
00349    case 'a':   option++;
00350                switch(*option)
00351                {
00352                case 'i':   globalattribwhitespacescompress=WHITESPACE_IGNORE;SkipArgumentString(2);return;
00353                case 'g':   globalattribwhitespacescompress=WHITESPACE_STOREGLOBAL;SkipArgumentString(2);return;
00354                }
00355                break;
00356 
00357       // Sets the handling of special sections (comment, CDATA, DOCTYPE, PI)
00358    case 'n':   option++;
00359                switch(*option)
00360                {
00361                case 'c':   ignore_comment=1;SkipArgumentString(2);return;
00362                case 't':   ignore_doctype=1;SkipArgumentString(2);return;
00363                case 'p':   ignore_pi=1;SkipArgumentString(2);return;
00364                case 'd':   ignore_cdata=1;;SkipArgumentString(2);return;
00365                }
00366                break;
00367 #endif
00368 #ifdef XDEMILL
00369       // All options for output formatting
00370 
00371 
00372 
00373    case 'o':   option++;
00374                switch(*option)
00375                {
00376                case 's':   // Use space indentation
00377                {
00378                   SkipArgumentString(2);
00379                   option=GetNextArgument(&len);
00380                   SkipArgumentString(len);
00381 
00382                   int spccount=atoi(option);
00383                   if(spccount<=0)
00384                   {
00385                      Error("Option '-os' must be followed be a positive integer");
00386                      Exit();
00387                   }
00388                   output.Init(XMLINTENT_SPACES,0,spccount);
00389                   output_initialized=1;
00390                   return;
00391                }
00392                   // Use tab indentation
00393                case 't':   SkipArgumentString(2);
00394                            output.Init(XMLINTENT_TABS);
00395                            output_initialized=1;
00396                            return;
00397 
00398                   // Use no indentation
00399                case 'n':   SkipArgumentString(2);
00400                            output.Init(XMLINTENT_NONE);
00401                            output_initialized=1;
00402                            return;
00403 
00404                   // Determines type of newline (DOS or UNIX)
00405                case 'd':   usedosnewline=1;
00406                            SkipArgumentString(2);
00407                            return;
00408                case 'u':   usedosnewline=0;
00409                            SkipArgumentString(2);
00410                            return;
00411 
00412 /*
00413                case 'w':
00414                {
00415                   int wrapcount;
00416                   option+=2;
00417                   wrapcount=atoi(option);
00418                   if(wrapcount<=0)
00419                   {
00420                      Error("Option '-ow' must be followed be a positive integer");
00421                      Exit();
00422                   }
00423                   while((*option>='0')&&(*option<='9'))
00424                      option++;
00425                   output.Init(XMLINTENT_WRAP,0,wrapcount);
00426                   output_initialized=1;
00427                   return;
00428                }
00429 */
00430 
00431         }
00432 
00433 
00434 #endif // XDEMILL
00435    }
00436 #ifdef XMILL
00437    // Determines the compression rate index for zlib
00438    if((*option>='1')&&(*option<='9'))
00439    {
00440       zlib_compressidx=(unsigned char)(*option-'0');
00441       SkipArgumentString(1);
00442       return;
00443    }
00444 #endif
00445 
00446    Error("Invalid option '-");
00447    ErrorCont(option);
00448    ErrorCont("'");
00449    Exit();
00450 }

void ParseOptionFile char *    filename [inline]
 

Definition at line 205 of file Options.cpp.

Referenced by InterpretOptionString().

00207 {
00208    Input input;
00209    char  *ptr;
00210    int   len;
00211 
00212    // We exit, if there is already an option file
00213    if(optfiledata!=NULL)
00214    {
00215       Error("Only one option file allowed!");
00216       Exit();
00217    }
00218 
00219    if(input.OpenFile(filename)==0)
00220    {
00221       Error("Could not open parameter file '");
00222       ErrorCont(filename);
00223       ErrorCont("'!");
00224       Exit();
00225    }
00226 
00227    len=input.GetCurBlockPtr(&ptr);
00228 
00229    if(len>30000)  // Just to make sure that the file fits into one
00230                   // single buffer -- i.e. we don't read another block
00231    {
00232       Error("Input file '");
00233       ErrorCont(filename);
00234       ErrorCont("' is too large!");
00235       Exit();
00236    }
00237 
00238    // Let's allocate and copy the data
00239    optfiledata=new char[len+1];
00240    memcpy(optfiledata,ptr,len);
00241    optfiledata[len]=0;
00242 
00243    curfileptr=optfiledata;
00244 
00245    input.CloseFile();
00246 }

void PrintUsage char    showmoreoptions
 

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 }

void SkipArgumentString int    len [inline]
 

Definition at line 193 of file Options.cpp.

Referenced by InterpretOptionString().

00196 {
00197    if(curfileptr!=NULL)
00198       curfileptr+=len;
00199    else
00200       curargptr+=len;
00201 }


Variable Documentation

int argnum
 

Definition at line 116 of file Options.cpp.

char** argstrings
 

Definition at line 115 of file Options.cpp.

int curargidx
 

Definition at line 116 of file Options.cpp.

char* curargptr
 

Definition at line 118 of file Options.cpp.

char* curfileptr
 

Definition at line 121 of file Options.cpp.

char delete_inputfiles = 0
 

Definition at line 64 of file Options.cpp.

char globalfullwhitespacescompress = WHITESPACE_IGNORE
 

Definition at line 54 of file Options.cpp.

unsigned long memory_cutoff = 8L*1024L*1024L
 

Definition at line 61 of file Options.cpp.

char no_output = 0
 

Definition at line 98 of file Options.cpp.

char* optfiledata
 

Definition at line 120 of file Options.cpp.

char output_initialized = 0
 

Definition at line 101 of file Options.cpp.

char overwrite_files = 0
 

Definition at line 66 of file Options.cpp.

VPathExprMan pathexprman
 

Definition at line 56 of file Options.cpp.

char skip_all_files = 0
 

Definition at line 67 of file Options.cpp.

char usedosnewline = 0
 

Definition at line 50 of file Options.cpp.

char usestdout = 0
 

Definition at line 99 of file Options.cpp.

char verbose = 0
 

Definition at line 100 of file Options.cpp.


Generated on Sat Dec 22 16:01:55 2001 for XMILLforBinaryFormat by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001