diff options
-rw-r--r-- | testing/toxic/friendlist.c | 6 | ||||
-rw-r--r-- | testing/toxic/main.c | 29 | ||||
-rw-r--r-- | testing/toxic/prompt.c | 6 |
3 files changed, 20 insertions, 21 deletions
diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c index 56061cf9..1a77440e 100644 --- a/testing/toxic/friendlist.c +++ b/testing/toxic/friendlist.c | |||
@@ -13,7 +13,7 @@ | |||
13 | #include "windows.h" | 13 | #include "windows.h" |
14 | 14 | ||
15 | extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM]; | 15 | extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM]; |
16 | extern int add_window(ToxWindow w, int n); | 16 | extern int add_window(Messenger *m, ToxWindow w, int n); |
17 | extern ToxWindow new_chat(Messenger *m, int friendnum); | 17 | extern ToxWindow new_chat(Messenger *m, int friendnum); |
18 | 18 | ||
19 | extern int active_window; | 19 | extern int active_window; |
@@ -54,7 +54,7 @@ void friendlist_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *str, | |||
54 | for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { | 54 | for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { |
55 | if (WINDOW_STATUS[i] == -1) { | 55 | if (WINDOW_STATUS[i] == -1) { |
56 | WINDOW_STATUS[i] = num; | 56 | WINDOW_STATUS[i] = num; |
57 | add_window(new_chat(m, num), i); | 57 | add_window(m, new_chat(m, num), i); |
58 | active_window = i; | 58 | active_window = i; |
59 | break; | 59 | break; |
60 | } | 60 | } |
@@ -121,7 +121,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key) | |||
121 | if (WINDOW_STATUS[i] == -1) { | 121 | if (WINDOW_STATUS[i] == -1) { |
122 | WINDOW_STATUS[i] = num_selected; | 122 | WINDOW_STATUS[i] = num_selected; |
123 | friends[num_selected].chatwin = num_selected; | 123 | friends[num_selected].chatwin = num_selected; |
124 | add_window(new_chat(m, num_selected), i); | 124 | add_window(m, new_chat(m, num_selected), i); |
125 | active_window = i; | 125 | active_window = i; |
126 | break; | 126 | break; |
127 | } | 127 | } |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 40ff5d09..8ab2d393 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -40,8 +40,6 @@ char WINDOW_STATUS[MAX_WINDOW_SLOTS]; | |||
40 | static ToxWindow windows[MAX_WINDOW_SLOTS]; | 40 | static ToxWindow windows[MAX_WINDOW_SLOTS]; |
41 | static ToxWindow* prompt; | 41 | static ToxWindow* prompt; |
42 | 42 | ||
43 | static Messenger *m; | ||
44 | |||
45 | int w_num; | 43 | int w_num; |
46 | int active_window; | 44 | int active_window; |
47 | 45 | ||
@@ -103,7 +101,7 @@ void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t l | |||
103 | } | 101 | } |
104 | } | 102 | } |
105 | 103 | ||
106 | void on_friendadded(int friendnumber) | 104 | void on_friendadded(Messenger *m, int friendnumber) |
107 | { | 105 | { |
108 | friendlist_onFriendAdded(m, friendnumber); | 106 | friendlist_onFriendAdded(m, friendnumber); |
109 | } | 107 | } |
@@ -129,10 +127,10 @@ static void init_term() | |||
129 | refresh(); | 127 | refresh(); |
130 | } | 128 | } |
131 | 129 | ||
132 | static void init_tox() | 130 | static Messenger * init_tox() |
133 | { | 131 | { |
134 | /* Init core */ | 132 | /* Init core */ |
135 | m = initMessenger(); | 133 | Messenger *m = initMessenger(); |
136 | 134 | ||
137 | /* Callbacks */ | 135 | /* Callbacks */ |
138 | m_callback_friendrequest(m, on_request, NULL); | 136 | m_callback_friendrequest(m, on_request, NULL); |
@@ -147,6 +145,7 @@ static void init_tox() | |||
147 | #else | 145 | #else |
148 | setname(m, (uint8_t*) "Hipster", sizeof("Hipster")); | 146 | setname(m, (uint8_t*) "Hipster", sizeof("Hipster")); |
149 | #endif | 147 | #endif |
148 | return m; | ||
150 | } | 149 | } |
151 | 150 | ||
152 | #define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ | 151 | #define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ |
@@ -207,7 +206,7 @@ void init_window_status() | |||
207 | WINDOW_STATUS[j] = -1; | 206 | WINDOW_STATUS[j] = -1; |
208 | } | 207 | } |
209 | 208 | ||
210 | int add_window(ToxWindow w, int n) | 209 | int add_window(Messenger *m, ToxWindow w, int n) |
211 | { | 210 | { |
212 | if (w_num >= TOXWINDOWS_MAX_NUM) | 211 | if (w_num >= TOXWINDOWS_MAX_NUM) |
213 | return -1; | 212 | return -1; |
@@ -241,13 +240,13 @@ void del_window(ToxWindow *w, int f_num) | |||
241 | refresh(); | 240 | refresh(); |
242 | } | 241 | } |
243 | 242 | ||
244 | static void init_windows() | 243 | static void init_windows(Messenger *m) |
245 | { | 244 | { |
246 | w_num = 0; | 245 | w_num = 0; |
247 | int n_prompt = 0; | 246 | int n_prompt = 0; |
248 | int n_friendslist = 1; | 247 | int n_friendslist = 1; |
249 | if (add_window(new_prompt(), n_prompt) == -1 | 248 | if (add_window(m, new_prompt(), n_prompt) == -1 |
250 | || add_window(new_friendlist(), n_friendslist) == -1) { | 249 | || add_window(m, new_friendlist(), n_friendslist) == -1) { |
251 | fprintf(stderr, "add_window() failed.\n"); | 250 | fprintf(stderr, "add_window() failed.\n"); |
252 | endwin(); | 251 | endwin(); |
253 | exit(1); | 252 | exit(1); |
@@ -255,7 +254,7 @@ static void init_windows() | |||
255 | prompt = &windows[n_prompt]; | 254 | prompt = &windows[n_prompt]; |
256 | } | 255 | } |
257 | 256 | ||
258 | static void do_tox() | 257 | static void do_tox(Messenger *m) |
259 | { | 258 | { |
260 | static int conn_try = 0; | 259 | static int conn_try = 0; |
261 | static int conn_err = 0; | 260 | static int conn_err = 0; |
@@ -279,7 +278,7 @@ static void do_tox() | |||
279 | doMessenger(m); | 278 | doMessenger(m); |
280 | } | 279 | } |
281 | 280 | ||
282 | static void load_data(char *path) | 281 | static void load_data(Messenger *m, char *path) |
283 | { | 282 | { |
284 | FILE *fd; | 283 | FILE *fd; |
285 | size_t len; | 284 | size_t len; |
@@ -451,12 +450,12 @@ int main(int argc, char *argv[]) | |||
451 | } | 450 | } |
452 | 451 | ||
453 | init_term(); | 452 | init_term(); |
454 | init_tox(); | 453 | Messenger *m = init_tox(); |
455 | init_windows(); | 454 | init_windows(m); |
456 | init_window_status(); | 455 | init_window_status(); |
457 | 456 | ||
458 | if(f_loadfromfile) | 457 | if(f_loadfromfile) |
459 | load_data(DATA_FILE); | 458 | load_data(m, DATA_FILE); |
460 | free(DATA_FILE); | 459 | free(DATA_FILE); |
461 | 460 | ||
462 | if (f_flag == -1) { | 461 | if (f_flag == -1) { |
@@ -474,7 +473,7 @@ int main(int argc, char *argv[]) | |||
474 | } | 473 | } |
475 | while(true) { | 474 | while(true) { |
476 | /* Update tox */ | 475 | /* Update tox */ |
477 | do_tox(); | 476 | do_tox(m); |
478 | 477 | ||
479 | /* Draw */ | 478 | /* Draw */ |
480 | a = &windows[active_window]; | 479 | a = &windows[active_window]; |
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index b1d6693f..c01ed710 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c | |||
@@ -15,7 +15,7 @@ | |||
15 | uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX | 15 | uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX |
16 | uint8_t num_requests=0; // XXX | 16 | uint8_t num_requests=0; // XXX |
17 | 17 | ||
18 | extern void on_friendadded(int friendnumber); | 18 | extern void on_friendadded(Messenger *m, int friendnumber); |
19 | static char prompt_buf[MAX_STR_SIZE] = {0}; | 19 | static char prompt_buf[MAX_STR_SIZE] = {0}; |
20 | static int prompt_buf_pos = 0; | 20 | static int prompt_buf_pos = 0; |
21 | 21 | ||
@@ -87,7 +87,7 @@ void cmd_accept(ToxWindow *self, Messenger *m, char **args) | |||
87 | wprintw(self->window, "Failed to add friend.\n"); | 87 | wprintw(self->window, "Failed to add friend.\n"); |
88 | else { | 88 | else { |
89 | wprintw(self->window, "Friend accepted as: %d.\n", num); | 89 | wprintw(self->window, "Friend accepted as: %d.\n", num); |
90 | on_friendadded(num); | 90 | on_friendadded(m, num); |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
@@ -146,7 +146,7 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) | |||
146 | break; | 146 | break; |
147 | default: | 147 | default: |
148 | wprintw(self->window, "Friend added as %d.\n", num); | 148 | wprintw(self->window, "Friend added as %d.\n", num); |
149 | on_friendadded(num); | 149 | on_friendadded(m, num); |
150 | break; | 150 | break; |
151 | } | 151 | } |
152 | } | 152 | } |