#! /bin/sh

lqword -A |
mawk '

BEGIN {
    ResetState()
}

/^[^0-9]/ {
    next
}

# format of input is now:
#
# WID word block-in-file word-in-block flags sep FID filename
# 1   2    3             4             5     6   7   8
#
# we want
# delta-block delta-wib flags-different? sep-used?
{
    if ($7 != theFID || $1 != theWID) {
	ResetState($7)
    }

    if (theBlock == $3){
	theWIB = 0
	printf "0 %d", $4
    } else {
	printf "%d %d", $3 - theBlock, $4 - theWIB
    }
    theBlock = $3

    if ($5 != theFlags || $6 != 1) {
	theFlags = $5
	printf " %d", theFlags
    }

    if ($6 != 1) {
	printf " %d", $6
    }

    # printf "\t%s", $0

    printf "\n"

}

function ResetState(newFID)
{
    theFID = newFID
    theBlock = 0
    theWIB = 0
    theFlags = 0
    theSep = 1
    theWID = -1
}
'
