X-Git-Url: http://gitweb.hachti.de/?a=blobdiff_plain;f=pc-tools%2Fldc2%2Fsrc%2Fconfiguration_manager.cpp;fp=pc-tools%2Fldc2%2Fsrc%2Fconfiguration_manager.cpp;h=418410508fa72074f42968ebf32c85fa3d78a851;hb=50c86ded564f01101a88eb741f2a76621b30a02f;hp=418beab22d3f4c69f7a2052d627621520cf9c836;hpb=909d36034504f2511a5bc4ef7e50d407964e247a;p=h316.git diff --git a/pc-tools/ldc2/src/configuration_manager.cpp b/pc-tools/ldc2/src/configuration_manager.cpp index 418beab..4184105 100644 --- a/pc-tools/ldc2/src/configuration_manager.cpp +++ b/pc-tools/ldc2/src/configuration_manager.cpp @@ -1,5 +1,7 @@ #include "configuration_manager.hh" #include +#include +#include #define MAX_LINE_LENGTH 80 @@ -225,6 +227,7 @@ vector 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 configuration_manager::read_file(string filename){ + vectorresult; + 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 to which lots of helpful