From 684da169482b10b7a5cf6e6ce7c87537d9848cc5 Mon Sep 17 00:00:00 2001 From: dockes Date: Thu, 29 Oct 2009 18:09:37 +0000 Subject: [PATCH] support wildcard filtering in getConfNames() + implement config checking function in test driver --- src/common/rclconfig.cpp | 47 +++++++++++++++++++++++++++++++++++----- src/common/rclconfig.h | 10 ++++++--- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index d0ada65c..9c942112 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -934,13 +934,15 @@ using namespace std; static char *thisprog; -static char usage [] = -" \n\n" +static char usage [] = "\n" +"-c: check a few things in the configuration files\n" +"[-s subkey] -q param : query parameter value\n" +" : default: print parameters\n" ; static void Usage(void) { - fprintf(stderr, "%s: usage:\n%s [-s subkey] [-q param]", thisprog, usage); + fprintf(stderr, "%s: usage: %s\n", thisprog, usage); exit(1); } @@ -948,7 +950,7 @@ static int op_flags; #define OPT_MOINS 0x1 #define OPT_s 0x2 #define OPT_q 0x4 - +#define OPT_c 0x8 int main(int argc, char **argv) { string pname, skey; @@ -963,6 +965,7 @@ int main(int argc, char **argv) Usage(); while (**argv) switch (*(*argv)++) { + case 'c': op_flags |= OPT_c; break; case 's': op_flags |= OPT_s; if (argc < 2) Usage(); skey = *(++argv); argc--; @@ -994,8 +997,42 @@ int main(int argc, char **argv) exit(1); } printf("[%s] -> [%s]\n", pname.c_str(), value.c_str()); + } else if (op_flags & OPT_c) { + // Check that all known mime types have an icon and belong to + // some category + list catnames; + config->getMimeCategories(catnames); + cout << "Categories: "; + set allmtsfromcats; + for (list::const_iterator it = catnames.begin(); + it != catnames.end(); it++) { + cout << *it << " "; + } + cout << endl; + for (list::const_iterator it = catnames.begin(); + it != catnames.end(); it++) { + list cts; + config->getMimeCatTypes(*it, cts); + for (list::const_iterator it1 = cts.begin(); + it1 != cts.end(); it1++) { + // Already in map -> duplicate + if (allmtsfromcats.find(*it1) != allmtsfromcats.end()) { + cout << "Duplicate: [" << *it1 << "]" << endl; + } + allmtsfromcats.insert(*it1); + } + } + + list mtypes = config->getAllMimeTypes(); + for (list::const_iterator it = mtypes.begin(); + it != mtypes.end(); it++) { + if (allmtsfromcats.find(*it) == allmtsfromcats.end()) { + cout << "Not found in catgs: [" << *it << "]" << endl; + } + } } else { - list names = config->getConfNames(""); + config->setKeyDir(""); + list names = config->getConfNames(); names.sort(); names.unique(); for (list::iterator it = names.begin(); diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 4ce03c73..cf7a829e 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -83,6 +83,13 @@ class RclConfig { /** Variant with autoconversion to bool */ bool getConfParam(const std::string &name, bool *value); + /** + * Get list of config names under current sk, with possible + * wildcard filtering + */ + list getConfNames(const char *pattern = 0) { + return m_conf->getNames(m_keydir, pattern); + } /** Get default charset for current keydir (was set during setKeydir) * filenames are handled differently */ const string &getDefCharset(bool filename = false); @@ -187,9 +194,6 @@ class RclConfig { } return *this; } - list getConfNames(const string &sk) { - return m_conf->getNames(sk); - } private: int m_ok;