diff --git a/src/utils/conftree.cpp b/src/utils/conftree.cpp index 01e77ef4..bd4a0f0a 100755 --- a/src/utils/conftree.cpp +++ b/src/utils/conftree.cpp @@ -25,6 +25,7 @@ static char rcsid [] = "@(#$Id: conftree.cpp,v 1.16 2008-07-01 11:51:51 dockes E #include // for access(2) #include +#include #include #include @@ -59,6 +60,7 @@ void ConfSimple::parseinput(istream &input) char cline[LL]; bool appending = false; string line; + bool eof = false; for (;;) { input.getline(cline, LL-1); @@ -68,21 +70,31 @@ void ConfSimple::parseinput(istream &input) status = STATUS_ERROR; return; } - // Must be eof ? + // Must be eof ? But maybe we have a partial line which + // must be processed. This happens if the last line before + // eof ends with a backslash + if (appending) { + eof = true; + goto processline; + } + break; } - int ll = strlen(cline); - while (ll > 0 && (cline[ll-1] == '\n' || cline[ll-1] == '\r')) { - cline[ll-1] = 0; - ll--; - } + { + int ll = strlen(cline); + while (ll > 0 && (cline[ll-1] == '\n' || cline[ll-1] == '\r')) { + cline[ll-1] = 0; + ll--; + } + } if (appending) line += cline; else line = cline; + processline: // Note that we trim whitespace before checking for backslash-eol // This avoids invisible problems. trimstring(line); @@ -130,6 +142,8 @@ void ConfSimple::parseinput(istream &input) continue; } i_set(nm, val, submapkey, true); + if (eof == true) + break; } } @@ -483,7 +497,7 @@ void ConfSimple::listall() write(std::cout); } -list ConfSimple::getNames(const string &sk) +list ConfSimple::getNames(const string &sk, const char *pattern) { std::list mylist; if (!ok()) @@ -494,6 +508,8 @@ list ConfSimple::getNames(const string &sk) } map::const_iterator it; for (it = ss->second.begin();it != ss->second.end();it++) { + if (pattern && FNM_NOMATCH == fnmatch(pattern, it->first.c_str(), 0)) + continue; mylist.push_back(it->first); } mylist.sort(); @@ -992,10 +1008,16 @@ int main(int argc, char **argv) //printf("WALK\n");conf->sortwalk(mywalker, 0); printf("\nNAMES in global space:\n"); list names = conf->getNames(""); - for (list::iterator it = names.begin();it!=names.end(); - it++) - printf("%s\n", (*it).c_str()); - + for (list::iterator it = names.begin(); + it!=names.end(); it++) + cout << *it << " "; + cout << endl; + printf("\nNAMES in global space matching t* \n"); + names = conf->getNames("", "t*"); + for (list::iterator it = names.begin(); + it!=names.end(); it++) + cout << *it << " "; + cout << endl; } } diff --git a/src/utils/conftree.h b/src/utils/conftree.h index 7b60c914..e93ac208 100755 --- a/src/utils/conftree.h +++ b/src/utils/conftree.h @@ -99,7 +99,7 @@ public: virtual int set(const string &nm, const string &val, const string &sk = string()) = 0; virtual bool ok() = 0; - virtual list getNames(const string &sk) = 0; + virtual list getNames(const string &sk, const char* = 0) = 0; virtual int erase(const string &, const string &) = 0; virtual int eraseKey(const string &) = 0; virtual void listall() {}; @@ -193,10 +193,8 @@ public: /** List all values to stdout */ virtual void listall(); - /** - * Return all names in given submap - */ - virtual list getNames(const string &sk); + /** Return all names in given submap. */ + virtual list getNames(const string &sk, const char *pattern = 0); /** * Return all subkeys @@ -272,6 +270,9 @@ private: * NOTE: contrary to common behaviour, the global or root space is NOT * designated by '/' but by '' (empty subkey). A '/' subkey will not * be searched at all. + * + * Note: getNames() : uses ConfSimple method, this does *not* inherit + * names from englobing submaps. */ class ConfTree : public ConfSimple { @@ -405,13 +406,13 @@ public: return m_confs.front()->holdWrites(on); } - virtual list getNames(const string &sk) + virtual list getNames(const string &sk, const char *pattern = 0) { list nms; typename list::iterator it; for (it = m_confs.begin();it != m_confs.end(); it++) { list lst; - lst = (*it)->getNames(sk); + lst = (*it)->getNames(sk, pattern); nms.insert(nms.end(), lst.begin(), lst.end()); } nms.sort();