1 /* ldc2 preliminary main program */
12 #include "tape_block.hh"
13 #include "configuration_manager.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());
27 int main(int argc
, char ** args
){
29 /* Configuration data */
31 string infile
, outfile
;
32 int infile_set
, outfile_set
, config_file_set
;
41 split_objects_numbered
,
43 ignore_checksum_errors
,
44 pause_on_checksum_error
,
45 ignore_unknown_block_errors
,
46 ignore_object_integrity_errors
;
50 in_fd
=0; /* stdin {O _ \ */
51 out_fd
=1; /* stdout {O ^ / */
53 configuration_manager
ar("ldc2");
55 /* Here come the configuration switches */
56 ar
.add_option_switch("h","help",
57 "Output this help text and exit.",
60 ar
.add_option_switch("a","output_info",
61 "Print tape data information (default)",
64 ar
.add_option_switch("c","output_called",
65 "Print all called symbols from the object(s).",
68 ar
.add_option_switch("e","output_exported",
69 "Print all exported symbols from the object(s).",
72 ar
.add_option_switch("u","output_unsatisfied",
73 "List all unsatisfied symbols.",
76 ar
.add_option_switch("s","split_objects",
77 "Split input data into distinct object files.",
80 ar
.add_option_switch("S","split_objects_numbered",
81 "Split input data into distinct numbered files",
82 &split_objects_numbered
);
84 ar
.add_option_switch("b","ignore_block_errors",
85 "Ignore block integrity errors. This will output broken blocks,too",
86 &ignore_block_errors
);
88 ar
.add_option_switch("k","ignore_checksum_errors",
89 "Ignore block checksum errors. Errors will be converted to warnings.",
90 &ignore_checksum_errors
);
92 ar
.add_option_switch("p","pause_on_checksum_error",
93 "Wait for user input on checksum error.",
94 &pause_on_checksum_error
);
96 ar
.add_option_switch("n","ignore_unknown_block_errors",
97 "Ignore errors caused by unknown block types. Errors will be converted to warnings.",
98 &ignore_unknown_block_errors
);
100 ar
.add_option_switch("g","ignore_object_integrity_errors",
101 "Ignore errors caused by objects without proper end block. \
102 Errors will be converted to warnings.",
103 &ignore_object_integrity_errors
);
105 ar
.add_option_value("i","input_file",
106 "specify input file",
110 ar
.add_option_value("o","output_file",
111 "Specify output file.",
112 &outfile_set
,&outfile
,
116 ar
.add_argument("File from where data is read",
120 ar
.add_argument("File to where output is redirected",
121 &outfile_set
,&outfile
,
124 ar
.add_option_value("F","config_file",
125 "Use the specified configuration file.",
126 &config_file_set
,&config_file
,
129 // Process command line first time
130 if((dump_vector(ar
.read_args(argc
,args
))||do_help
)){
131 dump_vector(ar
.get_help());
135 // If user has a config file, use it.
136 if (config_file_set
){
137 if(dump_vector(ar
.read_file(config_file
))){
138 dump_vector(ar
.get_help());
141 // Process command line a second time to override values from config file.
142 if(dump_vector(ar
.read_args(argc
,args
))||do_help
){
143 dump_vector(ar
.get_help());
152 printf("Opening file for input:%s\n",infile
.c_str());
153 in_fd
=open(infile
.c_str(),O_RDONLY
);
155 printf("Error: could not open file:%s\n",infile
.c_str());
163 vector
<tape_block
*> tape
;
166 tape_block
* block
=0;
168 block
=tape_block::gen_from_fd(in_fd
);
169 if (block
->get_state()==tape_block::TBS_OK
){
170 tape
.insert(tape
.end(),block
);
171 dump_vector(block
->get_description());
176 switch(block
->get_state()){
177 case tape_block::TBS_EOF_LEGAL
: printf("File successfully read.\n");
179 case tape_block::TBS_EOF_ILLEGAL
: printf("EOF while in block!\n");
181 case tape_block::TBS_CHECKSUM
:
182 printf("Checksum error!\n");
184 case tape_block::TBS_DEFAULT
:
185 printf("TBS_DEFAULT encountered ->> SEVERY INTERNAL ERROR!\n");
187 case tape_block::TBS_IOERR
:
188 printf("I/O Error... Why?\n");