From 84847d8e29723eda622d5f4b1edc9c9a7cfb5296 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Wed, 7 Aug 2013 10:57:17 -0700 Subject: [PATCH] Manually merged prompt.c to upstream --- prompt.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/prompt.c b/prompt.c index 24b728f..b6827ce 100644 --- a/prompt.c +++ b/prompt.c @@ -52,9 +52,21 @@ static void execute(ToxWindow *self, char *u_cmd) cmd[i - newlines] = u_cmd[i]; } + int leading_spc = 0; + for (i = 0; i < 256 && isspace(cmd[i]); ++i) + leading_spc++; + memmove(cmd, cmd + leading_spc, 256 - leading_spc); + + int cmd_end = strlen(cmd); + while (cmd_end > 0 && cmd_end--) + if (!isspace(cmd[cmd_end])) + break; + cmd[cmd_end + 1] = '\0'; + if (cmd[0] == '/') { + wprintw(self->window,"Warning: Run your command without the /, this may not work\n"); int i; - for (i = i; i < strlen(cmd); i++) { //This doesn't work when it doesn't end with a space and another word + for (i = 1; i < strlen(cmd); i++) { //This doesn't work when it doesn't end with a space and another word cmd[i - 1] = cmd[i]; //Still working on why } } @@ -171,6 +183,54 @@ static void execute(ToxWindow *self, char *u_cmd) } else if (!strncmp(cmd, "status ", strlen("status "))) { + char *status = strchr(cmd, ' '); + char *msg; + char *status_text; + if (status == NULL) { + wprintw(self->window, "Invalid syntax.\n"); + return; + } + status++; + USERSTATUS_KIND status_kind; + if (!strncmp(status, "online", strlen("online"))) { + status_kind = USERSTATUS_KIND_ONLINE; + status_text = "ONLINE"; + } + + else if (!strncmp(status, "away", strlen("away"))) { + status_kind = USERSTATUS_KIND_AWAY; + status_text = "AWAY"; + } + + else if (!strncmp(status, "busy", strlen("busy"))) { + status_kind = USERSTATUS_KIND_BUSY; + status_text = "BUSY"; + } + + else if (!strncmp(status, "offline", strlen("offline"))) { + status_kind = USERSTATUS_KIND_OFFLINE; + status_text = "OFFLINE"; + } + + else + { + wprintw(self->window, "Invalid status.\n"); + return; + } + + msg = strchr(status, ' '); + if (msg == NULL) { + m_set_userstatus_kind(status_kind); + wprintw(self->window, "Status set to: %s\n", status_text); + } + else { + msg++; + m_set_userstatus(status_kind, (uint8_t*) msg, strlen(msg)+1); + wprintw(self->window, "Status set to: %s, %s\n", status_text, msg); + } + } + + else if (!strncmp(cmd, "statusmsg ", strlen("statumsg "))) { char *msg = strchr(cmd, ' '); if (msg == NULL) { wprintw(self->window, "Invalid syntax.\n"); @@ -313,7 +373,8 @@ static void print_usage(ToxWindow *self) wprintw(self->window, " connect : Connect to DHT server\n"); wprintw(self->window, " add : Add friend\n"); - wprintw(self->window, " status : Set your status\n"); + wprintw(self->window, " status : Set your status\n"); + wprintw(self->window, " statusmsg : Set your status\n"); wprintw(self->window, " nick : Set your nickname\n"); wprintw(self->window, " accept : Accept friend request\n"); wprintw(self->window, " myid : Print your ID\n");