mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:03:02 +01:00
prefer param over static
Conflicts: testing/toxic/main.c
This commit is contained in:
parent
ce9d066054
commit
5d07842d96
@ -13,7 +13,7 @@
|
|||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
|
||||||
extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM];
|
extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM];
|
||||||
extern int add_window(ToxWindow w, int n);
|
extern int add_window(Messenger *m, ToxWindow w, int n);
|
||||||
extern ToxWindow new_chat(Messenger *m, int friendnum);
|
extern ToxWindow new_chat(Messenger *m, int friendnum);
|
||||||
|
|
||||||
extern int active_window;
|
extern int active_window;
|
||||||
@ -54,7 +54,7 @@ void friendlist_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *str,
|
|||||||
for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) {
|
for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) {
|
||||||
if (WINDOW_STATUS[i] == -1) {
|
if (WINDOW_STATUS[i] == -1) {
|
||||||
WINDOW_STATUS[i] = num;
|
WINDOW_STATUS[i] = num;
|
||||||
add_window(new_chat(m, num), i);
|
add_window(m, new_chat(m, num), i);
|
||||||
active_window = i;
|
active_window = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key)
|
|||||||
if (WINDOW_STATUS[i] == -1) {
|
if (WINDOW_STATUS[i] == -1) {
|
||||||
WINDOW_STATUS[i] = num_selected;
|
WINDOW_STATUS[i] = num_selected;
|
||||||
friends[num_selected].chatwin = num_selected;
|
friends[num_selected].chatwin = num_selected;
|
||||||
add_window(new_chat(m, num_selected), i);
|
add_window(m, new_chat(m, num_selected), i);
|
||||||
active_window = i;
|
active_window = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
29
main.c
29
main.c
@ -40,8 +40,6 @@ char WINDOW_STATUS[MAX_WINDOW_SLOTS];
|
|||||||
static ToxWindow windows[MAX_WINDOW_SLOTS];
|
static ToxWindow windows[MAX_WINDOW_SLOTS];
|
||||||
static ToxWindow* prompt;
|
static ToxWindow* prompt;
|
||||||
|
|
||||||
static Messenger *m;
|
|
||||||
|
|
||||||
int w_num;
|
int w_num;
|
||||||
int active_window;
|
int active_window;
|
||||||
|
|
||||||
@ -103,7 +101,7 @@ void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t l
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_friendadded(int friendnumber)
|
void on_friendadded(Messenger *m, int friendnumber)
|
||||||
{
|
{
|
||||||
friendlist_onFriendAdded(m, friendnumber);
|
friendlist_onFriendAdded(m, friendnumber);
|
||||||
}
|
}
|
||||||
@ -129,10 +127,10 @@ static void init_term()
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_tox()
|
static Messenger * init_tox()
|
||||||
{
|
{
|
||||||
/* Init core */
|
/* Init core */
|
||||||
m = initMessenger();
|
Messenger *m = initMessenger();
|
||||||
|
|
||||||
/* Callbacks */
|
/* Callbacks */
|
||||||
m_callback_friendrequest(m, on_request, NULL);
|
m_callback_friendrequest(m, on_request, NULL);
|
||||||
@ -147,6 +145,7 @@ static void init_tox()
|
|||||||
#else
|
#else
|
||||||
setname(m, (uint8_t*) "Hipster", sizeof("Hipster"));
|
setname(m, (uint8_t*) "Hipster", sizeof("Hipster"));
|
||||||
#endif
|
#endif
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */
|
#define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */
|
||||||
@ -207,7 +206,7 @@ void init_window_status()
|
|||||||
WINDOW_STATUS[j] = -1;
|
WINDOW_STATUS[j] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int add_window(ToxWindow w, int n)
|
int add_window(Messenger *m, ToxWindow w, int n)
|
||||||
{
|
{
|
||||||
if (w_num >= TOXWINDOWS_MAX_NUM)
|
if (w_num >= TOXWINDOWS_MAX_NUM)
|
||||||
return -1;
|
return -1;
|
||||||
@ -241,13 +240,13 @@ void del_window(ToxWindow *w, int f_num)
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_windows()
|
static void init_windows(Messenger *m)
|
||||||
{
|
{
|
||||||
w_num = 0;
|
w_num = 0;
|
||||||
int n_prompt = 0;
|
int n_prompt = 0;
|
||||||
int n_friendslist = 1;
|
int n_friendslist = 1;
|
||||||
if (add_window(new_prompt(), n_prompt) == -1
|
if (add_window(m, new_prompt(), n_prompt) == -1
|
||||||
|| add_window(new_friendlist(), n_friendslist) == -1) {
|
|| add_window(m, new_friendlist(), n_friendslist) == -1) {
|
||||||
fprintf(stderr, "add_window() failed.\n");
|
fprintf(stderr, "add_window() failed.\n");
|
||||||
endwin();
|
endwin();
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -255,7 +254,7 @@ static void init_windows()
|
|||||||
prompt = &windows[n_prompt];
|
prompt = &windows[n_prompt];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_tox()
|
static void do_tox(Messenger *m)
|
||||||
{
|
{
|
||||||
static int conn_try = 0;
|
static int conn_try = 0;
|
||||||
static int conn_err = 0;
|
static int conn_err = 0;
|
||||||
@ -279,7 +278,7 @@ static void do_tox()
|
|||||||
doMessenger(m);
|
doMessenger(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_data(char *path)
|
static void load_data(Messenger *m, char *path)
|
||||||
{
|
{
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -451,12 +450,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_term();
|
init_term();
|
||||||
init_tox();
|
Messenger *m = init_tox();
|
||||||
init_windows();
|
init_windows(m);
|
||||||
init_window_status();
|
init_window_status();
|
||||||
|
|
||||||
if(f_loadfromfile)
|
if(f_loadfromfile)
|
||||||
load_data(DATA_FILE);
|
load_data(m, DATA_FILE);
|
||||||
free(DATA_FILE);
|
free(DATA_FILE);
|
||||||
|
|
||||||
if (f_flag == -1) {
|
if (f_flag == -1) {
|
||||||
@ -474,7 +473,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
while(true) {
|
while(true) {
|
||||||
/* Update tox */
|
/* Update tox */
|
||||||
do_tox();
|
do_tox(m);
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
a = &windows[active_window];
|
a = &windows[active_window];
|
||||||
|
6
prompt.c
6
prompt.c
@ -15,7 +15,7 @@
|
|||||||
uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX
|
uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX
|
||||||
uint8_t num_requests=0; // XXX
|
uint8_t num_requests=0; // XXX
|
||||||
|
|
||||||
extern void on_friendadded(int friendnumber);
|
extern void on_friendadded(Messenger *m, int friendnumber);
|
||||||
static char prompt_buf[MAX_STR_SIZE] = {0};
|
static char prompt_buf[MAX_STR_SIZE] = {0};
|
||||||
static int prompt_buf_pos = 0;
|
static int prompt_buf_pos = 0;
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ void cmd_accept(ToxWindow *self, Messenger *m, char **args)
|
|||||||
wprintw(self->window, "Failed to add friend.\n");
|
wprintw(self->window, "Failed to add friend.\n");
|
||||||
else {
|
else {
|
||||||
wprintw(self->window, "Friend accepted as: %d.\n", num);
|
wprintw(self->window, "Friend accepted as: %d.\n", num);
|
||||||
on_friendadded(num);
|
on_friendadded(m, num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
wprintw(self->window, "Friend added as %d.\n", num);
|
wprintw(self->window, "Friend added as %d.\n", num);
|
||||||
on_friendadded(num);
|
on_friendadded(m, num);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user