#!/usr/bin/env sh
# Output the line numbers for lines added and removed in a unified diff

exec awk '
# Skip lines between diff and @@.
/^@@/ { skip = 0 }
skip == 1 { next }
/^diff/ { skip = 1 }


# Skip "\ No newline at end of file"
/^\\/ { next }

/^diff/ { print $0; next }
/^@@/ {
    cur_line = substr($3, 2)
    sub(/,.*$/, "", cur_line)
    if (cur_line < 1) cur_line = 1
    next
}
/^\s*-/ || /^\s*\+/ {
    add_or_rm = substr($0, 1, 1)
    print cur_line, add_or_rm "\t" substr($0, 2)
    if (add_or_rm != "-") { cur_line += 1 }
    next
}

{
    print "Generate diff with -U0. Got context line:\n" $0 > "/dev/stderr"
    exit 1
}
'
