1 /* ldc2 preliminary main program */
9 #include "tape_block.hh"
10 #include "data_block_0.hh"
15 *\brief The main routine.
17 int main(int argc
, char ** args
){
19 // Do all the configuration stuff
22 // Now we go to read the data!
25 vector
<tape_block
*> tape
;
26 vector
<vector
<tape_block
*> > objects
;
27 vector
<tape_block
*> current_object
;
41 block
=tape_block::gen_from_fd(in_fd
);
43 block_start
=read_pointer
+block
->get_discarded_bytes();
44 block_end
=block_start
+block
->get_raw_size()-1;
45 read_pointer
=block_end
+1;
46 //printf("Discarded:%2x, Raw Size:%2x\n",block->get_discarded_bytes(),block->get_raw_size());
47 switch(block
->get_state()){ // switchy
48 case tape_block::TBS_EOF_LEGAL
:
51 fprintf(stderr
,"File successfully read.\n");
53 if (cfg_ignore_object_integrity_errors
){
54 fprintf(stderr
,"Warning: Object integrity check failed!\n");
57 fprintf(stderr
,"Error: Object integrity check failed!\n");
64 case tape_block::TBS_EOF_ILLEGAL
:
66 if (cfg_ignoreblock_errors
){
67 fprintf(stderr
,"Warning: Block integrity check failed!\n");
70 fprintf(stderr
,"Error: Block integrity check failed!\n");
76 case tape_block::TBS_CHECKSUM
:
79 snprintf(buffer
,200,"Block No. %3i: Start(hex):%5x End(hex):%5x Size(hex):%3x\n",
83 block
->get_raw_size());
84 if (cfg_ignorechecksum_errors
){
86 snprintf(buffer
,200,"Block No. %3i: Start(hex):%5x End(hex):%5x Size(hex):%3x\n",
90 block
->get_raw_size());
91 write (out_fd
,buffer
,strlen(buffer
));
92 fprintf(stderr
,"Warning: Block checksum wrong!\n");
93 fprintf(stderr
,buffer
);
96 fprintf(stderr
,"Error: Block checksum wrong!\n");
97 fprintf(stderr
,buffer
);
103 case tape_block::TBS_DEFAULT
:
105 fprintf(stderr
,"TBS_DEFAULT encountered ->> SEVERE INTERNAL ERROR!\n");
110 case tape_block::TBS_IOERR
:
113 fprintf(stderr
,"Error: Could not read from \"%s\"!\n",cfg_infile
.c_str());
115 fprintf(stderr
,"Error: Could not read from stdin!\n");
120 case tape_block::TBS_OK
:
121 tape
.insert(tape
.end(),block
);
126 snprintf(buffer
,200,"Block No. %3i: Start(hex):%5x End(hex):%5x Size(hex):%3x\n",
130 block
->get_raw_size());
131 write (out_fd
,buffer
,strlen(buffer
));
134 if(cfg_list_contents
)
135 dump_vector(block
->get_description());
137 if (block
->get_type()==0x10){ // Unknown data block!
138 if (cfg_ignore_unknown_block_errors
){
139 fprintf(stderr
,"Warning: Unknown block type!\n");
142 fprintf(stderr
,"Error: Unknown block type!\n");
149 current_object
.insert(current_object
.end(),block
);
151 if ((block
->get_type()==data_block::TBT_EOT
)
152 ||((block
->get_type()==0)&&(block
->get_subtype()==3))
153 ||((block
->get_type()==4)||(block
->get_type()==3))
154 ||((block
->get_type()==0)&&(block
->get_subtype()==014))){
156 objects
.insert(objects
.end(),current_object
);
157 current_object
.clear();
167 // Now we have our blocks, tell the user about that!
169 sprintf(buffer
,"Bytes read:%i Blocks read:%i\nErrors:%i Warnings:%i\n",
170 read_pointer
,blocks_read
,errors
,warnings
);
172 write (out_fd
,buffer
,strlen(buffer
));
174 // fprintf(stderr,buffer);
178 fprintf(stderr
,"Errors make me sick. Goodbye!\n");