1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 05:13:03 +01:00

a few fixes and improve error messages

This commit is contained in:
Jfreegman 2014-08-04 14:35:34 -04:00
parent 6fdafceda8
commit 28633be2dd
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
5 changed files with 60 additions and 120 deletions

View File

@ -341,7 +341,7 @@ void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
const char *error_str; const char *error_str;
if (argc != 0) { if (argc != 0) {
error_str = "Invalid syntax!"; error_str = "Unknown arguments.";
goto on_error; goto on_error;
} }
@ -376,7 +376,7 @@ void cmd_answer(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
const char *error_str; const char *error_str;
if (argc != 0) { if (argc != 0) {
error_str = "Invalid syntax!"; error_str = "Unknown arguments.";
goto on_error; goto on_error;
} }
@ -407,7 +407,7 @@ void cmd_reject(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
const char *error_str; const char *error_str;
if (argc != 0) { if (argc != 0) {
error_str = "Invalid syntax!"; error_str = "Unknown arguments.";
goto on_error; goto on_error;
} }
@ -438,7 +438,7 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
const char *error_str; const char *error_str;
if (argc != 0) { if (argc != 0) {
error_str = "Invalid syntax!"; error_str = "Unknown arguments.";
goto on_error; goto on_error;
} }
@ -635,10 +635,10 @@ void cmd_mute(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
DeviceType type; DeviceType type;
if ( strcmp(argv[1], "in") == 0 ) /* Input devices */ if ( strcasecmp(argv[1], "in") == 0 ) /* Input devices */
type = input; type = input;
else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */ else if ( strcasecmp(argv[1], "out") == 0 ) /* Output devices */
type = output; type = output;
else { else {

View File

@ -44,30 +44,19 @@ extern uint8_t num_active_file_senders;
void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 2) { if (argc < 2) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid syntax."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Requires type in|out and the file ID.");
return; return;
} }
const char *inoutstr = argv[1]; const char *inoutstr = argv[1];
int filenum = atoi(argv[2]); int filenum = atoi(argv[2]);
if (filenum > MAX_FILES || filenum < 0) { if (filenum >= MAX_FILES || filenum < 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid file ID."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid file ID.");
return; return;
} }
int inout; if (strcasecmp(inoutstr, "in") == 0) { /* cancel an incoming file transfer */
if (strcasecmp(inoutstr, "in") == 0) {
inout = 1;
} else if (strcasecmp(inoutstr, "out") == 0) {
inout = 0;
} else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error: Type must be 'in' or 'out'.");
return;
}
if (inout == 1) { /* cancel an incoming file transfer */
if (!friends[self->num].file_receiver.active[filenum]) { if (!friends[self->num].file_receiver.active[filenum]) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid file ID."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid file ID.");
return; return;
@ -79,7 +68,8 @@ void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer for '%s' canceled.", name); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer for '%s' canceled.", name);
tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0); tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
chat_close_file_receiver(self->num, filenum); chat_close_file_receiver(self->num, filenum);
} else { /* cancel an outgoing file transfer */ return;
} else if (strcasecmp(inoutstr, "out") == 0) { /* cancel an outgoing file transfer */
int i; int i;
bool match = false; bool match = false;
@ -99,30 +89,29 @@ void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
char msg[MAX_STR_SIZE]; char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "File transfer for '%s' canceled.", filename); snprintf(msg, sizeof(msg), "File transfer for '%s' canceled.", filename);
close_file_sender(self, m, i, msg, TOX_FILECONTROL_KILL, filenum, self->num); close_file_sender(self, m, i, msg, TOX_FILECONTROL_KILL, filenum, self->num);
return;
} else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type must be 'in' or 'out'.");
return;
} }
} }
void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *errmsg;
if (argc < 1) { if (argc < 1) {
errmsg = "Invalid syntax"; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group number required.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
int groupnum = atoi(argv[1]); int groupnum = atoi(argv[1]);
if (groupnum == 0 && strcmp(argv[1], "0")) { /* atoi returns 0 value on invalid input */ if (groupnum == 0 && strcmp(argv[1], "0")) { /* atoi returns 0 value on invalid input */
errmsg = "Invalid syntax."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid group number.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
if (tox_invite_friend(m, self->num, groupnum) == -1) { if (tox_invite_friend(m, self->num, groupnum) == -1) {
errmsg = "Failed to invite contact to group."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to invite contact to group.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -131,33 +120,27 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *errmsg;
if (get_num_active_windows() >= MAX_WINDOWS_NUM) { if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
errmsg = " * Warning: Too many windows are open."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
return; return;
} }
const char *groupkey = friends[self->num].groupchat_key; const char *groupkey = friends[self->num].groupchat_key;
if (!friends[self->num].groupchat_pending) { if (!friends[self->num].groupchat_pending) {
errmsg = "No pending group chat invite."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending group chat invite.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
int groupnum = tox_join_groupchat(m, self->num, (uint8_t *) groupkey); int groupnum = tox_join_groupchat(m, self->num, (uint8_t *) groupkey);
if (groupnum == -1) { if (groupnum == -1) {
errmsg = "Group chat instance failed to initialize."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat instance failed to initialize.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
if (init_groupchat_win(prompt, m, groupnum) == -1) { if (init_groupchat_win(prompt, m, groupnum) == -1) {
errmsg = "Group chat window failed to initialize."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
tox_del_groupchat(m, groupnum); tox_del_groupchat(m, groupnum);
return; return;
} }
@ -165,32 +148,27 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *errmsg; if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File ID required.");
if (argc != 1) {
errmsg = "Invalid syntax.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
uint8_t filenum = atoi(argv[1]); uint8_t filenum = atoi(argv[1]);
if ((filenum == 0 && strcmp(argv[1], "0")) || filenum >= MAX_FILES) { if ((filenum == 0 && strcmp(argv[1], "0")) || filenum >= MAX_FILES) {
errmsg = "No pending file transfers with that number."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending file transfers with that ID.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
if (!friends[self->num].file_receiver.pending[filenum]) { if (!friends[self->num].file_receiver.pending[filenum]) {
errmsg = "No pending file transfers with that number."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending file transfers with that ID.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
const char *filename = friends[self->num].file_receiver.filenames[filenum]; const char *filename = friends[self->num].file_receiver.filenames[filenum];
if (tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0) == 0) { if (tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0) == 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Saving file as [%d]: '%s'", filenum, filename); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Saving file [%d] as: '%s'", filenum, filename);
/* prep progress bar line */ /* prep progress bar line */
char progline[MAX_STR_SIZE]; char progline[MAX_STR_SIZE];
@ -199,13 +177,11 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
friends[self->num].file_receiver.line_id[filenum] = self->chatwin->hst->line_end->id + 2; friends[self->num].file_receiver.line_id[filenum] = self->chatwin->hst->line_end->id + 2;
if ((friends[self->num].file_receiver.files[filenum] = fopen(filename, "a")) == NULL) { if ((friends[self->num].file_receiver.files[filenum] = fopen(filename, "a")) == NULL) {
errmsg = "* Error writing to file."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, "* Error writing to file.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0); tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
} }
} else { } else {
errmsg = "File transfer failed."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer failed.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
} }
friends[self->num].file_receiver.pending[filenum] = false; friends[self->num].file_receiver.pending[filenum] = false;
@ -214,23 +190,19 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *errmsg;
if (max_file_senders_index >= (MAX_FILES - 1)) { if (max_file_senders_index >= (MAX_FILES - 1)) {
errmsg = "Please wait for some of your outgoing file transfers to complete."; const char *errmsg = "Please wait for some of your outgoing file transfers to complete.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
if (argc < 1) { if (argc < 1) {
errmsg = "Invalid syntax."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File path required.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
if (argv[1][0] != '\"') { if (argv[1][0] != '\"') {
errmsg = "File path must be enclosed in quotes."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File path must be enclosed in quotes.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -241,16 +213,14 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
path[path_len] = '\0'; path[path_len] = '\0';
if (path_len >= MAX_STR_SIZE) { if (path_len >= MAX_STR_SIZE) {
errmsg = "File path exceeds character limit."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File path exceeds character limit.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
FILE *file_to_send = fopen(path, "r"); FILE *file_to_send = fopen(path, "r");
if (file_to_send == NULL) { if (file_to_send == NULL) {
errmsg = "File not found."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File not found.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -264,8 +234,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
int filenum = tox_new_file_sender(m, self->num, filesize, (const uint8_t *) filename, namelen); int filenum = tox_new_file_sender(m, self->num, filesize, (const uint8_t *) filename, namelen);
if (filenum == -1) { if (filenum == -1) {
errmsg = "Error sending file."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error sending file.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }

View File

@ -52,7 +52,7 @@ void prep_prog_line(char *progline)
for (i = 0; i < NUM_PROG_MARKS; ++i) for (i = 0; i < NUM_PROG_MARKS; ++i)
strcat(progline, "-"); strcat(progline, "-");
strcat(progline, "] 0%%"); strcat(progline, "] 0%");
} }
/* prints a progress bar for file transfers. /* prints a progress bar for file transfers.

View File

@ -46,28 +46,24 @@ extern uint8_t num_frnd_requests;
/* command functions */ /* command functions */
void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
char *msg; if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Request ID required.");
if (argc != 1) {
msg = "Invalid syntax.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return; return;
} }
int req = atoi(argv[1]); int req = atoi(argv[1]);
if ((req == 0 && strcmp(argv[1], "0")) || req >= MAX_FRIENDS_NUM) { if ((req == 0 && strcmp(argv[1], "0")) || req >= MAX_FRIENDS_NUM) {
msg = "No pending friend request with that number."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return; return;
} }
if (!strlen(pending_frnd_requests[req])) { if (!strlen(pending_frnd_requests[req])) {
msg = "No pending friend request with that number."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return; return;
} }
const char *msg;
int32_t friendnum = tox_add_friend_norequest(m, (uint8_t *) pending_frnd_requests[req]); int32_t friendnum = tox_add_friend_norequest(m, (uint8_t *) pending_frnd_requests[req]);
if (friendnum == -1) if (friendnum == -1)
@ -135,11 +131,8 @@ void cmd_add_helper(ToxWindow *self, Tox *m, char *id_bin, char *msg)
void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *errmsg;
if (argc < 1) { if (argc < 1) {
errmsg = "Invalid syntax."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Tox ID or address required.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -148,8 +141,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
if (argc > 1) { if (argc > 1) {
if (argv[2][0] != '\"') { if (argv[2][0] != '\"') {
errmsg = "Message must be enclosed in quotes."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Message must be enclosed in quotes.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -181,8 +173,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
xx[2] = '\0'; xx[2] = '\0';
if (sscanf(xx, "%02x", &x) != 1) { if (sscanf(xx, "%02x", &x) != 1) {
errmsg = "Invalid ID."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid Tox ID.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -205,12 +196,8 @@ void cmd_clear(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *errmsg;
/* check arguments */
if (argc != 3) { if (argc != 3) {
errmsg = "Invalid syntax."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Require: <ip> <port> <key>");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -219,8 +206,7 @@ void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
const char *key = argv[3]; const char *key = argv[3];
if (atoi(port) == 0) { if (atoi(port) == 0) {
errmsg = "Invalid syntax."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid port.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -231,30 +217,25 @@ void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *errmsg;
if (get_num_active_windows() >= MAX_WINDOWS_NUM) { if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
errmsg = " * Warning: Too many windows are open."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
return; return;
} }
int groupnum = tox_add_groupchat(m); int groupnum = tox_add_groupchat(m);
if (groupnum == -1) { if (groupnum == -1) {
errmsg = "Group chat instance failed to initialize."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat instance failed to initialize.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
if (init_groupchat_win(prompt, m, groupnum) == -1) { if (init_groupchat_win(prompt, m, groupnum) == -1) {
errmsg = "Group chat window failed to initialize."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
tox_del_groupchat(m, groupnum); tox_del_groupchat(m, groupnum);
return; return;
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat created as %d.", groupnum); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat [%d] created.", groupnum);
} }
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -324,12 +305,8 @@ void cmd_myid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *errmsg;
/* check arguments */
if (argc < 1) { if (argc < 1) {
errmsg = "Invalid name."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Input required.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -346,8 +323,7 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
} }
if (!valid_nick(nick)) { if (!valid_nick(nick)) {
errmsg = "Invalid name."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid name.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -362,17 +338,13 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *errmsg;
if (argc < 1) { if (argc < 1) {
errmsg = "Wrong number of arguments."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Input required.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
if (argv[1][0] != '\"') { if (argv[1][0] != '\"') {
errmsg = "Note must be enclosed in quotes."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Note must be enclosed in quotes.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -403,8 +375,8 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
if (argc >= 2) { if (argc >= 2) {
have_note = true; have_note = true;
} else if (argc != 1) { } else if (argc < 1) {
errmsg = "Wrong number of arguments."; errmsg = "Require a status. Statuses are: online, busy and away.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }
@ -432,8 +404,7 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
if (have_note) { if (have_note) {
if (argv[2][0] != '\"') { if (argv[2][0] != '\"') {
errmsg = "Note must be enclosed in quotes."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Note must be enclosed in quotes.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return; return;
} }

View File

@ -136,15 +136,15 @@ static void help_draw_global(ToxWindow *self)
wprintw(win, "Global Commands:\n"); wprintw(win, "Global Commands:\n");
wattroff(win, A_BOLD | COLOR_PAIR(RED)); wattroff(win, A_BOLD | COLOR_PAIR(RED));
wprintw(win, " /add <id> <msg> : Add contact with optional message\n"); wprintw(win, " /add <addr> <msg> : Add contact with optional message\n");
wprintw(win, " /accept <n> : Accept friend request\n"); wprintw(win, " /accept <id> : Accept friend request\n");
wprintw(win, " /connect <ip> <port> <key> : Manually connect to a DHT node\n"); wprintw(win, " /connect <ip> <port> <key> : Manually connect to a DHT node\n");
wprintw(win, " /status <type> <msg> : Set status with optional note\n"); wprintw(win, " /status <type> <msg> : Set status with optional note\n");
wprintw(win, " /note <msg> : Set a personal note\n"); wprintw(win, " /note <msg> : Set a personal note\n");
wprintw(win, " /nick <nick> : Set your nickname\n"); wprintw(win, " /nick <nick> : Set your nickname\n");
wprintw(win, " /log <on> or <off> : Enable/disable logging\n"); wprintw(win, " /log <on> or <off> : Enable/disable logging\n");
wprintw(win, " /groupchat : Create a group chat\n"); wprintw(win, " /groupchat : Create a group chat\n");
wprintw(win, " /myid : Print your ID\n"); wprintw(win, " /myid : Print your Tox ID\n");
wprintw(win, " /clear : Clear window history\n"); wprintw(win, " /clear : Clear window history\n");
wprintw(win, " /close : Close the current chat window\n"); wprintw(win, " /close : Close the current chat window\n");
wprintw(win, " /quit or /exit : Exit Toxic\n"); wprintw(win, " /quit or /exit : Exit Toxic\n");