*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / configuration_manager.cpp
index 3194ec3eec3e029740acffe8ee5b1cc8d9ad4e9f..f21de674ca791c2e7f03b97f85a82d05b2a85e78 100644 (file)
@@ -1,7 +1,32 @@
+/******************************************************************************
+ * 
+ * LDC2 source code
+ *
+ * $Date: 2008/08/25 21:02:24 $
+ * $Author: hachti $
+ *
+ * $Log: configuration_manager.cpp,v $
+ * Revision 2.3  2008/08/25 21:02:24  hachti
+ * *** empty log message ***
+ *
+ * Revision 2.2  2007-06-15 12:46:04  hachti
+ * Some small changes in configuration_manager output - added (c/f) info.
+ * Changed order in tool.hh:add_unique....
+ *
+ * Revision 2.1  2007-03-26 04:05:37  hachti
+ * *** empty log message ***
+ *
+ * Revision 2.0  2007-03-26 01:00:38  hachti
+ * *** empty log message ***
+ *
+ *
+ ******************************************************************************/
 #include "configuration_manager.hh"
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
+#include <string.h>
 
 #define MAX_LINE_LENGTH 80
 
@@ -25,9 +50,14 @@ configuration_manager::configuration_manager(string  name){
  *                 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 string to put the value in. 
- *\placeholder A placeholder for the documentation. 
+ *\param target Pointer to string to put the value in. 
+ *\param placeholder A placeholder for the documentation. 
  *             For example <filename> in -f<filename>
+ *\param allow_cmdline Specifies if this value may be specified on the
+ *                     command line.
+ *\param allow_conffile Specifies if this value may be specified in a
+ *                      configuration file.
+ *
  */
 void configuration_manager::add_option_value (const string & shortname, 
                                              const string & longname,
@@ -115,7 +145,7 @@ void configuration_manager::add_argument(const string & description,
 
 
 /*!
- *\Read in the args passed to main().
+ *\brief Read in the args passed to main().
  *\returns empty vector on success or the error messages to be output.
  */
 vector<string> configuration_manager::read_args(int argc, char ** args){
@@ -135,7 +165,8 @@ vector<string> configuration_manager::read_args(int argc, char ** args){
     string argstring;
     
     // Look for long parameters.
-    if ((argv[arg_no].substr(0,2)=="--")&&(free_parms_count==0)){
+    //    if ((argv[arg_no].substr(0,2)=="--")&&(free_parms_count==0)){
+    if ((argv[arg_no].substr(0,2)=="--")){ // Changed for comfort.
       argstring=argv[arg_no].substr(2);
 
       // Look for long switches.
@@ -180,7 +211,8 @@ vector<string> configuration_manager::read_args(int argc, char ** args){
     }
 
     // Look for short parameters
-    if ((argv[arg_no].substr(0,1)=="-")&&(free_parms_count==0)&&(!found)){ // Short parameters
+    // if ((argv[arg_no].substr(0,1)=="-")&&(free_parms_count==0)&&(!found)){ // Short parameters
+    if ((argv[arg_no].substr(0,1)=="-")&&(!found)){                        // Changed for comfort.
       found=true;
       argstring=argv[arg_no].substr(1); // Reassign, with one more character now
       for (unsigned int pos=0;pos < argstring.length();pos++){
@@ -433,7 +465,12 @@ void configuration_manager::get_help(vector<string> & target){
     /* 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 rline="(" ;
+      if (akt_sw.allow_cmdline) rline+="c/";
+      else rline+="-/";
+      if (akt_sw.allow_conffile) rline+="f)";
+      else rline+="-)";
+      rline+=" "+akt_sw.description;
       string lline="-"+akt_sw.shortname+", --"+akt_sw.longname;
       left.insert(left.end(),lline);
       right.insert(right.end(),rline);
@@ -449,10 +486,10 @@ void configuration_manager::get_help(vector<string> & target){
       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);
+      while (nl.length()>MAX_LINE_LENGTH){ // Too long???
+       int limit=nl.find_last_of(' ',MAX_LINE_LENGTH);
        target.insert(target.end(),nl.substr(0,limit));
-       nl=string(max_width+2,' ')+nl.substr(limit+1);
+       nl=string(max_width+2+6,' ')+nl.substr(limit+1);
       } 
       target.insert(target.end(),nl);
     }
@@ -469,8 +506,14 @@ void configuration_manager::get_help(vector<string> & target){
     
     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+", --"+
+      string rline="(" ;
+      if (akt_val.allow_cmdline) rline+="c/";
+      else rline+="-/";
+      if (akt_val.allow_conffile) rline+="f)";
+      else rline+="-)";
+      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);
@@ -481,18 +524,24 @@ void configuration_manager::get_help(vector<string> & target){
       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);
+      string nl(max_width,' ');               // Empty left side.
+      nl.replace(0,left[c].length(),left[c]); // Print in left side.
+      nl+="  "+right[c];                      // Add right side.
+
+      while (nl.length()>MAX_LINE_LENGTH){ // Too long???
+       int limit=nl.find_last_of(' ',MAX_LINE_LENGTH);
        target.insert(target.end(),nl.substr(0,limit));
-       nl=string(max_width+2,' ')+nl.substr(limit+1);
+       nl=string(max_width+2+6,' ')+nl.substr(limit+1);
       } 
       target.insert(target.end(),nl);
     }
   }
 
+  target.insert(target.end(),"");
+  target.insert(target.end(),"Legend (c/f):");
+  target.insert(target.end(),"              c: Allowed on command line.");
+  target.insert(target.end(),"              f: Allowed in configuration file.");
+  
   /* Output the Arguments */
   if (cmd_args.size()){
     target.insert(target.end(),"");
@@ -519,7 +568,6 @@ void configuration_manager::get_help(vector<string> & target){
       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);
       }