00001 00002 00003 00004 #include "options.h" 00005 00006 #include <stdlib.h> 00007 #include <iostream> 00008 #include <iomanip> 00009 00011 00012 bool protectmode=false; // true if protection mode, false if correction mode. 00013 char* progname=NULL; // name of the program, as it was called. 00014 00015 00016 char* protectedfname=NULL; // the filename that is protected 00017 char* eccfname=NULL; // the filename that contains protection info 00018 char* correctedfname=NULL; // when correcting, the file where the 00020 00021 int hblen=100; // number of blocks put into one hyperblock 00022 const int hbcorr=6; // number of blocks of error protection info 00023 // for one hyperblock. Unchangable 00024 00025 int verbose=0; // verbosity level 00026 00027 const char* optstring="?vb:cp"; 00028 00029 void printhelp(char* const progname) 00030 { 00031 std::cerr << progname << ": Synopsis:" << std::endl; 00032 std::cerr << progname << " [-?] [-c] [-p] [-v] [-b blocklen] protectedfile outfile [correctedfile]" << std::endl; 00033 std::cerr << "-c: correct, -p: protect, -v: verbose" << std::endl; 00034 abort(); 00035 } 00036 00037 void readoptions(int argc, char * const argv[]) 00038 { 00039 progname = basename(argv[0]); 00040 { 00041 bool corr = ( NULL != strstr(progname, "correct") ); 00042 bool prot = ( NULL != strstr(progname, "protect") ); 00043 if ( corr ) protectmode=false; 00044 if ( prot ) protectmode=true; 00045 if ( corr == prot ) { 00046 std::cerr << "Warning: " << progname 00047 << ": name under which the programm was called " 00048 << "was not recognized. Defaulting to protection mode.\n"; 00049 protectmode=true; 00050 } 00051 } 00052 char optchar; 00053 while (-1 != (optchar = getopt(argc,argv,optstring)) ) { 00054 switch(optchar) { 00055 case ':': 00056 case '?': printhelp(progname); // printhelp never returns 00057 case 'p': protectmode=true; break; 00058 case 'c': protectmode=false; break; 00059 case 'v': verbose=1; break; 00060 case 'b': hblen=atoi(optarg); assert(1<=hblen); 00061 assert(hblen<=249); break; 00062 } 00063 } 00064 if ( protectmode && (optind+2 != argc) ) 00065 printhelp(progname); // printhelp never returns 00066 if ( (!protectmode) && (optind+2 != argc) && (optind+3 != argc) ) 00067 printhelp(progname); // printhelp never returns 00068 protectedfname = argv[optind++]; 00069 eccfname = argv[optind++]; 00070 if ( optind == argc ) correctedfname = protectedfname; 00071 else correctedfname = argv[optind++]; 00072 if(verbose) { 00073 P(protectmode); 00074 P(protectedfname); 00075 P(eccfname); 00076 P(correctedfname); 00077 P(hblen); 00078 P(hbcorr); 00079 P(verbose); 00080 P(100*hbcorr/hblen); 00081 } 00082 }