Formatting and ERR utility

This commit is contained in:
Emil 2023-08-02 07:22:22 -06:00
parent 39fbceed7e
commit f62c8d4f75

View File

@ -13,6 +13,8 @@
#define CHANNEL "#/g/chad" #define CHANNEL "#/g/chad"
#define USERNAME "probotic" #define USERNAME "probotic"
#define ERR(msg,ret) do { fputs(msg); return ret; } while (0)
irc_session_t * session; irc_session_t * session;
irc_callbacks_t callbacks; irc_callbacks_t callbacks;
@ -22,9 +24,7 @@ char * get_username(const char * origin)
int i = 0; int i = 0;
char * r; char * r;
while (origin[i] != USERNAME_TERMINATOR) while (origin[i] != USERNAME_TERMINATOR)
{ { i++; }
i++;
}
r = (char *) malloc(i + 1); r = (char *) malloc(i + 1);
strncpy(r, origin, i); strncpy(r, origin, i);
r[i] = '\00'; r[i] = '\00';
@ -82,15 +82,11 @@ init(void)
callbacks.event_channel = event_channel; callbacks.event_channel = event_channel;
session = irc_create_session(&callbacks); session = irc_create_session(&callbacks);
if (!session) { if (!session)
fprintf(stderr, "Error creating IRC session\n"); { ERR("Error creating IRC session\n", 1); }
return 1;
}
irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME); irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME);
if (irc_run(session) != 0) { if (irc_run(session) != 0)
fprintf(stderr, "Error running IRC session\nNo net?"); { ERR("Error running IRC session\nNo net?", 1); }
return 1;
}
return 0; return 0;
} }