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

reduce syntactic complexity - these don't need to be void

This commit is contained in:
Jfreegman 2013-11-29 17:48:08 -05:00
parent e4e7ed7e4e
commit 7ad520f128
7 changed files with 47 additions and 43 deletions

View File

@ -13,6 +13,7 @@
#include "toxic_windows.h" #include "toxic_windows.h"
#include "execute.h" #include "execute.h"
#include "misc_tools.h" #include "misc_tools.h"
#include "friendlist.h"
extern char *DATA_FILE; extern char *DATA_FILE;
extern int store_data(Tox *m, char *path); extern int store_data(Tox *m, char *path);
@ -23,7 +24,7 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint1
if (self->num != num) if (self->num != num)
return; return;
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
tox_get_name(m, num, nick); tox_get_name(m, num, nick);
@ -49,7 +50,7 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t st
if (self->num != num) if (self->num != num)
return; return;
StatusBar *statusbar = (StatusBar *) self->stb; StatusBar *statusbar = self->stb;
statusbar->is_online = status == 1 ? true : false; statusbar->is_online = status == 1 ? true : false;
} }
@ -58,7 +59,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
if (self->num != num) if (self->num != num)
return; return;
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
tox_get_name(m, num, nick); tox_get_name(m, num, nick);
@ -87,7 +88,7 @@ static void chat_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS
if (self->num != num) if (self->num != num)
return; return;
StatusBar *statusbar = (StatusBar *) self->stb; StatusBar *statusbar = self->stb;
statusbar->status = status; statusbar->status = status;
} }
@ -96,7 +97,7 @@ static void chat_onStatusMessageChange(ToxWindow *self, int num, uint8_t *status
if (self->num != num) if (self->num != num)
return; return;
StatusBar *statusbar = (StatusBar *) self->stb; StatusBar *statusbar = self->stb;
statusbar->statusmsg_len = len; statusbar->statusmsg_len = len;
memcpy(statusbar->statusmsg, status, len); memcpy(statusbar->statusmsg, status, len);
} }
@ -107,7 +108,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t fil
if (self->num != num) if (self->num != num)
return; return;
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
int idx = strlen(pathname) - 1; int idx = strlen(pathname) - 1;
while (pathname[idx] == '/' && idx >= 0) { while (pathname[idx] == '/' && idx >= 0) {
@ -167,7 +168,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int num, uint8_t receive
if (self->num != num) if (self->num != num)
return; return;
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
uint8_t *filename; uint8_t *filename;
if (receive_send == 0) if (receive_send == 0)
@ -200,7 +201,7 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int num, uint8_t filenum, u
if (self->num != num) if (self->num != num)
return; return;
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
uint8_t *filename = friends[num].file_receiver.filenames[filenum]; uint8_t *filename = friends[num].file_receiver.filenames[filenum];
FILE *file_to_save = fopen(filename, "a"); FILE *file_to_save = fopen(filename, "a");
@ -227,7 +228,7 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_
if (self->num != friendnumber) if (self->num != friendnumber)
return; return;
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
uint8_t name[TOX_MAX_NAME_LENGTH] = {'\0'}; uint8_t name[TOX_MAX_NAME_LENGTH] = {'\0'};
if (tox_get_name(m, friendnumber, name) == -1) if (tox_get_name(m, friendnumber, name) == -1)
@ -268,8 +269,8 @@ static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *acti
static void chat_onKey(ToxWindow *self, Tox *m, wint_t key) static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
{ {
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
StatusBar *statusbar = (StatusBar *) self->stb; StatusBar *statusbar = self->stb;
int x, y, y2, x2; int x, y, y2, x2;
getyx(self->window, y, x); getyx(self->window, y, x);
@ -363,10 +364,10 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
int x, y; int x, y;
getmaxyx(self->window, y, x); getmaxyx(self->window, y, x);
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
/* Draw status bar */ /* Draw status bar */
StatusBar *statusbar = (StatusBar *) self->stb; StatusBar *statusbar = self->stb;
mvwhline(statusbar->topline, 1, 0, ACS_HLINE, x); mvwhline(statusbar->topline, 1, 0, ACS_HLINE, x);
wmove(statusbar->topline, 0, 0); wmove(statusbar->topline, 0, 0);
@ -441,7 +442,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
self->x = x; self->x = x;
/* Init statusbar info */ /* Init statusbar info */
StatusBar *statusbar = (StatusBar *) self->stb; StatusBar *statusbar = self->stb;
statusbar->status = tox_get_user_status(m, self->num); statusbar->status = tox_get_user_status(m, self->num);
statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1; statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1;
@ -451,7 +452,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
statusbar->statusmsg_len = tox_get_status_message_size(m, self->num); statusbar->statusmsg_len = tox_get_status_message_size(m, self->num);
/* Init subwindows */ /* Init subwindows */
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
statusbar->topline = subwin(self->window, 2, x, 0, 0); statusbar->topline = subwin(self->window, 2, x, 0, 0);
ctx->history = subwin(self->window, y-CHATBOX_HEIGHT+1, x, 0, 0); ctx->history = subwin(self->window, y-CHATBOX_HEIGHT+1, x, 0, 0);
scrollok(ctx->history, 1); scrollok(ctx->history, 1);

View File

@ -11,6 +11,7 @@
#include "toxic_windows.h" #include "toxic_windows.h"
#include "misc_tools.h" #include "misc_tools.h"
#include "friendlist.h"
extern ToxWindow *prompt; extern ToxWindow *prompt;
extern int num_groupchats; extern int num_groupchats;

View File

@ -165,7 +165,7 @@ static void select_friend(ToxWindow *self, Tox *m, wint_t key)
static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key) static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
{ {
tox_del_friend(m, f_num); tox_del_friend(m, f_num);
memset(&friends[f_num], 0, sizeof(friend_t)); memset(&friends[f_num], 0, sizeof(ToxicFriend));
int i; int i;

View File

@ -102,7 +102,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
if (self->num != groupnum) if (self->num != groupnum)
return; return;
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
tox_group_peername(m, groupnum, peernum, nick); tox_group_peername(m, groupnum, peernum, nick);
@ -180,7 +180,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
qsort(groupchats[groupnum].peer_names, groupchats[groupnum].num_peers, TOX_MAX_NAME_LENGTH, name_compare); qsort(groupchats[groupnum].peer_names, groupchats[groupnum].num_peers, TOX_MAX_NAME_LENGTH, name_compare);
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
print_time(ctx->history); print_time(ctx->history);
switch (change) { switch (change) {
@ -220,7 +220,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key) static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
{ {
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
int x, y, y2, x2; int x, y, y2, x2;
getyx(self->window, y, x); getyx(self->window, y, x);
@ -307,7 +307,7 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
int x, y; int x, y;
getmaxyx(self->window, y, x); getmaxyx(self->window, y, x);
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
wclrtobot(ctx->sidebar); wclrtobot(ctx->sidebar);
mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x); mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x);
mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y-CHATBOX_HEIGHT); mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y-CHATBOX_HEIGHT);
@ -341,7 +341,7 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
int x, y; int x, y;
getmaxyx(self->window, y, x); getmaxyx(self->window, y, x);
ChatContext *ctx = (ChatContext *) self->chatwin; ChatContext *ctx = self->chatwin;
ctx->history = subwin(self->window, y-CHATBOX_HEIGHT+1, x-SIDEBAR_WIDTH-1, 0, 0); ctx->history = subwin(self->window, y-CHATBOX_HEIGHT+1, x-SIDEBAR_WIDTH-1, 0, 0);
scrollok(ctx->history, 1); scrollok(ctx->history, 1);
ctx->linewin = subwin(self->window, 2, x, y-CHATBOX_HEIGHT, 0); ctx->linewin = subwin(self->window, 2, x, y-CHATBOX_HEIGHT, 0);

View File

@ -89,7 +89,7 @@ static void init_term(void)
refresh(); refresh();
} }
static Tox *init_tox() static Tox *init_tox(void)
{ {
/* Init core */ /* Init core */
Tox *m = tox_new(TOX_ENABLE_IPV6_DEFAULT); Tox *m = tox_new(TOX_ENABLE_IPV6_DEFAULT);
@ -380,7 +380,7 @@ static void do_file_senders(Tox *m)
/* If file transfer has timed out kill transfer and send kill control */ /* If file transfer has timed out kill transfer and send kill control */
if (timed_out(file_senders[i].timestamp, current_time, TIMEOUT_FILESENDER)) { if (timed_out(file_senders[i].timestamp, current_time, TIMEOUT_FILESENDER)) {
ChatContext *ctx = (ChatContext *) file_senders[i].toxwin->chatwin; ChatContext *ctx = file_senders[i].toxwin->chatwin;
if (ctx != NULL) { if (ctx != NULL) {
wprintw(ctx->history, "File transfer for '%s' timed out.\n", pathname); wprintw(ctx->history, "File transfer for '%s' timed out.\n", pathname);
@ -404,7 +404,7 @@ static void do_file_senders(Tox *m)
tox_file_data_size(m, friendnum), fp); tox_file_data_size(m, friendnum), fp);
if (file_senders[i].piecelen == 0) { if (file_senders[i].piecelen == 0) {
ChatContext *ctx = (ChatContext *) file_senders[i].toxwin->chatwin; ChatContext *ctx = file_senders[i].toxwin->chatwin;
if (ctx != NULL) { if (ctx != NULL) {
wprintw(ctx->history, "File '%s' successfuly sent.\n", pathname); wprintw(ctx->history, "File '%s' successfuly sent.\n", pathname);

View File

@ -23,7 +23,7 @@ static int prompt_buf_pos = 0;
/* Updates own nick in prompt statusbar */ /* Updates own nick in prompt statusbar */
void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len) void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len)
{ {
StatusBar *statusbar = (StatusBar *) prompt->stb; StatusBar *statusbar = prompt->stb;
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick); snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
statusbar->nick_len = len; statusbar->nick_len = len;
} }
@ -31,7 +31,7 @@ void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len)
/* Updates own statusmessage in prompt statusbar */ /* Updates own statusmessage in prompt statusbar */
void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len) void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len)
{ {
StatusBar *statusbar = (StatusBar *) prompt->stb; StatusBar *statusbar = prompt->stb;
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg); snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
statusbar->statusmsg_len = len; statusbar->statusmsg_len = len;
} }
@ -39,14 +39,14 @@ void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t
/* Updates own status in prompt statusbar */ /* Updates own status in prompt statusbar */
void prompt_update_status(ToxWindow *prompt, TOX_USERSTATUS status) void prompt_update_status(ToxWindow *prompt, TOX_USERSTATUS status)
{ {
StatusBar *statusbar = (StatusBar *) prompt->stb; StatusBar *statusbar = prompt->stb;
statusbar->status = status; statusbar->status = status;
} }
/* Updates own connection status in prompt statusbar */ /* Updates own connection status in prompt statusbar */
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected) void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected)
{ {
StatusBar *statusbar = (StatusBar *) prompt->stb; StatusBar *statusbar = prompt->stb;
statusbar->is_online = is_connected; statusbar->is_online = is_connected;
} }
@ -125,7 +125,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
--y; --y;
} }
StatusBar *statusbar = (StatusBar *) self->stb; StatusBar *statusbar = self->stb;
werase(statusbar->topline); werase(statusbar->topline);
mvwhline(statusbar->topline, 1, 0, ACS_HLINE, x2); mvwhline(statusbar->topline, 1, 0, ACS_HLINE, x2);
wmove(statusbar->topline, 0, 0); wmove(statusbar->topline, 0, 0);
@ -239,7 +239,7 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
getmaxyx(self->window, y, x); getmaxyx(self->window, y, x);
/* Init statusbar info */ /* Init statusbar info */
StatusBar *statusbar = (StatusBar *) self->stb; StatusBar *statusbar = self->stb;
statusbar->status = TOX_USERSTATUS_NONE; statusbar->status = TOX_USERSTATUS_NONE;
statusbar->is_online = false; statusbar->is_online = false;

