aboutsummaryrefslogtreecommitdiff
path: root/diffbas
blob: fe69304ef9c12c498188681099323688aece5624 (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
#!/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"
}

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

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

## cat <<EOF
## file1: $file1
## file2: $file2
## listbasopts: $listbasopts
## diffopts: $diffopts
## EOF
## exit 0

dir="$( mktemp -d )"
[ -d "$dir" ] || exit 1
cd "$dir" || exit 1
listbas $listbasopts "$file1" > 1
listbas $listbasopts "$file2" > 2
diff $diffopts 1 2
cd
rm -rf "$dir"