hirc

IRC client
Log | Files | Refs

commit f39c934205050554d66a9b242ad2f2dd94e5cfe2
parent 2025ea4e39a7ac782c6d0543b7fbdc0c6a249a04
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 24 Oct 2021 17:56:41 +0100

Make selected_* vars into a struct

Diffstat:
Mchan.c | 2+-
Mhandle.c | 18+++++++++---------
Mhirc.h | 3+--
Mmain.c | 10++++------
Mserv.c | 2+-
Mstruct.h | 7+++++++
Mui.c | 8+++-----
7 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/chan.c b/chan.c @@ -48,7 +48,7 @@ chan_create(struct Server *server, char *name) { int chan_selected(struct Channel *channel) { - if (selected_channel == channel) + if (selected.channel == channel) return 1; else return 0; diff --git a/handle.c b/handle.c @@ -52,9 +52,9 @@ handle_JOIN(char *msg, char **params, struct Server *server, time_t timestamp) { hist_add(server, chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); if (nick_isself(nick)) { - selected_server = server; - selected_channel = chan; - } else if (selected_channel == chan) { + selected.server = server; + selected.channel = chan; + } else if (selected.channel == chan) { ui_draw_nicklist(); } @@ -78,11 +78,11 @@ handle_PART(char *msg, char **params, struct Server *server, time_t timestamp) { if (nick_isself(nick)) { chan_setold(chan, 1); nick_free_list(&chan->nicks); - if (chan == selected_channel) - selected_channel = NULL; + if (chan == selected.channel) + selected.channel = NULL; } else { nick_remove(&chan->nicks, nick->nick); - if (chan == selected_channel) + if (chan == selected.channel) ui_draw_nicklist(); } @@ -110,7 +110,7 @@ handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp) { if (nick_get(&chan->nicks, nick->nick) != NULL) { nick_remove(&chan->nicks, nick->nick); hist_add(server, chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); - if (chan == selected_channel) + if (chan == selected.channel) ui_draw_nicklist(); } } @@ -232,7 +232,7 @@ handle_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestam oldnick->priv = priv; } - if (selected_channel == chan) + if (selected.channel == chan) ui_draw_nicklist(); param_free(nicksref); } @@ -275,7 +275,7 @@ handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp) { if ((chnick = nick_get(&chan->nicks, nick->nick)) != NULL) { nick_add(&chan->nicks, newnick, chnick->priv, server); nick_remove(&chan->nicks, nick->nick); - if (selected_channel == chan) + if (selected.channel == chan) ui_draw_nicklist(); } } diff --git a/hirc.h b/hirc.h @@ -113,8 +113,7 @@ void command_eval(char *str); extern struct HistInfo *main_buf; /* ui.c */ -extern struct Channel *selected_channel; -extern struct Server *selected_server; +extern struct Selected selected; extern struct Window mainwindow; extern struct Window inputwindow; extern struct Window nicklist; diff --git a/main.c b/main.c @@ -176,8 +176,6 @@ sighandler(int signal) { int main(int argc, char **argv) { - struct Channel *old_selected_channel; - struct Server *old_selected_server; struct Server *sp; FILE *file; struct pollfd fds[] = { @@ -192,7 +190,7 @@ main(int argc, char **argv) { main_buf->history = NULL; ui_init(); - selected_server = serv_add(&servers, "hlircnet", "irc.hhvn.uk", "6667", "hhvn", "Fanatic", "gopher://hhvn.uk", 1, 0); + selected.server = serv_add(&servers, "hlircnet", "irc.hhvn.uk", "6667", "hhvn", "Fanatic", "gopher://hhvn.uk", 1, 0); /* serv_add(&servers, "dataswamp", "127.0.0.1", "6697", "hhvn", "Fanatic", "gopher://hhvn.uk", 1, 0); */ for (sp = servers; sp; sp = sp->next) serv_connect(sp); @@ -228,7 +226,7 @@ main(int argc, char **argv) { } } - if (old_selected_channel != selected_channel || old_selected_server != selected_server) { + if (selected.oldchannel != selected.channel || selected.oldserver != selected.server) { ui_draw_nicklist(); wrefresh(nicklist.window); } @@ -238,8 +236,8 @@ main(int argc, char **argv) { ui_read(); - old_selected_channel = selected_channel; - old_selected_server = selected_server; + selected.oldchannel = selected.channel; + selected.oldserver = selected.server; } return 0; diff --git a/serv.c b/serv.c @@ -284,7 +284,7 @@ serv_disconnect(struct Server *server, int reconnect) { int serv_selected(struct Server *server) { - if (!selected_channel && selected_server == server) + if (!selected.channel && selected.server == server) return 1; else return 0; diff --git a/struct.h b/struct.h @@ -143,4 +143,11 @@ struct Window { WINDOW *window; }; +struct Selected { + struct Channel *channel; + struct Server *server; + struct Channel *oldchannel; + struct Server *oldserver; +}; + #endif /* H_STRUCT */ diff --git a/ui.c b/ui.c @@ -14,9 +14,7 @@ struct Window mainwindow; struct Window inputwindow; struct Window nicklist; struct Window winlist; - -struct Channel *selected_channel = NULL; -struct Server *selected_server = NULL; +struct Selected selected; struct { char string[INPUT_MAX]; @@ -239,14 +237,14 @@ ui_draw_nicklist(void) { struct Nick *p; wclear(nicklist.window); - if (!selected_channel || !nicklist.location) + if (!selected.channel || !nicklist.location) return; wmove(nicklist.window, 0, 0); /* TODO: sort nicks here * TODO: more nicks than screen height? */ - for (p = selected_channel->nicks; p; p = p->next) { + for (p = selected.channel->nicks; p; p = p->next) { /* TODO: colourize nicks */ wprintw(nicklist.window, "%c%s\n", p->priv, p->nick); }