diff options
-rw-r--r-- | Makefile.hush | 3 | ||||
-rwxr-xr-x | bin/combine_ttyrecs | 22 | ||||
-rwxr-xr-x | bin/htmlwish | 126 | ||||
-rw-r--r-- | bin/local/timettyrec.c | 101 | ||||
-rwxr-xr-x | bin/mark_asc | 7 | ||||
-rwxr-xr-x | bin/nhgrep | 91 | ||||
-rwxr-xr-x | bin/timettyrecs | 61 | ||||
-rwxr-xr-x | bin/ttyslice | 51 | ||||
-rwxr-xr-x | bin/ttywish | 193 |
9 files changed, 1 insertions, 654 deletions
diff --git a/Makefile.hush b/Makefile.hush index e8c8fd2..0da58f5 100644 --- a/Makefile.hush +++ b/Makefile.hush @@ -31,8 +31,7 @@ INSTALL_CUSTOM := \ BUILD := \ wunderground \ - mpdscribble/mpdscribble.conf \ - bin/local/timettyrec + mpdscribble/mpdscribble.conf clean :: @crontab -r diff --git a/bin/combine_ttyrecs b/bin/combine_ttyrecs deleted file mode 100755 index 719cd37..0000000 --- a/bin/combine_ttyrecs +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -if [[ "$1x" == '-vx' ]]; then - verbose=1 - shift -else - verbose=0 -fi - -mkdir -p combined - -filenum=0 -for file in *.ttyrec; do - if ttygrep 'welcome to NetHack!' $file | grep -q "ttyrec"; then - filenum=$((filenum+1)) - fi - if [[ $verbose -eq 1 ]]; then - printf "%03d: %s\n" $filenum $file - fi - filename=$(printf "%03d\n" $filenum).ttyrec - cat $file >> combined/$filename -done diff --git a/bin/htmlwish b/bin/htmlwish deleted file mode 100755 index e8eb662..0000000 --- a/bin/htmlwish +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -# I have no idea how long this will take... -# Should probably run it with a nice of 10 or something. -# Sample usage: ./nao_wishes.pl ttyrec oldttyrec -# I could modify it to work on a player-by-player basis -# easy to add caching too - -# One problem with this is that it'll take so long that it can never be -# perfectly accurate unless people just stop playing (or at least, wishing) - -# TODO: make it understand wishes better -# (i.e. "The Orb of Fate" == "Orb of Fate" -# could probably just get rid of "greased" and "fixed" too - -my $output_with_numbers = 'wishes.html'; -my $output_without_numbers = 'wishes-n.html'; - -my %wishes; -my %wishes_n; -my $total = 0; - -while (@ARGV) -{ - my $file = shift @ARGV; - next if $file =~ m{(?:^|/)\.+$}; - - if (-d $file) - { - print STDERR "Recursing into $file\n"; - opendir(my $dirhandle, $file) or next; - push @ARGV, map {"$file/$_"} readdir($dirhandle); - close $dirhandle; - } - else - { - next unless $file =~ /\.ttyrec(\.bz2)?$/; - print STDERR "Working on $file\n"; - my $output; - - if (defined($1)) - { - $output = `bzcat $file | ttywish`; - } - else - { - $output = `cat $file | ttywish`; - } - - foreach my $wish (split /\n/, $output) - { - $wish =~ s/^[^ ]+ //; - $wish =~ s/ (?:named|called).*$//; - $wishes{$wish}++; - $wish =~ s/\d+/N/g; - $wishes_n{$wish}++; - } - } -} - -foreach my $count (values %wishes) -{ - $total += $count; -} - -foreach my $file ($output_with_numbers, $output_without_numbers) -{ - open(my $handle, '>', $file) or die "Unable to open '$file': $!"; - my $numbers = $file eq $output_with_numbers; - my $title = $numbers ? "NetHack wishes" : "NetHack wishes without numbers"; - - print {$handle} << "EOHD"; -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" - "http://www.w3.org/TR/html4/loose.dtd"> -<HTML><HEAD><TITLE>alt.org - $title</TITLE> -<link rel="icon" href="http://alt.org/nethack/alt_favicon.png"><link rel="shortcut icon" href="http://alt.org/nethack/alt_favicon.png"><link rel="stylesheet" type="text/css" href="http://alt.org/nethack/altorg.css"> -</HEAD> -<BODY> - -<DIV class="headerbar"> -<A class="header" href="/"><IMG src="http://alt.org/images/altorgheader.png" class="header" alt="alt.org"></A> -</DIV> - -<DIV class="body"> - -<H1>$title</H1> -<BR> -<TABLE> - -<TR> -<TH>Rank</TH> -<TH align="right">Number</TH> -<TH>Percentage</TH> -<TH> Wish</TH> -</TR> -EOHD - - my $rank = 0; - my %w = $numbers ? %wishes : %wishes_n; - - foreach my $wish (sort {$w{$b} <=> $w{$a} || $a cmp $b} keys %w) - { - printf $handle "<TR class=\"%s\"><TD>%d</TD><TD align=\"RIGHT\">%d </TD><TD> %.2f</TD><TD> %s</TD></TR>\n", ($rank % 2 ? 'odd' : 'even'), ++$rank, $w{$wish}, 100 * $w{$wish} / $total, $wish; - } - -# not quite the same format as the rest of NAO, but close enough - my $time = localtime; - - print {$handle} << "EOHD2"; -</TABLE><P class="lastupdate">This page last updated on $time</P></DIV> - -<DIV class="footertxt">All original content on this site is -copyright (c)2000-2113 M. Drew Streib and licensed under the -<A href="http://www.opencontent.org/opl.shtml">OpenContent -License</A> unless otherwise noted.</DIV> - -<DIV class="footerbar"></DIV> - -</BODY> -</HTML> -EOHD2 - -} - diff --git a/bin/local/timettyrec.c b/bin/local/timettyrec.c deleted file mode 100644 index 77d97e3..0000000 --- a/bin/local/timettyrec.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2004, Jilles Tjoelker - * All rights reserved. - * - * Redistribution and use in source and binary forms, with - * or without modification, are permitted provided that the - * following conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/time.h> - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> - -int -main(int argc, char *argv[]) -{ - unsigned char buf[12]; - char data[65536]; - int n; - int r; - struct timeval totaltime, prev, cur, diff, thres; - int first = 1; - - if (argc != 1) - { - fprintf(stderr, "Usage: %s\n", argv[0]); - return 1; - } - - timerclear(&totaltime); - thres.tv_sec = 10; - thres.tv_usec = 0; - - while ((errno = 0), fread(buf, 1, 12, stdin) == 12) - { - cur.tv_sec = (((((buf[3] << 8) | buf[2]) << 8) | buf[1]) << 8) | buf[0]; - cur.tv_usec = (((((buf[7] << 8) | buf[6]) << 8) | buf[5]) << 8) | buf[4]; - if (first) - first = 0; - else - { - timersub(&cur, &prev, &diff); - if (timercmp(&diff, &thres, >)) - diff = thres; - timeradd(&totaltime, &diff, &totaltime); - } - prev = cur; - n = (((((buf[11] << 8) | buf[10]) << 8) | buf[9]) << 8) | buf[8]; - if ((unsigned int)n > sizeof(data)) - { - fprintf(stderr, "h->len too big (%d)\n", n); - exit(1); - } - r = fread(data, 1, n, stdin); - if (n != r) - { - perror("read stdin"); - exit(1); - } - } - - if (errno != 0) - { - perror("read stdin"); - exit(1); - } - - printf("%ld.%06ld\n", totaltime.tv_sec, totaltime.tv_usec); - - return 0; -} - -/* vim:ts=8:cin:sw=4 - * */ diff --git a/bin/mark_asc b/bin/mark_asc deleted file mode 100755 index b57a4bb..0000000 --- a/bin/mark_asc +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -for file in *.ttyrec; do - if ttygrep 'ascend to the status of Demi' $file | grep -q ttyrec; then - mv $file $(echo $file | sed 's/\(.*\)\.\(ttyrec\)/\1a.\2/') - fi -done diff --git a/bin/nhgrep b/bin/nhgrep deleted file mode 100755 index bb353d9..0000000 --- a/bin/nhgrep +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; -use Term::TtyRec::Plus; -use Getopt::Long; - -my $full_frame = 0; -my $hide_time = 0; -my $hide_turn = 0; -my $hide_dlvl = 0; -my $hide_frame = 0; -my $hide_file = @ARGV <= 1 ? 1 : 0; -my $concat = 1; -my $first_only = 0; - -GetOptions -( - full_frame => \$full_frame, - time => \$hide_time, - turn => \$hide_turn, - dlvl => \$hide_dlvl, - file => \$hide_file, - number => \$hide_frame, - concat => \$concat, - 1 => \$first_only, - first => \$first_only, -); - -my $regex = shift; - -sub serialize -{ - my $seconds = int shift; - my $hours = int($seconds / 3600); - $seconds %= 3600; - my $minutes = int($seconds / 60); - $seconds %= 60; - - return sprintf '%dh%dm%ds', $hours, $minutes, $seconds if $hours; - return sprintf '%dm%ds', $minutes, $seconds if $minutes; - return "${seconds}s"; -} - -my ($turn, $dlvl, $time, $frame) = ('?', '?', 0, 0); - -FILE: for my $file (@ARGV) -{ - my $ttp = Term::TtyRec::Plus->new(infile => $file); - - if (not $concat) - { - $turn = '?'; - $dlvl = '?'; - $time = 0; - $frame = 0; - } - - FRAME: while (my $frame_ref = $ttp->next_frame()) - { - $time += $frame_ref->{diff}; - ++$frame; - - if ($frame_ref->{data} =~ / T:(\d+)/) - { - $turn = $1; - } - - if ($frame_ref->{data} =~ /(Dlvl:\d+|Home \d+)/) - { - ($dlvl = $1) =~ s/://g; - } - - $frame_ref->{data} =~ s/\e/\\e/g; - if ($frame_ref->{data} =~ s/($regex)/\e[1;31m$1\e[0m/go) - { - my @out; - - push @out, $file if not $hide_file; - push @out, "T$turn" if not $hide_turn; - push @out, $dlvl if not $hide_dlvl; - push @out, serialize($time) if not $hide_time; - push @out, $frame if not $hide_frame; - - push @out, $full_frame ? $frame_ref->{data} : $1; - - print join(':', @out), "\n"; - next FILE if $first_only; - } - } -} - diff --git a/bin/timettyrecs b/bin/timettyrecs deleted file mode 100755 index bebf02a..0000000 --- a/bin/timettyrecs +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -my $total = 0; - -sub duration -{ - use integer; - my $seconds = int shift; - -# my $days = $seconds / (24 * 60 * 60); -# $seconds %= 24 * 60 * 60; - my $hours = $seconds / (60 * 60); - $seconds %= 60 * 60; - my $minutes = $seconds / 60; - $seconds %= 60; - - my $out = ' '; -# $out .= $days . 'd ' if $days; - $out .= $hours . 'h ' if $hours; - $out .= $minutes . 'm ' if $minutes; - $out .= $seconds . 's ' if $seconds || $out eq ' '; - - return substr($out, 1); -} - -my @files; - -for (@ARGV) -{ - if (-d $_) - { - my $dir = $_; - opendir(DIR, $dir); - push @files, map {"$dir/$_"} sort grep {!/^\.+$/} readdir DIR; - closedir DIR; - } - else - { - push @files, $_; - } -} - -for (@files) -{ - my $cat = "cat"; - $cat = "bzcat" if /\.bz2$/; - my $time = `$cat $_ | timettyrec`; - $time =~ s/.*\n// if $time =~ y/\n/\n/ > 1; - if ($time !~ /^\d/) - { - print "$_ isn't being timed correctly. Skipping.\n"; - next; - } - $total += $time; - $time = duration($time) . "\n"; - print ((@files>1?"$_: ":"").$time); -} - -print "total: " . duration($total) . "\n" if @files > 1; diff --git a/bin/ttyslice b/bin/ttyslice deleted file mode 100755 index 17d6f19..0000000 --- a/bin/ttyslice +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -if (@ARGV != 3) -{ - die "usage: $0 start end ttyrec\n"; -} - -my $frame = 0; -my $DEC = 0; -my $start = shift || 1; -my $end = shift || -1; -my $prev = ''; -my $handle; - -open($handle, '<', $ARGV[0]) or die "Unable to open '$ARGV[0]': $!"; - -while ((my $hgot = read($handle, my $hdr, 12)) > 0) -{ - ++$frame; - - die "Unexpected EOF in '$ARGV[0]' frame $frame header (expected 12 bytes, got $hgot)" if $hgot < 12; - - my @hval = unpack "VVV", $hdr; - my $dlen = $hval[2]; - my $dgot = read $handle, my ($data), $dlen; - - die "Unexpected EOF in '$ARGV[0]' frame $frame data (expected $dlen bytes, got $dgot)" if $dgot < $dlen; - - $DEC = 1 if $data =~ /\e\)0/; - - if ($frame < $start) - { - # we can modify $data because we're not printing it anyway - $prev = '' if $data =~ s/.*\e\[2J//; - $prev .= $data; - } - - if ($frame == $start && $frame > 1) - { - $data = "\e\[2J" . $prev . $data; - $data = "\e)0" . $data if $DEC; - } - - $hval[2] = length($data); - $hdr = pack "VVV", @hval; - - print "$hdr$data" if $frame >= $start && ($end == -1 || $frame <= $end); -} - diff --git a/bin/ttywish b/bin/ttywish deleted file mode 100755 index ddc244c..0000000 --- a/bin/ttywish +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/perl -l - -# Copyright (c) 2006 Shawn M Moore - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -# ttywish 1.4 - searches a NetHack ttyrec for wish strings -# It should handle backspaces, long wishes which span two lines, ^P, and -# "For what do you wish? hits!" -# There may be more holes, please notify me if you discover one! - -# originally based on Simon Tatham's ttygrep -# http://www.chiark.greenend.org.uk/~sgtatham/ipbt/ - -# changelog: -# 1.1 add support for piping input into ttywish -# 1.2 better fix for ^P -# 1.3 fix problem with ttyrecs without showturns -# 1.4 add realtime (-r) -- defaults to 10 sec threshold like timettyrec -# arg for suppression of turns (-t) - -use strict; -use warnings; - -my $threshold = 10; # seconds - -sub timeify -{ - my $seconds = int(shift); - - my $minutes = int($seconds / 60); - $seconds %= 60; - my $hours = int($minutes / 60); - $minutes %= 60; - my $days = int($hours / 24); - $hours %= 24; - - my $ret = ''; - $ret .= "${days}d " if $days; - $ret .= "${hours}h " if $hours; - $ret .= "${minutes}m " if $minutes; - $ret .= "${seconds}s " if $seconds; - return substr($ret, 0, -1); -} - -if (defined($ARGV[0]) && ($ARGV[0] eq '--help' || $ARGV[0] eq '-h')) -{ - print STDERR "Usage: $0 [-rt] [<file> [<file> [<file> ...]]]"; - exit 1; -} - -my $wish; -my $turn; -my $include_turn = 1; -my $include_time = 0; -my $time = 0; -my $prev; - -# poor man's argument parsing, this should be handled by a (core) module -@ARGV = grep -{ - if ($_ eq '-r') - { - $include_time = 1; - 0 - } - elsif ($_ eq '-t') - { - $include_turn = 0; - 0 - } - elsif (/^-(?:rt|tr)$/) - { - $include_time = 1; - $include_turn = 0; - 0 - } - else - { - 1 - } -} @ARGV; - -push @ARGV, '-' if @ARGV == 0; - -TTYREC: foreach my $file (@ARGV) -{ - my $handle; - - # if we're reading from one only, don't bother telling the user - my $file_prefix = @ARGV == 1 ? "" : "$file:"; - if ($file eq '-') - { - $handle = *STDIN; - } - else - { - open $handle, '<', $file or die "$0: Unable to open '$file': $!"; - } - my $frame = 0; - - while ((my $hgot = read $handle, my $hdr, 12)) - { - next TTYREC if $hgot == 0; # clean EOF - if ($hgot < 12) - { - print STDERR "Unexpected EOF in '$file' frame $frame header (expected 12 bytes, got $hgot)"; - next TTYREC; - } - - my @hdr = unpack "VVV", $hdr; - - my $timestamp = $hdr[0] + $hdr[1] / 1_000_000; - if (defined($prev)) - { - my $diff = $timestamp - $prev; - $diff = $threshold if $diff > $threshold; - $time += $diff; - } - $prev = $timestamp; - - my $dgot = read $handle, my ($data), $hdr[2]; - - if ($dgot < $hdr[2]) - { - print STDERR "Unexpected EOF in '$file' frame $frame data (expected $hdr[2] bytes, got $dgot)"; - next TTYREC; - } - - ($turn) = $1 if $data =~ / T:(\d+)/; - - if ($data =~ /\e\[HFor what do you wish/) - { - # try to get rid of "For what do you wish? hits!" - unless ($data =~ /\e\[HFor what do you wish\? \s*[^\e]/) - { - $wish = ''; - } - } - elsif (defined($wish)) - { - # this handles very long wishes which wrap to the next line - $data =~ s/\e\[K\e\[K\r/ /g; - - DATA: foreach (split //, $data) - { - if ($_ eq "\e") - { - my $time_out = $include_time ? timeify($time) . ':' : ''; - my $turn_out = $include_turn && defined($turn) ? "T$turn:" : ''; - my $space = $time_out eq '' && $turn_out eq '' ? '' : ' '; - $wish =~ s/\s*$//; - $wish =~ s/ \n//g; - - print $file_prefix . $turn_out . $time_out . $space . $wish; - - undef $wish; - last DATA; - } - - if ($_ eq "\b") - { - chop $wish; - } - else - { - $wish .= $_; - } - } - } - - ++$frame; - } -} - - - |