diff options
Diffstat (limited to 'examples/cmdline/lookup.cpp')
-rw-r--r-- | examples/cmdline/lookup.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/examples/cmdline/lookup.cpp b/examples/cmdline/lookup.cpp new file mode 100644 index 0000000..6f67ed7 --- /dev/null +++ b/examples/cmdline/lookup.cpp @@ -0,0 +1,51 @@ +#include <stdio.h> +#include <iostream> +#include <stdlib.h> +#include <swmgr.h> + +int main(int argc, char **argv) +{ + SWMgr manager; + SWModule *target; + ModMap::iterator it; + + if (argc != 3) { + fprintf(stderr, "usage: %s <modname> <\"lookup key\">\n", argv[0]); + exit(-1); + } + + it = manager.Modules.find(argv[1]); + if (it == manager.Modules.end()) { + fprintf(stderr, "Could not find module [%s]. Available modules:\n", argv[1]); + for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) { + fprintf(stderr, "[%s]\t - %s\n", (*it).second->Name(), (*it).second->Description()); + } + exit(-1); + } + + target = (*it).second; + + target->SetKey(argv[2]); + + (const char *)*target; // force an entry lookup to resolve key so we + // get the idxbuf entry for the key + std::cout << (const char *)(SWKey &)*target << ":\n"; + std::cout << target->StripText(); + std::cout << "\n"; + std::cout << "==========================\n"; + std::cout << "Entry Attributes:\n\n"; + AttributeTypeList::iterator i1; + AttributeList::iterator i2; + AttributeValue::iterator i3; + for (i1 = target->getEntryAttributes().begin(); i1 != target->getEntryAttributes().end(); i1++) { + std::cout << "[ " << i1->first << " ]\n"; + for (i2 = i1->second.begin(); i2 != i1->second.end(); i2++) { + std::cout << "\t[ " << i2->first << " ]\n"; + for (i3 = i2->second.begin(); i3 != i2->second.end(); i3++) { + std::cout << "\t\t" << i3->first << " = " << i3->second << "\n"; + } + } + } + std::cout << std::endl; + return 0; +} |