summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authordeva <deva>2009-07-06 13:50:56 +0000
committerdeva <deva>2009-07-06 13:50:56 +0000
commitca32aba4df1b021b1acaa8f0650fa6a0cd7b9d80 (patch)
treec5556cefdc68846cf3c3343d54ae964c43ba65ec /server
parentce3ee895ae8c893c0202e4cddb068dce9919cd0d (diff)
Rewrite of parameter handler. A new fieldnames module... currently does nothing useful.
Diffstat (limited to 'server')
-rw-r--r--server/src/Makefile.am3
-rw-r--r--server/src/macrotool.cc23
-rw-r--r--server/src/macrotool_dump.cc30
-rw-r--r--server/src/macrotool_dump.h3
-rw-r--r--server/src/macrotool_fieldnames.cc80
-rw-r--r--server/src/macrotool_fieldnames.h36
6 files changed, 158 insertions, 17 deletions
diff --git a/server/src/Makefile.am b/server/src/Makefile.am
index 768f563..c1ba9e4 100644
--- a/server/src/Makefile.am
+++ b/server/src/Makefile.am
@@ -47,6 +47,7 @@ macrotool_SOURCES = \
log.cc \
macroparser.cc \
macrotool_dump.cc \
+ macrotool_fieldnames.cc \
pracrodao.cc \
pracrodaopgsql.cc \
saxparser.cc \
@@ -69,6 +70,8 @@ EXTRA_DIST = \
luaquerymapper.h \
luaresume.h \
macroparser.h \
+ macrotool_dump.h \
+ macrotool_fieldnames.h \
pracrodao.h \
pracrodaopgsql.h \
resumeparser.h \
diff --git a/server/src/macrotool.cc b/server/src/macrotool.cc
index 46fbc24..44beeef 100644
--- a/server/src/macrotool.cc
+++ b/server/src/macrotool.cc
@@ -31,12 +31,16 @@
// For getopt_long and friends
#include <getopt.h>
+#include <vector>
+#include <string>
+
#include "configurationparser.h"
#include "configuration.h"
#include "debug.h"
#include "macrotool_dump.h"
+#include "macrotool_fieldnames.h"
static const char version_str[] =
"Pracro server v" VERSION "\n"
@@ -62,6 +66,8 @@ static const char usage_str[] =
"\n"
"Commands:\n"
" dump entity Dumps 'entity' to screen ('dump help' to see list of entities).\n"
+" fieldnames entity Add/delete/update entries in the fieldnames database\n"
+" ('fieldnames help' to see list of entities).\n"
;
ConfigurationParser *configparser = NULL;
@@ -125,8 +131,6 @@ int main(int argc, char *argv[])
printf(usage_str, argv[0]);
exit(EXIT_FAILURE);
}
-
- std::string command = argv[optind];
if(debugstr) {
pracro_debug_parse(debugstr);
@@ -140,16 +144,15 @@ int main(int argc, char *argv[])
Conf::xml_basedir = xml_basedir;
}
- if(command == "dump") {
- optind++;
- if(optind >= argc) {
- fprintf(stderr, "Missing command parameter\n");
- printf(usage_str, argv[0]);
- exit(EXIT_FAILURE);
- }
- macrotool_dump(argv[optind]);
+ std::string command = argv[optind++];
+ std::vector<std::string> params;
+ while(optind < argc) {
+ params.push_back(argv[optind++]);
}
+ if(command == "dump") macrotool_dump(params);
+ if(command == "fieldnames") macrotool_fieldnames(params);
+
// Clean up
if(configfile) free(configfile);
diff --git a/server/src/macrotool_dump.cc b/server/src/macrotool_dump.cc
index 93a96a3..9248d03 100644
--- a/server/src/macrotool_dump.cc
+++ b/server/src/macrotool_dump.cc
@@ -264,23 +264,41 @@ static void dump_templates()
}
}
-void macrotool_dump(std::string param)
+void macrotool_dump(std::vector<std::string> params)
{
- PRACRO_DEBUG(dump, "dump: %s\n", param.c_str());
-
- if(param == "help") {
+ if(params.size() < 1) {
printf(usage_str);
return;
}
- if(param == "macros") {
+ PRACRO_DEBUG(fieldnames, "dump: %s\n", params[0].c_str());
+
+ if(params[0] == "macros") {
+ if(params.size() != 1) {
+ printf("The command 'macro' doen't take any parameters.\n");
+ printf(usage_str);
+ return;
+ }
dump_macros();
return;
}
- if(param == "templates") {
+ if(params[0] == "templates") {
+ if(params.size() != 1) {
+ printf("The command 'templates' doen't take any parameters.\n");
+ printf(usage_str);
+ return;
+ }
dump_templates();
return;
}
+ if(params[0] == "help") {
+ printf(usage_str);
+ return;
+ }
+
+ printf("Unknown command '%s'\n", params[0].c_str());
+ printf(usage_str);
+ return;
}
diff --git a/server/src/macrotool_dump.h b/server/src/macrotool_dump.h
index cc5adff..1f2101d 100644
--- a/server/src/macrotool_dump.h
+++ b/server/src/macrotool_dump.h
@@ -28,8 +28,9 @@
#ifndef __PRACRO_MACROTOOL_DUMP_H__
#define __PRACRO_MACROTOOL_DUMP_H__
+#include <vector>
#include <string>
-void macrotool_dump(std::string param);
+void macrotool_dump(std::vector<std::string> params);
#endif/*__PRACRO_MACROTOOL_DUMP_H__*/
diff --git a/server/src/macrotool_fieldnames.cc b/server/src/macrotool_fieldnames.cc
new file mode 100644
index 0000000..f2475f2
--- /dev/null
+++ b/server/src/macrotool_fieldnames.cc
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * macrotool_fieldnames.cc
+ *
+ * Mon Jul 6 14:15:05 CEST 2009
+ * Copyright 2009 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "macrotool_fieldnames.h"
+
+#include "debug.h"
+
+#include "pracrodaopgsql.h"
+#include "configuration.h"
+
+static const char usage_str[] =
+" help Prints this helptext.\n"
+" set name desc Add a field (or update) called 'name', described as 'desc'\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());
+ PracroDAOPgsql sql(Conf::database_addr, "",
+ Conf::database_user,
+ Conf::database_passwd, "");
+#else /*WITHOUT_DB*/
+ printf("Project not compiled with db spport.")
+#endif/*WITHOUT_DB*/
+
+}
+
+void macrotool_fieldnames(std::vector<std::string> params)
+{
+ if(params.size() < 1) {
+ printf(usage_str);
+ return;
+ }
+
+ PRACRO_DEBUG(fieldnames, "fieldnames: %s\n", params[0].c_str());
+
+ if(params[0] == "set") {
+ if(params.size() != 3) {
+ printf("The command 'set' needs 2 parameters.\n");
+ printf(usage_str);
+ return;
+ }
+ add(params[1], params[2]);
+ return;
+ }
+
+ if(params[0] == "help") {
+ printf(usage_str);
+ return;
+ }
+
+ printf("Unknown command '%s'\n", params[0].c_str());
+ printf(usage_str);
+ return;
+}
diff --git a/server/src/macrotool_fieldnames.h b/server/src/macrotool_fieldnames.h
new file mode 100644
index 0000000..0ac2759
--- /dev/null
+++ b/server/src/macrotool_fieldnames.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * macrotool_fieldnames.h
+ *
+ * Mon Jul 6 14:15:05 CEST 2009
+ * Copyright 2009 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_MACROTOOL_FIELDNAMES_H__
+#define __PRACRO_MACROTOOL_FIELDNAMES_H__
+
+#include <vector>
+#include <string>
+
+void macrotool_fieldnames(std::vector<std::string> params);
+
+#endif/*__PRACRO_MACROTOOL_FIELDNAMES_H__*/