*** empty log message ***
authorhachti <hachti>
Tue, 19 Dec 2006 08:12:09 +0000 (08:12 +0000)
committerhachti <hachti>
Tue, 19 Dec 2006 08:12:09 +0000 (08:12 +0000)
pc-tools/ldc2/Makefile
pc-tools/ldc2/data/test1.asm [new file with mode: 0644]
pc-tools/ldc2/doc/cover.tex
pc-tools/ldc2/doc/main.tex
pc-tools/ldc2/src/configuration_manager.cpp
pc-tools/ldc2/src/configuration_manager.hh
pc-tools/ldc2/src/main.cpp

index 2d3c8358aa281313846ea6844037c3cf6b17b58f..335774aa8912e0eb056fba6e747904e2c351c597 100644 (file)
@@ -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 (file)
index 0000000..bafd108
--- /dev/null
@@ -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
index 5924d6a7d87c9f88ae44241eaf5b69bed5918fc4..e03f60d13d60eb4f7999cbc3610025b66895ebf8 100644 (file)
@@ -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
index 77d163b257f2d20e33008421e36734e1025ad672..01d31ab2db8f82ba8872a0f3ec4a96f840b1ef38 100644 (file)
@@ -12,7 +12,7 @@
 \pagestyle{empty}
 \pagenumbering{roman}
 
-\input cover
+%\input cover
 
 \newpage
 \pagestyle{plain}
index 4ded4f77a5ee36dfdfe1ed85597a53c79b8e5ddd..418beab22d3f4c69f7a2052d627621520cf9c836 100644 (file)
@@ -1,6 +1,8 @@
 #include "configuration_manager.hh"
 #include <stdio.h>
 
+#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 <filename> in -f<filename>
  */
