2 # compare - compare output
3 # usage: compare original-servent-file reader-program
5 # $NetBSD: compare,v 1.3 2008/03/08 23:32:38 dholland Exp $
13 echo "$0: usage: $0 original-servent-file reader-program" 1>&2
16 if [ ! -f "$1" ]; then
17 echo "$0: $1 missing" 1>&2
20 if [ ! -x "$2" ]; then
21 echo "$0: $2 missing" 1>&2
27 # (1) match output format of the test program
28 # (2) fold all names for the same port/proto together
29 # (3) prune duplicates
31 tr '\t' ' ' < "$1" |
awk '
32 function add(key, name, i, n, ar) {
33 n = split(names[key], ar);
34 for (i=1; i<=n; i++) {
40 names[key] = names[key] " " name;
50 for (i=3; i<=NF; i++) {
57 sub("/", ", proto=", portproto);
58 portproto = "port=" portproto;
60 n = split(names[key], ar);
61 printf "name=%s, %s, aliases=", ar[1], portproto;
62 for (i=2; i<=n; i++) {
75 $2 |
sed 's/ *$//' |
sort > $OBS
77 diff $REF $OBS >$DIFFS 2>&1
79 if [ -s $DIFFS ]; then
80 echo "servent: Observed output does not match reference output" 1>&2
81 echo "servent: Outputs left in `pwd`" 1>&2
84 rm -f $REF $OBS $DIFFS