From bd3c14104ab73c181773608931732ccf3684f731 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 24 Sep 2013 16:12:33 -0400 Subject: [PATCH] command fixes --- src/chat.c | 2 +- src/commands.c | 33 +++++++++++++++++++++------------ src/groupchat.c | 2 +- src/main.c | 4 ++++ src/prompt.c | 2 +- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/chat.c b/src/chat.c index c214860..17d323d 100644 --- a/src/chat.c +++ b/src/chat.c @@ -118,7 +118,7 @@ static void print_chat_help(ChatContext *ctx) wprintw(ctx->history, " /help : Print this message again\n"); wattron(ctx->history, A_BOLD); - wprintw(ctx->history, "\n * Messages must be enclosed in quotation marks.\n"); + wprintw(ctx->history, "\n * Command argument messages must be enclosed in quotation marks.\n"); wattroff(ctx->history, A_BOLD); wattroff(ctx->history, COLOR_PAIR(CYAN)); diff --git a/src/commands.c b/src/commands.c index ab40367..5a57af4 100644 --- a/src/commands.c +++ b/src/commands.c @@ -48,7 +48,7 @@ void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) { - if (argc < 1 || argc > 2) { + if (argc < 1) { wprintw(window, "Invalid syntax.\n"); return; } @@ -62,7 +62,7 @@ void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) uint8_t *msg; - if (argc == 2) { + if (argc > 1) { msg = argv[2]; if (msg == NULL) { @@ -71,7 +71,7 @@ void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) } if (msg[0] != '\"') { - wprintw(window, "Messages must be enclosed in quotes.\n"); + wprintw(window, "Message must be enclosed in quotes.\n"); return; } @@ -192,12 +192,12 @@ void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **a int groupnum = tox_add_groupchat(m); if (groupnum == -1) { - wprintw(window, "Group chat failed to initialize.\n"); + wprintw(window, "Group chat instnace failed to initialize.\n"); return; } if (init_groupchat_win(prompt, m, groupnum) == -1) { - wprintw(window, "Group chat failed to initialize.\n"); + wprintw(window, "Group chat window failed to initialize.\n"); tox_del_groupchat(m, groupnum); return; } @@ -235,7 +235,7 @@ void cmd_invite(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv return; } - wprintw(window, "Invited friend %s to group chat %d.\n", friendname, groupnum); + wprintw(window, "Invited '%s' to group chat %d.\n", friendname, groupnum); } void cmd_join(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) @@ -281,25 +281,34 @@ void cmd_join(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) void cmd_msg(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) { /* check arguments */ - if (argc != 2) { + if (argc < 2) { wprintw(window, "Invalid syntax.\n"); return; } - char *id = argv[1]; + uint8_t *name = argv[1]; uint8_t *msg = argv[2]; - if (id == NULL || msg == NULL) { + if (name == NULL || msg == NULL) { wprintw(window, "Invalid syntax.\n"); return; } + if (msg[0] != '\"') { + wprintw(window, "Messages must be enclosed in quotes.\n"); + return; + } + msg[strlen(++msg)-1] = L'\0'; + int friendnum = get_friendnum(name); - if (tox_sendmessage(m, atoi(id), msg, strlen(msg) + 1) == 0) + if (friendnum == -1) { + wprintw(window, "Friend '%s' not found.\n", name); + return; + } + + if (tox_sendmessage(m, friendnum, msg, strlen(msg) + 1) == 0) wprintw(window, "Failed to send message.\n"); - else - wprintw(window, "Message successfully sent.\n"); } void cmd_myid(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) diff --git a/src/groupchat.c b/src/groupchat.c index 68ebd6d..6df0efb 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -88,7 +88,7 @@ static void print_groupchat_help(ChatContext *ctx) wprintw(ctx->history, " /help : Print this message again\n"); wattron(ctx->history, A_BOLD); - wprintw(ctx->history, "\n * Messages must be enclosed in quotation marks.\n"); + wprintw(ctx->history, "\n * Command argument messages must be enclosed in quotation marks.\n"); wattroff(ctx->history, A_BOLD); wattroff(ctx->history, COLOR_PAIR(CYAN)); diff --git a/src/main.c b/src/main.c index ca1a8a5..c2f96b9 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,8 @@ #include #include #include +#include + #ifdef _WIN32 #include @@ -449,6 +451,8 @@ int main(int argc, char *argv[]) /* Draw */ draw_active_window(m); + + usleep((uint)1000); } exit_toxic(m); diff --git a/src/prompt.c b/src/prompt.c index 7df2d7c..08d82d4 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -99,7 +99,7 @@ static void print_prompt_help(ToxWindow *self) wprintw(self->window, " /clear : Clear this window\n"); wattron(self->window, A_BOLD); - wprintw(self->window, " * Messages must be enclosed in quotation marks.\n"); + wprintw(self->window, " * Command argument messages must be enclosed in quotation marks.\n"); wprintw(self->window, " * Use the TAB key to navigate through the tabs.\n"); wattroff(self->window, A_BOLD);