-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 "<input-file>".
  *\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<string> configuration_manager::read_args(int argc, char ** args){
-  vector<string> result;
+  
+  vector<string> messages;
   vector<string> 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<string>::iterator akt_p=argv.begin()+1;akt_p<argv.end();akt_p++){ //Argument loop
+
+  // Loop through the command line arguments
+  for (unsigned int arg_no=0;arg_no<argv.size();arg_no++){
+    bool found=false;
+    string argstring;
     
-    // Look for long argument
-    if ((akt_p->substr(0,2)=="--")&&(free_parms_count==0)){
-      int found=0;
-      for (vector<opt_t>::iterator parm_p=opt_v.begin();parm_p<opt_v.end();parm_p++){
-       if (akt_p->substr(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+1<argv.end()) { // If next word existend
-               *(parm_p->status)=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_no<option_switches.size();switch_no++){
+       string switch_name=option_switches[switch_no].longname;
+       if (argstring.compare(0,switch_name.length(),switch_name,0,switch_name.length())==0){
+         string value=analyse_string(argstring);
+         bool result=analyse_bool(value);
+         *(option_switches[switch_no].status)=result;
+         found=true;
+       }
+      }
+
+      // Look for long values.
+      for (unsigned int value_no=0;value_no<option_values.size();value_no++){
+       string value_name=option_values[value_no].longname;
+       if (argstring.compare(0,value_name.length(),value_name,0,value_name.length())==0){
+         string value=analyse_string(argstring);
+         *(option_values[value_no].status)=1;
+         *(option_values[value_no].target)=value;
+         found=true;
        }
-      } // search for loop
-      if (!found) result.insert(result.end(),"Unknown parameter: "+*akt_p);
-    } else { // No -- param, now look for switches
-      if (((*akt_p)[0]=='-')&&(free_parms_count==0)){
-       int stop_char_loop=0;
-       for (unsigned int pos=1; pos<akt_p->length()&& !stop_char_loop ;pos++){
-         int found=0;
-         for (vector<opt_t>::iterator parm_p=opt_v.begin();parm_p<opt_v.end();parm_p++){
-           if (parm_p->shortname[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+1<argv.end()) { // If next word existend
-                   *(parm_p->target)=*(++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_count<arg_v.size()){
-         *(arg_v[free_parms_count].target)=*akt_p;
-         *(arg_v[free_parms_count].status)=1;
-       } 
+      }
+      if (! found) {
+       messages.insert(messages.begin(),"Unknown option: --"+argstring+"!");
+       found=true; // Oh!
+      }
+    }
+
+    // Look for short parameters
+    if ((argv[arg_no].substr(0,1)=="-")&&(free_parms_count==0)&&(!found)){ // Short parameters
+      found=true;
+      argstring=argv[arg_no].substr(1); // Reassign, with one more character now
+      for (unsigned int pos=0;pos < argstring.length();pos++){
+       bool short_found=false;
+       
+       // First, find short switches
+       for (unsigned int switch_no=0;switch_no<option_switches.size();switch_no++){
+         string short_name=option_switches[switch_no].shortname;
+         if (short_name.compare(0,short_name.length(),argstring,pos,short_name.length())==0){
+           *(option_switches[switch_no].status)=1;
+           short_found=true;
+           pos+=short_name.length()-1;
+         }
+       }
+       
+       // Now, find short values
+       if (!short_found){
+         for (unsigned int value_no=0;value_no<option_values.size();value_no++){
+           string short_name=option_values[value_no].shortname;
+           
+           if (short_name.compare(0,short_name.length(),argstring,pos,short_name.length())==0){
+             if (pos==argstring.length()-1){ // Last character, where's the value?
+               if (arg_no<argv.size()-1){ // Take next complete argument as value!
+                 *(option_values[value_no].status)=1;
+                 *(option_values[value_no].target)=argv[arg_no+1];
+                 arg_no+=1; // Consume the next argument
+                 short_found=true;
+               } else { // No argument left!
+                 messages.insert(messages.begin(),"Missing value for -"+short_name+"!");
+                 short_found=true;
+               }
+             } else {
+               *(option_values[value_no].status)=1;
+               *(option_values[value_no].target)=argstring.substr(pos+1);
+               pos=argstring.length(); // Do not analyse other characters.
+               short_found=true;
+             }
+           }
+         }
+       }
+       if (!short_found) messages.insert(messages.begin(),"Unknown Option: -"+argstring.substr(pos,1)+"!");
+      }
+    }
+    
+    if (!found) { // Must be a free form parameter...
+      if (free_parms_count<cmd_args.size()){ // Space available
+       *(cmd_args[free_parms_count].target)=argv[arg_no];
+       *(cmd_args[free_parms_count].status)=1;
        free_parms_count++;
+      } else { // No more space for free form parameters!
+       messages.insert(messages.begin(),"Too many arguments!");
       }
-    } //looking for not -- args
-  } // argv loop
-  if (free_parms_count>arg_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<string> to which lots of helpful
@@ -145,19 +253,30 @@ vector<string> configuration_manager::read_args(int argc, char ** args){
 void configuration_manager::get_help(vector<string> & target){
   target.insert(target.end(),"");
   string line="Usage: "+app_name;
-  for (vector<opt_t>::iterator parm_p=opt_v.begin();parm_p<opt_v.end();parm_p++){
+
+  for (vector<opt_switch_t>::iterator parm_p=option_switches.begin();parm_p<option_switches.end();parm_p++){
     string addstr=" [-"+parm_p->shortname;
-    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<arg_t>::iterator parm_p=arg_v.begin();parm_p<arg_v.end();parm_p++){
-    if (line.length()+parm_p->placeholder.length()>79){
+
+  for (vector<opt_value_t>::iterator parm_p=option_values.begin();parm_p<option_values.end();parm_p++){
+    string addstr=" [-"+parm_p->shortname;
+    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<cmd_arg_t>::iterator parm_p=cmd_args.begin();parm_p<cmd_args.end();parm_p++){
+    if (line.length()+parm_p->placeholder.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<string> & target){
   }
   target.insert(target.end(),line);
   
-  /*******************************/
-
+  /* Here comes the documentation output. */
+  
   vector<string> left,right;
-  for (vector<opt_t>::iterator parm_p=opt_v.begin();parm_p<opt_v.end();parm_p++){
-    line=parm_p->description;
-    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<arg_t>::iterator parm_p=arg_v.begin();parm_p<arg_v.end();parm_p++){
-    string st2;
-    line=parm_p->description;
-    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<string>();
+    right=vector<string>();
+    max_width=0;
+        
+    /* Now lets insert switches into left and right */
+    for (unsigned int sw=0; sw<option_switches.size();sw++){
+      opt_switch_t akt_sw=option_switches[sw];
+      string rline=akt_sw.description;
+      string lline="-"+akt_sw.shortname+", --"+akt_sw.longname;
+      left.insert(left.end(),lline);
+      right.insert(right.end(),rline);
+    }
+    
+    // Determine maximal width for left column
+    max_width=0;
+    for (unsigned int c=0; c<left.size();c++)
+      if(left[c].length()>max_width) max_width=left[c].length();
+    
+    /* output all the mess */
+    for (unsigned int c=0; c<left.size();c++){
+      string nl(max_width,' ');
+      nl.replace(0,left[c].length(),left[c]);
+      nl+="  "+right[c];
+      while (nl.length()>80){ // 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<string>();
+    right=vector<string>();
+    max_width=0;
+    
+    for (unsigned int val=0; val<option_values.size();val++){
+      opt_value_t akt_val=option_values[val];
+      string rline=akt_val.description;
+      string lline=" -"+akt_val.shortname+akt_val.placeholder+", --"+
+       akt_val.longname+akt_val.placeholder;
+      left.insert(left.end(),lline);
+      right.insert(right.end(),rline);
+    }
+    
+    // Determine maximal width for left column
+    for (unsigned int c=0; c<left.size();c++)
+      if(left[c].length()>max_width) max_width=left[c].length();
+    /* output all the mess */
+    for (unsigned int c=0; c<left.size();c++){
+      string nl(max_width,' ');
+      nl.replace(0,left[c].length(),left[c]);
+      nl+="  "+right[c];
+      while (nl.length()>80){ // 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; c<opt_v.size();c++)
-    if(left[c].length()>max_width) max_width=left[c].length();
-  for (unsigned int c=0; c<opt_v.size();c++){
-    string nl(max_width,' ');
-    nl.replace(0,left[c].length(),left[c]);
-    nl+="  "+right[c];
-    while (nl.length()>80){ // 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(); c<opt_v.size()+arg_v.size();c++)
-    if(left[c].length()>max_width) max_width=left[c].length();  
-  for (unsigned int c=opt_v.size(); c<opt_v.size()+arg_v.size();c++){
-    string nl(max_width,' ');
-    nl.replace(0,left[c].length(),left[c]);
-    nl+="  "+right[c];
     
-    while (nl.length()>80){ // 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<string>();
+    right=vector<string>();
+    max_width=0;
+        
+    for (unsigned int arg=0; arg<cmd_args.size();arg++){
+      cmd_arg_t akt_arg=cmd_args[arg];
+      left.insert(left.end(),akt_arg.placeholder);
+      right.insert(right.end(),akt_arg.description);
+    }
+    
+    // Determine maximal width for left column
+    max_width=0;
+    for (unsigned int c=0; c<left.size();c++)
+      if(left[c].length()>max_width) max_width=left[c].length();
+    
+    for (unsigned int c=0; c<left.size();c++){
+      string nl(max_width,' ');
+      nl.replace(0,left[c].length(),left[c]);
+      nl+="  "+right[c];
+      while (nl.length()>MAX_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<string> 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;
+}
index ffd77218a361074c40f832b325044858d20b9b6e..60a215d05725523ae350b870b1d5827b1813d01f 100644 (file)
@@ -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("<string>")
-                  );
-  
-  void add_argument (string  longname, 
-                    string  description, 
-                    int    *status, 
-                    string *target=NULL, 
-                    string  placeholder=string("<string>")
-                    );
-
-  vector<string> read_args(int argc, char ** args);
-  vector<string> read_file(string filename);
-  void get_help (vector<string> & target);
-  vector<string> 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("<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>"));
-  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("<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("<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("<string>")
+                    );
+  
+  vector<string> read_args(int argc, char ** args);
+  vector<string> read_file(string filename);
+  
+  void get_help (vector<string> & target);
+  vector<string> get_help();
+  
+protected: // members
   vector<opt_switch_t>option_switches;
   vector<opt_value_t>option_values;
   vector<cmd_arg_t>cmd_args;
   string app_name;
 
+protected: // methods
+  string analyse_string(const string & line);
+  bool analyse_bool(const string & data);
 }; // class configuration_manager
 
 
 #endif
+  
index 3e1244b19e98690c7456d1682e49238ebf4321bb..a86291b519c9ed0d5e2750050a6c091d3b6e8dec 100644 (file)
@@ -10,7 +10,7 @@
 #include <fcntl.h>
 
 #include "tape_block.hh"
-#include "argument_reader.hh"
+#include "configuration_manager.hh"
 
 using namespace std;
 
@@ -27,32 +27,110 @@ int dump_vector(vector<string> 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("<input-file>","File from where data is read",&infile_set,&infile);
-  ar.add_argument("<output-file>","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,
+                 "<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>");
+  
+  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_block*> tape;