1 /* ldc2 preliminary main program */
10 #include "tape_block.hh"
11 #include "data_block_0.hh"
16 #define BUILD_STAMP ""
23 #define ID_STRING "\n ldc2 - The X16 object analyser\n\
24 (C) 2007 Philipp Hachtmann\n\n\
25 Version %s, built %s\n %s\n\n"
30 *\brief The main routine.
32 int main(int argc
, char ** args
){
35 // Do all the configuration stuff
39 fprintf(stderr
, ID_STRING
, VERSION
, BUILD_DATE
, BUILD_STAMP
);
43 vector
<tape_block
*> tape
;
44 vector
<vector
<tape_block
*> > objects
;
45 vector
<tape_block
*> current_object
;
65 block
=tape_block::gen_from_fd(in_fd
);
67 tape
.insert(tape
.end(),block
);
68 block_start
=read_pointer
+block
->get_discarded_bytes();
69 block_end
=block_start
+block
->get_raw_size()-1;
70 read_pointer
=block_end
+1;
74 if (!spaced
) fprintf(stderr
,"\n");
77 snprintf(buffer
,200,"Block No.%03i: Start:0x%04x End:0x%04x Size:0x%02x\n",
81 block
->get_raw_size());
82 fprintf(stderr
,buffer
);
85 dump_vector(block
->get_description());
88 catch(tape_block::eof_legal_exception
&e
){
89 read_pointer
+=e
.get_consumed();
90 break; // Immediately leave read loop.
93 catch(tape_block::io_error_exception
){
95 fprintf(stderr
,"Error: Could not read from \"%s\"!\n",cfg_infile
.c_str());
97 fprintf(stderr
,"Error: Could not read from stdin!\n");
101 break; // Immediately leave read loop.
104 catch(tape_block::eof_illegal_exception
&e
){
107 tape
.insert(tape
.end(),block
);
108 block_start
=read_pointer
+block
->get_discarded_bytes();
109 block_end
=block_start
+block
->get_raw_size()-1;
110 read_pointer
=block_end
+1;
112 if (!spaced
) fprintf(stderr
,"\n");
115 snprintf(buffer
,200,"Block No.%03i: Start:0x%04x End:0x%04x Size:0x%02x\n",
119 block
->get_raw_size());
120 fprintf(stderr
,buffer
);
122 if (cfg_ignore_block_errors
){
123 fprintf(stderr
,"Warning: Block integrity check failed!\n");
126 fprintf(stderr
,"Error: Block integrity check failed!\n");
131 if(cfg_list_contents
)
132 dump_vector(block
->get_description());
133 fprintf(stderr
,"\n");
137 catch(tape_block::checksum_error_exception
&e
){
140 tape
.insert(tape
.end(),block
);
141 block_start
=read_pointer
+block
->get_discarded_bytes();
142 block_end
=block_start
+block
->get_raw_size()-1;
143 read_pointer
=block_end
+1;
146 if (!spaced
) fprintf(stderr
,"\n");
149 snprintf(buffer
,200,"Block No.%03i: Start:0x%04x End:0x%04x Size:0x%02x\n",
153 block
->get_raw_size());
154 fprintf(stderr
,buffer
);
156 if (cfg_ignore_checksum_errors
){
157 fprintf(stderr
,"Warning: Block checksum wrong!\n");
160 fprintf(stderr
,"Error: Block checksum wrong!\n");
165 if(cfg_list_contents
)
166 dump_vector(block
->get_description());
167 fprintf(stderr
,"\n");
172 } // while (read_ahead)
174 // Now we have our blocks, tell the user about that!
175 if (!spaced
) fprintf(stderr
,"\n");
178 sprintf(buffer
,"Bytes read:%i Blocks read:%i\nErrors:%i Warnings:%i\n",
179 read_pointer
,blocks_read
,errors
,warnings
);
181 write (out_fd
,buffer
,strlen(buffer
));
183 fprintf(stderr
,buffer
);
187 fprintf(stderr
,"Failed. (%i)\n",errcode
);
192 fprintf(stderr
,"Data read successfully.\n");
196 // switch(block->get_state()){ // switchy
197 // case tape_block::TBS_EOF_LEGAL:
200 // fprintf(stderr,"File successfully read.\n");
202 // if (cfg_ignore_object_integrity_errors){
203 // fprintf(stderr,"Warning: Object integrity check failed!\n");
206 // fprintf(stderr,"Error: Object integrity check failed!\n");
213 // case tape_block::TBS_EOF_ILLEGAL:
215 // case tape_block::TBS_CHECKSUM:
217 // case tape_block::TBS_DEFAULT:
219 // fprintf(stderr,"TBS_DEFAULT encountered ->> SEVERE INTERNAL ERROR!\n");
224 // case tape_block::TBS_IOERR:
225 // case tape_block::TBS_OK:
226 // tape.insert(tape.end(),block);
231 // snprintf(buffer,200,"Block No. %3i: Start(hex):%5x End(hex):%5x Size(hex):%3x\n",
235 // block->get_raw_size());
236 // write (out_fd,buffer,strlen(buffer));
239 // if(cfg_list_contents)
240 // dump_vector(block->get_description());
242 // if (block->get_type()==0x10){ // Unknown data block!
243 // if (cfg_ignore_unknown_block_errors){
244 // fprintf(stderr,"Warning: Unknown block type!\n");
247 // fprintf(stderr,"Error: Unknown block type!\n");
254 // current_object.insert(current_object.end(),block);
256 // if ((block->get_type()==data_block::TBT_EOT)
257 // ||((block->get_type()==0)&&(block->get_subtype()==3))
258 // ||((block->get_type()==4)||(block->get_type()==3))
259 // ||((block->get_type()==0)&&(block->get_subtype()==014))){
261 // objects.insert(objects.end(),current_object);
262 // current_object.clear();
269 // } // generate loop