View File

@ -51,9 +51,11 @@ enum {
Uncomment if necessary */ Uncomment if necessary */
//#define URXVT_FIX //#define URXVT_FIX
typedef struct ToxWindow_ ToxWindow; typedef struct ToxWindow ToxWindow;
typedef struct StatusBar StatusBar;
typedef struct ChatContext ChatContext;
struct ToxWindow_ { struct ToxWindow {
void(*onKey)(ToxWindow *, Tox *, wint_t); void(*onKey)(ToxWindow *, Tox *, wint_t);
void(*onDraw)(ToxWindow *, Tox *); void(*onDraw)(ToxWindow *, Tox *);
void(*onInit)(ToxWindow *, Tox *); void(*onInit)(ToxWindow *, Tox *);
@ -78,13 +80,13 @@ struct ToxWindow_ {
int num; int num;
int x; int x;
void *chatwin; ChatContext *chatwin;
void *stb; StatusBar *stb;
WINDOW *window; WINDOW *window;
}; };
typedef struct { struct StatusBar {
WINDOW *topline; WINDOW *topline;
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH]; uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
uint16_t statusmsg_len; uint16_t statusmsg_len;
@ -92,15 +94,15 @@ typedef struct {
uint16_t nick_len; uint16_t nick_len;
TOX_USERSTATUS status; TOX_USERSTATUS status;
bool is_online; bool is_online;
} StatusBar; };
typedef struct { struct ChatContext {
wchar_t line[MAX_STR_SIZE]; wchar_t line[MAX_STR_SIZE];
size_t pos; size_t pos;
WINDOW *history; WINDOW *history;
WINDOW *linewin; WINDOW *linewin;
WINDOW *sidebar; WINDOW *sidebar;
} ChatContext; };
/* Start file transfer code */ /* Start file transfer code */
@ -124,10 +126,10 @@ typedef struct {
FileSender file_senders[MAX_FILES]; FileSender file_senders[MAX_FILES];
uint8_t max_file_senders_index; uint8_t max_file_senders_index;
typedef struct { struct FileReceiver {
uint8_t filenames[MAX_FILES][MAX_STR_SIZE]; uint8_t filenames[MAX_FILES][MAX_STR_SIZE];
bool pending[MAX_FILES]; bool pending[MAX_FILES];
} FileReceiver; };
/* End file transfer code */ /* End file transfer code */
@ -142,10 +144,10 @@ typedef struct {
bool active; bool active;
bool online; bool online;
TOX_USERSTATUS status; TOX_USERSTATUS status;
FileReceiver file_receiver; struct FileReceiver file_receiver;
} friend_t; } ToxicFriend;
friend_t friends[MAX_FRIENDS_NUM]; ToxicFriend friends[MAX_FRIENDS_NUM];
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);
void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdata); void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdata);