diff --git a/src/autocomplete.c b/src/autocomplete.c index d74ff61..03588ca 100644 --- a/src/autocomplete.c +++ b/src/autocomplete.c @@ -99,7 +99,11 @@ int complete_line(ToxWindow *self, const void *list, size_t n_items, size_t size { ChatContext *ctx = self->chatwin; - if (ctx->pos <= 0 || ctx->len <= 0 || ctx->pos > ctx->len || ctx->len >= MAX_STR_SIZE || size > MAX_STR_SIZE) { + if (ctx->pos <= 0 || ctx->len <= 0 || ctx->pos > ctx->len) { + return -1; + } + + if (ctx->len >= MAX_STR_SIZE || size > MAX_STR_SIZE) { return -1; } diff --git a/src/execute.c b/src/execute.c index 1a2d693..58711a0 100644 --- a/src/execute.c +++ b/src/execute.c @@ -181,11 +181,10 @@ static int parse_command(WINDOW *w, ToxWindow *self, const char *input, char (*a } int num_args = 0; - int i = 0; // index of last char in an argument /* characters wrapped in double quotes count as one arg */ while (num_args < MAX_NUM_ARGS) { - i = char_find(0, cmd, ' '); + int i = char_find(0, cmd, ' '); // index of last char in an argument memcpy(args[num_args], cmd, i); args[num_args++][i] = '\0'; diff --git a/src/global_commands.c b/src/global_commands.c index fdd67b8..f443921 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -592,14 +592,11 @@ void cmd_requests(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { - bool have_note = false; const char *errmsg; lock_status(); - if (argc >= 2) { - have_note = true; - } else if (argc < 1) { + if (argc < 1) { errmsg = "Require a status. Statuses are: online, busy and away."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg); goto finish; @@ -622,24 +619,8 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ tox_self_set_status(m, status); prompt_update_status(prompt, status); + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your status has been changed to %s.", status_str); - if (have_note) { - if (argv[2][0] != '\"') { - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Note must be enclosed in quotes."); - goto finish; - } - - /* remove opening and closing quotes */ - char msg[MAX_STR_SIZE]; - snprintf(msg, sizeof(msg), "%s", &argv[2][1]); - int len = strlen(msg) - 1; - msg[len] = '\0'; - - prompt_update_statusmessage(prompt, m, msg); - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your status has been changed to %s: \"%s\".", status_str, msg); - } else { - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your status has been changed to %s.", status_str); - } finish: unlock_status(); diff --git a/src/term_mplex.c b/src/term_mplex.c index f3f09a4..c1e54b4 100644 --- a/src/term_mplex.c +++ b/src/term_mplex.c @@ -33,7 +33,7 @@ #include -#include "global_commands.h" +#include "execute.h" #include "windows.h" #include "term_mplex.h" #include "toxic.h" @@ -390,15 +390,16 @@ static void mplex_timer_handler(Tox *m) return; } - char argv[3][MAX_STR_SIZE]; - strcpy(argv[0], "/status"); - strcpy(argv[1], (new_status == TOX_USER_STATUS_AWAY ? "away" : - new_status == TOX_USER_STATUS_BUSY ? "busy" : "online")); - argv[2][0] = '\"'; - strcpy(argv[2] + 1, new_note); - strcat(argv[2], "\""); + char status_str[MAX_STR_SIZE]; + char note_str[MAX_STR_SIZE]; + const char *status = new_status == TOX_USER_STATUS_AWAY ? "away" : + new_status == TOX_USER_STATUS_BUSY ? "busy" : "online"; + snprintf(status_str, sizeof(status_str), "/status %s", status); + snprintf(note_str, sizeof(status_str), "/note %s", new_note); + pthread_mutex_lock(&Winthread.lock); - cmd_status(prompt->chatwin->history, prompt, m, 2, argv); + execute(prompt->chatwin->history, prompt, m, status_str, GLOBAL_COMMAND_MODE); + execute(prompt->chatwin->history, prompt, m, note_str, GLOBAL_COMMAND_MODE); pthread_mutex_unlock(&Winthread.lock); }