1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 16:33:03 +01:00

prefer param over static

Conflicts:
	testing/toxic/main.c
This commit is contained in:
Aaron Lipinski 2013-08-13 09:34:46 +12:00
parent ce9d066054
commit 5d07842d96
3 changed files with 20 additions and 21 deletions

View File

@ -13,7 +13,7 @@
#include "windows.h"
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 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) {
if (WINDOW_STATUS[i] == -1) {
WINDOW_STATUS[i] = num;
add_window(new_chat(m, num), i);
add_window(m, new_chat(m, num), i);
active_window = i;
break;
}
@ -121,7 +121,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key)
if (WINDOW_STATUS[i] == -1) {
WINDOW_STATUS[i] = 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;
break;
}

29
main.c
View File

@ -40,8 +40,6 @@ char WINDOW_STATUS[MAX_WINDOW_SLOTS];
static ToxWindow windows[MAX_WINDOW_SLOTS];
static ToxWindow* prompt;
static Messenger *m;
int w_num;
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);
}
@ -129,10 +127,10 @@ static void init_term()
refresh();
}
static void init_tox()
static Messenger * init_tox()
{
/* Init core */
m = initMessenger();
Messenger *m = initMessenger();
/* Callbacks */
m_callback_friendrequest(m, on_request, NULL);
@ -147,6 +145,7 @@ static void init_tox()
#else
setname(m, (uint8_t*) "Hipster", sizeof("Hipster"));
#endif
return m;
}
#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;
}
int add_window(ToxWindow w, int n)
int add_window(Messenger *m, ToxWindow w, int n)
{
if (w_num >= TOXWINDOWS_MAX_NUM)
return -1;
@ -241,13 +240,13 @@ void del_window(ToxWindow *w, int f_num)
refresh();
}
static void init_windows()
static void init_windows(Messenger *m)
{
w_num = 0;
int n_prompt = 0;
int n_friendslist = 1;
if (add_window(new_prompt(), n_prompt) == -1
|| add_window(new_friendlist(), n_friendslist) == -1) {
if (add_window(m, new_prompt(), n_prompt) == -1
|| add_window(m, new_friendlist(), n_friendslist) == -1) {
fprintf(stderr, "add_window() failed.\n");
endwin();
exit(1);
@ -255,7 +254,7 @@ static void init_windows()
prompt = &windows[n_prompt];
}
static void do_tox()
static void do_tox(Messenger *m)
{
static int conn_try = 0;
static int conn_err = 0;
@ -279,7 +278,7 @@ static void do_tox()
doMessenger(m);
}
static void load_data(char *path)
static void load_data(Messenger *m, char *path)
{
FILE *fd;
size_t len;
@ -451,12 +450,12 @@ int main(int argc, char *argv[])
}
init_term();
init_tox();
init_windows();
Messenger *m = init_tox();
init_windows(m);
init_window_status();
if(f_loadfromfile)
load_data(DATA_FILE);
load_data(m, DATA_FILE);
free(DATA_FILE);
if (f_flag == -1) {
@ -474,7 +473,7 @@ int main(int argc, char *argv[])
}
while(true) {
/* Update tox */
do_tox();
do_tox(m);
/* Draw */
a = &windows[active_window];

View File

@ -15,7 +15,7 @@
uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // 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 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");
else {
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;
default:
wprintw(self->window, "Friend added as %d.\n", num);
on_friendadded(num);
on_friendadded(m, num);
break;
}
}