-
Notifications
You must be signed in to change notification settings - Fork 149
/
commands.c
52 lines (46 loc) · 1.61 KB
/
commands.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "main.h"
STRING_IDX utox_run_command(char_t *string, STRING_IDX string_length, char_t **cmd, char_t **argument, int trusted){
if(trusted == 0){
return 0; /* We don't currently support commands from non-trusted sources, before you run commands from friends
* or elsewhere, you MUST implement error checking better than what exists */
}
STRING_IDX cmd_length, argument_length;
if (string[0] == '/') { /* Cool it's a command we support! */
// debug("command found!\n");
uint16_t i;
for (i = 0; i < string_length; ++i) {
if (string[i] == ' ') {
cmd_length = i;
break;
}
}
++i;
for (; i < string_length; ++i) {
if (string[i] != ' ') {
argument_length = string_length - i;
*argument = string + i;
break;
}
}
if(cmd_length){
--cmd_length;
*cmd = string + 1;
}
} else {
// debug("No command found\n"); /* Sad, we don't support this command. */
*argument = string;
cmd = NULL;
return 0;
}
/* Start accepting actions */
if ((cmd_length == 5) && (memcmp(*cmd, "alias", 5) == 0) && *argument ) {
if(selected_item->item == ITEM_FRIEND) {
FRIEND *f = selected_item->data;
friend_set_alias(f, *argument, argument_length);
cmd_length = -1; /* We'll take care of this, don't return to edit */
}
} else {
// debug("Command unsupported!\n");
}
return cmd_length;
}