diff options
author | Max Kellermann <max@duempel.org> | 2015-12-16 11:05:33 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-12-18 01:08:16 +0100 |
commit | e6e7d6dbd654b9936b04f27b8153fb4ed945b9d3 (patch) | |
tree | ae4f965fd7a24ce01aad50117a5776610c861af6 /src/config | |
parent | fe60c52c70705b721bee7fbd6e3aae076a3b99c9 (diff) |
fs/io/Reader: use C++ exceptions instead of class Error
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/ConfigFile.cxx | 44 | ||||
-rw-r--r-- | src/config/ConfigFile.hxx | 4 | ||||
-rw-r--r-- | src/config/ConfigGlobal.cxx | 6 | ||||
-rw-r--r-- | src/config/ConfigGlobal.hxx | 4 |
4 files changed, 23 insertions, 35 deletions
diff --git a/src/config/ConfigFile.cxx b/src/config/ConfigFile.cxx index 844dc5bb9..364e2dd46 100644 --- a/src/config/ConfigFile.cxx +++ b/src/config/ConfigFile.cxx @@ -25,7 +25,6 @@ #include "ConfigTemplates.hxx" #include "util/Tokenizer.hxx" #include "util/StringUtil.hxx" -#include "util/Error.hxx" #include "util/Domain.hxx" #include "util/RuntimeError.hxx" #include "fs/Path.hxx" @@ -65,17 +64,14 @@ config_read_name_value(ConfigBlock &block, char *input, unsigned line) } static ConfigBlock * -config_read_block(BufferedReader &reader, Error &error) +config_read_block(BufferedReader &reader) try { std::unique_ptr<ConfigBlock> block(new ConfigBlock(reader.GetLineNumber())); while (true) { char *line = reader.ReadLine(); - if (line == nullptr) { - if (reader.Check(error)) - throw std::runtime_error("Expected '}' before end-of-file"); - return nullptr; - } + if (line == nullptr) + throw std::runtime_error("Expected '}' before end-of-file"); line = StripLeft(line); if (*line == 0 || *line == CONF_COMMENT) @@ -114,11 +110,10 @@ Append(ConfigBlock *&head, ConfigBlock *p) *i = p; } -static bool +static void ReadConfigBlock(ConfigData &config_data, BufferedReader &reader, const char *name, ConfigBlockOption o, - Tokenizer &tokenizer, - Error &error) + Tokenizer &tokenizer) { const unsigned i = unsigned(o); const ConfigTemplate &option = config_block_templates[i]; @@ -143,12 +138,9 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader, throw FormatRuntimeError("line %u: Unknown tokens after '{'", reader.GetLineNumber()); - auto *param = config_read_block(reader, error); - if (param == nullptr) - return false; - + auto *param = config_read_block(reader); + assert(param != nullptr); Append(head, param); - return true; } gcc_nonnull_all @@ -196,13 +188,13 @@ ReadConfigParam(ConfigData &config_data, BufferedReader &reader, Append(head, param); } -static bool -ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error) +static void +ReadConfigFile(ConfigData &config_data, BufferedReader &reader) { while (true) { char *line = reader.ReadLine(); if (line == nullptr) - return true; + return; line = StripLeft(line); if (*line == 0 || *line == CONF_COMMENT) @@ -224,9 +216,8 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error) ReadConfigParam(config_data, reader, name, o, tokenizer); } else if ((bo = ParseConfigBlockOptionName(name)) != ConfigBlockOption::MAX) { - if (!ReadConfigBlock(config_data, reader, name, bo, - tokenizer, error)) - return false; + ReadConfigBlock(config_data, reader, name, bo, + tokenizer); } else { throw FormatRuntimeError("unrecognized parameter in config file at " "line %u: %s\n", @@ -235,19 +226,16 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error) } } -bool -ReadConfigFile(ConfigData &config_data, Path path, Error &error) +void +ReadConfigFile(ConfigData &config_data, Path path) { assert(!path.IsNull()); const std::string path_utf8 = path.ToUTF8(); FormatDebug(config_file_domain, "loading file %s", path_utf8.c_str()); - FileReader file(path, error); - if (!file.IsDefined()) - return false; + FileReader file(path); BufferedReader reader(file); - return ReadConfigFile(config_data, reader, error) && - reader.Check(error); + ReadConfigFile(config_data, reader); } diff --git a/src/config/ConfigFile.hxx b/src/config/ConfigFile.hxx index 30bee0614..8aeb055d7 100644 --- a/src/config/ConfigFile.hxx +++ b/src/config/ConfigFile.hxx @@ -24,7 +24,7 @@ class Error; class Path; struct ConfigData; -bool -ReadConfigFile(ConfigData &data, Path path, Error &error); +void +ReadConfigFile(ConfigData &data, Path path); #endif diff --git a/src/config/ConfigGlobal.cxx b/src/config/ConfigGlobal.cxx index 192baffec..657f871eb 100644 --- a/src/config/ConfigGlobal.cxx +++ b/src/config/ConfigGlobal.cxx @@ -45,10 +45,10 @@ void config_global_init(void) { } -bool -ReadConfigFile(Path path, Error &error) +void +ReadConfigFile(Path path) { - return ReadConfigFile(config_data, path, error); + return ReadConfigFile(config_data, path); } static void diff --git a/src/config/ConfigGlobal.hxx b/src/config/ConfigGlobal.hxx index b24b9aada..622105248 100644 --- a/src/config/ConfigGlobal.hxx +++ b/src/config/ConfigGlobal.hxx @@ -42,8 +42,8 @@ config_global_finish(); void config_global_check(); -bool -ReadConfigFile(Path path, Error &error); +void +ReadConfigFile(Path path); gcc_pure const config_param * |