diff options
author | Max Kellermann <max@duempel.org> | 2013-08-10 11:10:30 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-08-10 11:52:31 +0200 |
commit | 1c823e9d1f52ae54677bae884b1f5995292869f3 (patch) | |
tree | 8feab2a54efe07f3425c5684ca21699a9c7742c6 /src | |
parent | 25e338a098c66f08a1b6bb166cf06c0f6a2f21a8 (diff) |
ConfigData: overload GetBlockPath() with default value
Diffstat (limited to 'src')
-rw-r--r-- | src/ConfigData.cxx | 23 | ||||
-rw-r--r-- | src/ConfigData.hxx | 3 |
2 files changed, 21 insertions, 5 deletions
diff --git a/src/ConfigData.cxx b/src/ConfigData.cxx index eab5f0ed4..2ed8e2f3b 100644 --- a/src/ConfigData.cxx +++ b/src/ConfigData.cxx @@ -96,24 +96,37 @@ config_param::DupBlockString(const char *name, const char *default_value) const } Path -config_param::GetBlockPath(const char *name, GError **error_r) const +config_param::GetBlockPath(const char *name, const char *default_value, + GError **error_r) const { assert(error_r != nullptr); assert(*error_r == nullptr); + int line2 = line; + const char *s; + const block_param *bp = GetBlockParam(name); - if (bp == nullptr) - return Path::Null(); + if (bp != nullptr) { + line2 = bp->line; + s = bp->value.c_str(); + } else + s = default_value; - Path path = ParsePath(bp->value.c_str(), error_r); + Path path = ParsePath(s, error_r); if (gcc_unlikely(path.IsNull())) g_prefix_error(error_r, "Invalid path in \"%s\" at line %i: ", - name, bp->line); + name, line2); return path; } +Path +config_param::GetBlockPath(const char *name, GError **error_r) const +{ + return GetBlockPath(name, nullptr, error_r); +} + unsigned config_param::GetBlockValue(const char *name, unsigned default_value) const { diff --git a/src/ConfigData.hxx b/src/ConfigData.hxx index 4d9c0af79..a7a733e4d 100644 --- a/src/ConfigData.hxx +++ b/src/ConfigData.hxx @@ -112,6 +112,9 @@ struct config_param { * Same as config_dup_path(), but looks up the setting in the * specified block. */ + Path GetBlockPath(const char *name, const char *default_value, + GError **error_r) const; + Path GetBlockPath(const char *name, GError **error_r) const; gcc_pure |