mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-13 02:43:02 +01:00
remove externs in favor of includes
This commit is contained in:
parent
063523a042
commit
2c81fd5e4b
10
chat.c
10
chat.c
@ -13,6 +13,8 @@
|
||||
#include "../../core/network.h"
|
||||
|
||||
#include "windows.h"
|
||||
#include "friendlist.h"
|
||||
#include "chat.h"
|
||||
|
||||
#define CURS_Y_OFFSET 3
|
||||
|
||||
@ -24,10 +26,8 @@ typedef struct {
|
||||
WINDOW* linewin;
|
||||
} ChatContext;
|
||||
|
||||
extern int active_window;
|
||||
static delWindowFn *del_window;
|
||||
|
||||
extern void del_window(ToxWindow *w, int f_num);
|
||||
extern void fix_name(uint8_t *name);
|
||||
void print_help(ChatContext *self);
|
||||
void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd);
|
||||
|
||||
@ -320,7 +320,6 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd)
|
||||
}
|
||||
|
||||
else if (strcmp(ctx->line, "/close") == 0) {
|
||||
active_window = 0; // Go to prompt screen
|
||||
int f_num = ctx->friendnum;
|
||||
delwin(ctx->linewin);
|
||||
del_window(self, f_num);
|
||||
@ -371,8 +370,9 @@ void print_help(ChatContext *self)
|
||||
wattroff(self->history, COLOR_PAIR(2));
|
||||
}
|
||||
|
||||
ToxWindow new_chat(Messenger *m, int friendnum)
|
||||
ToxWindow new_chat(Messenger *m, int friendnum, delWindowFn *f)
|
||||
{
|
||||
del_window = f;
|
||||
ToxWindow ret;
|
||||
memset(&ret, 0, sizeof(ret));
|
||||
|
||||
|
7
chat.h
Normal file
7
chat.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef CHAT_H_6489PZ13
|
||||
#define CHAT_H_6489PZ13
|
||||
|
||||
typedef void (delWindowFn)(ToxWindow *w, int f_num);
|
||||
ToxWindow new_chat(Messenger *m, int friendnum, delWindowFn f);
|
||||
|
||||
#endif /* end of include guard: CHAT_H_6489PZ13 */
|
25
friendlist.c
25
friendlist.c
@ -10,13 +10,12 @@
|
||||
#include "../../core/Messenger.h"
|
||||
#include "../../core/network.h"
|
||||
|
||||
#include "windows.h"
|
||||
#include "friendlist.h"
|
||||
|
||||
extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM];
|
||||
extern int add_window(Messenger *m, ToxWindow w, int n);
|
||||
extern ToxWindow new_chat(Messenger *m, int friendnum);
|
||||
|
||||
extern int active_window;
|
||||
static delWindowFn *del_window;
|
||||
static setActiveWindowFn *set_active_window;
|
||||
static addWindowFn *add_window;
|
||||
static char * WINDOW_STATUS;
|
||||
|
||||
typedef struct {
|
||||
uint8_t name[MAX_NAME_LENGTH];
|
||||
@ -54,8 +53,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(m, new_chat(m, num), i);
|
||||
active_window = i;
|
||||
add_window(m, new_chat(m, num, del_window), i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -111,7 +109,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key)
|
||||
int i;
|
||||
for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) {
|
||||
if (WINDOW_STATUS[i] == num_selected) {
|
||||
active_window = i;
|
||||
set_active_window(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -121,8 +119,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(m, new_chat(m, num_selected), i);
|
||||
active_window = i;
|
||||
add_window(m, new_chat(m, num_selected, del_window), i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -169,7 +166,11 @@ static void friendlist_onInit(ToxWindow *self, Messenger *m)
|
||||
|
||||
}
|
||||
|
||||
ToxWindow new_friendlist() {
|
||||
ToxWindow new_friendlist(delWindowFn dw, setActiveWindowFn saw, addWindowFn aw, char * ws) {
|
||||
del_window = dw;
|
||||
set_active_window = saw;
|
||||
add_window = aw;
|
||||
WINDOW_STATUS = ws;
|
||||
ToxWindow ret;
|
||||
memset(&ret, 0, sizeof(ret));
|
||||
|
||||
|
14
friendlist.h
Normal file
14
friendlist.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef FRIENDLIST_H_53I41IM
|
||||
#define FRIENDLIST_H_53I41IM
|
||||
|
||||
|
||||
#include "windows.h"
|
||||
#include "chat.h"
|
||||
typedef void (setActiveWindowFn)(int ch);
|
||||
typedef int (addWindowFn)(Messenger *m, ToxWindow w, int n);
|
||||
ToxWindow new_friendlist(delWindowFn dw, setActiveWindowFn saw, addWindowFn aw, char * ws);
|
||||
int friendlist_onFriendAdded(Messenger *m, int num);
|
||||
void disable_chatwin(int f_num);
|
||||
void fix_name(uint8_t *name);
|
||||
|
||||
#endif /* end of include guard: FRIENDLIST_H_53I41IM */
|
84
main.c
84
main.c
@ -21,14 +21,9 @@
|
||||
|
||||
#include "configdir.h"
|
||||
#include "windows.h"
|
||||
#include "prompt.h"
|
||||
#include "friendlist.h"
|
||||
|
||||
extern ToxWindow new_prompt();
|
||||
extern ToxWindow new_friendlist();
|
||||
|
||||
extern int friendlist_onFriendAdded(Messenger *m, int num);
|
||||
extern void disable_chatwin(int f_num);
|
||||
extern int add_req(uint8_t *public_key); // XXX
|
||||
extern unsigned char *hex_string_to_bin(char hex_string[]);
|
||||
|
||||
/* Holds status of chat windows */
|
||||
char WINDOW_STATUS[MAX_WINDOW_SLOTS];
|
||||
@ -221,12 +216,14 @@ int add_window(Messenger *m, ToxWindow w, int n)
|
||||
windows[n] = w;
|
||||
w.onInit(&w, m);
|
||||
w_num++;
|
||||
active_window = n;
|
||||
return n;
|
||||
}
|
||||
|
||||
/* Deletes window w and cleans up */
|
||||
void del_window(ToxWindow *w, int f_num)
|
||||
{
|
||||
active_window = 0; // Go to prompt screen
|
||||
delwin(w->window);
|
||||
int i;
|
||||
for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) {
|
||||
@ -240,13 +237,48 @@ void del_window(ToxWindow *w, int f_num)
|
||||
refresh();
|
||||
}
|
||||
|
||||
/* Shows next window when tab or back-tab is pressed */
|
||||
void set_active_window(int ch)
|
||||
{
|
||||
int f_inf = 0;
|
||||
int max = MAX_WINDOW_SLOTS-1;
|
||||
if (ch == '\t') {
|
||||
int i = (active_window + 1) % max;
|
||||
while (true) {
|
||||
if (WINDOW_STATUS[i] != -1) {
|
||||
active_window = i;
|
||||
return;
|
||||
}
|
||||
i = (i + 1) % max;
|
||||
if (f_inf++ > max) { // infinite loop check
|
||||
endwin();
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
int i = active_window - 1;
|
||||
if (i < 0) i = max;
|
||||
while (true) {
|
||||
if (WINDOW_STATUS[i] != -1) {
|
||||
active_window = i;
|
||||
return;
|
||||
}
|
||||
if (--i < 0) i = max;
|
||||
if (f_inf++ > max) {
|
||||
endwin();
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void init_windows(Messenger *m)
|
||||
{
|
||||
w_num = 0;
|
||||
int n_prompt = 0;
|
||||
int n_friendslist = 1;
|
||||
if (add_window(m, new_prompt(), n_prompt) == -1
|
||||
|| add_window(m, new_friendlist(), n_friendslist) == -1) {
|
||||
if (add_window(m, new_prompt(on_friendadded), n_prompt) == -1
|
||||
|| add_window(m, new_friendlist(del_window, set_active_window, add_window, WINDOW_STATUS), n_friendslist) == -1) {
|
||||
fprintf(stderr, "add_window() failed.\n");
|
||||
endwin();
|
||||
exit(1);
|
||||
@ -378,40 +410,6 @@ void prepare_window(WINDOW *w)
|
||||
wresize(w, LINES-2, COLS);
|
||||
}
|
||||
|
||||
/* Shows next window when tab or back-tab is pressed */
|
||||
void set_active_window(int ch)
|
||||
{
|
||||
int f_inf = 0;
|
||||
int max = MAX_WINDOW_SLOTS-1;
|
||||
if (ch == '\t') {
|
||||
int i = (active_window + 1) % max;
|
||||
while (true) {
|
||||
if (WINDOW_STATUS[i] != -1) {
|
||||
active_window = i;
|
||||
return;
|
||||
}
|
||||
i = (i + 1) % max;
|
||||
if (f_inf++ > max) { // infinite loop check
|
||||
endwin();
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
int i = active_window - 1;
|
||||
if (i < 0) i = max;
|
||||
while (true) {
|
||||
if (WINDOW_STATUS[i] != -1) {
|
||||
active_window = i;
|
||||
return;
|
||||
}
|
||||
if (--i < 0) i = max;
|
||||
if (f_inf++ > max) {
|
||||
endwin();
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
6
prompt.c
6
prompt.c
@ -11,11 +11,12 @@
|
||||
#include "../../core/network.h"
|
||||
|
||||
#include "windows.h"
|
||||
#include "prompt.h"
|
||||
|
||||
uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX
|
||||
uint8_t num_requests=0; // XXX
|
||||
|
||||
extern void on_friendadded(Messenger *m, int friendnumber);
|
||||
static friendAddedFn *on_friendadded;
|
||||
static char prompt_buf[MAX_STR_SIZE] = {0};
|
||||
static int prompt_buf_pos = 0;
|
||||
|
||||
@ -428,8 +429,9 @@ static void prompt_onInit(ToxWindow *self, Messenger *m)
|
||||
wclrtoeol(self->window);
|
||||
}
|
||||
|
||||
ToxWindow new_prompt()
|
||||
ToxWindow new_prompt(friendAddedFn *f)
|
||||
{
|
||||
on_friendadded = f;
|
||||
ToxWindow ret;
|
||||
memset(&ret, 0, sizeof(ret));
|
||||
ret.onKey = &prompt_onKey;
|
||||
|
14
prompt.h
Normal file
14
prompt.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef PROMPT_H_UZYGWFFL
|
||||
#define PROMPT_H_UZYGWFFL
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
typedef void (friendAddedFn)(Messenger *m, int friendnumber);
|
||||
|
||||
ToxWindow new_prompt(friendAddedFn *f);
|
||||
int add_req(uint8_t *public_key);
|
||||
unsigned char *hex_string_to_bin(char hex_string[]);
|
||||
|
||||
#endif /* end of include guard: PROMPT_H_UZYGWFFL */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user