#!/bin/rc rfork en prog=cat when=`{date -n} irchost=mordor while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){ switch($1){ case -t prog=(tail +0f) shift case -[0-9]* when=`{echo $when '+(' $1 '*60*60*24)' | hoc} shift case * echo 'usage: irclog [-n d] [-t]' >[1=2] echo ' -n print logs for d days ago (default=0=today)' >[1=2] echo ' -t "tail -f" the log file' >[1=2] exit 'usage' } } now = `{ date $when | sed ' s/ ([0-9])/ 0\1/ s/Jan/01/ s/Feb/02/ s/Mar/03/ s/Apr/04/ s/May/05/ s/Jun/06/ s/Jul/07/ s/Aug/08/ s/Sep/09/ s/Oct/10/ s/Nov/11/ s/Dec/12/'} 9fs $irchost f=/n/$irchost/usr/web/irclog/$now(6)^/$now(2)^$now(3)^/plan9*.txt* for (file in `{ls -t $f >[2] /dev/null}){ $prog $file | tr '\001\015' '• ' | sed ' / :•VERSION• $/d s/ :•ACTION *(.*)• $/ :«\1»/ ' | awk ' $1 == "PING" { tick++; } $2 == "JOIN" { who = user($1); printf("+%-8s\n", who); owho = ""; } $2 == "QUIT" || $2 == "PART" { who = user($1); printf("-%-8s\n", who); owho = ""; } $2 == "PRIVMSG" { who = user($1); if (who != owho){ if (tick > 1){ printf("\n--------- %d min\n", tick *3); tick = 0; } printf("%s\n", who); } msg = $4; gsub("^:", "", msg); for (i = 5; i <= NF; i++){ if ((length(msg)+length($i)) > 70){ printf("\t%s%s%s\n", pre, msg, post); msg = ""; } msg = msg " " $i; } if (msg != "") printf("\t%s%s%s\n", pre, msg, post); owho = who; pre = post = ""; tick = 0; } function user(s){ gsub("^:", "", s); gsub("!.*$", "", s); return s; } ' }