*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / main.cpp
1 /* ldc2 preliminary main program */
2
3 #include <vector>
4 #include <string>
5
6 #include <stdio.h>
7 #include <unistd.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11
12 #include "tape_block.hh"
13 #include "argument_reader.hh"
14
15 using namespace std;
16
17 int dump_vector(vector<string> arguments){
18 int res=0;
19 for (vector<string>::iterator iter=arguments.begin();iter<arguments.end();iter++){
20 printf("%s\n",(*iter).c_str());
21 res=1;
22 }
23 return res;
24 }
25
26
27
28 int main(int argc, char ** args){
29
30 string infile, outfile;
31 int infile_set, outfile_set;
32 int help_wanted;
33
34 int greet_want;
35 string greetings;
36
37 int in_fd, out_fd;
38
39 in_fd=0; //stdin {O _ \
40 out_fd=1; //stdout {O ^ /
41
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);
46
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);
49
50
51 if((dump_vector(ar.read_args(argc,args))||help_wanted)){
52 dump_vector(ar.get_help());
53 exit(1);
54 }
55 if(greet_want)printf("Hallo!\n");
56
57 if (infile_set==1){
58 printf("Opening file for input:%s\n",infile.c_str());
59 in_fd=open(infile.c_str(),O_RDONLY);
60 if (in_fd<0){
61 printf("Error: could not open file:%s\n",infile.c_str());
62 exit (3);
63 }
64 }
65
66 vector<tape_block*> tape;
67
68
69 tape_block * block=0;
70 while(1){
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());
75 }
76 else break;
77 }
78
79 switch(block->get_state()){
80 case tape_block::TBS_EOF_LEGAL: printf("File successfully read.\n");
81 break;
82 case tape_block::TBS_EOF_ILLEGAL: printf("EOF while in block!\n");
83 break;
84 case tape_block::TBS_CHECKSUM:
85 printf("Checksum error!\n");
86 break;
87 case tape_block::TBS_DEFAULT:
88 printf("TBS_DEFAULT encountered ->> SEVERY INTERNAL ERROR!\n");
89 exit(88);
90 case tape_block::TBS_IOERR:
91 printf("I/O Error... Why?\n");
92 exit (43);
93 }
94
95 return 0;
96 } // main()
97