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" |
909d3603 |
13 | #include "configuration_manager.hh" |
798b0c1d |
14 | |
15 | using namespace std; |
16 | |
ad324d29 |
17 | int 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 |
28 | int main(int argc, char ** args){ |
ad324d29 |
29 | |
909d3603 |
30 | /* Configuration data */ |
31 | string config_file; |
ad324d29 |
32 | string infile, outfile; |
909d3603 |
33 | int infile_set, outfile_set, config_file_set; |
ad324d29 |
34 | |
909d3603 |
35 | int |
36 | do_help, |
37 | output_info, |
38 | output_called, |
39 | output_exported, |
40 | output_unsatisfied, |
41 | split_objects, |
42 | split_objects_numbered, |
43 | ignore_block_errors, |
44 | ignore_checksum_errors, |
45 | pause_on_checksum_error, |
46 | ignore_unknown_block_errors, |
47 | ignore_object_integrity_errors; |
ad324d29 |
48 | |
49 | int in_fd, out_fd; |
50 | |
909d3603 |
51 | in_fd=0; /* stdin {O _ \ */ |
52 | out_fd=1; /* stdout {O ^ / */ |
798b0c1d |
53 | |
909d3603 |
54 | configuration_manager ar("ldc2"); |
55 | |
56 | /* Here come the configuration switches */ |
57 | ar.add_option_switch("h","help", |
58 | "Output this help text and exit.", |
59 | &do_help,true,false); |
60 | |
61 | ar.add_option_switch("a","output_info", |
62 | "Print tape data information (default)", |
63 | &output_info); |
64 | |
65 | ar.add_option_switch("c","output_called", |
66 | "Print all called symbols from the object(s).", |
67 | &output_called); |
68 | |
69 | ar.add_option_switch("e","output_exported", |
70 | "Print all exported symbols from the object(s).", |
71 | &output_exported); |
72 | |
73 | ar.add_option_switch("u","output_unsatisfied", |
74 | "List all unsatisfied symbols.", |
75 | &output_unsatisfied); |
76 | |
77 | ar.add_option_switch("s","split_objects", |
78 | "Split input data into distinct object files.", |
79 | &split_objects); |
80 | |
81 | ar.add_option_switch("S","split_objects_numbered", |
82 | "Split input data into distinct numbered files", |
83 | &split_objects_numbered); |
84 | |
85 | ar.add_option_switch("b","ignore_block_errors", |
86 | "Ignore block integrity errors. This will output broken blocks,too", |
87 | &ignore_block_errors); |
88 | |
89 | ar.add_option_switch("k","ignore_checksum_errors", |
90 | "Ignore block checksum errors. Errors will be converted to warnings.", |
91 | &ignore_checksum_errors); |
92 | |
93 | ar.add_option_switch("p","pause_on_checksum_error", |
94 | "Wait for user input on checksum error.", |
95 | &pause_on_checksum_error); |
96 | |
97 | ar.add_option_switch("n","ignore_unknown_block_errors", |
98 | "Ignore errors caused by unknown block types. Errors will be converted to warnings.", |
99 | &ignore_unknown_block_errors); |
100 | |
101 | ar.add_option_switch("g","ignore_object_integrity_errors", |
102 | "Ignore errors caused by objects without proper end block. \ |
103 | Errors will be converted to warnings.", |
104 | &ignore_object_integrity_errors); |
105 | |
106 | ar.add_option_value("i","input_file", |
107 | "specify input file", |
108 | &infile_set,&infile, |
109 | "<input-file>"); |
110 | |
111 | ar.add_option_value("o","output_file", |
112 | "Specify output file.", |
113 | &outfile_set,&outfile, |
114 | "<output_file>"); |
115 | |
116 | |
117 | ar.add_argument("File from where data is read", |
118 | &infile_set,&infile, |
119 | "<input-file>"); |
120 | |
121 | ar.add_argument("File to where output is redirected", |
122 | &outfile_set,&outfile, |
123 | "<output-file>"); |
124 | |
125 | ar.add_option_value("F","config_file", |
126 | "Use the specified configuration file.", |
127 | &config_file_set,&config_file, |
128 | "<file-name>"); |
129 | |
130 | if((dump_vector(ar.read_args(argc,args))||do_help)){ |
632a71a2 |
131 | dump_vector(ar.get_help()); |
132 | exit(1); |
133 | } |
ad324d29 |
134 | |
135 | if (infile_set==1){ |
136 | printf("Opening file for input:%s\n",infile.c_str()); |
137 | in_fd=open(infile.c_str(),O_RDONLY); |
138 | if (in_fd<0){ |
139 | printf("Error: could not open file:%s\n",infile.c_str()); |
140 | exit (3); |
141 | } |
142 | } |
143 | |
909d3603 |
144 | |
145 | |
146 | |
ad324d29 |
147 | vector<tape_block*> tape; |
148 | |
149 | |
150 | tape_block * block=0; |
151 | while(1){ |
152 | block=tape_block::gen_from_fd(in_fd); |
153 | if (block->get_state()==tape_block::TBS_OK){ |
154 | tape.insert(tape.end(),block); |
155 | dump_vector(block->get_description()); |
156 | } |
157 | else break; |
158 | } |
798b0c1d |
159 | |
ad324d29 |
160 | switch(block->get_state()){ |
161 | case tape_block::TBS_EOF_LEGAL: printf("File successfully read.\n"); |
162 | break; |
163 | case tape_block::TBS_EOF_ILLEGAL: printf("EOF while in block!\n"); |
164 | break; |
165 | case tape_block::TBS_CHECKSUM: |
166 | printf("Checksum error!\n"); |
167 | break; |
168 | case tape_block::TBS_DEFAULT: |
169 | printf("TBS_DEFAULT encountered ->> SEVERY INTERNAL ERROR!\n"); |
170 | exit(88); |
171 | case tape_block::TBS_IOERR: |
172 | printf("I/O Error... Why?\n"); |
173 | exit (43); |
174 | } |
175 | |
176 | return 0; |
177 | } // main() |
798b0c1d |
178 | |