commit 464dc39752f8e03673b63ae3c2af72b195956081
parent f2566b59c9134617d935a4eafdb24fd5e49cd097
Author: hhvn <dev@hhvn.uk>
Date: Sat, 20 Nov 2021 17:58:18 +0000
commands.c handle.c hirc.h: make repetitive functions static
Diffstat:
M | commands.c | | | 40 | +++++++++++++++++++++++++++------------- |
M | handle.c | | | 52 | +++++++++++++++++++++++++++++++++++----------------- |
M | hirc.h | | | 30 | ------------------------------ |
3 files changed, 62 insertions(+), 60 deletions(-)
diff --git a/commands.c b/commands.c
@@ -8,6 +8,20 @@
#include <sys/types.h>
#include "hirc.h"
+static void command_quit(struct Server *server, char *str);
+static void command_join(struct Server *server, char *str);
+static void command_part(struct Server *server, char *str);
+static void command_ping(struct Server *server, char *str);
+static void command_quote(struct Server *server, char *str);
+static void command_connect(struct Server *server, char *str);
+static void command_select(struct Server *server, char *str);
+static void command_set(struct Server *server, char *str);
+static void command_format(struct Server *server, char *str);
+static void command_server(struct Server *server, char *str);
+static void command_names(struct Server *server, char *str);
+static void command_topic(struct Server *server, char *str);
+static void command_help(struct Server *server, char *str);
+
static char *command_optarg;
enum {
opt_error = -2,
@@ -67,13 +81,13 @@ struct Command commands[] = {
{NULL, NULL},
};
-void
+static void
command_quit(struct Server *server, char *str) {
cleanup(str ? str : config_gets("misc.quitmessage"));
exit(EXIT_SUCCESS);
}
-void
+static void
command_join(struct Server *server, char *str) {
if (!str) {
ui_error("/join requires argument", NULL);
@@ -87,7 +101,7 @@ command_join(struct Server *server, char *str) {
handle_expect(server, Expect_join, str);
}
-void
+static void
command_part(struct Server *server, char *str) {
char *channel;
@@ -104,7 +118,7 @@ command_part(struct Server *server, char *str) {
handle_expect(server, Expect_join, channel);
}
-void
+static void
command_ping(struct Server *server, char *str) {
if (!str) {
ui_error("/ping requires argument", NULL);
@@ -115,7 +129,7 @@ command_ping(struct Server *server, char *str) {
handle_expect(server, Expect_pong, str);
}
-void
+static void
command_quote(struct Server *server, char *str) {
if (!str) {
ui_error("/quote requires argument", NULL);
@@ -130,7 +144,7 @@ command_quote(struct Server *server, char *str) {
ircprintf(server, "%s\r\n", str);
}
-void
+static void
command_connect(struct Server *server, char *str) {
struct Server *tserver;
char *network = NULL;
@@ -221,7 +235,7 @@ command_connect(struct Server *server, char *str) {
ui_select(tserver, NULL);
}
-void
+static void
command_select(struct Server *server, char *str) {
struct Server *sp;
struct Channel *chp;
@@ -292,7 +306,7 @@ command_select(struct Server *server, char *str) {
} else ui_error("/select requires argument", NULL);
}
-void
+static void
command_set(struct Server *server, char *str) {
char *name, *val;
@@ -304,7 +318,7 @@ command_set(struct Server *server, char *str) {
config_set(name, val);
}
-void
+static void
command_format(struct Server *server, char *str) {
char *newstr;
int len;
@@ -321,7 +335,7 @@ command_format(struct Server *server, char *str) {
free(newstr);
}
-void
+static void
command_server(struct Server *server, char *str) {
struct Server *nserver;
char *tserver, *cmd, *arg;
@@ -353,7 +367,7 @@ command_server(struct Server *server, char *str) {
ui_error("no such commands: '%s'", cmd);
}
-void
+static void
command_names(struct Server *server, char *str) {
char *channel, *save = NULL;
@@ -373,7 +387,7 @@ command_names(struct Server *server, char *str) {
handle_expect(server, Expect_names, channel);
}
-void
+static void
command_topic(struct Server *server, char *str) {
char *channel, *topic = NULL;
int clear = 0, ret;
@@ -419,7 +433,7 @@ command_topic(struct Server *server, char *str) {
} else ircprintf(server, "TOPIC %s :%s\r\n", channel, topic);
}
-void
+static void
command_help(struct Server *server, char *str) {
int cmdonly = 0;
int i, j;
diff --git a/handle.c b/handle.c
@@ -6,6 +6,24 @@
#include <stdlib.h>
#include "hirc.h"
+static void handle_PING(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_PONG(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_JOIN(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_PART(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_RPL_WELCOME(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_RPL_ISUPPORT(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_RPL_NOTOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_RPL_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_RPL_TOPICWHOTIME(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_RPL_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_RPL_ENDOFNAMES(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_RPL_ENDOFMOTD(char *msg, char **params, struct Server *server, time_t timestamp);
+static void handle_ERR_NICKNAMEINUSE(char *msg, char **params, struct Server *server, time_t timestamp);
+
struct Handler handlers[] = {
{ "PING", handle_PING },
{ "PONG", handle_PONG },
@@ -28,7 +46,7 @@ struct Handler handlers[] = {
{ NULL, NULL },
};
-void
+static void
handle_PING(char *msg, char **params, struct Server *server, time_t timestamp) {
if (**params == ':')
params++;
@@ -39,7 +57,7 @@ handle_PING(char *msg, char **params, struct Server *server, time_t timestamp) {
ircprintf(server, "PONG :%s\r\n", *(params+1));
}
-void
+static void
handle_PONG(char *msg, char **params, struct Server *server, time_t timestamp) {
int len;
@@ -58,7 +76,7 @@ handle_PONG(char *msg, char **params, struct Server *server, time_t timestamp) {
}
}
-void
+static void
handle_JOIN(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
struct Nick *nick;
@@ -92,7 +110,7 @@ handle_JOIN(char *msg, char **params, struct Server *server, time_t timestamp) {
nick_free(nick);
}
-void
+static void
handle_PART(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
struct Nick *nick;
@@ -125,7 +143,7 @@ handle_PART(char *msg, char **params, struct Server *server, time_t timestamp) {
nick_free(nick);
}
-void
+static void
handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
struct Nick *nick;
@@ -152,7 +170,7 @@ handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp) {
nick_free(nick);
}
-void
+static void
handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t timestamp) {
int act_direct = Activity_hilight, act_regular = Activity_message;
struct Channel *chan;
@@ -196,7 +214,7 @@ handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t timestamp
nick_free(nick);
}
-void
+static void
handle_RPL_ISUPPORT(char *msg, char **params, struct Server *server, time_t timestamp) {
char *key, *value;
@@ -224,7 +242,7 @@ handle_RPL_ISUPPORT(char *msg, char **params, struct Server *server, time_t time
}
}
-void
+static void
handle_RPL_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
struct Nick *oldnick;
@@ -277,7 +295,7 @@ handle_RPL_NAMREPLY(char *msg, char **params, struct Server *server, time_t time
param_free(nicksref);
}
-void
+static void
handle_RPL_ENDOFNAMES(char *msg, char **params, struct Server *server, time_t timestamp) {
char *target;
@@ -293,7 +311,7 @@ handle_RPL_ENDOFNAMES(char *msg, char **params, struct Server *server, time_t ti
handle_expect(server, Expect_names, NULL);
}
-void
+static void
handle_ERR_NICKNAMEINUSE(char *msg, char **params, struct Server *server, time_t timestamp) {
char nick[64]; /* should be limited to 9 chars, but newer servers *shrug*/
@@ -305,7 +323,7 @@ handle_ERR_NICKNAMEINUSE(char *msg, char **params, struct Server *server, time_t
ircprintf(server, "NICK %s\r\n", nick);
}
-void
+static void
handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Nick *nick, *chnick;
struct Channel *chan;
@@ -340,7 +358,7 @@ handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp) {
}
}
-void
+static void
handle_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
@@ -355,7 +373,7 @@ handle_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp)
}
}
-void
+static void
handle_RPL_NOTOPIC(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
char *target;
@@ -376,7 +394,7 @@ handle_RPL_NOTOPIC(char *msg, char **params, struct Server *server, time_t times
}
}
-void
+static void
handle_RPL_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
char *target, *topic;
@@ -402,7 +420,7 @@ handle_RPL_TOPIC(char *msg, char **params, struct Server *server, time_t timesta
}
}
-void
+static void
handle_RPL_TOPICWHOTIME(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
char *target;
@@ -423,13 +441,13 @@ handle_RPL_TOPICWHOTIME(char *msg, char **params, struct Server *server, time_t
}
}
-void
+static void
handle_RPL_WELCOME(char *msg, char **params, struct Server *server, time_t timestamp) {
server->status = ConnStatus_connected;
hist_add(server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL);
}
-void
+static void
handle_RPL_ENDOFMOTD(char *msg, char **params, struct Server *server, time_t timestamp) {
/* If server doesn't support RPL_WELCOME, use RPL_ENDOFMOTD to set status */
server->status = ConnStatus_connected;
diff --git a/hirc.h b/hirc.h
@@ -87,23 +87,6 @@ void support_set(struct Server *server, char *key, char *value);
void handle(int rfd, struct Server *server);
void handle_expect(struct Server *server, enum Expect cmd, char *about);
char * handle_expect_get(struct Server *server, enum Expect cmd);
-void handle_PING(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_PONG(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_JOIN(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_PART(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_RPL_WELCOME(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_RPL_ISUPPORT(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_RPL_NOTOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_RPL_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_RPL_TOPICWHOTIME(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_RPL_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_RPL_ENDOFNAMES(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_RPL_ENDOFMOTD(char *msg, char **params, struct Server *server, time_t timestamp);
-void handle_ERR_NICKNAMEINUSE(char *msg, char **params, struct Server *server, time_t timestamp);
/* ui.c */
void ui_init(void);
@@ -139,19 +122,6 @@ void ui_tls_error_(char *file, int line, struct tls *ctx, char *str);
/* commands.c */
void command_eval(char *str);
int command_getopt(char **str, struct CommandOpts *opts);
-void command_quit(struct Server *server, char *str);
-void command_join(struct Server *server, char *str);
-void command_part(struct Server *server, char *str);
-void command_ping(struct Server *server, char *str);
-void command_quote(struct Server *server, char *str);
-void command_connect(struct Server *server, char *str);
-void command_select(struct Server *server, char *str);
-void command_set(struct Server *server, char *str);
-void command_format(struct Server *server, char *str);
-void command_server(struct Server *server, char *str);
-void command_names(struct Server *server, char *str);
-void command_topic(struct Server *server, char *str);
-void command_help(struct Server *server, char *str);
/* config.c */
void config_get_print(char *name);