#!/bin/rc
if(~ $#* 0){
echo usage: $0 file ... >[1=2]
exit usage
}
awk 'BEGIN{
n=0
}
function hex(h){
v=0
h=tolower(h)
if(!sub(/^0x/, "", h))
return h
for(i=1; i<=length(h); ++i){
x=index("0123456789abcdef", substr(h, i, 1))
if(!x)
return -1
v=(16*v)+x-1
}
return v
}
{
if(FNR == 1){
if(NR == 1){
hx=$1
hy=$2
}
next
}
if(length($3) == 0)
next
f=$3
d=FILENAME
if(sub(/\/[^\/]+$/, "", d))
f=sprintf("%s/%s", d, f)
if(system(sprintf("test -e %s", f))){
printf("%s:%d missing %s\n", FILENAME, FNR, f) >"/fd/2"
next
}
s = hex($1)
e = hex($2)
if(e < s)
next
for(i=0; i<n; i++){
if(s >= as[i] && s <= ae[i])
s = ae[i]+1
if(e >= as[i] && e <= ae[i])
e = as[i]-1
if(s > e)
next
}
as[n] = hex($1)
ae[n] = hex($2)
ax[n] = f
n++;
}
END{
printf("%d %d\n", hx, hy)
for(i=0; i<n; i++){
printf("0x%.4x 0x%.4x ", as[i], ae[i])
system(sprintf("cleanname %s", ax[i]))
}
}' $1 `{awk '{
x=$1
y=$2
if(NR == 1){
hx=x
hy=y
}
a=y-hy
if(a < 0)
a = -a
printf("%d %s\n", a, FILENAME)
nextfile
}' $* | sort | uniq | awk '{print $2}'}
|