+ while(read_ahead){
+
+ bool err_checksum=false; //! Checksum error flag.
+ bool err_integrity=false; //! Integrity error flag.
+
+ bool warning=false; //! Warning flag.
+ bool error=false; //! Error flag.
+
+ // Try to generate block
+ try{
+ block=tape_block::gen_from_fd(in_fd);
+ }
+
+ catch(tape_block::eof_legal_exception &e){
+ read_pointer+=e.get_consumed();
+ break; // Immediately leave read loop.
+ }
+
+ catch(tape_block::io_error_exception){
+ if (in_fd){
+ fprintf(stderr,"Error: Could not read from \"%s\"!\n",
+ cfg_infile.c_str());
+ } else {
+ fprintf(stderr,"Error: Could not read from stdin!\n");
+ }
+ error=true;
+ errcode=2;
+ break; // Immediately leave read loop.
+ }
+
+ catch(tape_block::eof_illegal_exception &e){
+ block=e.get_block();
+ err_integrity=true;
+ read_ahead=false;
+ if (cfg_ignore_block_errors){
+ message="Warning: Block integrity check failed!\n";
+ warning=true;
+ } else {
+ message="Error: Block integrity check failed!\n";
+ error=true;
+ errcode=3;
+ }
+ }
+
+ catch(tape_block::checksum_error_exception &e){
+ block=e.get_block();
+ err_checksum=true;
+ if (cfg_ignore_checksum_errors){
+ message="Warning: Block checksum wrong!\n";
+ warning=true;
+ } else {
+ message="Error: Block checksum wrong!\n";
+ error=true;
+ read_ahead=false;
+ errcode=4;
+ }
+ }
+
+ // Now let's check for block type
+ if ((!error)&&(!warning)&&!block->has_known_type()){
+ if (cfg_ignore_unknown_block_errors){
+ message="Warning: Unknown Block type!";
+ warning=true;
+ }else{
+ message="Error: Unknown Block type!";
+ error=true;
+ read_ahead=false;
+ errcode=5;
+ }
+ }
+
+ // Count block.
+ blocks_read++;
+ tape.insert(tape.end(),block);
+ block_start=read_pointer+block->get_discarded_bytes();
+ block_end=block_start+block->get_raw_size()-1;
+ read_pointer=block_end+1;
+
+ FILE * fp=stdwarn;
+ if (error) fp=stderr;
+
+ if (cfg_verbose||error||warning){
+ if (!spaced) fprintf(fp,"\n");
+ spaced=false;
+ fprintf(fp,"Block No.%03i: Start:0x%04x End:0x%04x Size:0x%02x\n",
+ blocks_read-1,
+ block_start,
+ block_end,
+ block->get_raw_size());
+ }
+
+ if (error) fprintf(stderr,message.c_str());
+ if (warning) fprintf(stdwarn,message.c_str());
+
+ if(error||warning){
+ dump_vector(block->get_description());
+ } else {
+ if(cfg_list_contents){
+ FILE * tmp_fp=fdopen(out_fd,"w");
+ dump_vector_fp(block->get_description(),tmp_fp);
+ if (!error&&!warning) spaced=false;
+ }
+ }
+
+ if (error||warning||cfg_verbose){
+ fprintf(fp,"\n");
+ spaced=true;
+ }
+ if (error) errors++;
+ if (warning) warnings++;
+ } // while....
+ if (cfg_verbose){
+ close(in_fd);
+ fprintf(stderr,"Reading finished.\n");
+ fprintf(stderr,"Bytes read:%i, Blocks read:%i\n",read_pointer,blocks_read);
+ }
+} // read_tape()
+
+
+/******************************************************************************/
+/*!
+ *\brief Do integrity test and object or block dumps.
+ */
+void process_tape(){
+ if (cfg_verbose) fprintf(stdwarn,"\nProcessing Data.\n");