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

remove redundant cmd func args, use global prompt instead

This commit is contained in:
Jfreegman 2013-11-19 15:32:35 -05:00
parent b16ff16abc
commit f43d735861
15 changed files with 76 additions and 74 deletions

View File

@ -294,7 +294,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
bool close_win = false; bool close_win = false;
if (line[0] == '/') { if (line[0] == '/') {
if (close_win = !strncmp(line, "/close", strlen("/close"))) { if (close_win = !strcmp(line, "/close")) {
int f_num = self->num; int f_num = self->num;
delwin(ctx->linewin); delwin(ctx->linewin);
delwin(statusbar->topline); delwin(statusbar->topline);
@ -303,7 +303,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
} else if (!strncmp(line, "/me ", strlen("/me "))) } else if (!strncmp(line, "/me ", strlen("/me ")))
send_action(self, ctx, m, line + strlen("/me ")); send_action(self, ctx, m, line + strlen("/me "));
else else
execute(ctx->history, self->prompt, m, self->num, line, CHAT_COMMAND_MODE); execute(ctx->history, self, m, line, CHAT_COMMAND_MODE);
} else { } else {
/* make sure the string has at least non-space character */ /* make sure the string has at least non-space character */
if (!string_is_empty(line)) { if (!string_is_empty(line)) {
@ -442,11 +442,11 @@ static void chat_onInit(ToxWindow *self, Tox *m)
scrollok(ctx->history, 1); scrollok(ctx->history, 1);
ctx->linewin = subwin(self->window, 0, x, y-4, 0); ctx->linewin = subwin(self->window, 0, x, y-4, 0);
wprintw(ctx->history, "\n\n"); wprintw(ctx->history, "\n\n");
execute(ctx->history, self->prompt, m, self->num, "/help", CHAT_COMMAND_MODE); execute(ctx->history, self, m, "/help", CHAT_COMMAND_MODE);
wmove(self->window, y - CURS_Y_OFFSET, 0); wmove(self->window, y - CURS_Y_OFFSET, 0);
} }
ToxWindow new_chat(Tox *m, ToxWindow *prompt, int friendnum) ToxWindow new_chat(Tox *m, int friendnum)
{ {
ToxWindow ret; ToxWindow ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
@ -482,7 +482,6 @@ ToxWindow new_chat(Tox *m, ToxWindow *prompt, int friendnum)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ret.prompt = prompt;
ret.num = friendnum; ret.num = friendnum;
return ret; return ret;

View File

@ -1,6 +1,8 @@
#ifndef CHAT_H_6489PZ13 #ifndef CHAT_H_6489PZ13
#define CHAT_H_6489PZ13 #define CHAT_H_6489PZ13
ToxWindow new_chat(Tox *m, ToxWindow *prompt, int friendnum); #include "toxic_windows.h"
ToxWindow new_chat(Tox *m, int friendnum);
#endif /* end of include guard: CHAT_H_6489PZ13 */ #endif /* end of include guard: CHAT_H_6489PZ13 */

View File

@ -12,7 +12,9 @@
#include "toxic_windows.h" #include "toxic_windows.h"
#include "misc_tools.h" #include "misc_tools.h"
void cmd_chat_help(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) extern ToxWindow *prompt;
void cmd_chat_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
wattron(window, COLOR_PAIR(CYAN) | A_BOLD); wattron(window, COLOR_PAIR(CYAN) | A_BOLD);
wprintw(window, "Chat commands:\n"); wprintw(window, "Chat commands:\n");
@ -39,7 +41,7 @@ void cmd_chat_help(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc,
wattroff(window, COLOR_PAIR(CYAN)); wattroff(window, COLOR_PAIR(CYAN));
} }
void cmd_groupinvite(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
wprintw(window, "Invalid syntax.\n"); wprintw(window, "Invalid syntax.\n");
@ -53,7 +55,7 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int arg
return; return;
} }
if (tox_invite_friend(m, num, groupnum) == -1) { if (tox_invite_friend(m, self->num, groupnum) == -1) {
wprintw(window, "Failed to invite friend.\n"); wprintw(window, "Failed to invite friend.\n");
return; return;
} }
@ -61,16 +63,16 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int arg
wprintw(window, "Invited friend to group chat %d.\n", groupnum); wprintw(window, "Invited friend to group chat %d.\n", groupnum);
} }
void cmd_join_group(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
uint8_t *groupkey = friends[num].pending_groupchat; uint8_t *groupkey = friends[self->num].pending_groupchat;
if (groupkey[0] == '\0') { if (groupkey[0] == '\0') {
wprintw(window, "No pending group chat invite.\n"); wprintw(window, "No pending group chat invite.\n");
return; return;
} }
int groupnum = tox_join_groupchat(m, num, groupkey); int groupnum = tox_join_groupchat(m, self->num, groupkey);
if (groupnum == -1) { if (groupnum == -1) {
wprintw(window, "Group chat instance failed to initialize.\n"); wprintw(window, "Group chat instance failed to initialize.\n");
@ -84,7 +86,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc
} }
} }
void cmd_savefile(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc != 1) { if (argc != 1) {
wprintw(window, "Invalid syntax.\n"); wprintw(window, "Invalid syntax.\n");
@ -98,22 +100,22 @@ void cmd_savefile(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc,
return; return;
} }
if (!friends[num].file_receiver.pending[filenum]) { if (!friends[self->num].file_receiver.pending[filenum]) {
wprintw(window, "No pending file transfers with that number.\n"); wprintw(window, "No pending file transfers with that number.\n");
return; return;
} }
uint8_t *filename = friends[num].file_receiver.filenames[filenum]; uint8_t *filename = friends[self->num].file_receiver.filenames[filenum];
if (tox_file_sendcontrol(m, num, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0)) if (tox_file_sendcontrol(m, self->num, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0))
wprintw(window, "Accepted file transfer %u. Saving file as: '%s'\n", filenum, filename); wprintw(window, "Accepted file transfer %u. Saving file as: '%s'\n", filenum, filename);
else else
wprintw(window, "File transfer failed.\n"); wprintw(window, "File transfer failed.\n");
friends[num].file_receiver.pending[filenum] = false; friends[self->num].file_receiver.pending[filenum] = false;
} }
void cmd_sendfile(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (num_file_senders >= MAX_FILES) { if (num_file_senders >= MAX_FILES) {
wprintw(window,"Please wait for some of your outgoing file transfers to complete.\n"); wprintw(window,"Please wait for some of your outgoing file transfers to complete.\n");
@ -151,7 +153,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc,
uint64_t filesize = ftell(file_to_send); uint64_t filesize = ftell(file_to_send);
fseek(file_to_send, 0, SEEK_SET); fseek(file_to_send, 0, SEEK_SET);
int filenum = tox_new_filesender(m, num, filesize, path, path_len + 1); int filenum = tox_new_filesender(m, self->num, filesize, path, path_len + 1);
if (filenum == -1) { if (filenum == -1) {
wprintw(window, "Error sending file.\n"); wprintw(window, "Error sending file.\n");
@ -167,10 +169,10 @@ void cmd_sendfile(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc,
file_senders[i].chatwin = window; file_senders[i].chatwin = window;
file_senders[i].file = file_to_send; file_senders[i].file = file_to_send;
file_senders[i].filenum = (uint8_t) filenum; file_senders[i].filenum = (uint8_t) filenum;
file_senders[i].friendnum = num; file_senders[i].friendnum = self->num;
file_senders[i].timestamp = (uint64_t)time(NULL); file_senders[i].timestamp = (uint64_t)time(NULL);
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1, file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
tox_filedata_size(m, num), file_to_send); tox_filedata_size(m, self->num), file_to_send);
wprintw(window, "Sending file: '%s'\n", path); wprintw(window, "Sending file: '%s'\n", path);

View File

@ -2,8 +2,8 @@
* Toxic -- Tox Curses Client * Toxic -- Tox Curses Client
*/ */
void cmd_chat_help(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_chat_help(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_groupinvite(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_groupinvite(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_join_group(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_join_group(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_savefile(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_savefile(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_sendfile(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_sendfile(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);

View File

@ -12,7 +12,7 @@
struct cmd_func { struct cmd_func {
const char *name; const char *name;
void (*func)(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]); void (*func)(WINDOW *w, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
}; };
#define GLOBAL_NUM_COMMANDS 13 #define GLOBAL_NUM_COMMANDS 13
@ -79,14 +79,14 @@ static int parse_command(WINDOW *w, char *cmd, char (*args)[MAX_STR_SIZE])
} }
/* Matches command to respective function. Returns 0 on match, 1 on no match */ /* Matches command to respective function. Returns 0 on match, 1 on no match */
static int do_command(WINDOW *w, ToxWindow *prompt, Tox *m, int num, int num_args, int num_cmds, static int do_command(WINDOW *w, ToxWindow *self, Tox *m, int num_args, int num_cmds,
struct cmd_func *commands, char (*args)[MAX_STR_SIZE]) struct cmd_func *commands, char (*args)[MAX_STR_SIZE])
{ {
int i; int i;
for (i = 0; i < num_cmds; ++i) { for (i = 0; i < num_cmds; ++i) {
if (strcmp(args[0], commands[i].name) == 0) { if (strcmp(args[0], commands[i].name) == 0) {
(commands[i].func)(w, prompt, m, num, num_args-1, args); (commands[i].func)(w, self, m, num_args-1, args);
return 0; return 0;
} }
} }
@ -94,7 +94,7 @@ static int do_command(WINDOW *w, ToxWindow *prompt, Tox *m, int num, int num_arg
return 1; return 1;
} }
void execute(WINDOW *w, ToxWindow *prompt, Tox *m, int num, char *cmd, int mode) void execute(WINDOW* w, ToxWindow *self, Tox *m, char *cmd, int mode)
{ {
if (string_is_empty(cmd)) if (string_is_empty(cmd))
return; return;
@ -111,7 +111,7 @@ void execute(WINDOW *w, ToxWindow *prompt, Tox *m, int num, char *cmd, int mode)
Note: Global commands must come last in case of duplicate command names */ Note: Global commands must come last in case of duplicate command names */
switch (mode) { switch (mode) {
case CHAT_COMMAND_MODE: case CHAT_COMMAND_MODE:
if (do_command(w, prompt, m, num, num_args, CHAT_NUM_COMMANDS, chat_commands, args) == 0) if (do_command(w, self, m, num_args, CHAT_NUM_COMMANDS, chat_commands, args) == 0)
return; return;
break; break;
@ -119,7 +119,7 @@ void execute(WINDOW *w, ToxWindow *prompt, Tox *m, int num, char *cmd, int mode)
break; break;
} }
if (do_command(w, prompt, m, num, num_args, GLOBAL_NUM_COMMANDS, global_commands, args) == 0) if (do_command(w, self, m, num_args, GLOBAL_NUM_COMMANDS, global_commands, args) == 0)
return; return;
wprintw(w, "Invalid command.\n"); wprintw(w, "Invalid command.\n");

View File

@ -10,4 +10,4 @@ enum {
GROUPCHAT_COMMAND_MODE, GROUPCHAT_COMMAND_MODE,
}; };
void execute(WINDOW *w, ToxWindow *prompt, Tox *m, int num, char *cmd, int mode); void execute(WINDOW *w, ToxWindow *self, Tox *m, char *cmd, int mode);

View File

@ -12,6 +12,7 @@
#include <tox/tox.h> #include <tox/tox.h>
#include "chat.h"
#include "friendlist.h" #include "friendlist.h"
extern char *DATA_FILE; extern char *DATA_FILE;
@ -57,7 +58,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str,
return; return;
if (friends[num].chatwin == -1) if (friends[num].chatwin == -1)
friends[num].chatwin = add_window(m, new_chat(m, prompt, friends[num].num)); friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
} }
static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t status) static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t status)
@ -140,7 +141,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8
return; return;
if (friends[num].chatwin == -1) if (friends[num].chatwin == -1)
friends[num].chatwin = add_window(m, new_chat(m, prompt, friends[num].num)); friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
} }
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *group_pub_key) static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *group_pub_key)
@ -149,7 +150,7 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *
return; return;
if (friends[num].chatwin == -1) if (friends[num].chatwin == -1)
friends[num].chatwin = add_window(m, new_chat(m, prompt, friends[num].num)); friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
} }
static void select_friend(Tox *m, wint_t key) static void select_friend(Tox *m, wint_t key)
@ -197,7 +198,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
if (friends[f].chatwin != -1) { if (friends[f].chatwin != -1) {
set_active_window(friends[f].chatwin); set_active_window(friends[f].chatwin);
} else { } else {
friends[f].chatwin = add_window(m, new_chat(m, prompt, friends[f].num)); friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
set_active_window(friends[f].chatwin); set_active_window(friends[f].chatwin);
} }
} else if (key == 0x107 || key == 0x8 || key == 0x7f) { } else if (key == 0x107 || key == 0x8 || key == 0x7f) {

View File

@ -2,9 +2,8 @@
#define FRIENDLIST_H_53I41IM #define FRIENDLIST_H_53I41IM
#include "toxic_windows.h" #include "toxic_windows.h"
#include "chat.h"
ToxWindow new_friendlist(); ToxWindow new_friendlist(void);
void disable_chatwin(int f_num); void disable_chatwin(int f_num);
int get_friendnum(uint8_t *name); int get_friendnum(uint8_t *name);
void sort_friendlist_index(void); void sort_friendlist_index(void);

View File

@ -13,13 +13,14 @@
#include "misc_tools.h" #include "misc_tools.h"
extern char *DATA_FILE; extern char *DATA_FILE;
extern ToxWindow *prompt;
extern uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE]; extern uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
extern uint8_t num_frnd_requests; extern uint8_t num_frnd_requests;
extern int num_groupchats; extern int num_groupchats;
/* command functions */ /* command functions */
void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
/* check arguments */ /* check arguments */
if (argc != 1) { if (argc != 1) {
@ -60,7 +61,7 @@ void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, ch
num_frnd_requests = i; num_frnd_requests = i;
} }
void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
wprintw(window, "Invalid syntax.\n"); wprintw(window, "Invalid syntax.\n");
@ -144,13 +145,13 @@ void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char
} }
} }
void cmd_clear(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_clear(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
wclear(window); wclear(window);
wprintw(window, "\n\n"); wprintw(window, "\n\n");
} }
void cmd_connect(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
/* check arguments */ /* check arguments */
if (argc != 3) { if (argc != 3) {
@ -174,7 +175,7 @@ void cmd_connect(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, c
free(binary_string); free(binary_string);
} }
void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (num_groupchats >= MAX_GROUPCHAT_NUM) { if (num_groupchats >= MAX_GROUPCHAT_NUM) {
wprintw(window, "\nMaximum number of group chats has been reached.\n"); wprintw(window, "\nMaximum number of group chats has been reached.\n");
@ -197,7 +198,7 @@ void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc,
wprintw(window, "Group chat created as %d.\n", groupnum); wprintw(window, "Group chat created as %d.\n", groupnum);
} }
void cmd_myid(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_myid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {0}; char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {0};
uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
@ -214,7 +215,7 @@ void cmd_myid(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char
wprintw(window, "%s\n", id); wprintw(window, "%s\n", id);
} }
void cmd_nick(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
/* check arguments */ /* check arguments */
if (argc != 1) { if (argc != 1) {
@ -242,7 +243,7 @@ void cmd_nick(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char
store_data(m, DATA_FILE); store_data(m, DATA_FILE);
} }
void cmd_note(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
wprintw(window, "Wrong number of arguments.\n"); wprintw(window, "Wrong number of arguments.\n");
@ -259,10 +260,11 @@ void cmd_note(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char
msg[strlen(++msg)-1] = L'\0'; msg[strlen(++msg)-1] = L'\0';
uint16_t len = strlen(msg) + 1; uint16_t len = strlen(msg) + 1;
tox_set_statusmessage(m, msg, len); tox_set_statusmessage(m, msg, len);
prompt_update_statusmessage(prompt, msg, len); prompt_update_statusmessage(prompt, msg, len);
} }
void cmd_prompt_help(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
wclear(window); wclear(window);
wattron(window, COLOR_PAIR(CYAN) | A_BOLD); wattron(window, COLOR_PAIR(CYAN) | A_BOLD);
@ -289,12 +291,12 @@ void cmd_prompt_help(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int arg
wattroff(window, COLOR_PAIR(CYAN)); wattroff(window, COLOR_PAIR(CYAN));
} }
void cmd_quit(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_quit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
exit_toxic(m); exit_toxic(m);
} }
void cmd_status(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
uint8_t *msg = NULL; uint8_t *msg = NULL;

View File

@ -2,14 +2,14 @@
* Toxic -- Tox Curses Client * Toxic -- Tox Curses Client
*/ */
void cmd_accept(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_accept(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_add(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_add(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_clear(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_clear(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_connect(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_connect(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_groupchat(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_groupchat(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_myid(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_myid(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_nick(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_nick(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_note(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_note(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_prompt_help(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_prompt_help(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_quit(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_quit(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_status(WINDOW *, ToxWindow *, Tox *, int num, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_status(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);

View File

@ -18,7 +18,7 @@ static GroupChat groupchats[MAX_GROUPCHAT_NUM];
static int max_groupchat_index = 0; static int max_groupchat_index = 0;
int num_groupchats = 0; int num_groupchats = 0;
ToxWindow new_group_chat(Tox *m, ToxWindow *prompt, int groupnum); ToxWindow new_group_chat(Tox *m, int groupnum);
extern char *DATA_FILE; extern char *DATA_FILE;
extern int store_data(Tox *m, char *path); extern int store_data(Tox *m, char *path);
@ -29,7 +29,7 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
for (i = 0; i <= max_groupchat_index; ++i) { for (i = 0; i <= max_groupchat_index; ++i) {
if (!groupchats[i].active) { if (!groupchats[i].active) {
groupchats[i].chatwin = add_window(m, new_group_chat(m, prompt, groupnum)); groupchats[i].chatwin = add_window(m, new_group_chat(m, groupnum));
groupchats[i].active = true; groupchats[i].active = true;
set_active_window(groupchats[i].chatwin); set_active_window(groupchats[i].chatwin);
@ -153,7 +153,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
bool close_win = false; bool close_win = false;
if (line[0] == '/') { if (line[0] == '/') {
if (close_win = strncmp(line, "/close", strlen("/close")) == 0) { if (close_win = strcmp(line, "/close") == 0) {
set_active_window(0); set_active_window(0);
int groupnum = self->num; int groupnum = self->num;
delwin(ctx->linewin); delwin(ctx->linewin);
@ -162,7 +162,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
} else if (strncmp(line, "/help", strlen("/help")) == 0) } else if (strncmp(line, "/help", strlen("/help")) == 0)
print_groupchat_help(ctx); print_groupchat_help(ctx);
else else
execute(ctx->history, self->prompt, m, self->num, line, GROUPCHAT_COMMAND_MODE); execute(ctx->history, self, m, line, GROUPCHAT_COMMAND_MODE);
} else { } else {
/* make sure the string has at least non-space character */ /* make sure the string has at least non-space character */
if (!string_is_empty(line)) { if (!string_is_empty(line)) {
@ -216,7 +216,7 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
wmove(self->window, y - CURS_Y_OFFSET, 0); wmove(self->window, y - CURS_Y_OFFSET, 0);
} }
ToxWindow new_group_chat(Tox *m, ToxWindow *prompt, int groupnum) ToxWindow new_group_chat(Tox *m, int groupnum)
{ {
ToxWindow ret; ToxWindow ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
@ -241,7 +241,6 @@ ToxWindow new_group_chat(Tox *m, ToxWindow *prompt, int groupnum)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ret.prompt = prompt;
ret.num = groupnum; ret.num = groupnum;
return ret; return ret;

View File

@ -24,4 +24,4 @@ char *wc_to_char(wchar_t ch);
bool timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime); bool timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime);
/* Beeps and makes window tab blink */ /* Beeps and makes window tab blink */
void alert_window(ToxWindow *self); void alert_window(ToxWindow *self);

View File

@ -102,7 +102,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
/* RETURN key: execute command */ /* RETURN key: execute command */
else if (key == '\n') { else if (key == '\n') {
wprintw(self->window, "\n"); wprintw(self->window, "\n");
execute(self->window, self, m, self->num, prompt_buf, GLOBAL_COMMAND_MODE); execute(self->window, self, m, prompt_buf, GLOBAL_COMMAND_MODE);
prompt_buf_pos = 0; prompt_buf_pos = 0;
prompt_buf[0] = '\0'; prompt_buf[0] = '\0';
} }
@ -180,7 +180,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
static void prompt_onInit(ToxWindow *self, Tox *m) static void prompt_onInit(ToxWindow *self, Tox *m)
{ {
scrollok(self->window, true); scrollok(self->window, true);
execute(self->window, self, m, self->num, "/help", GLOBAL_COMMAND_MODE); execute(self->window, self, m, "/help", GLOBAL_COMMAND_MODE);
wclrtoeol(self->window); wclrtoeol(self->window);
} }

View File

@ -66,14 +66,12 @@ struct ToxWindow_ {
void(*onFileData)(ToxWindow *, Tox *, int, uint8_t, uint8_t *, uint16_t); void(*onFileData)(ToxWindow *, Tox *, int, uint8_t, uint8_t *, uint16_t);
char name[TOX_MAX_NAME_LENGTH]; char name[TOX_MAX_NAME_LENGTH];
bool blink;
int num; int num;
int x; int x;
void *chatwin; void *chatwin;
void *stb; void *stb;
void *prompt;
bool blink;
WINDOW *window; WINDOW *window;
}; };

View File

@ -13,8 +13,8 @@ extern char *DATA_FILE;
static ToxWindow windows[MAX_WINDOWS_NUM]; static ToxWindow windows[MAX_WINDOWS_NUM];
static ToxWindow *active_window; static ToxWindow *active_window;
static ToxWindow *prompt;
static Tox *m; static Tox *m;
static ToxWindow *prompt;
/* CALLBACKS START */ /* CALLBACKS START */
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)