mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 17:53:01 +01:00
/add command no longer requires quotes around the message
This commit is contained in:
parent
e9a0a30408
commit
afbd185222
@ -119,13 +119,14 @@ static struct cmd_func conference_commands[] = {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef PYTHON
|
#ifdef PYTHON
|
||||||
#define SPECIAL_COMMANDS 7
|
#define SPECIAL_COMMANDS 8
|
||||||
#else
|
#else
|
||||||
#define SPECIAL_COMMANDS 6
|
#define SPECIAL_COMMANDS 7
|
||||||
#endif /* PYTHON */
|
#endif /* PYTHON */
|
||||||
|
|
||||||
/* Special commands are commands that only take one argument even if it contains spaces */
|
/* Special commands are commands that only take one argument even if it contains spaces */
|
||||||
static const char special_commands[SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = {
|
static const char special_commands[SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||||
|
"/add",
|
||||||
"/avatar",
|
"/avatar",
|
||||||
"/nick",
|
"/nick",
|
||||||
"/note",
|
"/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,
|
static int do_command(WINDOW *w, ToxWindow *self, Tox *m, int num_args, struct cmd_func *commands,
|
||||||
char (*args)[MAX_STR_SIZE])
|
char (*args)[MAX_STR_SIZE])
|
||||||
{
|
{
|
||||||
int i;
|
for (size_t i = 0; commands[i].name != NULL; ++i) {
|
||||||
|
|
||||||
for (i = 0; commands[i].name != NULL; ++i) {
|
|
||||||
if (strcmp(args[0], commands[i].name) == 0) {
|
if (strcmp(args[0], commands[i].name) == 0) {
|
||||||
(commands[i].func)(w, self, m, num_args - 1, args);
|
(commands[i].func)(w, self, m, num_args - 1, args);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -157,22 +157,22 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char msg[MAX_STR_SIZE] = {0};
|
||||||
|
|
||||||
const char *id = argv[1];
|
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 (is_tox_id) {
|
||||||
if (argv[2][0] != '\"') {
|
// we have to manually parse the message due to this command being a special case
|
||||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Message must be enclosed in quotes.");
|
int idx = char_find(0, id, ' ');
|
||||||
return;
|
|
||||||
|
if (idx > 0 && idx < arg_length - 1) {
|
||||||
|
snprintf(msg, sizeof(msg), "%s", &id[idx + 1]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* remove opening and closing quotes */
|
if (!msg[0]) {
|
||||||
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 {
|
|
||||||
char selfname[TOX_MAX_NAME_LENGTH];
|
char selfname[TOX_MAX_NAME_LENGTH];
|
||||||
tox_self_get_name(m, (uint8_t *) selfname);
|
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};
|
char id_bin[TOX_ADDRESS_SIZE] = {0};
|
||||||
uint16_t id_len = (uint16_t) strlen(id);
|
|
||||||
|
|
||||||
/* try to add tox ID */
|
/* try to add tox ID */
|
||||||
if (id_len == 2 * TOX_ADDRESS_SIZE) {
|
if (is_tox_id) {
|
||||||
size_t i;
|
size_t i;
|
||||||
char xx[3];
|
char xx[3];
|
||||||
uint32_t x;
|
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) {
|
for (i = 0; i < TOX_ADDRESS_SIZE; ++i) {
|
||||||
xx[0] = id[2 * i];
|
xx[0] = id[2 * i];
|
||||||
xx[1] = id[2 * i + 1];
|
xx[1] = id[2 * i + 1];
|
||||||
xx[2] = '\0';
|
xx[2] = 0;
|
||||||
|
|
||||||
if (sscanf(xx, "%02x", &x) != 1) {
|
if (sscanf(xx, "%02x", &x) != 1) {
|
||||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid Tox ID.");
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid Tox ID.");
|
||||||
|
Loading…
Reference in New Issue
Block a user