summaryrefslogtreecommitdiff
path: root/server/src/macrotool_fieldnames.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/macrotool_fieldnames.cc')
-rw-r--r--server/src/macrotool_fieldnames.cc119
1 files changed, 115 insertions, 4 deletions
diff --git a/server/src/macrotool_fieldnames.cc b/server/src/macrotool_fieldnames.cc
index f2475f2..eeed648 100644
--- a/server/src/macrotool_fieldnames.cc
+++ b/server/src/macrotool_fieldnames.cc
@@ -27,9 +27,12 @@
*/
#include "macrotool_fieldnames.h"
+#include "macrotool_util.h"
+#include "macroparser.h"
+
#include "debug.h"
-#include "pracrodaopgsql.h"
+#include "database.h"
#include "configuration.h"
static const char usage_str[] =
@@ -41,15 +44,113 @@ static void add(std::string name, std::string desc)
{
#ifndef WITHOUT_DB
PRACRO_DEBUG("SET (name: %s - desc: %s)\n", name.c_str(), desc.c_str());
- PracroDAOPgsql sql(Conf::database_addr, "",
- Conf::database_user,
- Conf::database_passwd, "");
#else /*WITHOUT_DB*/
printf("Project not compiled with db spport.")
#endif/*WITHOUT_DB*/
}
+static std::vector<std::string> getWidgetNames(Widget &w)
+{
+ std::vector<std::string> v;
+ if(w.attributes.find("name") != w.attributes.end()) v.push_back(w.attributes["name"]);
+
+ std::vector< Widget >::iterator i = w.widgets.begin();
+ while(i != w.widgets.end()) {
+ std::vector<std::string> _v = getWidgetNames(*i);
+ v.insert(v.end(), _v.begin(), _v.end());
+ i++;
+ }
+
+ return v;
+}
+
+static std::map<std::string, std::vector<std::string> > getMacroRefsList()
+{
+ std::map<std::string, std::vector<std::string> > reflist;
+
+ std::vector<std::string> macrofiles = getMacros();
+ std::vector<std::string>::iterator mfs = macrofiles.begin();
+ while(mfs != macrofiles.end()) {
+ std::string name = mfs->substr(0, mfs->length() - 4);
+
+ MacroParser parser(name);
+ parser.parse();
+ Macro *macro = parser.getMacro();
+
+ std::string key = name;
+ reflist[key] = getWidgetNames(macro->window);
+
+ mfs++;
+ }
+
+ return reflist;
+}
+
+static std::vector<std::string> getMacroRefs(std::map<std::string, std::vector<std::string> > reflist, std::string name)
+{
+ std::vector<std::string> macros;
+ std::map<std::string, std::vector<std::string> >::iterator macro = reflist.begin();
+ while(macro != reflist.end()) {
+ std::vector<std::string>::iterator field = macro->second.begin();
+ while(field != macro->second.end()) {
+ if(*field == name) macros.push_back(macro->first);
+ field++;
+ }
+ macro++;
+ }
+ return macros;
+}
+
+static void list()
+{
+ Database db("pgsql", Conf::database_addr, "", Conf::database_user, Conf::database_passwd, "");
+
+ std::vector<Fieldname> fieldnames = db.getFieldnames();
+
+ std::map<std::string, std::vector<std::string> > reflist = getMacroRefsList();
+
+ size_t name_sz = 0;
+ size_t desc_sz = 0;
+ size_t time_sz = 0;
+
+ std::vector<Fieldname>::iterator i = fieldnames.begin();
+ while(i != fieldnames.end()) {
+ if(i->name.length() > name_sz) name_sz = i->name.length();
+ if(i->description.length() > desc_sz) desc_sz = i->description.length();
+ char ts[32];
+ sprintf(ts, "%u", (unsigned int)i->timestamp);
+ if(strlen(ts) > time_sz) time_sz = strlen(ts);
+ i++;
+ }
+
+ printcolumn("Name:", name_sz);
+ printcolumn("Description:", desc_sz);
+ printcolumn("Timestamp:", time_sz);
+ printf("Macros:");
+ printf("\n");
+
+ i = fieldnames.begin();
+ while(i != fieldnames.end()) {
+ printcolumn(i->name, name_sz);
+ printcolumn(i->description, desc_sz);
+ char ts[32];
+ sprintf(ts, "%u", (unsigned int)i->timestamp);
+ printcolumn(ts, time_sz);
+
+ std::vector<std::string> macros = getMacroRefs(reflist, i->name);
+ std::vector<std::string>::iterator j = macros.begin();
+ while(j != macros.end()) {
+ if(j != macros.begin()) printf(", ");
+ printf("%s", j->c_str());
+ j++;
+ }
+
+ printf("\n");
+ i++;
+ }
+}
+
void macrotool_fieldnames(std::vector<std::string> params)
{
if(params.size() < 1) {
@@ -59,6 +160,16 @@ void macrotool_fieldnames(std::vector<std::string> params)
PRACRO_DEBUG(fieldnames, "fieldnames: %s\n", params[0].c_str());
+ if(params[0] == "list") {
+ if(params.size() != 1) {
+ printf("The command 'list' does not need any parameters.\n");
+ printf(usage_str);
+ return;
+ }
+ list();
+ return;
+ }
+
if(params[0] == "set") {
if(params.size() != 3) {
printf("The command 'set' needs 2 parameters.\n");