#! /usr/bin/tclsh

#
# Substitute memory locations with symbols w1, w2 etc ...
#
set suffix .subst
foreach file [glob *.out*] {
	if {[string match *$suffix $file]} {
		continue
	}
	set fd [open $file r]
	set txt [read $fd]
	close $fd
	set i 0
	while {[regexp {0x[a-f0-9]+} $txt match]} {
		set txt [string map "$match w[incr i]" $txt]
	}
	if {$i == 0} {
		error "no substitutions occurred"
	}
	set fd [open $file$suffix w]
	puts -nonewline $fd $txt
	close $fd
}

#
# Create diffs
#
set wms {KDE KDE+after200 ICEWM TWM}
set i 0
foreach wm1 $wms {
	incr i
	foreach wm2 [lrange $wms $i 3] {
		set f1 [glob $wm1.out.subst]
		set f2 [glob $wm2.out.subst]
		if {($wm1 eq "KDE") && ($wm2 eq "KDE+after200")} { 
			# side by side diff
			catch {eval exec diff -t -y -W 210 $f1 $f2 > $wm1-$wm2.diff}
		} else {
			# unified diff
			catch {eval exec diff -u $f1 $f2 > $wm1-$wm2.diff}
		}
	}
}

# EOF
