mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Fix gbdiff script
Fix issues with spaces in input filenames, as well as a bunch more lint warnings.
This commit is contained in:
@@ -23,51 +23,51 @@
|
|||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
STATE=0
|
STATE=0
|
||||||
diff <(xxd $1) <(xxd $2) | while read -r LINE; do
|
diff <(xxd "$1") <(xxd "$2") | while read -r LINE; do
|
||||||
if [ $STATE -eq 0 ]; then
|
if [[ $STATE -eq 0 ]]; then
|
||||||
# Discard first line (line info)
|
# Discard first line (line info)
|
||||||
STATE=1
|
STATE=1
|
||||||
elif [ "$LINE" = '---' ]; then
|
elif [[ "$LINE" = '---' ]]; then
|
||||||
# Separator between files switches states
|
# Separator between files switches states
|
||||||
echo $LINE
|
echo "$LINE"
|
||||||
STATE=3
|
STATE=3
|
||||||
elif grep -Eq '^[0-9]+(,[0-9]+)?[cd][0-9]+(,[0-9]+)?' <<< "$LINE"; then
|
elif grep -Eq '^[0-9]+(,[0-9]+)?[cd][0-9]+(,[0-9]+)?' <<< "$LINE"; then
|
||||||
# Line info resets the whole thing
|
# Line info resets the whole thing
|
||||||
STATE=1
|
STATE=1
|
||||||
elif [ $STATE -eq 1 -o $STATE -eq 3 ]; then
|
elif [[ $STATE -eq 1 || $STATE -eq 3 ]]; then
|
||||||
# Compute the GB address from the ROM offset
|
# Compute the GB address from the ROM offset
|
||||||
OFS=$(cut -d ' ' -f 2 <<< "$LINE" | tr -d ':')
|
OFS=$(cut -d ' ' -f 2 <<< "$LINE" | tr -d ':')
|
||||||
BANK=$((0x$OFS / 0x4000))
|
BANK=$((0x$OFS / 0x4000))
|
||||||
ADDR=$((0x$OFS % 0x4000 + ($BANK != 0) * 0x4000))
|
ADDR=$((0x$OFS % 0x4000 + (BANK != 0) * 0x4000))
|
||||||
# Try finding the preceding symbol closest to the diff
|
# Try finding the preceding symbol closest to the diff
|
||||||
if [ $STATE -eq 1 ]; then
|
if [[ $STATE -eq 1 ]]; then
|
||||||
STATE=2
|
STATE=2
|
||||||
SYMFILE=${1%.*}.sym
|
SYMFILE=${1%.*}.sym
|
||||||
else
|
else
|
||||||
STATE=4
|
STATE=4
|
||||||
SYMFILE=${2%.*}.sym
|
SYMFILE=${2%.*}.sym
|
||||||
fi
|
fi
|
||||||
EXTRA=$(if [ -f "$SYMFILE" ]; then
|
EXTRA=$(if [[ -f "$SYMFILE" ]]; then
|
||||||
# Read the sym file for such a symbol
|
# Read the sym file for such a symbol
|
||||||
# Ignore comment lines, only pick matching bank
|
# Ignore comment lines, only pick matching bank
|
||||||
# (The bank regex ignores comments already, make `cut` and `tr` process less lines)
|
# (The bank regex ignores comments already, make `cut` and `tr` process less lines)
|
||||||
grep -Ei $(printf "^%02x:" $BANK) "$SYMFILE" |
|
grep -Ei "$(printf "^%02x:" $BANK)" "$SYMFILE" |
|
||||||
cut -d ';' -f 1 |
|
cut -d ';' -f 1 |
|
||||||
tr -d "\r" |
|
tr -d "\r" |
|
||||||
while read -r SYMADDR SYM; do
|
while read -r SYMADDR SYM; do
|
||||||
SYMADDR=$((0x${SYMADDR#*:}))
|
SYMADDR=$((0x${SYMADDR#*:}))
|
||||||
if [ $SYMADDR -le $ADDR ]; then
|
if [[ $SYMADDR -le $ADDR ]]; then
|
||||||
printf " (%s+%#x)\n" "$SYM" $(($ADDR - $SYMADDR))
|
printf " (%s+%#x)\n" "$SYM" $((ADDR - SYMADDR))
|
||||||
fi
|
fi
|
||||||
# TODO: assumes sorted sym files
|
# TODO: assumes sorted sym files
|
||||||
done | tail -n 1
|
done | tail -n 1
|
||||||
fi)
|
fi)
|
||||||
printf "%02x:%04x %s\n" $BANK $ADDR $EXTRA
|
printf "%02x:%04x %s\n" $BANK $ADDR "$EXTRA"
|
||||||
fi
|
fi
|
||||||
if [ $STATE -eq 2 -o $STATE -eq 4 ]; then
|
if [[ $STATE -eq 2 || $STATE -eq 4 ]]; then
|
||||||
OFS=$(cut -d ' ' -f 2 <<< "$LINE" | tr -d ':')
|
OFS=$(cut -d ' ' -f 2 <<< "$LINE" | tr -d ':')
|
||||||
BANK=$((0x$OFS / 0x4000))
|
BANK=$((0x$OFS / 0x4000))
|
||||||
ADDR=$((0x$OFS % 0x4000 + ($BANK != 0) * 0x4000))
|
ADDR=$((0x$OFS % 0x4000 + (BANK != 0) * 0x4000))
|
||||||
printf "%s %02x:%04x: %s\n" "${LINE:0:1}" $BANK $ADDR "${LINE#*: }"
|
printf "%s %02x:%04x: %s\n" "${LINE:0:1}" $BANK $ADDR "${LINE#*: }"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user