#!/usr/bin/perl -w # diff_debug_html.pl - Don Yang (uguu.org) # # Same as debug_html.pl, but drop string indices to make it more # friendly to diff. # # 06/26/11 use strict; # Load input my $text = join '', <>; # Extract string table and event list unless( $text =~ /string_table=\n(.*)\nvar events=\n(.*)\nevents\.push/s ) { die "Missing data arrays\n"; } my ($raw_strings, $raw_events) = ($1, $2); # Parse string table my @string_table = (); foreach my $i ($raw_strings =~ /"((?:[^"\\]|\\.)*)"/g) { push @string_table, $i; } # Parse event list and output CSV my $last_timestamp = 0; my @event = (); foreach my $i ($raw_events =~ /(\d+)[,\]]/g) { push @event, $i; next if (scalar @event) < 6; my ($offset, $duration, $type, $slot, $y, $x) = @event; @event = (); # Output timestamp my $t0 = $last_timestamp + $offset; my $t1 = ($duration == 0 ? "inf" : $t0 + $duration); print "$t0,$t1,$offset,$duration,"; $last_timestamp = $t0; if( $type == 0 ) { print "CURSOR,$slot,$y,$x,\n"; } elsif( $type == 1 || $type == 2 ) { print (($type == 1 ? "REPLACE" : "APPEND"), ",$slot,"); if( $y <= $#string_table ) { my $s = $string_table[$y] . " "; my $end = 0; for(my $length = 0; $length < $x; $length++) { if( substr($s, $end, 2) eq "\\u" ) { $end += 6; } elsif( substr($s, $end, 1) eq "\\" ) { $end += 2; } else { $end++; } } $s = substr($s, 0, $end); print "\"$s\"\n"; } else { print "ERROR\n"; } } elsif( $type == 3 ) { print "DELETE,$slot,$y,$x,\n"; } else { print "SLOW_CURSOR,$slot,$y,$x,", $type - 3, "\n"; } }