1 /* ldc2 preliminary main program */
12 #include "tape_block.hh"
13 #include "argument_reader.hh"
17 int dump_vector(vector
<string
> arguments
){
19 for (vector
<string
>::iterator iter
=arguments
.begin();iter
<arguments
.end();iter
++){
20 printf("%s\n",(*iter
).c_str());
28 int main(int argc
, char ** args
){
30 string infile
, outfile
;
31 int infile_set
, outfile_set
;
39 in_fd
=0; //stdin {O _ \
40 out_fd
=1; //stdout {O ^ /
42 argument_reader
ar("ldc2");
43 ar
.add_param("h","help","Output this help text.",&help_wanted
);
44 ar
.add_param("g","greet","Wonderful bla bla. It is here only to test the output\
45 capabilities of the arg_reader.",&greet_want
);
47 ar
.add_argument("<input-file>","File from where data is read",&infile_set
,&infile
);
48 ar
.add_argument("<output-file>","File to where output is redirected",&outfile_set
,&outfile
);
51 if((dump_vector(ar
.read_args(argc
,args
))||help_wanted
)){
52 dump_vector(ar
.get_help());
55 if(greet_want
)printf("Hallo!\n");
58 printf("Opening file for input:%s\n",infile
.c_str());
59 in_fd
=open(infile
.c_str(),O_RDONLY
);
61 printf("Error: could not open file:%s\n",infile
.c_str());
66 vector
<tape_block
*> tape
;
71 block
=tape_block::gen_from_fd(in_fd
);
72 if (block
->get_state()==tape_block::TBS_OK
){
73 tape
.insert(tape
.end(),block
);
74 dump_vector(block
->get_description());
79 switch(block
->get_state()){
80 case tape_block::TBS_EOF_LEGAL
: printf("File successfully read.\n");
82 case tape_block::TBS_EOF_ILLEGAL
: printf("EOF while in block!\n");
84 case tape_block::TBS_CHECKSUM
:
85 printf("Checksum error!\n");
87 case tape_block::TBS_DEFAULT
:
88 printf("TBS_DEFAULT encountered ->> SEVERY INTERNAL ERROR!\n");
90 case tape_block::TBS_IOERR
:
91 printf("I/O Error... Why?\n");