summaryrefslogtreecommitdiff
path: root/server/src/templateparser.cc
diff options
context:
space:
mode:
authordeva <deva>2008-05-20 14:03:10 +0000
committerdeva <deva>2008-05-20 14:03:10 +0000
commit556f00e4af55e78836c45f47b0662ab44bbb8b48 (patch)
treea5c315b35d400a397a35a86b86fe656d3a829af9 /server/src/templateparser.cc
parent91d56787bec83a3a7c2ad6afd84d2b82c5d869b9 (diff)
Made fixes pointed out by GCC 4.2 and -D_FORTIFY_SOURCES=2
Diffstat (limited to 'server/src/templateparser.cc')
-rw-r--r--server/src/templateparser.cc40
1 files changed, 16 insertions, 24 deletions
diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc
index 652a870..7a2a013 100644
--- a/server/src/templateparser.cc
+++ b/server/src/templateparser.cc
@@ -45,7 +45,7 @@
#include <errno.h>
-void TemplateParser::error(char* fmt, ...)
+void TemplateParser::error(const char* fmt, ...)
{
// TODO: Throw exception here.
@@ -66,7 +66,7 @@ TemplateParser::TemplateParser(std::string course)
current_macro = NULL;
current_map = NULL;
- std::string file = XML"/";
+ file = XML"/";
file.append(course);
file.append(".xml");
@@ -127,7 +127,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri
assert(t); // A Template has not yet been allocated, cannot create macro!
Macro m;
- // m.attributes = attributes;
+ m.attributes = attributes;
t->course.macroes.push_back(m);
current_macro = &(t->course.macroes.back());
@@ -195,9 +195,6 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri
current_macro->window.attributes["type"] = name;
Widget *current = &(current_macro->window);
-
- printf("%p %p\n", current); fflush(stdout);
-
widgetstack.push_back(current);
return;
@@ -213,21 +210,12 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri
w.attributes = attributes;
w.attributes["type"] = name;
- printf("1 %d\n", widgetstack.size() ); fflush(stdout);
-
Widget *parent = widgetstack.back();
-
- printf("%d\n", parent->widgets.size()); fflush(stdout);
-
parent->widgets.push_back(w);
-
- printf("2\n"); fflush(stdout);
Widget *current = &(parent->widgets.back());
widgetstack.push_back(current);
- printf("3\n"); fflush(stdout);
-
return;
}
@@ -258,23 +246,18 @@ void TemplateParser::endTag(std::string name)
if(name == "window") state = MACRO;
if(state == WINDOW) {
-
- printf("4\n"); fflush(stdout);
-
assert(widgetstack.size()); // Widget stack is empty, cannot pop!
widgetstack.pop_back();
-
- printf("5\n"); fflush(stdout);
-
if(widgetstack.size() == 0) state = MACRO;
-
- printf("6\n"); fflush(stdout);
}
}
int TemplateParser::readData(char *data, size_t size)
{
- if(fd == -1) return 0;
+ if(fd == -1) {
+ fprintf(stderr, "Invalid file descriptor.\n"); fflush(stderr);
+ return 0;
+ }
ssize_t r = read(fd, data, size);
if(r == -1) {
printf("Could not read...%s\n", strerror(errno)); fflush(stdout);
@@ -283,6 +266,15 @@ int TemplateParser::readData(char *data, size_t size)
return r;
}
+void TemplateParser::parseError(char *buf, size_t len, std::string error, int lineno)
+{
+ fprintf(stderr, "TemplateParser[%s] error at line %d: %s\n", file.c_str(), lineno, error.c_str());
+ fprintf(stderr, "\tBuffer %u bytes: [", len);
+ if(fwrite(buf, len, 1, stderr) != len) {}
+ fprintf(stderr, "]\n");
+ fflush(stderr);
+}
+
Template *TemplateParser::getTemplate()
{
return t;