diff --git a/build.sh b/build.sh index e8fe3a4..ff16ecc 100755 --- a/build.sh +++ b/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' diff --git a/src/main.c b/src/main.c index 9256b96..bd438f0 100644 --- a/src/main.c +++ b/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) {}