hirc

IRC client
Log | Files | Refs

commit bfc5891f81e9235934c929848957ee0af92a34c1
parent ae9c2bc42cf9e414ea126a5fe44fedfaaca58063
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 30 Apr 2022 21:44:42 +0100

Add utility for viewing logs more pleasantly

Diffstat:
M.gitignore | 1+
Mmisc/Makefile | 5++---
Amisc/hirc2txt | 0
Amisc/hirc2txt.1 | 34++++++++++++++++++++++++++++++++++
Amisc/hirc2txt.c | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amisc/hirc2txt.sh | 8++++++++
6 files changed, 112 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,3 +1,4 @@ +misc/hirc2txt misc/irccat doc/hirc.1 hirc diff --git a/misc/Makefile b/misc/Makefile @@ -17,13 +17,12 @@ PREFIX = /usr/local BINDIR = $(PREFIX)/bin MANDIR = $(PREFIX)/share/man -BINS = irccat -MANS = irccat.1 +BINS = irccat hirc2txt +MANS = irccat.1 hirc2txt.1 include ../config.mk all: $(BINS) -irccat: irccat.c install: mkdir -p $(BINDIR) $(MANDIR)/man1 diff --git a/misc/hirc2txt b/misc/hirc2txt Binary files differ. diff --git a/misc/hirc2txt.1 b/misc/hirc2txt.1 @@ -0,0 +1,34 @@ +.\" vim: set syntax=nroff : +.Dd COMMIT +.Dt hirc2txt 1 +.Os +.Sh NAME +.Nm hirc2txt +.Nd convert +.Xr hirc 1 +logs to "pretty" text +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +reads a log created by +.Xr hirc 1 +from standard input and reformats it as plaintext, +including a timestamp, before printing it to standard output. + +.Nm +does not handle mIRC formatting, so it is recommended to pipe the output to +.Xr irccat 1 "," +also included with +.Xr hirc 1 +in the +.Pa misc/ +directory. +.Sh EXAMPLES +An example script for interactively selecting a log file and subsequently veiwing it is located at +.Pa misc/hirc2txt.sh +.Sh SEE ALSO +.Xr hirc 1 "," +.Xr irccat 1 +.Sh AUTHOR +.An hhvn Aq Mt dev@hhvn.uk diff --git a/misc/hirc2txt.c b/misc/hirc2txt.c @@ -0,0 +1,67 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> + +char *topic = NULL; + +void +convert(char *line) { + char *tok[8]; + char *msg, *p; + char time[64]; + time_t timestamp; + int i; + + if (*line == 'v') + line = strchr(line, '\t'); + tok[0] = strtok_r(line, "\t", &msg); + for (i = 1; i < (sizeof(tok) / sizeof(tok[0])); i++) + tok[i] = strtok_r(NULL, "\t", &msg); + + if (!tok[0] || !tok[1] || !tok[2] || + !tok[3] || !tok[4] || !tok[5] || + !tok[6] || !tok[7] || !msg) + return; + + timestamp = (time_t)strtoll(tok[0], NULL, 10); + + strftime(time, sizeof(time), "[%Y-%m-%d %H:%M:%S]", localtime(&timestamp)); + + if (strncmp(msg, "PRIVMSG ", 8) == 0 && (p = strchr(msg, ':'))) { + printf("%s <%s%s> %s\n", time, *tok[4] != ' ' ? tok[4] : "", tok[5], p + 1); + } else if (strncmp(msg, "JOIN ", 5) == 0) { + printf("%s %s (%s@%s) joined.\n", time, tok[5], tok[6], tok[7]); + } else if (strncmp(msg, "PART ", 5) == 0) { + printf("%s %s (%s@%s) parted.\n", time, tok[5], tok[6], tok[7]); + } else if (strncmp(msg, "QUIT ", 5) == 0) { + printf("%s %s (%s@%s) quit.\n", time, tok[5], tok[6], tok[7]); + } else if (strncmp(msg, "332 ", 4) == 0 && (p = strchr(msg, ':'))) { + free(topic); + topic = strdup(p + 1); + } else if (strncmp(msg, "TOPIC ", 6) == 0 && (p = strchr(msg, ':'))) { + if (topic) + printf("%s %s changed the topic from \"%s\" to \"%s\"\n", time, tok[5], topic, p + 1); + else + printf("%s %s set the topic to \"%s\"\n", time, tok[5], p + 1); + free(topic); + topic = strdup(p + 1); + } else if (strncmp(msg, "NICK ", 5) == 0 && (p = strchr(msg, ':'))) { + printf("%s %s is now known as %s\n", time, tok[5], p + 1); + } else if (strncmp(msg, "MODE ", 5) == 0 && (p = msg + 5)) { + if ((p = strchr(p, ' '))) + printf("%s %s set mode(s) %s\n", time, tok[5], p + 1); + } + +} + +int +main(void) { + char buf[2048], *p; + + while (fgets(buf, sizeof(buf), stdin)) { + if ((p = strchr(buf, '\n')) && *(p+1) == '\0') + *p = '\0'; + convert(buf); + } +} diff --git a/misc/hirc2txt.sh b/misc/hirc2txt.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# Select logfile, and view with hirc2txt/irccat + +dir="$HOME/.local/hirc" + +file=$(find "$dir" -type f -name "*.log" | dmenu -i -p 'Log file:' | head -n 1) + +hirc2txt < $file | irccat | less -R