In eoParser::readFrom, added a test to avoid reading non-parser sections

as these generally contain many -xxx that generate a reading error
when xxx is not a keyword.
This allows to use State-savec files directly as parameter files
This commit is contained in:
evomarc 2001-05-08 03:49:35 +00:00
commit 42cb1981d5

View file

@ -142,61 +142,68 @@ void eoParser::updateParameters() const
void eoParser::readFrom(istream& is) void eoParser::readFrom(istream& is)
{ {
string str; string str;
// we must avoid processing \section{xxx} if xxx is NOT "Parser"
bool processing = true;
while (is >> str) while (is >> str)
{ {
if (str.find(string("\\section{"))==0) // found section begin
processing = (str.find(string("Parser"))<str.size());
if (str[0] == '#') if (processing) // right \section (or no \section at all)
{ // skip the rest of the line {
string tempStr; if (str[0] == '#')
getline(is, tempStr); { // skip the rest of the line
} string tempStr;
if (str[0] == '-') getline(is, tempStr);
{ }
if (str.size() < 2) if (str[0] == '-')
{ {
eoWarning("Missing parameter"); if (str.size() < 2)
needHelp.value() = true; {
return; eoWarning("Missing parameter");
} needHelp.value() = true;
return;
}
if (str[1] == '-') // two consecutive dashes if (str[1] == '-') // two consecutive dashes
{ {
string::iterator equalLocation = find(str.begin() + 2, str.end(), '='); string::iterator equalLocation = find(str.begin() + 2, str.end(), '=');
string value; string value;
if (equalLocation == str.end()) if (equalLocation == str.end())
{ // TODO: it should be the next string { // TODO: it should be the next string
value = ""; value = "";
} }
else else
{ {
value = string(equalLocation + 1, str.end()); value = string(equalLocation + 1, str.end());
} }
string name(str.begin() + 2, equalLocation); string name(str.begin() + 2, equalLocation);
longNameMap[name] = value; longNameMap[name] = value;
} }
else // it should be a char else // it should be a char
{ {
string value = "1"; // flags do not need a special string value = "1"; // flags do not need a special
if (str.size() >= 2) if (str.size() >= 2)
{ {
if (str[2] == '=') if (str[2] == '=')
{ {
if (str.size() >= 3) if (str.size() >= 3)
value = string(str.begin() + 3, str.end()); value = string(str.begin() + 3, str.end());
} }
else else
{ {
value = string(str.begin() + 2, str.end()); value = string(str.begin() + 2, str.end());
} }
} }
shortNameMap[str[1]] = value; shortNameMap[str[1]] = value;
} }
} }
}
} }
updateParameters(); updateParameters();