aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Stephen P. Bennett <spb@exherbo.org> 2006-04-10 03:04:11 +0000
committerAvatar Stephen P. Bennett <spb@exherbo.org> 2006-04-10 03:04:11 +0000
commit75927fb161a68059960a19e2d53ec1c37be13c7e (patch)
treeb883784881527a01ce181bb1b252a7942d3fe147
parent9fc013bc98eb721fa65f500a263383eae01f5fa3 (diff)
downloadpaludis-75927fb161a68059960a19e2d53ec1c37be13c7e.tar.gz
paludis-75927fb161a68059960a19e2d53ec1c37be13c7e.tar.xz
Add support for line-continuation in config files
-rw-r--r--paludis/config_file.cc22
-rw-r--r--paludis/config_file_TEST.cc11
2 files changed, 30 insertions, 3 deletions
diff --git a/paludis/config_file.cc b/paludis/config_file.cc
index ea363c9..391915e 100644
--- a/paludis/config_file.cc
+++ b/paludis/config_file.cc
@@ -77,19 +77,35 @@ ConfigFile::need_lines() const
if (_has_lines)
return;
- std::string line;
+ std::string line, accum;
unsigned line_number(0);
while (std::getline(*_stream, line))
{
Context c("When handling line " + stringify(++line_number) +
(_filename.empty() ? std::string(":") : " in file '" + _filename + "':"));
normalise_line(line);
- if (skip_line(line))
+
+ if (line.empty() || skip_line(line))
+ {
+ if (!accum.empty())
+ throw ConfigFileError("Line-continuation followed by a blank line or comment is invalid.");
+
+ continue;
+ }
+ if ('\\' == line.at(line.length() - 1))
+ {
+ line.erase(line.length() - 1);
+ accum += line;
continue;
- accept_line(line);
+ }
+
+ accept_line(accum + line);
+ accum.clear();
}
if (! _stream->eof())
throw ConfigFileError("Error reading from file");
+ if (! accum.empty())
+ throw ConfigFileError("Line-continuation needs a continuation.");
_has_lines = true;
}
diff --git a/paludis/config_file_TEST.cc b/paludis/config_file_TEST.cc
index c07c68b..b468377 100644
--- a/paludis/config_file_TEST.cc
+++ b/paludis/config_file_TEST.cc
@@ -219,6 +219,8 @@ namespace test_cases
t << "c=$d" << std::endl;
t << "d=$d" << std::endl;
t << "f = " << std::endl;
+ t << "g = foo \\" << std::endl;
+ t << " bar" << std::endl;
KeyValueConfigFile fg(&t, t_defs);
TEST_CHECK_EQUAL(fg.get("a"), "foo");
@@ -227,6 +229,7 @@ namespace test_cases
TEST_CHECK_EQUAL(fg.get("d"), "bar");
TEST_CHECK_EQUAL(fg.get("e"), "baz");
TEST_CHECK_EQUAL(fg.get("f"), "");
+ TEST_CHECK_EQUAL(fg.get("g"), "foo bar");
}
} test_key_value_config_file_vars;
@@ -264,6 +267,14 @@ namespace test_cases
std::stringstream s6;
s6 << "x=$" << std::endl;
TEST_CHECK_THROWS(KeyValueConfigFile ff(&s6), ConfigurationError);
+
+ std::stringstream s7;
+ s7 << "x=blah \\" << std::endl;
+ TEST_CHECK_THROWS(KeyValueConfigFile ff(&s7), ConfigurationError);
+
+ std::stringstream s8;
+ s8 << "x=blah \\" << std::endl << "# foo" << std::endl;
+ TEST_CHECK_THROWS(KeyValueConfigFile ff(&s8), ConfigurationError);
}
} test_key_value_config_file_errors;
}