oggz-diff.in 5.54 KB
Newer Older
conrad's avatar
conrad committed
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
#!/bin/sh

## Copyright (C) 2003 Commonwealth Scientific and Industrial Research
## Organisation (CSIRO) Australia
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions
## are met:
##
## - Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
##
## - Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimer in the
## documentation and/or other materials provided with the distribution.
##
## - Neither the name of CSIRO Australia nor the names of its
## contributors may be used to endorse or promote products derived from
## this software without specific prior written permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
## ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
## PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
## LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
## NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

version () {
conrad's avatar
conrad committed
34
  echo >&2 "oggz-diff version "@VERSION@
conrad's avatar
conrad committed
35
36
37
38
  exit 1
}

usage () {
conrad's avatar
conrad committed
39
  echo >&2 "oggz-diff, diff oggz-dumps of two Ogg files."
conrad's avatar
conrad committed
40
  echo >&2
conrad's avatar
conrad committed
41
  echo >&2 "Usage: oggz-diff [options] [OGGZDUMP_OPTIONS] [DIFF_OPTIONS] file1.ogg file2.ogg"
conrad's avatar
conrad committed
42
43
44
  echo >&2
  echo >&2 "options: [--verbose] [-v | --version] [-h | --help]"
  echo >&2
conrad's avatar
conrad committed
45
  echo >&2 "Supported oggz-dump and diff options:"
conrad's avatar
conrad committed
46
47
48
49
  echo >&2
  echo >&2 "OGGZDUMP_OPTIONS: [-b | --binary] [-x | --hexadecimal]"
  echo >&2 "    [-O | --hide-offset] [-S | --hide-serialno] [-G | --hide-granulepos]"
  echo >&2 "    [-P | --hide-packetno] [-s serialno | --serialno serialno]"
50
  echo >&2 "    [-c content-type | --content-type content-type]"
conrad's avatar
conrad committed
51
  echo >&2
52
  echo >&2 "DIFF_OPTIONS: [-q | --brief] [-C NUM | --context[=NUM]]"
conrad's avatar
conrad committed
53
54
55
56
57
58
59
60
61
  echo >&2 "     [-u | -U NUM | --unified[=NUM]] [-e | -ed] [--normal] [--rcs]"
  echo >&2 "     [-y | --side-by-side] [-l | --paginate]"
  echo >&2
  exit 1
}

GETOPTEST=`getopt --version`
case $GETOPTEST in
getopt*) # GNU getopt
62
63
  GETOPTARGS="-l verbose -l version -l brief -l context:: -l unified:: -l ed -l normal -l rcs -l side-by-side -l paginate -l binary -l hexadecimal -l serialno: -l content-type: -l hide-offset -l hide-serialno -l hide-granulepos -l hide-packetno -l help -- +qC:uU:eylbxs:c:OSGPhv"
  QARGS="--verbose --version --brief --context --unified --ed --normal --rcs --side-by-side --paginate --binary --hexadecimal --serialno --content-type --hide-offset --hide-serialno --hide-granulepos --hide-packetno --help -q -C -u -U -e -y -l -b -x -s -c -O -S -G -P -h -v"
conrad's avatar
conrad committed
64
65
  ;;
*) # POSIX getopt ?
66
67
  GETOPTARGS="qC:uU:eylbxs:c:OSGPhv"
  QARGS="-q -C -u -U -e -y -l -b -x -s -c -O -S -G -P -h -v"
conrad's avatar
conrad committed
68
69
70
  ;;
esac

71
72
73
74
75
76
77
# First check for -? option
if test "X$1" = "X-?"; then
  exit 0
fi

TEMP=`getopt $GETOPTARGS "$@"`

conrad's avatar
conrad committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
if test "$?" != "0"; then
  usage
fi

eval set -- "$TEMP"

DIFFOPTS="-w" # -w, --ignore-all-space
DUMPOPTS=""
VERBOSE=""

