From c80a1ea3452b313a9877991b6428044f072c9ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Tue, 31 Dec 2019 22:03:04 +0800 Subject: The second argument is now a path to a file Meant to be a log outputted by git log -1. Newlines are replaced with tabs, otherwise only the first line gets posted on IRC. --- dircpsa.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'dircpsa.c') diff --git a/dircpsa.c b/dircpsa.c index 1bc40b6..96252d0 100644 --- a/dircpsa.c +++ b/dircpsa.c @@ -4,7 +4,7 @@ typedef struct { char *channel; - char *message; + char *log; } irc_ctx_t; void event_connect(irc_session_t *session, const char *event, const char *origin @@ -18,18 +18,35 @@ void event_join(irc_session_t *session, const char *event, const char *origin , const char **params, unsigned int count) { irc_ctx_t *ctx = (irc_ctx_t *)irc_get_ctx(session); + FILE *fp = fopen(ctx->log, "r"); + size_t n = 0; + int c; + while ((c = fgetc(fp)) != EOF) + n++; + char message[n + 1]; + n = 0; + fp = freopen(ctx->log, "r", fp); + while ((c = fgetc(fp)) != EOF) { + if (c == '\n') + message[n++] = '\t'; + else + message[n++] = c; + } + message[n] = '\0'; + fclose(fp); + irc_cmd_user_mode(session, "+i"); - irc_cmd_msg(session, params[0], ctx->message); - irc_cmd_quit (session, "selesai"); + irc_cmd_msg(session, params[0], message); + irc_cmd_quit (session, "Selesai."); } int main (int argc, char *argv[]) { if (argc != 3) { - printf("Usage: %s \n", argv[0]); + printf("Usage: %s \n", argv[0]); return 1; } - irc_ctx_t ctx = {.channel = argv[1], .message = argv[2]}; + irc_ctx_t ctx = {.channel = argv[1], .log = argv[2]}; irc_callbacks_t callbacks; memset(&callbacks, 0, sizeof(callbacks)); -- cgit v1.2.3