1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-29 13:07:47 +02:00

/add command no longer requires quotes around the message

This commit is contained in:
jfreegman 2021-12-06 10:06:49 -05:00
parent e9a0a30408
commit afbd185222
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 18 additions and 20 deletions

View File

@ -119,13 +119,14 @@ static struct cmd_func conference_commands[] = {
#ifdef PYTHON
#define SPECIAL_COMMANDS 7
#define SPECIAL_COMMANDS 8
#else
#define SPECIAL_COMMANDS 6
#define SPECIAL_COMMANDS 7
#endif /* PYTHON */
/* Special commands are commands that only take one argument even if it contains spaces */
static const char special_commands[SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = {
"/add",
"/avatar",
"/nick",
"/note",
@ -219,9 +220,7 @@ static int parse_command(const char *input, char (*args)[MAX_STR_SIZE])
static int do_command(WINDOW *w, ToxWindow *self, Tox *m, int num_args, struct cmd_func *commands,
char (*args)[MAX_STR_SIZE])
{
int i;
for (i = 0; commands[i].name != NULL; ++i) {
for (size_t i = 0; commands[i].name != NULL; ++i) {
if (strcmp(args[0], commands[i].name) == 0) {
(commands[i].func)(w, self, m, num_args - 1, args);
return 0;

View File

@ -157,22 +157,22 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
return;
}
char msg[MAX_STR_SIZE] = {0};
const char *id = argv[1];
char msg[MAX_STR_SIZE];
const size_t arg_length = strlen(id);
const bool is_tox_id = arg_length >= (2 * TOX_ADDRESS_SIZE);
if (argc > 1) {
if (argv[2][0] != '\"') {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Message must be enclosed in quotes.");
return;
if (is_tox_id) {
// we have to manually parse the message due to this command being a special case
int idx = char_find(0, id, ' ');
if (idx > 0 && idx < arg_length - 1) {
snprintf(msg, sizeof(msg), "%s", &id[idx + 1]);
}
}
/* remove opening and closing quotes */
char tmp[MAX_STR_SIZE];
snprintf(tmp, sizeof(tmp), "%s", &argv[2][1]);
int len = strlen(tmp) - 1;
tmp[len] = '\0';
snprintf(msg, sizeof(msg), "%s", tmp);
} else {
if (!msg[0]) {
char selfname[TOX_MAX_NAME_LENGTH];
tox_self_get_name(m, (uint8_t *) selfname);
@ -182,10 +182,9 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
}
char id_bin[TOX_ADDRESS_SIZE] = {0};
uint16_t id_len = (uint16_t) strlen(id);
/* try to add tox ID */
if (id_len == 2 * TOX_ADDRESS_SIZE) {
if (is_tox_id) {
size_t i;
char xx[3];
uint32_t x;
@ -193,7 +192,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
for (i = 0; i < TOX_ADDRESS_SIZE; ++i) {
xx[0] = id[2 * i];
xx[1] = id[2 * i + 1];
xx[2] = '\0';
xx[2] = 0;
if (sscanf(xx, "%02x", &x) != 1) {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid Tox ID.");