From 4fc0fe750e011e3de47dd627778e4652643202ae Mon Sep 17 00:00:00 2001 From: Ian Stakenvicius Date: Fri, 24 Feb 2017 11:59:54 -0500 Subject: [PATCH] Allow multi-line config file options This commit represents another difference found in the final release of iwamatsu's slim-1.3.6 that I cannot trace the origins of. This code extends Cfg::readConf() to allow for the proper parsing of multi-line configuration options when lines termiate with '\'. --- cfg.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cfg.cpp b/cfg.cpp index 1c2dc9a..d3fbc4e 100644 --- a/cfg.cpp +++ b/cfg.cpp @@ -148,12 +148,26 @@ Cfg::~Cfg() { */ bool Cfg::readConf(string configfile) { int n = -1; - string line, fn(configfile); + size_t pos = 0; + string line, next, op, fn(configfile); map::iterator it; - string op; ifstream cfgfile( fn.c_str() ); if (cfgfile) { while (getline( cfgfile, line )) { + // Allow multi-line options when line terminated with '\' + if ((pos = line.find('\\')) != string::npos) { + if (line.length() == pos + 1) { + line.replace(pos,1," "); + next = next + line; + continue; + } else + line.replace(pos, line.length() - pos, " "); + } + if (!next.empty()) { + line = next + line; + next = ""; + } + it = options.begin(); while (it != options.end()) { op = it->first;