while test "X$1" != "X--"; do
  case "$1" in
    -q|--brief)
      DIFFOPTS=$DIFFOPTS" -q"
      ;;
    -C)
      shift
      DIFFOPTS=$DIFFOPTS" -C $1"
      ;;
    --context)
      shift
      if test "x$1" = "x"; then
        DIFFOPTS=$DIFFOPTS" --context"
      else
        DIFFOPTS=$DIFFOPTS" --context=$1"
      fi
      ;;
    -u)
      DIFFOPTS=$DIFFOPTS" -u"
      ;;
    -U)
      shift
      DIFFOPTS=$DIFFOPTS" -U $1"
      ;;
    --unified)
      shift
      if test "x$1" = "x"; then
        DIFFOPTS=$DIFFOPTS" --unified"
      else
        DIFFOPTS=$DIFFOPTS" --unified=$1"
      fi
      ;;
    -e|--ed)
      DIFFOPTS=$DIFFOPTS" -e"
      ;;
    --normal)
      DIFFOPTS=$DIFFOPTS" --normal"
      ;;
    --rcs)
      DIFFOPTS=$DIFFOPTS" --rcs"
      ;;
    -y|--side-by-side)
      DIFFOPTS=$DIFFOPTS" -y"
      ;;
    -l|--paginate)
      DIFFOPTS=$DIFFOPTS" -l"
      ;;
    -b|--binary)
      DUMPOPTS=$DUMPOPTS" -b"
      ;;
    -x|--hexadecimal)
      DUMPOPTS=$DUMPOPTS" -x"
      ;;
    -s|--serialno)
      shift
143
      DUMPOPTS=$DUMPOPTS" -s $1"
conrad's avatar
conrad committed
144
      ;;
145
146
147
148
    -c)
      shift
      DUMPOPTS=$DUMPOPTS" -c $1"
      ;;
conrad's avatar
conrad committed
149
    -O|--hide-offset)
150
      DUMPOPTS=$DUMPOPTS" -O"
conrad's avatar
conrad committed
151
152
      ;;
    -S|--hide-serialno)
153
      DUMPOPTS=$DUMPOPTS" -S"
conrad's avatar
conrad committed
154
155
      ;;
    -G|--hide-granulepos)
156
      DUMPOPTS=$DUMPOPTS" -G"
conrad's avatar
conrad committed
157
158
      ;;
    -P|--hide-packetno)
159
      DUMPOPTS=$DUMPOPTS" -P"
conrad's avatar
conrad committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
      ;;
    --verbose)
      VERBOSE="y"
      ;;
    -v|--version)
      version
      ;;
    -h|--help)
      usage
      ;;
  esac
  shift
done

# Check that all options parsed ok
if test "x$1" != "x--"; then
  usage
fi
shift #get rid of the '--'

if test "x$1" = "x"; then
  usage
fi
if test "x$2" = "x"; then
  usage
fi

if test "x$VERBOSE" != "x"; then
  echo >&2 "OGGZDUMP_OPTIONS: " $DUMPOPTS
  echo >&2 "DIFF_OPTIONS: " $DIFFOPTS
fi

192
193
FIFO1="${TMPDIR:-/tmp}/`basename $1`.dump-1-$$"
FIFO2="${TMPDIR:-/tmp}/`basename $2`.dump-2-$$"
conrad's avatar
conrad committed
194
195
196
197

exec 5>$FIFO1
exec 6>$FIFO2

conrad's avatar
conrad committed
198
oggz-dump $DUMPOPTS $1 >&5
conrad's avatar
conrad committed
199
200
201
202
if test "$?" != "0"; then
  exit 1
fi

conrad's avatar
conrad committed
203
oggz-dump $DUMPOPTS $2 >&6
conrad's avatar
conrad committed
204
205
206
207
208
if test "$?" != "0"; then
  exit 1
fi

diff $DIFFOPTS $FIFO1 $FIFO2
209
ret=$?
conrad's avatar
conrad committed
210
211

rm $FIFO1 $FIFO2
212
213
214

exit $ret