Updated the main function to support options
This commit is contained in:
parent
55bdf8bd52
commit
fc31f9884b
2
build.sh
2
build.sh
@ -8,7 +8,7 @@ PROGN=${PROGN:-probotic}
|
||||
PREFIX=${PREFIX:-$DIR}
|
||||
|
||||
CC=${CC-cc}
|
||||
CFLAGS='-std=c99 -Wall -Wextra -Wpedantic -Wno-unused-parameter'
|
||||
CFLAGS='-std=c99 -Wall -Wextra -Wpedantic'
|
||||
CPPFLAGS="-I/usr/bin/ircclient/ -Iinclude -D_GNU_SOURCE -DPROGN=\"$PROGN\""
|
||||
LDFLAGS='-lircclient'
|
||||
|
||||
|
42
src/main.c
42
src/main.c
@ -30,6 +30,8 @@
|
||||
irc_session_t * session;
|
||||
irc_callbacks_t callbacks;
|
||||
|
||||
const char * channel;
|
||||
|
||||
char * get_username(const char * origin)
|
||||
{
|
||||
const char USERNAME_TERMINATOR = '!';
|
||||
@ -55,7 +57,7 @@ msg_wrapper(const char* fmt,
|
||||
{ exit(1); }
|
||||
|
||||
puts(fmtdmsg);
|
||||
irc_cmd_msg(session, CHANNEL, fmtdmsg);
|
||||
irc_cmd_msg(session, channel, fmtdmsg);
|
||||
|
||||
free(fmtdmsg);
|
||||
va_end(args);
|
||||
@ -68,6 +70,10 @@ event_connect(irc_session_t * session,
|
||||
const char ** params,
|
||||
unsigned int count)
|
||||
{
|
||||
(void) event;
|
||||
(void) origin;
|
||||
(void) params;
|
||||
(void) count;
|
||||
irc_cmd_join(session, CHANNEL, 0);
|
||||
}
|
||||
|
||||
@ -78,18 +84,22 @@ event_channel(irc_session_t * session,
|
||||
const char ** params,
|
||||
unsigned int count)
|
||||
{
|
||||
|
||||
const char * channel = params[0];
|
||||
const char * message = params[1];
|
||||
(void) session;
|
||||
(void) event;
|
||||
(void) origin;
|
||||
(void) channel;
|
||||
(void) message;
|
||||
|
||||
(void) count;
|
||||
char * swp = get_username(origin);
|
||||
msg_wrapper("%s, you are a faggot for this opinion.", swp);
|
||||
free(swp);
|
||||
}
|
||||
|
||||
int
|
||||
init(void)
|
||||
init(char const * username, char const * server, int port)
|
||||
{
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
callbacks.event_connect = event_connect;
|
||||
@ -98,17 +108,37 @@ init(void)
|
||||
session = irc_create_session(&callbacks);
|
||||
if (!session)
|
||||
{ ERR(1, "Error creating IRC session"); }
|
||||
irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME);
|
||||
irc_connect(session, server, port, 0, username, username, username);
|
||||
if (irc_run(session) != 0)
|
||||
{ ERR(1, "Error running IRC session\nNo net?"); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* args: server port channel [username] - defaults to probotic */
|
||||
|
||||
/* I'd have to give up constification for server:port */
|
||||
int
|
||||
main(int argc,
|
||||
char ** argv)
|
||||
char const ** argv)
|
||||
{
|
||||
if(!init())
|
||||
char const * username;
|
||||
char const * server;
|
||||
int port;
|
||||
if (argc > 5 || argc < 4)
|
||||
{
|
||||
ERRMSG("server port channel [username]");
|
||||
return 1;
|
||||
}
|
||||
if (argc > 4)
|
||||
{ username = argv[4]; }
|
||||
else
|
||||
{ username = "probotic"; }
|
||||
channel = argv[3];
|
||||
port = atoi(argv[2]);
|
||||
server = argv[1];
|
||||
fprintf(stderr, "-- %s:%d %s %s --", server, port, channel, username);
|
||||
if (!init(username, server, port))
|
||||
{
|
||||
while(1)
|
||||
{}
|
||||
|
Reference in New Issue
Block a user