diff options
author | June McEnroe <june@causal.agency> | 2019-12-31 18:41:39 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-12-31 18:41:39 -0500 |
commit | 12149d5b8a1482b6221245320fc2c4c8ce2525b0 (patch) | |
tree | a76b64463dbc7240d2e9b0791b370a67e5f2b84d | |
parent | Add scoop output format option (diff) | |
download | litterbox-12149d5b8a1482b6221245320fc2c4c8ce2525b0.tar.gz litterbox-12149d5b8a1482b6221245320fc2c4c8ce2525b0.zip |
Add scoop IRC output format
-rw-r--r-- | scoop.1 | 3 | ||||
-rw-r--r-- | scoop.c | 48 |
2 files changed, 44 insertions, 7 deletions
diff --git a/scoop.1 b/scoop.1 index 82ac29a..febeecc 100644 --- a/scoop.1 +++ b/scoop.1 @@ -89,7 +89,8 @@ The default path is as in .It Fl f Ar format Set the output format to one of .Cm plain , -.Cm color . +.Cm color , +.Cm irc . The default format is .Cm color if standard output is a terminal, diff --git a/scoop.c b/scoop.c index 55ee857..e33da1c 100644 --- a/scoop.c +++ b/scoop.c @@ -41,9 +41,6 @@ typedef void Format(bool group, struct Event event); static void formatPlain(bool group, struct Event e) { (void)group; - if (!e.target) e.target = ""; - if (!e.message) e.message = ""; - printf("%s/%s: [%s] ", e.network, e.context, e.time); switch (e.type) { break; case Privmsg: { @@ -93,9 +90,6 @@ static int color(const char *user) { } static void formatColor(bool group, struct Event e) { - if (!e.target) e.target = ""; - if (!e.message) e.message = ""; - static char network[256]; static char context[256]; if (group && (strcmp(e.network, network) || strcmp(e.context, context))) { @@ -146,6 +140,45 @@ static void formatColor(bool group, struct Event e) { #undef NICK } +static void formatIRC(bool group, struct Event e) { + (void)group; + if (!strcmp(e.host, e.nick)) { + printf("@time=%s :%s ", e.time, e.host); + } else { + printf("@time=%s :%s!%s@%s ", e.time, e.nick, e.user, e.host); + } + if (!strcmp(e.context, e.nick)) e.context = "*"; + switch (e.type) { + break; case Privmsg: { + printf("PRIVMSG %s :%s\r\n", e.context, e.message); + } + break; case Notice: { + printf("NOTICE %s :%s\r\n", e.context, e.message); + } + break; case Action: { + printf("PRIVMSG %s :\1ACTION %s\1\r\n", e.context, e.message); + } + break; case Join: { + printf("JOIN %s\r\n", e.context); + } + break; case Part: { + printf("PART %s :%s\r\n", e.context, e.message); + } + break; case Quit: { + printf("QUIT :%s\r\n", e.message); + } + break; case Kick: { + printf("KICK %s %s :%s\r\n", e.context, e.target, e.message); + } + break; case Nick: { + printf("NICK %s\r\n", e.target); + } + break; case Topic: { + printf("TOPIC %s :%s\r\n", e.context, e.message); + } + } +} + static const char *Inner = SQL( SELECT contexts.network, @@ -212,6 +245,7 @@ static const struct { } Formats[] = { { "plain", formatPlain }, { "color", formatColor }, + { "irc", formatIRC }, }; static Format *parseFormat(const char *name) { @@ -359,6 +393,8 @@ int main(int argc, char *argv[]) { .target = (const char *)sqlite3_column_text(stmt, 7), .message = (const char *)sqlite3_column_text(stmt, 8), }; + if (!event.target) event.target = ""; + if (!event.message) event.message = ""; format(group, event); } if (result != SQLITE_DONE) warnx("%s", sqlite3_errmsg(db)); |