From 13bcf233f1c74eba70017a6964e0a2c6514c9130 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Sun, 26 Oct 2003 22:42:45 -0500 Subject: [PATCH] Add an append= keyword that works in a somewhat similar way to default=. In the append= case, when looking up an entry, it also looks in the section named by the append= for something to append to the entry --HG-- extra : convert_revision : b51915094ad3ca151d7f241c29e19b6b29d3a3c0 --- base/inifile.cc | 30 ++++++++++++++++++++++++++++-- base/inifile.hh | 3 +++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/base/inifile.cc b/base/inifile.cc index 52468f46e..7e7485bcb 100644 --- a/base/inifile.cc +++ b/base/inifile.cc @@ -367,14 +367,40 @@ IniFile::findDefault(const string &_section, const string &entry, string &value) const { string section = _section; - while (!find(section, entry, value)) { - if (!find(section, "default", section)) + while (!findAppend(section, entry, value)) { + if (!find(section, "default", section)) { return false; + } } return true; } +bool +IniFile::findAppend(const string &_section, const string &entry, + string &value) const +{ + string section = _section; + bool ret = false; + bool first = true; + + do { + string val; + if (find(section, entry, val)) { + ret = true; + if (first) { + value = val; + first = false; + } else { + value += " "; + value += val; + } + + } + } while (find(section, "append", section)); + + return ret; +} bool IniFile::Section::printUnreferenced(const string §ionName) diff --git a/base/inifile.hh b/base/inifile.hh index 3a82f2d4d..34424eb4b 100644 --- a/base/inifile.hh +++ b/base/inifile.hh @@ -196,6 +196,9 @@ class IniFile bool findDefault(const std::string §ion, const std::string &entry, std::string &value) const; + bool findAppend(const std::string §ion, const std::string &entry, + std::string &value) const; + /// Print unreferenced entries in object. Iteratively calls /// printUnreferend() on all the constituent sections. bool printUnreferenced(); -- 2.30.2