Formatting and ERR utility
This commit is contained in:
parent
39fbceed7e
commit
f62c8d4f75
42
src/main.c
42
src/main.c
@ -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;
|
||||||
|
|
||||||
@ -21,10 +23,8 @@ char * get_username(const char * origin)
|
|||||||
const char USERNAME_TERMINATOR = '!';
|
const char USERNAME_TERMINATOR = '!';
|
||||||
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';
|
||||||
@ -50,26 +50,26 @@ msg_wrapper(const char* fmt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
event_connect(irc_session_t *session,
|
event_connect(irc_session_t * session,
|
||||||
const char *event,
|
const char * event,
|
||||||
const char *origin,
|
const char * origin,
|
||||||
const char **params,
|
const char ** params,
|
||||||
unsigned int count)
|
unsigned int count)
|
||||||
{
|
{
|
||||||
irc_cmd_join(session, CHANNEL, 0);
|
irc_cmd_join(session, CHANNEL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
event_channel(irc_session_t *session,
|
event_channel(irc_session_t * session,
|
||||||
const char *event,
|
const char * event,
|
||||||
const char *origin,
|
const char * origin,
|
||||||
const char **params,
|
const char ** params,
|
||||||
unsigned int count)
|
unsigned int count)
|
||||||
{
|
{
|
||||||
const char *channel = params[0];
|
const char * channel = params[0];
|
||||||
const char *message = params[1];
|
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);
|
msg_wrapper("%s, you are a faggot for this opinion.", swp);
|
||||||
free(swp);
|
free(swp);
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user