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 tape analyser\n\
24 (C) 2007 Philipp Hachtmann\n\n\
25 Version %s, built %s\n %s\n\n"
27 /******************************************************************************/
29 static FILE * stdwarn
; //! Suppressable warning output file pointer.
30 static vector
<tape_block
*> tape
; //! Represents the whole tape contents.
31 static vector
<vector
<tape_block
*> > objects
; //! Tape content in objects.
34 static int warnings
=0;
35 static int errcode
=0; //! Variable for error codes.
40 fprintf(stderr
,"Failed. (%i)\n",errcode
);
45 /******************************************************************************/
47 *\brief Read in Tape data and do some checks and messages.
49 * This routine reads in the tape data.
50 * During reading in, checksums are checked and
51 * /da001/ information is generated. No object integrity test.
52 * Tape block object pointers are put into the global vector
57 tape_block
* block
=0; //! Pointer to current block.
58 bool read_ahead
=true; //! Continue scanning for blocks.
59 int read_pointer
=0; //! Read position in input.
60 int block_start
=0; //! Start of block position in input.
61 int block_end
=0; //! End of block position in input.
62 int blocks_read
=0; //! Number of blocks read in.
64 bool spaced
=false; //! Help flag for spaced messages.
66 string message
; //! A warning or help message.
71 bool err_checksum
=false;
72 bool err_integrity
=false;
78 block
=tape_block::gen_from_fd(in_fd
);
81 catch(tape_block::eof_legal_exception
&e
){
82 read_pointer
+=e
.get_consumed();
83 break; // Immediately leave read loop.
86 catch(tape_block::io_error_exception
){
88 fprintf(stderr
,"Error: Could not read from \"%s\"!\n",cfg_infile
.c_str());
90 fprintf(stderr
,"Error: Could not read from stdin!\n");
94 break; // Immediately leave read loop.
97 catch(tape_block::eof_illegal_exception
&e
){
101 if (cfg_ignore_block_errors
){
102 message
="Warning: Block integrity check failed!\n";
105 message
="Error: Block integrity check failed!\n";
111 catch(tape_block::checksum_error_exception
&e
){
114 if (cfg_ignore_checksum_errors
){
115 message
="Warning: Block checksum wrong!\n";
118 message
="Error: Block checksum wrong!\n";
125 // Now let's check for block type
126 if ((!error
)&&(!warning
)&&!block
->has_known_type()){
127 if (cfg_ignore_unknown_block_errors
){
128 message
="Warning: Unknown Block type!";
131 message
="Error: Unknown Block type!";
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 (error
) fp
=stderr
;
148 if (cfg_verbose
||error
||warning
){
149 if (!spaced
) fprintf(fp
,"\n");
151 fprintf(fp
,"Block No.%03i: Start:0x%04x End:0x%04x Size:0x%02x\n",
155 block
->get_raw_size());
158 if (error
) fprintf(stderr
,message
.c_str());
159 if (warning
) fprintf(stdwarn
,message
.c_str());
161 if(cfg_list_contents
){
162 dump_vector(block
->get_description());
163 if (!error
&&!warning
) spaced
=false;
166 if (error
||warning
||cfg_verbose
){
171 if (warning
) warnings
++;
175 fprintf(stderr
,"Reading finished.\n");
176 fprintf(stderr
,"Bytes read:%i, Blocks read:%i\n",read_pointer
,blocks_read
);
180 /******************************************************************************/
186 for (unsigned int i
=0; i
<tape
.size();i
++){
188 if (!tape
[i
]->has_known_type()){
190 if (cfg_ignore_unknown_block_errors
){
198 spaced
=false;fprintf(fp
,"\n");
199 fprintf(fp
,"Warning: Unknown Block type! Block No.%i\n",i
);
200 dump_vector_fp(tape
[i
]->get_description(),fp
);
204 if (!cfg_ignore_unknown_block_errors
){
206 fprintf(stdwarn
,"Failed. (%i)\n",errcode
);
213 /******************************************************************************/
215 *\brief The main routine.
217 int main(int argc
, char ** args
){
220 // Do all the configuration stuff
221 do_config(argc
,args
);
223 // Output a version message if desired
225 fprintf(stderr
, ID_STRING
, VERSION
, BUILD_DATE
, BUILD_STAMP
);
229 // Assign warning output according to configuration
230 if (cfg_quiet
) stdwarn
=fopen("/dev/null","w");
233 read_tape(); // Process input to completion.
238 if (cfg_split_objects
){
239 for (unsigned int i
=0; i
<tape
.size();i
++){
240 tape
[i
]->dump_to_fd(out_fd
);