summaryrefslogtreecommitdiff
path: root/server/src/macrotool_dump.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/macrotool_dump.cc')
-rw-r--r--server/src/macrotool_dump.cc66
1 files changed, 66 insertions, 0 deletions
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<std::string> templates;
+ std::vector<std::string> 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<std::string> getFields(Widget &widget)
+{
+ std::vector<std::string> fields;
+
+ std::vector< Widget >::iterator w = widget.widgets.begin();
+ while(w != widget.widgets.end()) {
+ std::vector<std::string> 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<std::string, struct _macro> macroList()
{
std::map<std::string, struct _macro> macros;
@@ -84,6 +105,7 @@ static std::map<std::string, struct _macro> 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<std::string, struct _macro> macroList()
return macros;
}
+static void dump_fields()
+{
+ Database db("pgsql", Conf::database_addr, "", Conf::database_user, Conf::database_passwd, "");
+ std::vector<Fieldname> fieldnames = db.getFieldnames();
+
+ std::map<std::string, struct _macro> macros = macroList();
+ std::map<std::string, struct _macro>::iterator ms = macros.begin();
+ while(ms != macros.end()) {
+ printf("Macro: %s\n", ms->second.name.c_str());
+
+ std::vector<std::string>::iterator ts = ms->second.fields.begin();
+ while(ts != ms->second.fields.end()) {
+ bool reg = false;
+
+ std::vector<Fieldname>::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<std::string, struct _macro> macros = macroList();
@@ -242,6 +298,16 @@ void macrotool_dump(std::vector<std::string> 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");