*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / main.cpp
CommitLineData
798b0c1d 1/* ldc2 preliminary main program */
2
3#include <vector>
4#include <string>
f9d603d2 5
97b26985 6#include <stdio.h>
7#include <unistd.h>
ad324d29 8#include <sys/types.h>
9#include <sys/stat.h>
10#include <fcntl.h>
97b26985 11
12#include "tape_block.hh"
c8a4d02d 13#include "argument_reader.hh"
798b0c1d 14
15using namespace std;
16
ad324d29 17int dump_vector(vector<string> arguments){
18 int res=0;
798b0c1d 19 for (vector<string>::iterator iter=arguments.begin();iter<arguments.end();iter++){
20 printf("%s\n",(*iter).c_str());
ad324d29 21 res=1;
798b0c1d 22 }
ad324d29 23 return res;
798b0c1d 24}
25
ad324d29 26
27
798b0c1d 28int main(int argc, char ** args){
ad324d29 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 ^ /
798b0c1d 41
c8a4d02d 42 argument_reader ar("ldc2");
ad324d29 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\
45capabilities 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)){
632a71a2 52 dump_vector(ar.get_help());
53 exit(1);
54 }
ad324d29 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 }
798b0c1d 78
ad324d29 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()
798b0c1d 97