diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-01-25 09:43:09 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-01-25 10:14:44 -0800 |
commit | 34f0540da418b01dd4d49f6ecf72569d3cfecfdf (patch) | |
tree | bf7c4623b0d794e4db8c72b0906bb40807d62ba8 /src/monitor | |
parent | 9a4c3a44476f3306a8deed8a836e8fbc25ceb55f (diff) | |
download | tmwa-34f0540da418b01dd4d49f6ecf72569d3cfecfdf.tar.gz tmwa-34f0540da418b01dd4d49f6ecf72569d3cfecfdf.tar.bz2 tmwa-34f0540da418b01dd4d49f6ecf72569d3cfecfdf.tar.xz tmwa-34f0540da418b01dd4d49f6ecf72569d3cfecfdf.zip |
Implement unified config parsing (mostly)
Diffstat (limited to 'src/monitor')
-rw-r--r-- | src/monitor/main.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/monitor/main.cpp b/src/monitor/main.cpp index 934e24f..1bc9880 100644 --- a/src/monitor/main.cpp +++ b/src/monitor/main.cpp @@ -22,6 +22,7 @@ #include "../io/cxxstdio.hpp" #include "../io/read.hpp" +#include "../common/config_parse.hpp" #include "../common/utils.hpp" #include "../poison.hpp" @@ -57,7 +58,7 @@ FString make_path(XString base, XString path) } static -void parse_option(XString name, ZString value) +bool parse_option(XString name, ZString value) { if (name == "login_server") login_server = value; @@ -72,12 +73,15 @@ void parse_option(XString name, ZString value) FString name_ = name; FPRINTF(stderr, "WARNING: ingnoring invalid option '%s' : '%s'\n", name_, value); + return false; } + return true; } static -void read_config(ZString filename) +bool read_config(ZString filename) { + bool rv = true; io::ReadFile in(filename); if (!in.is_open()) { @@ -88,13 +92,25 @@ void read_config(ZString filename) FString line; while (in.getline(line)) { + if (is_comment(line)) + continue; XString name; ZString value; - if (!split_key_value(line, &name, &value)) + if (!config_split(line, &name, &value)) + { + PRINTF("Bad line: %s\n", line); + rv = false; continue; + } - parse_option(name, value); + if (!parse_option(name, value)) + { + PRINTF("Bad key/value: %s\n", line); + rv = false; + continue; + } } + return rv; } static |