From: hachti Date: Tue, 19 Dec 2006 08:12:09 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://gitweb.hachti.de/?a=commitdiff_plain;h=909d36034504f2511a5bc4ef7e50d407964e247a;p=h316.git *** empty log message *** --- diff --git a/pc-tools/ldc2/Makefile b/pc-tools/ldc2/Makefile index 2d3c835..335774a 100644 --- a/pc-tools/ldc2/Makefile +++ b/pc-tools/ldc2/Makefile @@ -1,5 +1,5 @@ APP_NAME=ldc2 -APP_OBJECTS= main.o silent_code.o argument_reader.o +APP_OBJECTS= main.o silent_code.o argument_reader.o configuration_manager.o CCFLAGS+=-Wall BLOCK_OBJECTS=data_block_0_10.o data_block_0_14.o data_block_0_1.o data_block_0_24.o\ data_block_0_2.o data_block_0_30.o data_block_0_3.o data_block_0_4.o\ diff --git a/pc-tools/ldc2/data/test1.asm b/pc-tools/ldc2/data/test1.asm new file mode 100644 index 0000000..bafd108 --- /dev/null +++ b/pc-tools/ldc2/data/test1.asm @@ -0,0 +1,11 @@ + SUBR SONNE,SUN + SUBR BLUME,BLU + REL + ORG '1000 + NOP + NOP +BLU NOP +SUN NOP + END + + \ No newline at end of file diff --git a/pc-tools/ldc2/doc/cover.tex b/pc-tools/ldc2/doc/cover.tex index 5924d6a..e03f60d 100644 --- a/pc-tools/ldc2/doc/cover.tex +++ b/pc-tools/ldc2/doc/cover.tex @@ -19,7 +19,7 @@ Object Program Analysis Tool\\ \normalsize Labor Softwaretechnik 2\\ Prof. Andreas Spillner\\ \vspace{3cm} -\small Wintersemester 2006/2007\\ +{\small Wintersemester 2006/2007}\\ \end{center} } \ No newline at end of file diff --git a/pc-tools/ldc2/doc/main.tex b/pc-tools/ldc2/doc/main.tex index 77d163b..01d31ab 100644 --- a/pc-tools/ldc2/doc/main.tex +++ b/pc-tools/ldc2/doc/main.tex @@ -12,7 +12,7 @@ \pagestyle{empty} \pagenumbering{roman} -\input cover +%\input cover \newpage \pagestyle{plain} diff --git a/pc-tools/ldc2/src/configuration_manager.cpp b/pc-tools/ldc2/src/configuration_manager.cpp index 4ded4f7..418beab 100644 --- a/pc-tools/ldc2/src/configuration_manager.cpp +++ b/pc-tools/ldc2/src/configuration_manager.cpp @@ -1,6 +1,8 @@ #include "configuration_manager.hh" #include +#define MAX_LINE_LENGTH 80 + /*! *\brief Constructor. * @@ -16,34 +18,78 @@ configuration_manager::configuration_manager(string name){ /*! *\brief Add a new configuration value to be searched for. *\param shortname A character for the short form. - * For example the h in -h + * For example the o in -o *\param longname The double dash longname. For example - * input_file in --input_file= or + * output_file in --output_file= *\param description A detailed description of the value. *\param status Pointer to an integer. Will be set to 1 if arg found. - *\target Pointer to to string to put the value in. + *\target Pointer to string to put the value in. *\placeholder A placeholder for the documentation. * For example in -f */ -void configuration_manager::add_option_value (string shortname, string longname, - string description, - bool allow_cmdline, - bool allow_conffile, - int * status, - string * target, string placeholder){ +void configuration_manager::add_option_value (const string & shortname, + const string & longname, + const string & description, + int * status, + string * target, + const string & placeholder, + const bool & allow_cmdline, + const bool & allow_conffile + ){ - if(status!=NULL) option_values.insert(opt_v.end(), - opt_value_t(shortname,longname, description, - status,target,placeholder) - ); + if(status!=NULL) if (target!=NULL) + option_values.insert(option_values.end(), + opt_value_t(shortname, + longname, + description, + status, + target, + placeholder, + allow_cmdline, + allow_conffile + ) + ); } + +/*! + *\brief Add a new configuration switch to be searched for. + *\param shortname A character for the short form. + * For example the h in -h + *\param longname The double dash longname. For example + * help in --help + *\param description A detailed description of the value. + *\param status Pointer to an integer. Will be set to 1 if arg found. + *\param allow_cmdline Specifies whether the switch is acceptable on the + * command line. + *\param allow_conffile Specifies whether the switch is acceptable + * in a configuration file. + */ +void configuration_manager::add_option_switch (const string & shortname, + const string & longname, + const string & description, + int * status, + const bool & allow_cmdline, + const bool & allow_conffile + ){ + + if(status!=NULL) + option_switches.insert(option_switches.end(), + opt_switch_t(shortname, + longname, + description, + status, + allow_cmdline, + allow_conffile) + ); +} + /*! *\brief Add an accepted argument to the argument reader. *\param placeholder Something like "". *\param description Text describing the argument. - *\param status A pointer to a status variable. Will be set to 0 immediately. + *\param status A pointer to a status variable. Will be set to 0 by default. * If the argument is filled in, it will be set to 1. *\param target A pointer to a c++ string where the argument goes to. * @@ -51,9 +97,18 @@ void configuration_manager::add_option_value (string shortname, string longname, * argument reader. * There would be no other way to determine the order. */ -void configuration_manager::add_argument(string placeholder, string description, int * status, string * target){ +void configuration_manager::add_argument(const string & description, + int * status, + string * target, + const string & placeholder){ + + + if (target!=NULL) if(status!=NULL) - arg_v.insert(arg_v.end(),arg_t(placeholder,description,status,target)); + cmd_args.insert(cmd_args.end(),cmd_arg_t(placeholder, + description, + status, + target)); } @@ -62,81 +117,134 @@ void configuration_manager::add_argument(string placeholder, string description, *\returns empty vector on success or the error messages to be output. */ vector configuration_manager::read_args(int argc, char ** args){ - vector result; + + vector messages; vector argv; - for (char ** akt=args; *akt ;akt++) argv.insert(argv.end(),string(*akt)); + // First we make a C++ string vector out of the **argv. + for (char ** akt=args+1; *akt ;akt++) argv.insert(argv.end(),string(*akt)); + + // Counter for the free command line parameters. unsigned int free_parms_count=0; - for (vector::iterator akt_p=argv.begin()+1;akt_psubstr(0,2)=="--")&&(free_parms_count==0)){ - int found=0; - for (vector::iterator parm_p=opt_v.begin();parm_psubstr(2,parm_p->longname.length())==parm_p->longname){ - found=1; - *(parm_p->status)=1; - if (parm_p->target){ - if (akt_p->length()>2+parm_p->longname.length()){ - *(parm_p->target)=akt_p->substr(2+parm_p->longname.length()); - - } else // Word not long enough - if (akt_p+1status)=1; - *(parm_p->target)=*(++akt_p); - } else { // No next word :-( - result.insert(result.end(), - "Parameter --"+parm_p->longname+parm_p->placeholder+" needs an Argument!"); - } - } // arg needed + // Look for long parameters. + if ((argv[arg_no].substr(0,2)=="--")&&(free_parms_count==0)){ + argstring=argv[arg_no].substr(2); + + // Look for long switches. + for (unsigned int switch_no=0;switch_nolength()&& !stop_char_loop ;pos++){ - int found=0; - for (vector::iterator parm_p=opt_v.begin();parm_pshortname[0]==(*akt_p)[pos]){ - found=1; - (*parm_p->status)=1; - if (parm_p->target){ // Need argument - if (akt_p->length()>pos+1){ - *(parm_p->target)=akt_p->substr(pos+1); - stop_char_loop=1; - } else { // Word not long enough - if (akt_p+1target)=*(++akt_p); - stop_char_loop=1; - } else { // No next word :-( - result.insert(result.end(), - "Parameter --"+parm_p->longname+parm_p->placeholder+" needs an Argument!"); - } - } - } // arg needed - } //if match - } //args loop - if (!found) result.insert(result.end(),"Unknown switch: "+akt_p->substr(pos,1)); - } // char loop - }// switch found - else{ // no switch found - if (free_parms_countarg_v.size()) result.insert(result.begin(),"Too many arguments!"); - if (!result.empty()){ - result.insert(result.begin(),"Error!"); - result.insert(result.begin(),""); + } + } + if (!messages.empty()){ + messages.insert(messages.begin(),"Error!"); + messages.insert(messages.begin(),""); } + return messages; +} + +/*! + *\brief Extract a value from a configuration file line or + * a command line argument + */ +string configuration_manager::analyse_string(const string & line){ + string result=""; + unsigned int pos=line.find("="); + if (pos!=string::npos) result=line.substr(pos+1); return result; } +/*! + *\brief Extract a boolean value out of a string. + */ +bool configuration_manager::analyse_bool(const string & data){ + if ((data=="false")||(data=="0")||(data=="no")) return false; + return true; +} + /*! *\brief Generate help. *\arg target Reference to a vector to which lots of helpful @@ -145,19 +253,30 @@ vector configuration_manager::read_args(int argc, char ** args){ void configuration_manager::get_help(vector & target){ target.insert(target.end(),""); string line="Usage: "+app_name; - for (vector::iterator parm_p=opt_v.begin();parm_p::iterator parm_p=option_switches.begin();parm_pshortname; - if (parm_p->target!=0) addstr+=parm_p->placeholder; addstr+="]"; - if (line.length()+addstr.length()>79){ + if (line.length()+addstr.length()>MAX_LINE_LENGTH){ target.insert(target.end(),line); line=string(7+app_name.length(),' '); } line+=addstr; } - - for (vector::iterator parm_p=arg_v.begin();parm_pplaceholder.length()>79){ + + for (vector::iterator parm_p=option_values.begin();parm_pshortname; + addstr+=parm_p->placeholder; + addstr+="]"; + if (line.length()+addstr.length()>MAX_LINE_LENGTH){ + target.insert(target.end(),line); + line=string(7+app_name.length(),' '); + } + line+=addstr; + } + + for (vector::iterator parm_p=cmd_args.begin();parm_pplaceholder.length()>MAX_LINE_LENGTH){ target.insert(target.end(),line); line=string(7+app_name.length(),' '); } @@ -165,70 +284,117 @@ void configuration_manager::get_help(vector & target){ } target.insert(target.end(),line); - /*******************************/ - + /* Here comes the documentation output. */ + vector left,right; - for (vector::iterator parm_p=opt_v.begin();parm_pdescription; - string st2=" -"+parm_p->shortname; - if (parm_p->target)st2+=" "+parm_p->placeholder; - st2+=", --"+parm_p->longname; - if (parm_p->target)st2+=parm_p->placeholder; - left.insert(left.end(),st2); - right.insert(right.end(),line); - } + unsigned int max_width; - for (vector::iterator parm_p=arg_v.begin();parm_pdescription; - st2+=" "+parm_p->placeholder; - left.insert(left.end(),st2); - right.insert(right.end(),line); + /* Output switches? */ + if (option_switches.size()){ + target.insert(target.end(),""); + target.insert(target.end(),"Switches:"); + + left=vector(); + right=vector(); + max_width=0; + + /* Now lets insert switches into left and right */ + for (unsigned int sw=0; swmax_width) max_width=left[c].length(); + + /* output all the mess */ + for (unsigned int c=0; c80){ // Too long??? + int limit=nl.find_last_of(' ',MAX_LINE_LENGTH+1); + target.insert(target.end(),nl.substr(0,limit)); + nl=string(max_width+2,' ')+nl.substr(limit+1); + } + target.insert(target.end(),nl); + } } - if (opt_v.size()){ + // Output values + if (option_values.size()){ target.insert(target.end(),""); - target.insert(target.end(),"Options:"); + target.insert(target.end(),"Option values:"); + + left=vector(); + right=vector(); + max_width=0; + + for (unsigned int val=0; valmax_width) max_width=left[c].length(); + /* output all the mess */ + for (unsigned int c=0; c80){ // Too long??? + int limit=nl.find_last_of(' ',MAX_LINE_LENGTH+1); + target.insert(target.end(),nl.substr(0,limit)); + nl=string(max_width+2,' ')+nl.substr(limit+1); + } + target.insert(target.end(),nl); + } } - unsigned int max_width=0; - for (unsigned int c=0; cmax_width) max_width=left[c].length(); - for (unsigned int c=0; c80){ // Too long??? - int limit=nl.find_last_of(' ',80); - target.insert(target.end(),nl.substr(0,limit)); - nl=string(max_width+2,' ')+nl.substr(limit+1); - } - target.insert(target.end(),nl); - } - - if (arg_v.size()){ + /* Output the Arguments */ + if (cmd_args.size()){ target.insert(target.end(),""); target.insert(target.end(),"Arguments:"); - } - - max_width=0; - for (unsigned int c=opt_v.size(); cmax_width) max_width=left[c].length(); - for (unsigned int c=opt_v.size(); c80){ // Too long??? - int limit=nl.find_last_of(' ',80); - printf("limit:%i\n",limit); - target.insert(target.end(),nl.substr(0,limit)); - nl=string(max_width+2,' ')+nl.substr(limit+1); - } - - target.insert(target.end(),nl); - } + left=vector(); + right=vector(); + max_width=0; + + for (unsigned int arg=0; argmax_width) max_width=left[c].length(); + + for (unsigned int c=0; cMAX_LINE_LENGTH){ // Too long??? + int limit=nl.find_last_of(' ',MAX_LINE_LENGTH+1); + // printf("limit:%i\n",limit); + target.insert(target.end(),nl.substr(0,limit)); + nl=string(max_width+2,' ')+nl.substr(limit+1); + } + target.insert(target.end(),nl); + } target.insert(target.end(),""); + } } /*! @@ -244,22 +410,53 @@ vector configuration_manager::get_help(){ /**************************************************/ -configuration_manager::opt_t::opt_t(string n_shortname, string n_longname,string n_description, int * n_status, - string * n_target, string n_placeholder){ - shortname=n_shortname; - longname=n_longname; - description=n_description; - status=n_status; - target=n_target; - placeholder=n_placeholder; + +configuration_manager::opt_value_t::opt_value_t(const string & shortname, + const string & longname, + const string & description, + int * status, + string * target, + const string & placeholder, + const bool & allow_conffile, + const bool & allow_cmdline + ){ + this->shortname=shortname; + this->longname=longname; + this->description=description; + this->status=status; + this->target=target; + this->placeholder=placeholder; + this->allow_conffile=allow_conffile; + this->allow_cmdline=allow_cmdline; if (status) *status=0; } -configuration_manager::arg_t::arg_t( string n_placeholder, string n_description, - int * n_status, string * n_target){ - description=n_description; - status=n_status; - target=n_target; - placeholder=n_placeholder; + +configuration_manager::opt_switch_t::opt_switch_t(const string & shortname, + const string & longname, + const string & description, + int * status, + const bool & allow_conffile, + const bool & allow_cmdline){ + this->shortname=shortname; + this->longname=longname; + this->description=description; + this->status=status; + this->target=target; + this->placeholder=placeholder; + this->allow_conffile=allow_conffile; + this->allow_cmdline=allow_cmdline; if (status) *status=0; } + + +configuration_manager::cmd_arg_t::cmd_arg_t(const string & placeholder, + const string & description, + int * status, + string * target){ + this->placeholder=placeholder; + this->description=description; + this->status=status; + this->target=target; + if (this->status) *(this->status)=0; +} diff --git a/pc-tools/ldc2/src/configuration_manager.hh b/pc-tools/ldc2/src/configuration_manager.hh index ffd7721..60a215d 100644 --- a/pc-tools/ldc2/src/configuration_manager.hh +++ b/pc-tools/ldc2/src/configuration_manager.hh @@ -14,102 +14,122 @@ using namespace std; * Additionally, it is able to interpret configuration files. * Usage:\n * - Create an instance. - * - Add Parameters/switches with add_param(). + * - Add Parameters/switches with add_option_*(). * - Add Arguments with add_argument(). * - Call read_args() with your main routine's arguments. * The vector returned by read_args() contains all error * messages. When it's empty, everything is fine! * - Call get_help() if you want nice formatted help output. * (You want!!!) - * Sould be easy to use..... Enjoy. + * Sould be easy to use.... */ class configuration_manager{ -public: - configuration_manager(string name); - - void add_option_switch (string shortname, - string longname, - string description, - int *status, - bool allow_commandline=true, - bool allow_config_file=true - ); - - void add_option_value (string shortname, - string longname, - string description, - int *status, - bool allow_commandline=true, - bool allow_config_file=true, - string *target=NULL, - string placeholder=string("") - ); - - void add_argument (string longname, - string description, - int *status, - string *target=NULL, - string placeholder=string("") - ); - - vector read_args(int argc, char ** args); - vector read_file(string filename); - - void get_help (vector & target); - vector get_help(); - -private: +protected: // Types /*! *\brief Container for an option switch */ - class opt_switch_t{ + class opt_switch_t{ public: - opt_switch_t (string shortname, string longname,string description, int * status - string * target=NULL, string placeholder=string("")); + opt_switch_t (const string & shortname, + const string & longname, + const string & description, + int * status, + const bool & allow_commandline=true, + const bool & allow_config_file=true); string shortname; string longname; int * status; string * target; string description; string placeholder; + bool allow_conffile; + bool allow_cmdline; }; + /*! *\brief Container for an option value */ -class opt_value_t{ + class opt_value_t{ public: - switch_t (string shortname, string longname,string description, int * status - string * target=NULL, string placeholder=string("")); - string shortname; - string longname; - int * status; - string * target; - string description; - string placeholder; - bool allow_conffile; - bool allow_cmdline; -}; - + opt_value_t (const string & shortname, + const string & longname, + const string & description, + int * status, + string * target, + const string & placeholder=string(""), + const bool & allow_commandline=true, + const bool & allow_config_file=true); + string shortname; + string longname; + int * status; + string * target; + string description; + string placeholder; + bool allow_conffile; + bool allow_cmdline; + }; + /*! *\brief Container for a commandline argument */ class cmd_arg_t{ public: - arg_t (string placeholder,string description, - int * status, string * target); + cmd_arg_t (const string & placeholder, + const string & description, + int * status, + string * target); int * status; string * target; string description; string placeholder; }; +public: // Methods + + configuration_manager(string name); + + void add_option_value (const string & shortname, + const string & longname, + const string & description, + int *status, + string *target=NULL, + const string & placeholder=string(""), + const bool & allow_commandline=true, + const bool & allow_config_file=true + ); + + void add_option_switch (const string & shortname, + const string & longname, + const string & description, + int *status, + const bool & allow_commandline=true, + const bool & allow_config_file=true + ); + + void add_argument (const string & description, + int *status, + string *target=NULL, + const string & placeholder=string("") + ); + + vector read_args(int argc, char ** args); + vector read_file(string filename); + + void get_help (vector & target); + vector get_help(); + +protected: // members vectoroption_switches; vectoroption_values; vectorcmd_args; string app_name; +protected: // methods + string analyse_string(const string & line); + bool analyse_bool(const string & data); }; // class configuration_manager #endif + diff --git a/pc-tools/ldc2/src/main.cpp b/pc-tools/ldc2/src/main.cpp index 3e1244b..a86291b 100644 --- a/pc-tools/ldc2/src/main.cpp +++ b/pc-tools/ldc2/src/main.cpp @@ -10,7 +10,7 @@ #include #include "tape_block.hh" -#include "argument_reader.hh" +#include "configuration_manager.hh" using namespace std; @@ -27,32 +27,110 @@ int dump_vector(vector arguments){ int main(int argc, char ** args){ + /* Configuration data */ + string config_file; string infile, outfile; - int infile_set, outfile_set; - int help_wanted; + int infile_set, outfile_set, config_file_set; - int greet_want; - string greetings; + 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 ^ / + in_fd=0; /* stdin {O _ \ */ + out_fd=1; /* stdout {O ^ / */ - argument_reader ar("ldc2"); - ar.add_param("h","help","Output this help text.",&help_wanted); - ar.add_param("g","greet","Wonderful bla bla. It is here only to test the output\ -capabilities of the arg_reader.",&greet_want); - - ar.add_argument("","File from where data is read",&infile_set,&infile); - ar.add_argument("","File to where output is redirected",&outfile_set,&outfile); - - - if((dump_vector(ar.read_args(argc,args))||help_wanted)){ + 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, + ""); + + ar.add_option_value("o","output_file", + "Specify output file.", + &outfile_set,&outfile, + ""); + + + ar.add_argument("File from where data is read", + &infile_set,&infile, + ""); + + ar.add_argument("File to where output is redirected", + &outfile_set,&outfile, + ""); + + ar.add_option_value("F","config_file", + "Use the specified configuration file.", + &config_file_set,&config_file, + ""); + + if((dump_vector(ar.read_args(argc,args))||do_help)){ dump_vector(ar.get_help()); exit(1); } - if(greet_want)printf("Hallo!\n"); if (infile_set==1){ printf("Opening file for input:%s\n",infile.c_str()); @@ -63,6 +141,9 @@ capabilities of the arg_reader.",&greet_want); } } + + + vector tape;