From f62c8d4f75a278de5b4483c5e46fd6c1715fd277 Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 2 Aug 2023 07:22:22 -0600 Subject: [PATCH] Formatting and ERR utility --- src/main.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main.c b/src/main.c index 2cfdbad..1cdd3fb 100644 --- a/src/main.c +++ b/src/main.c @@ -13,6 +13,8 @@ #define CHANNEL "#/g/chad" #define USERNAME "probotic" +#define ERR(msg,ret) do { fputs(msg); return ret; } while (0) + irc_session_t * session; irc_callbacks_t callbacks; @@ -21,10 +23,8 @@ char * get_username(const char * origin) const char USERNAME_TERMINATOR = '!'; int i = 0; char * r; - while (origin[i] !=USERNAME_TERMINATOR) - { - i++; - } + while (origin[i] != USERNAME_TERMINATOR) + { i++; } r = (char *) malloc(i + 1); strncpy(r, origin, i); r[i] = '\00'; @@ -50,26 +50,26 @@ msg_wrapper(const char* fmt, } void -event_connect(irc_session_t *session, - const char *event, - const char *origin, - const char **params, +event_connect(irc_session_t * session, + const char * event, + const char * origin, + const char ** params, unsigned int count) { irc_cmd_join(session, CHANNEL, 0); } void -event_channel(irc_session_t *session, - const char *event, - const char *origin, - const char **params, +event_channel(irc_session_t * session, + const char * event, + const char * origin, + const char ** params, unsigned int count) { - const char *channel = params[0]; - const char *message = params[1]; + const char * channel = params[0]; + const char * message = params[1]; - char* swp = get_username(origin); + char * swp = get_username(origin); msg_wrapper("%s, you are a faggot for this opinion.", swp); free(swp); } @@ -82,15 +82,11 @@ init(void) callbacks.event_channel = event_channel; session = irc_create_session(&callbacks); - if (!session) { - fprintf(stderr, "Error creating IRC session\n"); - return 1; - } + if (!session) + { ERR("Error creating IRC session\n", 1); } irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME); - if (irc_run(session) != 0) { - fprintf(stderr, "Error running IRC session\nNo net?"); - return 1; - } + if (irc_run(session) != 0) + { ERR("Error running IRC session\nNo net?", 1); } return 0; }