+/*!
+ *\brief Do integrity test and object or block dumps.
+ */
+void process_tape(){
+ if (cfg_verbose) fprintf(stdwarn,"\nProcessing Data.\n");
+
+ bool in_object=false;
+ char filename[100];
+ char filename_numbered[100];
+ string objname;
+ int unknown_count=-1;
+ int fd=-1, fd_numbered=-1;
+ int obj_no=0;
+ int obj_start_block;
+
+ for (unsigned int i=0; i<tape.size();i++){
+ tape_block * block=tape[i];
+
+ if (block->get_type()==tape_block::TBT_EOT){
+ objname="EOT";
+ if (in_object){
+ if (cfg_ignore_object_integrity_errors){
+ fprintf(stdwarn,"Warning: Object integrity error!\
+ (Object no %i, Block %i unexpected)\n",obj_no,i);
+ warnings++;
+ } else {
+ fprintf(stderr,"Error: Object integrity error!\
+ (Object no %i, Block %i unexpected)\n",obj_no,i);
+ errors++;
+ errcode=6;
+ return;
+ }
+ }
+ }
+ if (!in_object){ // object begin
+
+ obj_no++;
+ obj_start_block=i;
+
+ objname="UNKNOWN";
+ unknown_count++;
+
+ vector<string>names=block->get_exported_symbols();
+ for (unsigned int a=0; a<names.size();a++){
+ objname=names[0];
+ if (objname!=" "){
+ objname=objname.substr(0,objname.find_last_not_of(" ")+1);
+ unknown_count--;
+ break;
+ }
+ }
+
+ if (block->get_type()==tape_block::TBT_EOT){
+ objname="EOT";
+ }
+
+ // Open file for split objects
+ if (cfg_split_objects && (block->get_type()!=tape_block::TBT_EOT)){
+ if (objname=="UNKNOWN")snprintf(filename,99,"UNKNOWN%02i",
+ unknown_count);
+ else snprintf(filename,99,"%s",objname.c_str());
+ if (fd>-1) close (fd);
+ if (cfg_verbose) fprintf(stdwarn,"Writing file: %s\n",filename);
+ fd=open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666);
+ if (fd<0){
+ fprintf(stderr,"Error: could not open file \"%s\" for writing!\n",
+ filename);
+ errors++;
+ errcode=1;
+ return;
+ }
+ }
+
+ // Open file for split objects numbered
+ snprintf(filename_numbered,99,"%03i0-%s",obj_no,objname.c_str());
+ if (cfg_split_objects_numbered){
+ close (fd_numbered);
+ if (cfg_verbose) fprintf(stdwarn,"Writing file: %s\n",filename_numbered);
+ fd_numbered=open(filename_numbered,O_WRONLY|O_CREAT|O_TRUNC,0666);
+ if (fd_numbered<0){
+ fprintf(stderr,"Error: could not open file \"%s\" for writing!\n",
+ filename_numbered);
+ errors++;
+ errcode=1;
+ return;
+ }
+ }
+ in_object=true;
+ } // object begin
+
+ // Output block data
+ if (cfg_split_objects){
+ try{
+ if (block->get_type()!=tape_block::TBT_EOT) // Don't want EOT here
+ block->dump_to_fd(fd);
+ }
+ catch (tape_block::io_error_exception e){
+ fprintf(stderr,"Error: could write to file \"%s\"!\n",
+ filename);
+ errors++;
+ errcode=1;
+ return;
+ }
+ } // if (cfg_split_objects)