From 0396ce6456476bbc1519dcb9925cd1e9db850c27 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 18 Oct 2013 23:46:58 -0400 Subject: [PATCH] rm /msg command --- src/chat.c | 5 +++-- src/commands.c | 33 --------------------------------- src/commands.h | 4 +--- src/friendlist.c | 13 ------------- 4 files changed, 4 insertions(+), 51 deletions(-) diff --git a/src/chat.c b/src/chat.c index b36517c..5bfa6ae 100644 --- a/src/chat.c +++ b/src/chat.c @@ -571,8 +571,9 @@ ToxWindow new_chat(Tox *m, ToxWindow *prompt, int friendnum) ret.onFileData = &chat_onFileData; uint8_t name[TOX_MAX_NAME_LENGTH] = {'\0'}; - tox_getname(m, friendnum, name); - snprintf(ret.name, sizeof(ret.name), "%s", name); + uint16_t len = tox_getname(m, friendnum, name); + memcpy(ret.name, name, len); + ret.name[TOXIC_MAX_NAME_LENGTH] = '\0'; ChatContext *chatwin = calloc(1, sizeof(ChatContext)); StatusBar *stb = calloc(1, sizeof(StatusBar)); diff --git a/src/commands.c b/src/commands.c index 4d6b07d..fdca715 100644 --- a/src/commands.c +++ b/src/commands.c @@ -261,39 +261,6 @@ 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) { - wprintw(window, "Invalid syntax.\n"); - return; - } - - uint8_t *name = argv[1]; - uint8_t *msg = argv[2]; - - 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 (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"); -} - void cmd_myid(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) { char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {0}; diff --git a/src/commands.h b/src/commands.h index 1f64651..9b712b3 100644 --- a/src/commands.h +++ b/src/commands.h @@ -9,7 +9,6 @@ void cmd_clear(WINDOW *, ToxWindow *, Tox *m, int, char **); void cmd_connect(WINDOW *, ToxWindow *, Tox *m, int, char **); void cmd_groupchat(WINDOW *, ToxWindow *, Tox *m, int, char **); void cmd_join(WINDOW *, ToxWindow *, Tox *m, int, char **); -void cmd_msg(WINDOW *, ToxWindow *, Tox *m, int, char **); void cmd_myid(WINDOW *, ToxWindow *, Tox *m, int, char **); void cmd_nick(WINDOW *, ToxWindow *, Tox *m, int, char **); void cmd_note(WINDOW *, ToxWindow *, Tox *m, int, char **); @@ -18,7 +17,7 @@ void cmd_status(WINDOW *, ToxWindow *, Tox *m, int, char **); void execute(WINDOW *window, ToxWindow *prompt, Tox *m, char *u_cmd, int buf_len); -#define NUM_COMMANDS 14 +#define NUM_COMMANDS 13 static struct { char *name; @@ -31,7 +30,6 @@ static struct { { "/exit", cmd_quit }, { "/groupchat", cmd_groupchat }, { "/join", cmd_join }, - { "/msg", cmd_msg }, { "/myid", cmd_myid }, { "/nick", cmd_nick }, { "/note", cmd_note }, diff --git a/src/friendlist.c b/src/friendlist.c index 0e194f8..e65c636 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -255,19 +255,6 @@ void disable_chatwin(int f_num) friends[f_num].chatwin = -1; } -/* Returns the respective friend number of name. Returns -1 on no match */ -int get_friendnum(uint8_t *name) -{ - int i; - - for (i = 0; i < num_friends; ++i) { - if (strcmp(friends[i].name, name) == 0) - return friends[i].num; - } - - return -1; -} - static void friendlist_onInit(ToxWindow *self, Tox *m) {