From de4bd1760466a6ab7e5bb3088f2210615929b8e9 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 2 Nov 2009 12:49:03 +0000 Subject: New dump fields tool. --- server/src/macrotool_dump.cc | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/server/src/macrotool_dump.cc b/server/src/macrotool_dump.cc index f570a15..66b4ad7 100644 --- a/server/src/macrotool_dump.cc +++ b/server/src/macrotool_dump.cc @@ -44,10 +44,13 @@ #include "exception.h" +#include "database.h" + struct _macro { std::string name; std::string title; std::set templates; + std::vector fields; std::string file; std::string version; }; @@ -64,8 +67,26 @@ static const char usage_str[] = " help Prints this helptext.\n" " macros Writes macro names, versions, filenames, titles and template references to stdout.\n" " templates Writes template names, versions, filenames, titles and macro references to stdout.\n" +" fields Outputs all fields sorted by macro, with indication of those in the fieldnames table.\n" ; +static std::vector getFields(Widget &widget) +{ + std::vector fields; + + std::vector< Widget >::iterator w = widget.widgets.begin(); + while(w != widget.widgets.end()) { + std::vector fs = getFields(*w); + fields.insert(fields.end(), fs.begin(), fs.end()); + w++; + } + + if(widget.attributes.find("name") != widget.attributes.end()) + fields.push_back(widget.attributes["name"]); + + return fields; +} + static std::map macroList() { std::map macros; @@ -84,6 +105,7 @@ static std::map macroList() macros[key].name = macro->attributes["name"]; macros[key].file = *mfs; macros[key].title = macro->widgets.attributes["caption"]; + macros[key].fields = getFields(macro->widgets); macros[key].version = macro->attributes["version"]; } catch( Exception &e ) { printf("Skipping: %s: %s\n", mfs->c_str(), e.what()); @@ -116,6 +138,40 @@ static std::map macroList() return macros; } +static void dump_fields() +{ + Database db("pgsql", Conf::database_addr, "", Conf::database_user, Conf::database_passwd, ""); + std::vector fieldnames = db.getFieldnames(); + + std::map macros = macroList(); + std::map::iterator ms = macros.begin(); + while(ms != macros.end()) { + printf("Macro: %s\n", ms->second.name.c_str()); + + std::vector::iterator ts = ms->second.fields.begin(); + while(ts != ms->second.fields.end()) { + bool reg = false; + + std::vector::iterator fs = fieldnames.begin(); + while(fs != fieldnames.end()) { + if(*ts == fs->name) { + reg = true; + break; + } + fs++; + } + + printf("\t%s %s\n", reg?"(*)":" ", ts->c_str()); + ts++; + } + + printf("\n"); + ms++; + } + + printf("----\n(*) Indicates that the field is registered in the fieldnames table.\n"); +} + static void dump_macros() { std::map macros = macroList(); @@ -242,6 +298,16 @@ void macrotool_dump(std::vector params) PRACRO_DEBUG(fieldnames, "dump: %s\n", params[0].c_str()); + if(params[0] == "fields") { + if(params.size() != 1) { + printf("The command 'fields' doen't take any parameters.\n"); + printf(usage_str); + return; + } + dump_fields(); + return; + } + if(params[0] == "macros") { if(params.size() != 1) { printf("The command 'macro' doen't take any parameters.\n"); -- cgit v1.2.3