#include <stdio.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "tape_block.hh"
-#include "data_block.hh"
-
-#include "argument_reader.hh"
+#include "configuration_manager.hh"
using namespace std;
-void tape_start(void* m){
- printf("tape_start\n");
-}
-
-void tape_stop(void* m){
- printf("tape_stop\n");
-}
-
-void dump_vector(vector<string> arguments){
+int dump_vector(vector<string> arguments){
+ int res=0;
for (vector<string>::iterator iter=arguments.begin();iter<arguments.end();iter++){
printf("%s\n",(*iter).c_str());
+ res=1;
}
+ return res;
}
+
int main(int argc, char ** args){
- int help_needed;
- int name_set;
- int file_set;
- string name="Philipp";
- string filename;
-
- argument_reader ar("ldc2");
- ar.add_param("h","help","Give help",&help_needed);
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name Gelaber Gelaber Gelaber Gelaber M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
- ar.add_argument("<input-blaaaaaaaaaaaaaaa-filename>","File to read data from",&file_set,&filename);
-
- dump_vector(ar.read_args(argc,args));
-
- if (help_needed){
+
+ /* Configuration data */
+ string config_file;
+ string infile, outfile;
+ int infile_set, outfile_set, config_file_set;
+
+ int
+ do_help,
+ output_info,
+ output_called,
+ output_exported,
+ output_unsatisfied,
+ split_objects,
+ split_objects_numbered,
+ ignore_block_errors,
+ ignore_checksum_errors,
+ pause_on_checksum_error,
+ ignore_unknown_block_errors,
+ ignore_object_integrity_errors;
+
+ int in_fd, out_fd;
+
+ in_fd=0; /* stdin {O _ \ */
+ out_fd=1; /* stdout {O ^ / */
+
+ configuration_manager ar("ldc2");
+
+ /* Here come the configuration switches */
+ ar.add_option_switch("h","help",
+ "Output this help text and exit.",
+ &do_help,true,false);
+
+ ar.add_option_switch("a","output_info",
+ "Print tape data information (default)",
+ &output_info);
+
+ ar.add_option_switch("c","output_called",
+ "Print all called symbols from the object(s).",
+ &output_called);
+
+ ar.add_option_switch("e","output_exported",
+ "Print all exported symbols from the object(s).",
+ &output_exported);
+
+ ar.add_option_switch("u","output_unsatisfied",
+ "List all unsatisfied symbols.",
+ &output_unsatisfied);
+
+ ar.add_option_switch("s","split_objects",
+ "Split input data into distinct object files.",
+ &split_objects);
+
+ ar.add_option_switch("S","split_objects_numbered",
+ "Split input data into distinct numbered files",
+ &split_objects_numbered);
+
+ ar.add_option_switch("b","ignore_block_errors",
+ "Ignore block integrity errors. This will output broken blocks,too",
+ &ignore_block_errors);
+
+ ar.add_option_switch("k","ignore_checksum_errors",
+ "Ignore block checksum errors. Errors will be converted to warnings.",
+ &ignore_checksum_errors);
+
+ ar.add_option_switch("p","pause_on_checksum_error",
+ "Wait for user input on checksum error.",
+ &pause_on_checksum_error);
+
+ ar.add_option_switch("n","ignore_unknown_block_errors",
+ "Ignore errors caused by unknown block types. Errors will be converted to warnings.",
+ &ignore_unknown_block_errors);
+
+ ar.add_option_switch("g","ignore_object_integrity_errors",
+ "Ignore errors caused by objects without proper end block. \
+Errors will be converted to warnings.",
+ &ignore_object_integrity_errors);
+
+ ar.add_option_value("i","input_file",
+ "specify input file",
+ &infile_set,&infile,
+ "<input-file>");
+
+ ar.add_option_value("o","output_file",
+ "Specify output file.",
+ &outfile_set,&outfile,
+ "<output_file>");
+
+
+ ar.add_argument("File from where data is read",
+ &infile_set,&infile,
+ "<input-file>");
+
+ ar.add_argument("File to where output is redirected",
+ &outfile_set,&outfile,
+ "<output-file>");
+
+ ar.add_option_value("F","config_file",
+ "Use the specified configuration file.",
+ &config_file_set,&config_file,
+ "<file-name>");
+
+ // Process command line first time
+ if((dump_vector(ar.read_args(argc,args))||do_help)){
dump_vector(ar.get_help());
exit(1);
}
+
+ // If user has a config file, use it.
+ if (config_file_set){
+ if(dump_vector(ar.read_file(config_file))){
+ dump_vector(ar.get_help());
+ exit(1);
+ }
+ // Process command line a second time to override values from config file.
+ if(dump_vector(ar.read_args(argc,args))||do_help){
+ dump_vector(ar.get_help());
+ exit(1);
+ }
+ }
+
- printf("\n\n\nHallo %s!\n",name.c_str());
- exit(0);
- tape_block * myblock=0;
- do{
- if (myblock) delete myblock;
- myblock=tape_block::gen_from_fd(0);
-
- vector<string> desc=myblock->get_description();
- for (vector<string>::iterator iter=desc.begin();
- iter!=desc.end();iter++)
- printf("%s\n",(*iter).c_str());
- } while (myblock->get_state()==tape_block::TBS_OK);
- return 0;
-}
+
+
+ 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_block*> 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()