From 177cea995d02fd14dd82fa010957ebfbc1c5e760 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 17 Jul 2009 13:02:45 +0000 Subject: More work on the macrotool. Now fieldnames can be added and deleted, and a filehandler is able to add new macros assuring no conflicts in macro names/version/filenames happen. Error messages in MacroParser has been made more elaborate. --- server/src/macrotool_fieldnames.cc | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'server/src/macrotool_fieldnames.cc') diff --git a/server/src/macrotool_fieldnames.cc b/server/src/macrotool_fieldnames.cc index eeed648..3c3f8b7 100644 --- a/server/src/macrotool_fieldnames.cc +++ b/server/src/macrotool_fieldnames.cc @@ -37,17 +37,21 @@ static const char usage_str[] = " help Prints this helptext.\n" -" set name desc Add a field (or update) called 'name', described as 'desc'\n" +" add name desc Add a field called 'name', described as 'desc'\n" +" del name Delete a field called 'name'\n" +" list List all fieldnames as well as their macro references.\n" ; 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()); -#else /*WITHOUT_DB*/ - printf("Project not compiled with db spport.") -#endif/*WITHOUT_DB*/ + Database db("pgsql", Conf::database_addr, "", Conf::database_user, Conf::database_passwd, ""); + db.addFieldname(name, desc); +} +static void del(std::string name) +{ + Database db("pgsql", Conf::database_addr, "", Conf::database_user, Conf::database_passwd, ""); + db.delFieldname(name); } static std::vector getWidgetNames(Widget &w) @@ -170,9 +174,9 @@ void macrotool_fieldnames(std::vector params) return; } - if(params[0] == "set") { + if(params[0] == "add") { if(params.size() != 3) { - printf("The command 'set' needs 2 parameters.\n"); + printf("The command 'add' needs 2 parameters.\n"); printf(usage_str); return; } @@ -180,6 +184,16 @@ void macrotool_fieldnames(std::vector params) return; } + if(params[0] == "del") { + if(params.size() != 2) { + printf("The command 'del' needs 1 parameter.\n"); + printf(usage_str); + return; + } + del(params[1]); + return; + } + if(params[0] == "help") { printf(usage_str); return; -- cgit v1.2.3