Sync usage with man page.
[netbsd-mini2440.git] / regress / lib / libc / servent / compare
blob1ea59d4de46b0168ac329201543eb7424621f7c6
1 #!/bin/sh
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 $
8 REF=reference-output
9 OBS=observed-output
10 DIFFS=differences
12 if [ $# != 2 ]; then
13 echo "$0: usage: $0 original-servent-file reader-program" 1>&2
14 exit 1
16 if [ ! -f "$1" ]; then
17 echo "$0: $1 missing" 1>&2
18 exit 1
20 if [ ! -x "$2" ]; then
21 echo "$0: $2 missing" 1>&2
22 exit 1
26 # Munge original to:
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++) {
35 if (name == ar[i]) {
36 return;
39 delete ar;
40 names[key] = names[key] " " name;
44 sub("#.*", "", $0);
45 gsub(" *", " ", $0);
46 if (NF==0) {
47 next;
49 add($2, $1, 0);
50 for (i=3; i<=NF; i++) {
51 add($2, $i, 1);
54 END {
55 for (key in names) {
56 portproto = key;
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++) {
63 if (i>2) {
64 printf " ";
66 printf "%s", ar[i];
68 printf "\n";
69 delete ar;
72 ' | sort > $REF
74 # run test program
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
82 exit 1
84 rm -f $REF $OBS $DIFFS
85 exit 0