From: Aki Tuomi Date: Tue, 7 Apr 2015 18:13:01 +0000 (+0300) Subject: Move line parsing to its own method X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~98^2~16^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=07b7e0b57c94af47c9ba419f2b89a70d32920619;p=thirdparty%2Fpdns.git Move line parsing to its own method --- diff --git a/pdns/arguments.cc b/pdns/arguments.cc index 664207e6b2..04e5c4519c 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -381,6 +381,42 @@ void ArgvMap::preParse(int &argc, char **argv, const string &arg) } } +bool ArgvMap::parseLine(ifstream& f, const string& arg, string& line, bool lax) { + string pline; + string::size_type pos; + + if (!getline(f, pline)) return false; + trim_right(pline); + if(pline[pline.size()-1]=='\\') { + line+=pline.substr(0,pline.length()-1); + return true; + } + else + line+=pline; + + // strip everything after a # + if((pos=line.find("#"))!=string::npos) { + // make sure it's either first char or has whitespace before + // fixes issue #354 + if (pos == 0 || std::isspace(line[pos-1])) + line=line.substr(0,pos); + } + + // strip trailing spaces + trim_right(line); + + // strip leading spaces + if((pos=line.find_first_not_of(" \t\r\n"))!=string::npos) + line=line.substr(pos); + + // gpgsql-basic-query=sdfsdfs dfsdfsdf sdfsdfsfd + + parseOne( string("--") + line, arg, lax ); + line=""; + return true; +} + + bool ArgvMap::preParseFile(const char *fname, const string &arg, const string& theDefault) { params[arg]=theDefault; @@ -390,39 +426,8 @@ bool ArgvMap::preParseFile(const char *fname, const string &arg, const string& t return false; string line; - string pline; - string::size_type pos; - - while(getline(f,pline)) { - trim_right(pline); - - if(pline[pline.size()-1]=='\\') { - line+=pline.substr(0,pline.length()-1); - continue; - } - else - line+=pline; - - // strip everything after a # - if((pos=line.find("#"))!=string::npos) { - // make sure it's either first char or has whitespace before - // fixes issue #354 - if (pos == 0 || std::isspace(line[pos-1])) - line=line.substr(0,pos); - } - - // strip trailing spaces - trim_right(line); - - // strip leading spaces - if((pos=line.find_first_not_of(" \t\r\n"))!=string::npos) - line=line.substr(pos); - // gpgsql-basic-query=sdfsdfs dfsdfsdf sdfsdfsfd - - parseOne( string("--") + line, arg ); - line=""; - } + while(parseLine(f, arg, line, false)); return true; } @@ -444,36 +449,8 @@ bool ArgvMap::file(const char *fname, bool lax, bool included) set("include-dir","Directory to include configuration files from"); string line; - string pline; - string::size_type pos; - while(getline(f,pline)) { - trim_right(pline); - if(pline.empty()) - continue; - - if(pline[pline.size()-1]=='\\') { - line+=pline.substr(0,pline.length()-1); - - continue; - } - else - line+=pline; - - // strip everything after a # - if((pos=line.find("#"))!=string::npos) { - // make sure it's either first char or has whitespace before - // fixes issue #354 - if (pos == 0 || std::isspace(line[pos-1])) - line=line.substr(0,pos); - } - - // strip trailing spaces - trim(line); - - parseOne(string("--")+line,"",lax); - line=""; - } + while(parseLine(f, "", line, lax)); // handle include here (avoid re-include) if (!included && !params["include-dir"].empty()) { diff --git a/pdns/arguments.hh b/pdns/arguments.hh index a59ebc8147..87c9199fc5 100644 --- a/pdns/arguments.hh +++ b/pdns/arguments.hh @@ -92,6 +92,7 @@ public: { return file(fname,true); } + bool parseLine(ifstream& f, const string& arg, string& line, bool lax); // param_t; //!< use this if you need to know the content of the map bool parmIsset(const string &var); //!< Checks if a parameter is set to *a* value bool mustDo(const string &var); //!< if a switch is given, if we must do something (--help)