:
#	@(#) hwconfig.sh 23.3 91/08/29 
#
#	Copyright (C) 1990-1991 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#

INFILE=/usr/adm/hwconfig
AWKPROG=/usr/lib/hwconfig.awk

usage()
{
  cat 1>&2 << EOU
usage: $0 [-chlnq] [-f file] [field=value ...] [field ...]

       -c  Check for hardware interrupt, DMA and I/O address conflicts
       -h  Print header and neatly tabulated output
       -l  Include all fields, even when searching for particular entries
       -n  Include "name" fields
       -q  Check quietly for conflicts; returns 0 for OK, 1 for conflicts
       -f  Use file for input, rather than /usr/adm/hwconfig
       -c and -q together will print conflict reports only

       field=value  Print only those entries containing a matching field
       field	    Print only matching fields (with -h, same as field=value)
EOU
  exit 2
}

[ ! -r $AWKPROG ] && AWKPROG=hwconfig.awk
[ ! -r $AWKPROG ] && {
  echo 1>&2 $0: cannot read $AWKPROG
  exit 2
}

TABLE=0
CHECK=0
QUIET=0
ALL=0
CONDS=

set -- `getopt chlnqf: $* 2>/dev/null`

[ $? -ne 0 ] && usage

while [ $# -ne 0 ]; do
  case $1 in
    --) ;;
    -c) CHECK=`expr $CHECK + 1`;;
    -h) TABLE=1;;
    -f) INFILE=$2; shift;;
    -q) CHECK=`expr $CHECK + 1`; QUIET=1;;
    -l) ALL=1;;
    -n) CONDS="name,$CONDS";;
    -*|h|help) usage;;
     *) CONDS="$CONDS,$1";;
  esac
  shift
done

[ $TABLE -ne 0 ] && [ $QUIET -eq 0 ] &&
  echo 'device          address    vec  dma  comment
======          =======    ===  ===  ======='

awk -f $AWKPROG check=$CHECK quiet=$QUIET table=$TABLE conds=$CONDS all=$ALL $INFILE
