X-Git-Url: http://gitweb.hachti.de/?a=blobdiff_plain;f=pc-tools%2Fldc2%2Fsrc%2Fmain.cpp;h=53c764e0f6e31870aa6da8122b46d4c1eb4da41c;hb=ea4c19a49ff6621c58e0c4bba5ab5d271a3604c8;hp=068ca6e22439e3649ca89c65f6da2fd322ba07e8;hpb=fed2c751d37bf5e314fd26c98909471157cc86c0;p=h316.git diff --git a/pc-tools/ldc2/src/main.cpp b/pc-tools/ldc2/src/main.cpp index 068ca6e..53c764e 100644 --- a/pc-tools/ldc2/src/main.cpp +++ b/pc-tools/ldc2/src/main.cpp @@ -3,209 +3,25 @@ #include #include -#include -#include -#include -#include -#include +#include "config.hh" +#include "tool.hh" #include "tape_block.hh" #include "data_block_0.hh" -#include "configuration_manager.hh" - using namespace std; -static int in_fd, out_fd; - - -int dump_vector(vector arguments){ - int res=0; - for (vector::iterator iter=arguments.begin();iter",true,false); - - ar.add_option_value("o","out_file", - "Specify output file.", - &outfile_set,&outfile, - "",true,true); - - ar.add_argument("File from where data is read", - &infile_set,&infile, - ""); - ar.add_argument("File to where output is redirected", - &outfile_set,&outfile, - ""); - - ar.add_option_value("F","config_file", - "Use the specified configuration file.", - &config_file_set,&config_file, - "",false,true); - - - // If there's a config file mentioned in the environment, take it! - char * env_ldc_config=getenv("LDC_CONFIG"); - if(env_ldc_config){ - fprintf(stderr,"Using config file:\"%s\"\n",env_ldc_config); - if(dump_vector(ar.read_file(env_ldc_config))){ - dump_vector(ar.get_help()); - exit(1); - } - } - - // Process command line first time - if(dump_vector(ar.read_args(argc,args))){ - dump_vector(ar.get_help()); - exit(7); - } - - if (do_help) { - dump_vector(ar.get_help()); - exit(0); - } - - // If user has a config file, use it. - if (config_file_set){ - fprintf(stderr,"Using config file:\"%s\"\n",config_file.c_str()); - if(dump_vector(ar.read_file(config_file))){ - dump_vector(ar.get_help()); - exit(7); - } - - // Process command line a second time to override values from config file. - if(dump_vector(ar.read_args(argc,args))||do_help){ - dump_vector(ar.get_help()); - exit(7); - } - } + // Do all the configuration stuff + do_config(argc,args); - if (infile_set==1){ - fprintf(stderr,"Opening file for input:%s\n",infile.c_str()); - in_fd=open(infile.c_str(),O_RDONLY); - if (in_fd<0){ - fprintf(stderr,"Error: could not open file \"%s\" for reading!\n",infile.c_str()); - exit (1); - } - } + // Now we go to read the data! - if (outfile_set==1){ - fprintf(stderr,"Opening file for output:%s\n",outfile.c_str()); - out_fd=open(outfile.c_str(),O_WRONLY|O_TRUNC); - if (out_fd<0){ - fprintf(stderr,"Error: could not open file \"%s\" for writing!\n",outfile.c_str()); - exit (1); - } - } - // The configuration implications according to /cfg007/ - if (in_fd==0) pause_on_checksum_error=0; - if (pause_on_checksum_error==1) ignore_checksum_errors=1; - if (output_info||output_called||output_exported||output_unsatisfied) - list_contents=0; - - - // Now we go to read the data! - vector tape; vector > objects; vector current_object; @@ -234,7 +50,7 @@ Errors will be converted to warnings.", if (!in_object){ fprintf(stderr,"File successfully read.\n"); } else { - if (ignore_object_integrity_errors){ + if (cfg_ignore_object_integrity_errors){ fprintf(stderr,"Warning: Object integrity check failed!\n"); warnings++; } else { @@ -247,7 +63,7 @@ Errors will be converted to warnings.", break; case tape_block::TBS_EOF_ILLEGAL: delete block; - if (ignore_block_errors){ + if (cfg_ignoreblock_errors){ fprintf(stderr,"Warning: Block integrity check failed!\n"); warnings++; } else { @@ -259,11 +75,26 @@ Errors will be converted to warnings.", break; case tape_block::TBS_CHECKSUM: delete block; - if (ignore_checksum_errors){ + char buffer[200]; + snprintf(buffer,200,"Block No. %3i: Start(hex):%5x End(hex):%5x Size(hex):%3x\n", + blocks_read-1, + block_start, + block_end, + block->get_raw_size()); + if (cfg_ignorechecksum_errors){ + char buffer[200]; + snprintf(buffer,200,"Block No. %3i: Start(hex):%5x End(hex):%5x Size(hex):%3x\n", + blocks_read-1, + block_start, + block_end, + block->get_raw_size()); + write (out_fd,buffer,strlen(buffer)); fprintf(stderr,"Warning: Block checksum wrong!\n"); + fprintf(stderr,buffer); warnings++; } else { fprintf(stderr,"Error: Block checksum wrong!\n"); + fprintf(stderr,buffer); errors++; read_ahead=false; errcode=4; @@ -279,7 +110,7 @@ Errors will be converted to warnings.", case tape_block::TBS_IOERR: delete block; if (in_fd){ - fprintf(stderr,"Error: Could not read from \"%s\"!\n",infile.c_str()); + fprintf(stderr,"Error: Could not read from \"%s\"!\n",cfg_infile.c_str()); } else { fprintf(stderr,"Error: Could not read from stdin!\n"); } @@ -290,7 +121,7 @@ Errors will be converted to warnings.", tape.insert(tape.end(),block); blocks_read++; - if (verbose){ + if (cfg_verbose){ char buffer[200]; snprintf(buffer,200,"Block No. %3i: Start(hex):%5x End(hex):%5x Size(hex):%3x\n", blocks_read-1, @@ -300,11 +131,11 @@ Errors will be converted to warnings.", write (out_fd,buffer,strlen(buffer)); } - if(list_contents) + if(cfg_list_contents) dump_vector(block->get_description()); if (block->get_type()==0x10){ // Unknown data block! - if (ignore_unknown_block_errors){ + if (cfg_ignore_unknown_block_errors){ fprintf(stderr,"Warning: Unknown block type!\n"); warnings++; }else { @@ -337,10 +168,10 @@ Errors will be converted to warnings.", char buffer[200]; sprintf(buffer,"Bytes read:%i Blocks read:%i\nErrors:%i Warnings:%i\n", read_pointer,blocks_read,errors,warnings); - if(output_info){ + if(cfg_output_info){ write (out_fd,buffer,strlen(buffer)); - } else { - fprintf(stderr,buffer); +// } else { +// fprintf(stderr,buffer); } if (errors>0){