*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / configuration_manager.cpp
index 418beab22d3f4c69f7a2052d627621520cf9c836..418410508fa72074f42968ebf32c85fa3d78a851 100644 (file)
@@ -1,5 +1,7 @@
 #include "configuration_manager.hh"
 #include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
 
 #define MAX_LINE_LENGTH 80
 
@@ -225,6 +227,7 @@ vector<string> configuration_manager::read_args(int argc, char ** args){
   }
   return messages;
 }
+  
 
 /*!
  *\brief Extract a value from a configuration file line or
@@ -245,6 +248,45 @@ bool configuration_manager::analyse_bool(const string & data){
   return true;
 }
 
+/*!
+ *brief Read in and parse a configuration file.
+ *\arg file String containing the filename
+ *\return Empty Vector or Vector full of strings containing
+ *        the error message(s).
+ */
+vector<string> configuration_manager::read_file(string filename){
+  vector<string>result;
+  FILE * fp=fopen(filename.c_str(),"r");
+  if (! fp) {
+    result.insert(result.end(),"Error!");
+    result.insert(result.end(),"Could not open file:"+filename);
+    return result;
+  }
+
+  char buffer[1000];
+  while(fgets(buffer,1000,fp)){
+    if (strlen (buffer)){
+      char*l2=buffer+strspn(buffer," \t");
+      if (l2[0]!='#'){
+       string line=l2;
+       unsigned int pos=line.find("=");
+       if (pos==0){
+         result.insert(result.end(),"Error!");
+         result.insert(result.end(),"In File:"+filename);
+         result.insert(result.end(),"Line beginning with '='!");
+         return result;
+       }
+       
+      } // if not #
+      
+    } // if (strlen())
+  } // while(...)
+
+  
+  fclose (fp);
+  return result;
+}
+
 /*!
  *\brief Generate help.
  *\arg target Reference to a vector<string> to which lots of helpful