#!/usr/bin/perl

use warnings;
use strict;

use Cyrus::Skiplist;
use Data::Dumper;

my $file = shift;
my $sl = Cyrus::Skiplist->new_file($file);

print Dumper($sl->header());

my %offkey;
while (my $r = $sl->next_record()) {
  my $k = $r->{key} || ($r->{ptr} ? $offkey{$r->{ptr}} : '');
  my $val = $r->{value} || '';
  $offkey{$r->{offset}} = $k;
  my @l = $r->{ptrs} ? @{$r->{ptrs}} : ($r->{ptr}||'');
  my @xl = map { sprintf("%04X", $_) } @l;
  printf "%04X $r->{type} $k $val (@xl)\n", $r->{offset};
}
