aboutsummaryrefslogtreecommitdiff
path: root/diffbas
blob: ef621e5fc727341c228a25cd238a0f5830bbcb2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh

usage() {
  cat <<EOF
Usage: $( basename $0 ) [diff-opts] [-- listbas-opts] file1.bas file2.bas

Diff two tokenized Atari BASIC programs, using listbas(1) and diff(1).

[diff-opts] is passed through as-is to diff.
[listbas-opts] is passed through as-is to listbas.
EOF
  exit "$1"
}

cleanup() {
  if [ "$dir" != "" ]; then
    cd
    rm -rf "$dir"
  fi
}

if [ "$1" = "-h" -o "$1" = "--help" -o "$1" = "" ]; then
  usage 0
fi

for i in "$@"; do
  if [ -f "$i" ]; then
    if [ "$file1" = "" ]; then
      file1="$( realpath $i )"
      base1="$( basename $i )".lst
    elif [ "$file2" = "" ]; then
      file2="$( realpath $i )"
      base2="$( basename $i )".lst
    else
      usage 1
    fi
  elif [ "$i" = "--" ]; then
    opts="listbasopts"
  elif [ "$opts" = "listbasopts" ]; then
    listbasopts="$listbasopts $i"
  else
    diffopts="$diffopts $i"
  fi
done

dir="$( mktemp -d -t diffbas.XXXXXXXXXX )"
[ -d "$dir" ]
cd "$dir"
trap cleanup EXIT
set -e

listbas $listbasopts "$file1" > $base1
listbas $listbasopts "$file2" > $base2
diff $diffopts $base1 $base2

exit 0