summaryrefslogtreecommitdiff
path: root/src/msgparser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/msgparser.cc')
-rw-r--r--src/msgparser.cc102
1 files changed, 90 insertions, 12 deletions
diff --git a/src/msgparser.cc b/src/msgparser.cc
index 68de487..c6f83d5 100644
--- a/src/msgparser.cc
+++ b/src/msgparser.cc
@@ -96,28 +96,28 @@ MsgVector parse_msg(std::string data) {
if(prev_ch != '\\')
inside_quote = !inside_quote;
else {
- printf("Appending %c\n", ch);
+// printf("Appending %c\n", ch);
token += ch;
}
break;
case ' ':
if(inside_quote) {
- printf("Appending %c\n", ch);
+// printf("Appending %c\n", ch);
token += ch;
break;
}
if(token.empty()) continue; // skip multiple white spaces and pre white space
- printf("Adding token %s\n", token.c_str());
+// printf("Adding token %s\n", token.c_str());
tokens.push_back(token);
token.clear();
break;
case ';':
if(inside_quote) {
- printf("Appending %c\n", ch);
+// printf("Appending %c\n", ch);
token += ch;
break;
}
- printf("Adding msg...\n");
+// printf("Adding msg...\n");
if(!token.empty()) {
tokens.push_back(token);
}
@@ -126,7 +126,7 @@ MsgVector parse_msg(std::string data) {
token.clear();
break;
default:
- printf("Appending %c\n", ch);
+// printf("Appending %c\n", ch);
token += ch;
break;
}
@@ -143,7 +143,7 @@ MsgVector parse_msg(std::string data) {
tokens.clear();
}
- printf("Number of messages: %d\n", msglist.size());
+// printf("Number of messages: %d\n", msglist.size());
MsgVector v;
MsgList::iterator it_msg;
@@ -161,7 +161,7 @@ MsgVector parse_msg(std::string data) {
else if(t[0] == "update") m.cmd = cmd::update;
else m.cmd = cmd::error;
- printf("Number of tokens %d\n", t.size());
+// printf("Number of tokens %d\n", t.size());
switch(m.cmd) {
case cmd::add: {
@@ -169,10 +169,11 @@ MsgVector parse_msg(std::string data) {
printf("Wrong number of parameters\n");
continue;
}
- sprintf(m.add.title, "%s", t[0].c_str());
- sprintf(m.add.desc, "%s", t[1].c_str());
- m.add.x = atoi(t[2].c_str());
- m.add.y = atoi(t[3].c_str());
+ sprintf(m.add.title, "%s", t[1].c_str());
+ sprintf(m.add.desc, "%s", t[2].c_str());
+ m.add.x = atoi(t[3].c_str());
+ m.add.y = atoi(t[4].c_str());
+// printf("addcmd: %s %s %d %d\n", m.add.title, m.add.desc, m.add.x, m.add.y);
break;
}
case cmd::del: {
@@ -210,6 +211,83 @@ MsgVector parse_msg(std::string data) {
return v;
}
+msg_t create_msg(cmd::cmd_t type, task_t t) {
+ msg_t m;
+ m.cmd = type;
+ switch(type) {
+ case cmd::add: {
+ m.add.id = t.id;
+ m.add.x = t.x;
+ m.add.y = t.y;
+// m.add.title = t.title.c_str();
+// m.add.desc = t.desc.c_str();
+ snprintf(m.add.title, sizeof(m.add.title), "%s", t.title.c_str());
+ snprintf(m.add.desc, sizeof(m.add.desc), "%s", t.desc.c_str());
+ break;
+ }
+ case cmd::del: {
+ m.del.id = t.id;
+ break;
+ }
+ case cmd::move: {
+ m.move.id = t.id;
+ m.move.x = t.x;
+ m.move.y = t.y;
+ break;
+ }
+ case cmd::update: {
+ m.update.id = t.id;
+// m.update.title = t.title;
+// m.update.desc = t.desc;
+ snprintf(m.update.title, sizeof(m.update.title), "%s", t.title.c_str());
+ snprintf(m.update.desc, sizeof(m.update.desc), "%s", t.desc.c_str());
+ break;
+ };
+ default:
+ break;
+ }
+ return m;
+}
+
+#define BUF_SIZE 4096
+std::string msg_tostring(msg_t m) {
+ char buf[4096];
+ switch(m.cmd) {
+ case cmd::add: {
+ printf("msg: %d, %d, %d, %s, %s\n", m.add.id, m.add.x, m.add.y, m.add.title, m.add.desc);
+ snprintf(buf, BUF_SIZE, "add %d %s %s %d %d;",
+ m.add.id,
+ m.add.title, m.add.desc,
+ m.add.x, m.add.y);
+ break;
+ }
+ case cmd::del: {
+ snprintf(buf, BUF_SIZE, "del %d;", m.del.id);
+ break;
+ }
+ case cmd::move: {
+ snprintf(buf, BUF_SIZE, "move %d %d %d;", m.move.id, m.move.x, m.move.y);
+ break;
+ }
+ case cmd::update: {
+ //todo
+ break;
+ };
+ default:
+ break;
+ }
+
+ printf("buffer: %s\n", buf);
+
+ if(buf) {
+ std::string str(buf);
+ return str;
+ }
+ else {
+ return "";
+ }
+}
+
#ifdef TEST_MSGPARSER
//Additional dependency files
//deps: