summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/template.h2
-rw-r--r--server/src/templateparser.cc49
-rw-r--r--server/src/templateparser.h3
3 files changed, 54 insertions, 0 deletions
diff --git a/server/src/template.h b/server/src/template.h
index a069cff..e549ef3 100644
--- a/server/src/template.h
+++ b/server/src/template.h
@@ -84,6 +84,8 @@ public:
class Template {
public:
+ std::vector< Script > scripts;
+
std::vector< Macro > macros;
std::string name;
diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc
index b9c65f5..704b215 100644
--- a/server/src/templateparser.cc
+++ b/server/src/templateparser.cc
@@ -81,6 +81,10 @@ TemplateParser::~TemplateParser()
void TemplateParser::characterData(std::string &data)
{
+ if(state == SCRIPT) {
+ assert(current_script); // No script present!
+ current_script->code.append(data);
+ }
}
void TemplateParser::startTag(std::string name, attributes_t &attr)
@@ -127,6 +131,39 @@ void TemplateParser::startTag(std::string name, attributes_t &attr)
return;
}
+ // Enable script parsing
+ if(name == "scripts") {
+ if(state != MACRO) error("scripts found outside macro.");
+ state = SCRIPTS;
+
+ assert(t); // No template is currently available, cannot create maps!
+
+ return;
+ }
+
+ // Create script
+ if(name == "script") {
+
+ assert(t); // No template is currently available, cannot create script!
+
+ switch(state) {
+ case SCRIPTS:
+ {
+ state = SCRIPT;
+
+ Script s;
+ s.attributes = attr;
+ t->scripts.push_back(s);
+ current_script = &(t->scripts.back());
+ }
+ break;
+ default:
+ error("<script> tag found outside <scripts> or <resume> tags.");
+ break;
+ }
+ return;
+ }
+
error("Unknown/illegal tag: %s", name.c_str());
}
@@ -137,6 +174,18 @@ void TemplateParser::endTag(std::string name)
current_macro = NULL;
state = TEMPLATE;
}
+ if(name == "scripts") state = TEMPLATE;
+ if(name == "script") {
+ switch(state) {
+ case SCRIPT:
+ current_script = NULL;
+ state = SCRIPTS;
+ break;
+ default:
+ // tag mismatch?
+ break;
+ }
+ }
}
int TemplateParser::readData(char *data, size_t size)
diff --git a/server/src/templateparser.h b/server/src/templateparser.h
index 5b8302f..89f4917 100644
--- a/server/src/templateparser.h
+++ b/server/src/templateparser.h
@@ -34,6 +34,8 @@ typedef enum {
UNDEFINED,
TEMPLATE,
MACRO,
+ SCRIPTS,
+ SCRIPT
} ParserState;
class TemplateParser : public SAXParser {
@@ -60,6 +62,7 @@ private:
ParserState state;
Template *t;
Macro *current_macro;
+ Script *current_script;
std::vector< Widget* > widgetstack;
// Error callback function.