X-Git-Url: http://gitweb.hachti.de/?a=blobdiff_plain;f=pc-tools%2Fldc2%2Fsrc%2Fmain.cpp;h=3e1244b19e98690c7456d1682e49238ebf4321bb;hb=ca5fce3a3fc44f8ad44c2c89abd6a322717ca428;hp=4c74b0338cc7cdd2f0612c02918654e8d6ba36d8;hpb=27bbb60df360a89da0116eb56cc6937ba1d5d85f;p=h316.git diff --git a/pc-tools/ldc2/src/main.cpp b/pc-tools/ldc2/src/main.cpp index 4c74b03..3e1244b 100644 --- a/pc-tools/ldc2/src/main.cpp +++ b/pc-tools/ldc2/src/main.cpp @@ -1,30 +1,97 @@ -/* -$Id: main.cpp,v 1.2 2006/11/20 01:19:01 hachti Exp $ -*/ +/* ldc2 preliminary main program */ + +#include +#include + #include #include +#include +#include +#include #include "tape_block.hh" -#include "data_block.hh" +#include "argument_reader.hh" -void tape_start(void* m){ - printf("tape_start\n"); -} +using namespace std; -void tape_stop(void* m){ - printf("tape_stop\n"); +int dump_vector(vector arguments){ + int res=0; + for (vector::iterator iter=arguments.begin();iter desc=myblock->get_description(); - for (vector::iterator iter=desc.begin(); - iter!=desc.end();iter++) - printf("%s\n",(*iter).c_str()); - } while (myblock->get_state()==tape_block::TBS_OK); - return 0; -} + + +int main(int argc, char ** args){ + + string infile, outfile; + int infile_set, outfile_set; + int help_wanted; + + int greet_want; + string greetings; + + int in_fd, out_fd; + + in_fd=0; //stdin {O _ \ + out_fd=1; //stdout {O ^ / + + argument_reader ar("ldc2"); + ar.add_param("h","help","Output this help text.",&help_wanted); + ar.add_param("g","greet","Wonderful bla bla. It is here only to test the output\ +capabilities of the arg_reader.",&greet_want); + + ar.add_argument("","File from where data is read",&infile_set,&infile); + ar.add_argument("","File to where output is redirected",&outfile_set,&outfile); + + + if((dump_vector(ar.read_args(argc,args))||help_wanted)){ + dump_vector(ar.get_help()); + exit(1); + } + if(greet_want)printf("Hallo!\n"); + + if (infile_set==1){ + printf("Opening file for input:%s\n",infile.c_str()); + in_fd=open(infile.c_str(),O_RDONLY); + if (in_fd<0){ + printf("Error: could not open file:%s\n",infile.c_str()); + exit (3); + } + } + + vector tape; + + + tape_block * block=0; + while(1){ + block=tape_block::gen_from_fd(in_fd); + if (block->get_state()==tape_block::TBS_OK){ + tape.insert(tape.end(),block); + dump_vector(block->get_description()); + } + else break; + } + + switch(block->get_state()){ + case tape_block::TBS_EOF_LEGAL: printf("File successfully read.\n"); + break; + case tape_block::TBS_EOF_ILLEGAL: printf("EOF while in block!\n"); + break; + case tape_block::TBS_CHECKSUM: + printf("Checksum error!\n"); + break; + case tape_block::TBS_DEFAULT: + printf("TBS_DEFAULT encountered ->> SEVERY INTERNAL ERROR!\n"); + exit(88); + case tape_block::TBS_IOERR: + printf("I/O Error... Why?\n"); + exit (43); + } + + return 0; +} // main() +